This commit is contained in:
2025-05-13 05:18:03 +03:00
parent 0790b782f2
commit 2ca246b75c
1494 changed files with 22057 additions and 0 deletions
+132
View File
@@ -0,0 +1,132 @@
using UnityEngine;
using System.Collections;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class AdvancedGizmo {
public static void DrawCircle(Vector3 center, Vector3 normal, float radius, Color color, int tesselation = 12, bool drawNormal = false, int diagonalCount = 0){
if (tesselation < 3) {
Debug.LogError("Invalid tesselation value! Should be >= 3");
}
Vector3 right = Vector3.right;
if (Mathf.Abs (Vector3.Dot (right, normal)) > 0.999f) {
right = Vector3.up;
}
Vector3 front = Vector3.Cross (right, normal).normalized;
for(int i = 0; i < tesselation; ++i){
//Gizmos.DrawLine(
Debug.DrawLine(
center + Quaternion.AngleAxis((360.0f / (float)tesselation) * (float)(i + 0), normal) * front * radius,
center + Quaternion.AngleAxis((360.0f / (float)tesselation) * (float)(i + 1), normal) * front * radius,
color
);
}
for (int i = 0; i < diagonalCount; ++i) {
float a1 = (180.0f / (float)diagonalCount) * (float)(i);
float a2 = a1 + 180.0f;
Debug.DrawLine(
center + Quaternion.AngleAxis(a1, normal) * front * radius,
center + Quaternion.AngleAxis(a2, normal) * front * radius,
color
);
}
}
public static void DrawGrid(Vector3 center, float width, float height, int wSections = 1, int hSections = 1){
Vector3 topLeft = new Vector3 (-width * 0.5f, 0, height * 0.5f);
Vector3 wStep = new Vector3 (width / (float)wSections, 0, 0);
Vector3 hStep = new Vector3 (0, 0, -height / (float)hSections);
//draw horizontal lines
for (int i = 0; i <= hSections; ++i) {
Vector3 p1 = topLeft + hStep * (float)i + center;
Debug.DrawLine(p1, p1 + new Vector3(width, 0, 0));
}
//draw vertical lines
for (int i = 0; i <= hSections; ++i) {
Vector3 p1 = topLeft + wStep * (float)i + center;
Debug.DrawLine(p1, p1 + new Vector3(0, 0, -height));
}
}
public delegate float fx(float x);
public static void Plot2D(fx func, Matrix4x4 tranfsorm, Vector3 center, Vector3 xAxis, Vector3 yAxis, float xLen, float xScale, float yScale, int sampleCount, Color color){
float xStep = xLen / (float)(sampleCount - 1);
Vector3[] points = new Vector3[sampleCount];
for (int i = 0; i < sampleCount; ++i) {
float x1 = (float)i * xStep;
float arg1 = (x1 / xLen) * xScale;
float y1 = func(arg1) * yScale;
points[i] = center + xAxis * x1 + yAxis * y1;
}
#if UNITY_EDITOR
Color backup = Handles.color;
Handles.matrix = tranfsorm;
Handles.color = color;
Handles.DrawPolyLine(points);
Handles.color = backup;
Handles.matrix = Matrix4x4.identity;
#endif
}
public static void DrawMesh(Vector3[] vertices, int[] indices, bool drawNormals){
for(int i = 0; i < indices.Length; i+=3){
Vector3 v0 = vertices[indices[i + 0]];
Vector3 v1 = vertices[indices[i + 1]];
Vector3 v2 = vertices[indices[i + 2]];
Debug.DrawLine(v0, v1);
Debug.DrawLine(v1, v2);
Debug.DrawLine(v2, v0);
if(drawNormals){
Vector3 center = (v0 + v1 + v2) / 3.0f;
Vector3 normal = Vector3.Cross((v1 - v0), (v2 - v0));
Debug.DrawRay(center, normal);
}
}
}
public static void DrawMesh(Vector3[] vertices, bool drawNormals){
for(int i = 0; i < vertices.Length; i+=3){
Vector3 v0 = vertices[i + 0];
Vector3 v1 = vertices[i + 1];
Vector3 v2 = vertices[i + 2];
Debug.DrawLine(v0, v1);
Debug.DrawLine(v1, v2);
Debug.DrawLine(v2, v0);
if(drawNormals){
Vector3 center = (v0 + v1 + v2) / 3.0f;
Vector3 normal = Vector3.Cross((v1 - v0), (v2 - v0));
Debug.DrawRay(center, normal);
}
}
}
public static void DrawTriangle(Vector3 v0, Vector3 v1, Vector3 v2, bool drawNormal){
Debug.DrawLine(v0, v1);
Debug.DrawLine(v1, v2);
Debug.DrawLine(v2, v0);
if(drawNormal){
Vector3 center = (v0 + v1 + v2) / 3.0f;
Vector3 normal = Vector3.Cross((v1 - v0), (v2 - v0));
Debug.DrawRay(center, normal);
}
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 480c65a322036ac4eb4168494c92edc0
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+125
View File
@@ -0,0 +1,125 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public static class AdvancedMath {
public static float TriangleSquare(Vector3 va, Vector3 vb, Vector3 vc){
float a = Vector3.Distance (va, vb);
float b = Vector3.Distance (vb, vc);
float c = Vector3.Distance (vc, va);
float p = (a + b + c) * 0.5f;
return Mathf.Sqrt (p * (p - a) * (p - b) * (p - c));
}
public static Vector3 PrismCenterOfMass(Vector3 v0, Vector3 v1, Vector3 v2, Vector3 normal, float h0, float h1, float h2){
Vector3 a = v0 + normal * (h0 * 0.5f);
Vector3 c = v1 + normal * (h1 * 0.5f);
Vector3 b = v2 + normal * (h2 * 0.5f);
Vector3 f = (a + b + c) / 3.0f;
return (h0 * ((3.0f * f + a) / 4.0f) + h1 * ((3.0f * f + c) / 4.0f) + h2 * ((3.0f * f + b) / 4.0f)) / (h0 + h1 + h2);
}
public static float CylinderVolume(float r, float h){
return Mathf.PI * (r * r) * h;
}
public static Vector3 TriangleNormal(Vector3 va, Vector3 vb, Vector3 vc){
Vector3 ba = vb - va;
Vector3 ca = vc - va;
return Vector3.Cross(ba, ca).normalized;
}
public static Vector3 LineNearestPoint(Vector3 a, Vector3 b, Vector3 p){
Vector3 n = (b - a).normalized;
Vector3 pa = p - a;
float d = Vector3.Dot (n, pa);
return a + n * d;
}
public static float LineDistance(Vector3 a, Vector3 b, Vector3 p){
Vector3 lp = LineNearestPoint(a, b, p);
return Vector3.Distance (lp, p);
}
public static float Drag(float envDensity, float objVelocity, float dragCoeff, float referenceaArea){
return (envDensity * (objVelocity * objVelocity) * dragCoeff * referenceaArea) * 0.5f;
}
public static float SphereDrag(float envDensity, float objVelocity, float radius){
return Drag (envDensity, objVelocity, 0.47f, Mathf.PI * (radius * radius));
}
public static float BuoyantForce(float objectV, float objectDensity, float envDensity, float g){
return objectV * envDensity * g * ((3.0f * objectDensity) / (envDensity + 2.0f * objectDensity));
}
public static float SphereSegmentVolume(float r, float h){
return (Mathf.PI * (h * h) * (3.0f * r - h)) / 3.0f;
}
public static float SphereVolume(float r){
return (4.0f * Mathf.PI * (r * r * r)) / 3.0f;
}
public static float SphereSurfaceArea(float r){
return 4.0f * Mathf.PI * (r * r);
}
public static float PrismVolume(float baseArea, float h){
return baseArea * h;
}
public static float ConeVolume(float r, float h){
return (Mathf.PI * (r * r) * h) / 3.0f;
}
public static float PyramidVolume(float baseArea, float h){
return (baseArea * h) / 3.0f;
}
public static float RightTriangleArea(float a, float b){
return a * b * 0.5f;
}
public static float MeshVolume(Vector3[] srcVertices, int[] srcIndices, Matrix4x4 tf){
Vector3[] vertices = new Vector3[srcVertices.Length];
vertices[0] = tf.MultiplyPoint3x4(srcVertices[0]);
Vector3 vMin = vertices [0];
Vector3 vMax = vertices [0];
for (int i = 1; i < vertices.Length; ++i) {
vertices[i] = tf.MultiplyPoint3x4(srcVertices[i]);
vMin = Vector3.Min(vMin, vertices[i]);
vMax = Vector3.Max(vMax, vertices[i]);
}
Plane p = new Plane (Vector3.up, vMax + Vector3.up);
//split mesh by plane
List<Vector3> cuttedTriangles = AdvancedUtils.CutMesh (vertices, srcIndices, p);
float totalVolume = 0.0f;
for (int i = 0; i < cuttedTriangles.Count; i+=3) {
Vector3 v0 = cuttedTriangles[i + 0];
Vector3 v1 = cuttedTriangles[i + 1];
Vector3 v2 = cuttedTriangles[i + 2];
Vector3 normal = AdvancedMath.TriangleNormal(v0, v1, v2);
float sign = Mathf.Sign(Vector3.Dot (normal, p.normal));
float h0 = p.GetDistanceToPoint(v0);
float h1 = p.GetDistanceToPoint(v1);
float h2 = p.GetDistanceToPoint(v2);
float avgH = (h0 + h1 + h2) / 3.0f;
Vector3 vp0 = v0 - p.normal * h0;
Vector3 vp1 = v1 - p.normal * h1;
Vector3 vp2 = v2 - p.normal * h2;
float triangleSquare = AdvancedMath.TriangleSquare(vp0, vp1, vp2);
float prismVolume = AdvancedMath.PrismVolume(triangleSquare, avgH) * sign;
totalVolume += prismVolume;
}
return totalVolume;
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 68952730e6f7225499986e6d87ce9874
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+26
View File
@@ -0,0 +1,26 @@
using UnityEngine;
using System.Collections;
public static class AdvancedPhysics {
public class Matter{
public float Density; //kg/m^3
public float MeltingPoint; //*C
public float BoilingPoint; //*C
public float SoundSpeed; //м/с
public float GetMass(float volume){
return Density * volume;
}
public float GetVolume(float mass){
return mass / Density;
}
}
public static class Matters{
public static Matter Water = new Matter{ Density = 999.9720f, MeltingPoint = 0.0f, BoilingPoint = 99.974f, SoundSpeed = 1348.0f };
public static Matter Iron = new Matter{ Density = 7800.0f, MeltingPoint = 1538.85f, BoilingPoint = 2860.85f, SoundSpeed = 5130.0f};
public static Matter AbsPlastic = new Matter{ Density = 1020.0f, MeltingPoint = 105.0f, BoilingPoint = -1, SoundSpeed = -1};
public static Matter Glass = new Matter{ Density = 2500.0f, MeltingPoint = 1500.0f, BoilingPoint = -1, SoundSpeed = -1};
public static Matter Air = new Matter{ Density = 1.25f, MeltingPoint = -1, BoilingPoint = -1, SoundSpeed = -1};
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f39a3b1297b42ac4ab016ee73e53148c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+34
View File
@@ -0,0 +1,34 @@
using UnityEngine;
using System.Collections;
public class AdvancedPhysicsMaterial : MonoBehaviour {
public AdvancedPhysics.Matter matter;
private float mass = 0.0f;
private float volume = 0.0f;
public float Mass{
get{ return mass; }
}
public float Volume{
get{ return volume; }
}
// Use this for initialization
void Start () {
UpdateParameters ();
}
public void UpdateParameters(){
var mf = gameObject.GetComponent<MeshFilter> ();
var m = mf.sharedMesh;
volume = AdvancedMath.MeshVolume (m.vertices, m.triangles, gameObject.transform.localToWorldMatrix);
mass = matter == null ? 0.0f : matter.Density * volume;
if (rigidbody != null) {
rigidbody.mass = mass;
}
}
// Update is called once per frame
void Update () {
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4fbb75b1008dd564abee5aa5ff00b231
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+211
View File
@@ -0,0 +1,211 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
public static class AdvancedUtils {
public static GameObject CreateMeshObject(string name){
GameObject result = new GameObject(name);
MeshFilter meshFilter = (MeshFilter)result.AddComponent(typeof(MeshFilter));
result.AddComponent(typeof(MeshRenderer));
Mesh m = new Mesh();
m.name = result.name;
meshFilter.sharedMesh = m;
return result;
}
public static GameObject CreateMeshObject(){
return CreateMeshObject ("Unnamed object");
}
public static void GenerateCylinder(float radius, float length, int sides, int heightSegments,float uTile, float vTile, out Vector3[] vertices, out int[] indices, out Vector2[] uvs, out Vector3[] normals){
float yBottom = 0.0f;
Vector3 up = Vector3.up;
int ringVertexCount = (sides + 1);
int ringCount = heightSegments + 1;
int vertexCount = ringCount * ringVertexCount;
vertices = new Vector3[vertexCount];
uvs = new Vector2[vertices.Length];
normals = new Vector3[vertices.Length];
//generate vertices
for (int i = 0; i < ringVertexCount; ++i) {
float angle = ((Mathf.PI * 2.0f) / (float)sides) * (float)(i);
normals[i] = new Vector3(Mathf.Cos(angle), 0.0f, Mathf.Sin(angle));
vertices[i] = new Vector3(normals[i].x * radius, yBottom, normals[i].z * radius);
uvs[i] = new Vector2(((1.0f / (float)sides) * (float)i) * uTile, vTile);
}
for (int i = 1; i < ringCount; ++i) {
float ringY = (length / (float)heightSegments) * (float)i;
int ringVertexOffset = ringVertexCount * i;
for (int j = 0; j < ringVertexCount; ++j) {
vertices[ringVertexOffset + j] = vertices[j];
vertices[ringVertexOffset + j].y = ringY;
uvs[ringVertexOffset + j] = new Vector2(uvs[j].x, (1.0f - ((1.0f / (float)heightSegments) * (float)i)) * vTile);
normals[ringVertexOffset + j] = normals[j];
}
}
//generate indices
int triangleCount = (2 * sides) * heightSegments;
indices = new int[triangleCount * 3];
int idOffset = 0;
for (int i = 0; i < heightSegments; ++i) {
int segmentVertexOffset = i * ringVertexCount;
int nextSegmentVertexOffset = (i + 1) * ringVertexCount;
for (int j = 0; j < sides; ++j) {
int sideOffset = segmentVertexOffset + j;
indices[idOffset + 0] = segmentVertexOffset + j;
indices[idOffset + 2] = nextSegmentVertexOffset + j + 1;
indices[idOffset + 1] = nextSegmentVertexOffset + j;
indices[idOffset + 3] = segmentVertexOffset + j;
indices[idOffset + 5] = segmentVertexOffset + j + 1;
indices[idOffset + 4] = nextSegmentVertexOffset + j + 1;
idOffset+=6;
}
}
}
public static int[] cubeIndices = new int[]{
3,2,7,
7,2,6,
1,0,5,
0,4,5,
0,1,2,
0,2,3,
4,6,5,
4,7,6,
0,3,4,
3,7,4,
2,1,6,
1,5,6
};
public static Vector3[] cubeVertices = new[]{
new Vector3(-0.5f, 0.5f, -0.5f),
new Vector3(-0.5f, 0.5f, 0.5f),
new Vector3(0.5f, 0.5f, 0.5f),
new Vector3(0.5f, 0.5f, -0.5f),
new Vector3(-0.5f, -0.5f, -0.5f),
new Vector3(-0.5f, -0.5f, 0.5f),
new Vector3(0.5f, -0.5f, 0.5f),
new Vector3(0.5f, -0.5f, -0.5f),
};
public static void CreateMeshCube(Matrix4x4 matrix, out Vector3[] vertices, out int[] indices){
indices = new int[cubeIndices.Length];
Array.Copy (cubeIndices, indices, cubeIndices.Length);
int vertexCount = cubeVertices.Length;
vertices = new Vector3[vertexCount];
for (int i = 0; i < vertexCount; ++i) {
vertices[i] = matrix.MultiplyPoint3x4(cubeVertices[i]);
}
}
public static GameObject FindChild(GameObject parent, string childName){
if (parent == null) {
return null;
}
var tf = parent.transform.FindChild (childName);
return tf == null ? null : tf.gameObject;
}
public static List<Vector3> CutMesh(Vector3[] vertices, int[] indices, Plane p){
List<Vector3> cuttedTriangles = new List<Vector3> ();
int cut = 0;
int notCut = 0;
bool[] sideFlags = new bool[3];
for (int i = 0; i < indices.Length; i+=3) {
int outside = 0;
int lastOutsideId = 0;
int lastInsideId = 0;
for(int j = 0; j < 3; ++j){
sideFlags[j] = p.GetSide(vertices[indices[i + j]]);
if(sideFlags[j]){
outside++;
lastOutsideId = j;
}else{
lastInsideId = j;
}
}
if( outside ==3){
notCut++;
}else{
cut++;
}
switch(outside)
{
case 0:
for(int j = 0; j < 3; ++j){
cuttedTriangles.Add(vertices[indices[i + j]]);
}
break;
case 1:
{
Vector3 v0 = vertices[indices[i + lastOutsideId]];
Vector3 v1 = vertices[indices[i + (lastOutsideId + 1) % 3]];
Vector3 v2 = vertices[indices[i + (lastOutsideId + 2) % 3]];
float d0 = p.GetDistanceToPoint(v0);
float d1 = p.GetDistanceToPoint(v1);
float d2 = p.GetDistanceToPoint(v2);
float a = d0 / (d0 - d1);
float b = d0 / (d0 - d2);
Vector3 v3 = v0 + (v1 - v0) * a;
Vector3 v4 = v0 + (v2 - v0) * b;
cuttedTriangles.Add(v2);
cuttedTriangles.Add(v4);
cuttedTriangles.Add(v3);
cuttedTriangles.Add(v2);
cuttedTriangles.Add(v3);
cuttedTriangles.Add(v1);
}
break;
case 2:
{
Vector3 v0 = vertices[indices[i + lastInsideId]];
Vector3 v1 = vertices[indices[i + (lastInsideId + 1) % 3]];
Vector3 v2 = vertices[indices[i + (lastInsideId + 2) % 3]];
float d0 = p.GetDistanceToPoint(v0);
float d1 = p.GetDistanceToPoint(v1);
float d2 = p.GetDistanceToPoint(v2);
float a = d0 / (d0 - d1);
float b = d0 / (d0 - d2);
Vector3 v3 = v0 + (v1 - v0) * a;
Vector3 v4 = v0 + (v2 - v0) * b;
cuttedTriangles.Add(v0);
cuttedTriangles.Add(v3);
cuttedTriangles.Add(v4);
}
break;
}
}
return cuttedTriangles;
}
/**/
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2f5e26ce0ca3f1f4985b0c2edf827480
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+5
View File
@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: abb65c03b97f2834bb66ca1479965c49
folderAsset: yes
DefaultImporter:
userData:
+17
View File
@@ -0,0 +1,17 @@
using UnityEngine;
using System.Collections;
public class AxisRotation : MonoBehaviour {
public Vector3 axis = Vector3.up;
public float angle = 1.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.Rotate (axis, angle * Time.deltaTime);
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c33a13f9a7e8b5e4fa932faf314cf697
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+87
View File
@@ -0,0 +1,87 @@
using UnityEngine;
using System.Collections;
public class BallController : MonoBehaviour {
public Joystick joy;
public float acceleration = 1.0f;
public Camera cam;
public float maxAngularVelocity = 7;
public CheckpointManager manager;
public AudioClip floorContactSound;
public AudioClip rollingSound;
private AudioSource contactSource;
private AudioSource rollingSource;
// Use this for initialization
void Start () {
rigidbody.maxAngularVelocity = maxAngularVelocity;
contactSource = gameObject.AddComponent<AudioSource> ();
rollingSource = gameObject.AddComponent<AudioSource> ();
rollingSource.loop = true;
rollingSource.clip = rollingSound;
contactSource.volume = 0.4f;
}
// Update is called once per frame
void Update () {
//Debug.Log(rigidbody.angularVelocity);
if (joy != null && rigidbody != null) {
float angle = Mathf.Rad2Deg * joy.Angle;
var forward = cam.transform.right;
forward.y = 0;
forward.Normalize();
Quaternion rotation = Quaternion.AngleAxis (angle, Vector3.up);
Vector3 speedVector = (rotation * forward);
speedVector = speedVector.normalized * (joy.Value * acceleration);
rigidbody.angularVelocity += Time.deltaTime * speedVector;
}
float minAng = 0.0f;
float maxAng = 3.0f;
rollingSource.volume = (Mathf.Clamp (rigidbody.angularVelocity.magnitude, minAng, maxAng) / (maxAng - minAng)) * 3.0f;
bool grounded = false;
RaycastHit hit;
if (Physics.Raycast (this.transform.position - Vector3.up * collider.bounds.extents.y * 0.9f, -Vector3.up, out hit)) {
if (hit.distance < 0.1f) {
grounded = true;
}
}
if (rigidbody.angularVelocity.magnitude <= minAng || !grounded) {
if(rollingSource.isPlaying){
rollingSource.Stop ();
}
} else {
if(!rollingSource.isPlaying && grounded){
rollingSource.Play();
}
}
}
void OnKill(GameObject killer){
manager.OnPlayerKilled ();
}
void OnCollisionEnter(Collision collision) {
//foreach (ContactPoint contact in collision.contacts) {
// Debug.DrawRay(contact.point, contact.normal, Color.white);
//}
float maxMagnitude = 40.0f;
float minMagnitude = 4.0f;
audio.volume = Mathf.Clamp (collision.relativeVelocity.magnitude, minMagnitude, maxMagnitude) / (maxMagnitude - minMagnitude);
if (collision.relativeVelocity.magnitude > minMagnitude)
contactSource.PlayOneShot (floorContactSound);
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 575fc1e363d8a9143ac73f71ce64b9a5
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+5
View File
@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 6593b62cf90e02b4dbe58d53eed1fcf2
folderAsset: yes
DefaultImporter:
userData:
+128
View File
@@ -0,0 +1,128 @@
using UnityEngine;
using System.Collections;
public delegate void ButtonDelegate(Button sender);
[ExecuteInEditMode]
public class Button : MonoBehaviour {
public Texture2D image;
public Texture2D mask;
public Vector2 size;
public Material mat;
public Color baseColor;
private bool pressed;
private Rect buttonRect;
public event ButtonDelegate EventDown;
public event ButtonDelegate EventUp;
public event ButtonDelegate EventClick;
private int fingerId = -1;
private void OnDown(){
if (EventDown != null) {
EventDown(this);
}
}
private void OnUp(){
if (EventUp != null) {
EventUp(this);
}
}
private void OnClick(){
if (EventClick != null) {
EventClick(this);
}
}
public bool Pressed{
get{return pressed; }
}
// Use this for initialization
void Start () {
EventClick += new ButtonDelegate (clickDelegate);
}
void clickDelegate(Button sender){
}
bool PointInButton(Vector2 point){
return buttonRect.Contains(point);
}
// Update is called once per frame
void Update () {
buttonRect = new Rect (
transform.position.x - size.x / 2,
transform.position.y - size.y / 2,
size.x, size.y);
if (pressed) {
Vector2 releasePoint = Vector2.zero;
if (IsReleased (ref releasePoint)) {
if (PointInButton (releasePoint)) {
OnUp ();
OnClick ();
}
pressed = false;
}
} else {
if(IsPressing()){
pressed = true;
OnDown();
}
}
}
bool IsReleased(ref Vector2 point){
#if !UNITY_WP8 || UNITY_EDITOR
point = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
return Input.GetKeyUp (KeyCode.Mouse0);
#else
foreach (var t in Input.touches) {
if(t.fingerId == fingerId){
if((t.phase == TouchPhase.Canceled) || (t.phase == TouchPhase.Ended)){
point = new Vector2(t.position.x, Screen.height - t.position.y);
return true;
}else{
return false;
}
}
}
point = new Vector2(-1, -1);
return true;
#endif
}
bool IsPressing(){
#if !UNITY_WP8 || UNITY_EDITOR
if (Input.GetKeyDown (KeyCode.Mouse0)) {
Vector2 position = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
return buttonRect.Contains(position);
}
#else
foreach(var t in Input.touches){
Vector2 position = new Vector2(t.position.x, Screen.height - t.position.y);
if(buttonRect.Contains(position)){
fingerId = t.fingerId;
return true;
}
}
#endif
return false;
}
void OnGUI(){
if (Event.current.type == EventType.Repaint) {
mat.SetColor("_TintColor", baseColor);
Graphics.DrawTexture (buttonRect, image, mat);
}
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 211348e431c09f84b871736f3b207907
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+5
View File
@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: ed8f43320b73cc04fbd908b6c9894649
folderAsset: yes
DefaultImporter:
userData:
+34
View File
@@ -0,0 +1,34 @@
using UnityEngine;
using System.Collections;
public class Button1 : MonoBehaviour, Predicate {
private Vector3 startPosition;
public float logicLevel = 0.05f;
private bool pressed = false;
public bool Automatic = true;
void Start () {
startPosition = transform.position;
}
public bool Pressed{
get{return pressed;}
set{pressed = value;}
}
public bool State(){
return pressed;
}
void Update () {
}
void FixedUpdate(){
if (Automatic) {
pressed = Vector3.Distance(startPosition, transform.position) > logicLevel;
}
//Debug.Log ("Is pressed = " + pressed);
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f65a16dc29c523f4392f3209f3579550
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+15
View File
@@ -0,0 +1,15 @@
using UnityEngine;
using System.Collections;
public class CameraController : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 13103f0a071f5fd46be7d954fed87eb9
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+23
View File
@@ -0,0 +1,23 @@
using UnityEngine;
using System.Collections;
public class Checkpoint : MonoBehaviour {
public bool isChecked = false;
public bool checkOnce = true;
public CheckpointManager manager;
void OnTriggerEnter (Collider other) {
if (checkOnce && isChecked) {
return;
}
isChecked = true;
BallController ball = other.GetComponent<BallController> ();
if (ball != null && manager != null) {
manager.OnCheckPoint(this);
}
}
void OnDrawGizmos(){
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fc1035950a6bc6840bc69e80aa2e6438
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+57
View File
@@ -0,0 +1,57 @@
using UnityEngine;
using System.Collections;
public class CheckpointManager : MonoBehaviour {
public Checkpoint levelStart;
public GameObject player;
private Checkpoint lastCheckPoint;
private GameObject playerInstance;
public Camera playerCamera;
public AudioClip respawnSound;
private GameManager gameManager;
void Start () {
gameManager = GameObject.FindObjectOfType<GameManager> ();
lastCheckPoint = levelStart;
RespawnPlayer ();
}
void Update () {
}
public void OnCheckPoint(Checkpoint cp){
Debug.Log ("Enter check point: " + cp.name);
lastCheckPoint = cp;
}
public void OnPlayerKilled(){
RespawnPlayer ();
}
void RespawnPlayer(){
if (levelStart == null) {
Debug.LogError("Level entry point is not set!");
return;
}
if (player == null) {
Debug.LogError("Player respawn prototype is not set!");
return;
}
if (playerInstance != null) {
Destroy(playerInstance);
}
if (gameManager != null) {
gameManager.audio.volume = 2;
gameManager.audio.PlayOneShot (respawnSound);
}
playerInstance = (GameObject)Instantiate (player);
playerInstance.transform.position = lastCheckPoint.transform.position;
playerInstance.transform.rotation = lastCheckPoint.transform.rotation;
playerInstance.SetActive (true);
playerCamera.GetComponent<FollowCamera> ().target = playerInstance;
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5c2b416a603886e4091f596b3f4a5c39
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+5
View File
@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 2254506bcec8af7409f457dcc5b794de
folderAsset: yes
DefaultImporter:
userData:
@@ -0,0 +1,26 @@
using UnityEngine;
using System.Collections;
public class DiaphragmOpenButtonController : MonoBehaviour {
public Button1 openPredicate;
private float gateDirection = 1.0f;
public float gateSpeed = 1.0f;
private float gateState = 1.0f;
public Diaphragm target;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (openPredicate != null) {
gateDirection = openPredicate.State() ? -1.0f : 1.0f;
}
gateState = Mathf.Clamp01 (gateState + Time.deltaTime * gateSpeed * gateDirection);
if (target != null) {
target.State = gateState;
}
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fd816b8e4bc739843b0d9b8a34e5acd0
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
@@ -0,0 +1,15 @@
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 41162134139c77b4589696dbeded175a
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+6
View File
@@ -0,0 +1,6 @@
using UnityEngine;
using System.Collections;
public interface Predicate{
bool State();
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: dc300e6f2bc85ed4daddeb88b253ed3e
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+75
View File
@@ -0,0 +1,75 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CubeSlice : MonoBehaviour {
public Mesh testMesh;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnDrawGizmos(){
if (testMesh == null) {
return;
}
float totalVolume = AdvancedMath.MeshVolume (testMesh.vertices, testMesh.triangles, transform.localToWorldMatrix);
Debug.Log ("Underwater volume = " + totalVolume);
Debug.Log ("Expected volume = " + AdvancedMath.CylinderVolume(0.5f, 1.0f));
//List<Vector3> prismTriangles = new List<Vector3> ();
/*for (int i = 0; i < 1; ++i) {
Vector3 v0 = new Vector3(0,-1,0);
Vector3 v1 = new Vector3(1,-1,0);
Vector3 v2 = new Vector3(0.5f,-5,1);
Vector3 normal = AdvancedMath.TriangleNormal(v0, v1, v2);
float sign = Mathf.Sign(Vector3.Dot (normal, p.normal));
float h0 = p.GetDistanceToPoint(v0);
float h1 = p.GetDistanceToPoint(v1);
float h2 = p.GetDistanceToPoint(v2);
float avgH = (h0 + h1 + h2) / 3.0f;
Vector3 vp0 = v0 - p.normal * h0;
Vector3 vp1 = v1 - p.normal * h1;
Vector3 vp2 = v2 - p.normal * h2;
float triangleSquare = AdvancedMath.TriangleSquare(vp0, vp1, vp2);
float prismVolume = AdvancedMath.PrismVolume(triangleSquare, avgH) * sign;
totalVolume += prismVolume;
Vector3 com = AdvancedMath.PrismCenterOfMass(vp0, vp1, vp2, p.normal, h0, h1, h2);
AdvancedGizmo.DrawTriangle(v0, v1, v2, true);
AdvancedGizmo.DrawTriangle(vp0, vp1, vp2, true);
Debug.DrawLine(v0, vp0);
Debug.DrawLine(v1, vp1);
Debug.DrawLine(v2, vp2);
Gizmos.DrawSphere(new Vector3(com.x, com.y, com.z), 0.05f);
}*/
//Debug.Log ("Cut: " + cut);
//Debug.Log ("Not cut: " + notCut);
//AdvancedGizmo.DrawMesh (cuttedTriangles.ToArray (), true);
//AdvancedGizmo.DrawMesh (vertices, indices, false);
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 052d000a09b586b4ba4d26cb5579225b
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+5
View File
@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: dbdfdcd07baf5174cb4e375084467a31
folderAsset: yes
DefaultImporter:
userData:
@@ -0,0 +1,41 @@
using UnityEngine;
using System.Collections;
public class PlatformChemistry : MonoBehaviour {
public Material normalStateMaterial;
public Material enterStateMaterial;
private GameManager gameManager;
// Use this for initialization
void Start () {
gameManager = GameObject.FindObjectOfType<GameManager> ();
renderer.sharedMaterial = normalStateMaterial;
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other){
var c = other.gameObject.GetComponent<BallController> ();
if (c != null) {
renderer.sharedMaterial = enterStateMaterial;
if(gameManager != null){
gameManager.ActivateChemistry();
}
}
}
void OnTriggerExit(Collider other){
var c = other.gameObject.GetComponent<BallController> ();
if (c != null) {
renderer.sharedMaterial = normalStateMaterial;
if(gameManager != null){
gameManager.DeactivateChemistry();
}
}
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: be155548e54c4314284cb291d2f25159
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+19
View File
@@ -0,0 +1,19 @@
using UnityEngine;
using System.Collections;
public class DoNotDestroyOnLoad : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void Awake () {
DontDestroyOnLoad (transform.gameObject);
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3e26b466c5bdbdc4982ec7f8326f127c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+17
View File
@@ -0,0 +1,17 @@
using UnityEngine;
using System.Collections;
public class Escape : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.Escape)) {
Application.Quit();
}
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 64a398747564dfa44bada8627de0abd3
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+50
View File
@@ -0,0 +1,50 @@
using UnityEngine;
using System.Collections;
public class FollowCamera : MonoBehaviour {
public GameObject target;
public float minOffset = 0.5f;
public float maxOffset = 2.5f;
public float zenith;
public float azimuth;
public float mouseSpeed = 0.1f;
private float offset;
[Range (-(Mathf.PI * 0.5f), Mathf.PI * 0.5f)]
public float minZenith = -(Mathf.PI * 0.5f);
[Range (-(Mathf.PI * 0.5f), Mathf.PI * 0.5f)]
public float maxZenith = Mathf.PI * 0.5f;
/*[Range (-(Mathf.PI * 0.5f), Mathf.PI * 0.5f)]
public float minAzimuth = -(Mathf.PI * 0.5f);
[Range (-(Mathf.PI * 0.5f), Mathf.PI * 0.5f)]
public float maxAzimuth = Mathf.PI * 0.5f;*/
public bool mouseInput = true;
private SphericalCoordinate direction = new SphericalCoordinate();
void Start () {
offset = minOffset;
}
void Update () {
if (target != null && camera != null) {
offset = Mathf.Clamp(offset, minOffset, maxOffset);
if(mouseInput){
zenith += Input.GetAxis ("Mouse Y") * mouseSpeed;
azimuth -= Input.GetAxis ("Mouse X") * mouseSpeed;
}
zenith = Mathf.Clamp(zenith, minZenith, maxZenith);
direction.ElevationAngle = zenith;
direction.PolarAngle = azimuth;
camera.transform.position = target.transform.position + direction.Cartesian * offset;
camera.transform.LookAt (target.transform);
}
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9d73c026810919f48bd52e40e486ccc4
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+19
View File
@@ -0,0 +1,19 @@
using UnityEngine;
using System.Collections;
public class FpsView : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI(){
GUI.Label (new Rect(10, 10, 100, 100), "FPS: " + (1.0f / Time.deltaTime).ToString());
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f337a131f0607c44ead6628e202e5b43
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+91
View File
@@ -0,0 +1,91 @@
using UnityEngine;
using System.Collections;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System.Text;
public class GameManager : MonoBehaviour {
private const string saveFileName = "save.xml";
private MenuManager menuManager;
private int chemistryUsers = 0;
public class GameState{
public int gameFinishCount;
public int currentLevel;
public float Volume;
}
private GameState state = new GameState();
public GameState State{
get{return state; }
}
string GetSaveFilePath(){
return Application.persistentDataPath + "/" + saveFileName;
}
// Use this for initialization
void Start () {
var src = gameObject.AddComponent<AudioSource> ();
src.volume = 1.0f;
menuManager = GameObject.FindObjectOfType<MenuManager> ();
LoadState ();
}
public void ActivateChemistry(){
chemistryUsers++;
}
public void DeactivateChemistry(){
chemistryUsers--;
}
// Update is called once per frame
void Update () {
//Debug.Log (Time.timeScale);
}
public void NewGame(){
menuManager.ActivateMenu ("");
Application.LoadLevel ("Level0");
}
public void MainMenu(){
SaveState ();
menuManager.ActivateMenu ("");
Application.LoadLevel("StartScene");
}
public void SaveState(){
Debug.Log ("Saving game state!");
XmlSerializer serializer = new XmlSerializer (typeof(GameState));
FileStream fs = new FileStream (GetSaveFilePath(), FileMode.Create);
TextWriter writer = new StreamWriter(fs, new UTF8Encoding());
serializer.Serialize(writer, state);
writer.Close();
}
public void LoadState(){
Debug.Log ("Loading game state!");
if (File.Exists (GetSaveFilePath ())) {
XmlSerializer serializer = new XmlSerializer (typeof(GameState));
FileStream fs = new FileStream (GetSaveFilePath(), FileMode.Open);
TextReader reader = new StreamReader(fs, new UTF8Encoding());
state = (GameState)serializer.Deserialize(reader);
reader.Close();
}
}
public void LoadLevel(int id){
}
/*void OnGUI(){
if (chemistryUsers > 0) {
GUI.Button(new Rect(200,200,100,100), "Chemistry activated");
}
}*/
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9ee89f0e2d1ded44d88c10b678037270
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+5
View File
@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 724685afb2f472146b9e1a94449af0c3
folderAsset: yes
DefaultImporter:
userData:
+161
View File
@@ -0,0 +1,161 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
[Serializable]
public class GravityRayConfig{
public float radius = 0.5f;
public float length = 5.0f;
public float tileLength = 3.0f;
public static bool operator==(GravityRayConfig c1, GravityRayConfig c2){
return c1.radius == c2.radius && c1.length == c2.length && c1.tileLength == c2.tileLength;
}
public static bool operator!=(GravityRayConfig c1, GravityRayConfig c2){
return c1.radius != c2.radius || c1.length != c2.length || c1.tileLength != c2.tileLength;
}
public void AssignFrom(GravityRayConfig other){
radius = other.radius;
length = other.length;
tileLength = other.tileLength;
}
}
[ExecuteInEditMode]
public class GravityRayBody : MonoBehaviour {
public GravityRayConfig config;
private GravityRayConfig lastConfig = new GravityRayConfig();
private const string rayObjectName = "Beam";
public Material beamMaterial;
GameObject ray = null;
List<GameObject> capturedObjects = new List<GameObject>();
public float centeringForce = 0.5f;
public float dragForce = 0.5f;
// Use this for initialization
void Start () {
RebuildRay ();
lastConfig = config;
}
void RebuildRay(){
lastConfig.AssignFrom (config);
if (ray == null) {
ray = AdvancedUtils.FindChild(gameObject, rayObjectName);
}
if (ray == null) {
ray = AdvancedUtils.CreateMeshObject(rayObjectName);
ray.transform.parent = transform;
ray.transform.localPosition = Vector3.zero;
ray.transform.localRotation = Quaternion.identity;
ray.transform.localScale = Vector3.one;
}
CapsuleCollider c = gameObject.GetComponent<CapsuleCollider> ();
if (c == null) {
c = gameObject.AddComponent<CapsuleCollider>();
}
c.center = new Vector3 (0, config.length * 0.5f, 0);
c.radius = config.radius;
c.height = config.length;
c.direction = 1;
c.isTrigger = true;
var mf = ray.GetComponent<MeshFilter> ();
var m = mf.sharedMesh;
Vector3[] vertices;
Vector3[] normals;
int[] indices;
Vector2[] uvs;
AdvancedUtils.GenerateCylinder (config.radius, config.length, 33, 1,2, config.length / config.tileLength, out vertices, out indices, out uvs, out normals);
m.vertices = vertices;
m.SetIndices (indices, MeshTopology.Triangles, 0);
m.normals = normals;
m.uv = uvs;
m.RecalculateBounds ();
ray.renderer.sharedMaterial = beamMaterial;
}
// Update is called once per frame
void FixedUpdate () {
if (ray != null) {
ray.transform.Rotate (Vector3.up, Time.deltaTime * -90.0f);
}
if(lastConfig != config){
RebuildRay();
}
foreach (var obj in capturedObjects) {
Vector3 a;
Vector3 b;
GetCylinderPoints(out a, out b);
Vector3 n = (b - a).normalized;
Vector3 p = AdvancedMath.LineNearestPoint(a, b, obj.transform.position);
Vector3 centeringDir = (p - obj.transform.position).normalized;
//Debug.Log(centeringDir);
obj.rigidbody.velocity += centeringDir * centeringForce * Time.deltaTime;
float forwardSpeed = Vector3.Dot(n, obj.rigidbody.velocity);
float diff = dragForce - forwardSpeed;
obj.rigidbody.velocity += n * dragForce * Time.deltaTime * 0.9f * diff;
//obj.rigidbody.velocity =obj.rigidbody.velocity * 0.9f * Time.deltaTime + centeringDir * centeringForce * Time.deltaTime + n * dragForce * Time.deltaTime;
}
}
void GetCylinderPoints(out Vector3 a, out Vector3 b){
a = ray.transform.position;
b = ray.transform.position + ray.transform.up * config.length;
}
void OnTriggerEnter(Collider other){
if (other.rigidbody!= null && !other.rigidbody.isKinematic && !capturedObjects.Contains (other.gameObject)) {
capturedObjects.Add(other.gameObject);
other.rigidbody.useGravity = false;
other.rigidbody.velocity = Vector3.zero;
Debug.Log("Beam captured object: " + other.name);
}
}
void OnTriggerExit(Collider other){
if (capturedObjects.Contains (other.gameObject)) {
capturedObjects.Remove(other.gameObject);
other.rigidbody.useGravity = true;
Debug.Log("Beam lost object: " + other.name);
}
}
void OnDrawGizmos(){
if(lastConfig != config){
RebuildRay();
}
if(ray != null){
Vector3 a;
Vector3 b;
GetCylinderPoints(out a, out b);
Gizmos.DrawWireSphere(a, 0.2f);
Gizmos.DrawWireSphere(b, 0.2f);
}
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f4e90769116ed1342be1bfb352f78fd2
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+198
View File
@@ -0,0 +1,198 @@
using UnityEngine;
using System.Collections;
using System;
[Serializable]
public class ScreenSpacePosition{
public bool Relative;
public Vector2 Position;
public Vector2 PixelPosition{
get{
if(Relative){
return new Vector2(Position.x * Screen.width, Position.y * Screen.height);
}else{
return Position;
}
}
}
}
[ExecuteInEditMode]
public class Joystick : MonoBehaviour {
public bool Relative = false;
public float BaseJoystickRadius;
public float StickRadius;
public Texture2D circleImage;
private Rect baseRect;
private Rect stickRect;
private Vector2 basePosition;
private bool pressed = false;
private Vector2 pressPosition;
private Vector2 stickOffset;
private Vector2 stickPosition;
public Material Mat;
public Color BaseColor;
public Color StickColor;
private int fingerId = -1;
private float angle;
public ScreenSpacePosition ScreenPosition;
// Use this for initialization
void Start () {
}
public float Angle{
get{
return angle;
}
}
public bool Pressed{
get{
return pressed;
}
}
public float Value{
get{
return pressed ? Mathf.Clamp01(stickOffset.magnitude / BaseJoystickRadius) : 0;
}
}
public float ValueX{
get{
return pressed ? Mathf.Clamp((stickPosition.x - basePosition.x) / BaseJoystickRadius, -1, 1) : 0;
}
}
public float ValueY{
get{
return pressed ? Mathf.Clamp((stickPosition.y - basePosition.y) / BaseJoystickRadius, -1, 1) : 0;
}
}
public Vector2 Direction{
get{
return pressed ? stickOffset.normalized : Vector2.zero;
}
}
bool InsideDefaultStick(Vector2 position){
Vector2 diff = position - basePosition;
return diff.magnitude <= StickRadius;
}
bool GetPressPosition(ref Vector2 position){
#if !UNITY_WP8 || UNITY_EDITOR
if (Input.GetKeyDown (KeyCode.Mouse0)) {
position = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
return InsideDefaultStick(position);
}
return false;
#else
for (var i = 0; i < Input.touchCount; ++i) {
var tap = Input.GetTouch(i);
if(tap.phase == TouchPhase.Began){
position = new Vector2(tap.position.x, Screen.height - tap.position.y);
if(InsideDefaultStick(position)){
fingerId = tap.fingerId;
return true;
}
}
}
return false;
#endif
}
bool FindTouch(int finger, ref Touch t){
foreach (var touch in Input.touches) {
if(touch.fingerId == finger){
t = touch;
return true;
}
}
return false;
}
bool Released(){
#if !UNITY_WP8 || UNITY_EDITOR
return Input.GetKeyUp (KeyCode.Mouse0);
#else
Touch t = new Touch();
if(!FindTouch(fingerId, ref t)){
return true;
}
return (t.phase == TouchPhase.Ended) || (t.phase == TouchPhase.Canceled);
#endif
}
Vector2 GetMovePosition(){
#if !UNITY_WP8 || UNITY_EDITOR
return new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
#else
Touch t = new Touch();
FindTouch(fingerId, ref t);
return new Vector2(t.position.x, Screen.height - t.position.y);
#endif
}
// Update is called once per frame
void Update () {
basePosition = ScreenPosition.PixelPosition;
stickPosition = basePosition;
baseRect = new Rect (
basePosition.x - BaseJoystickRadius,
basePosition.y - BaseJoystickRadius,
BaseJoystickRadius * 2.0f,
BaseJoystickRadius * 2.0f);
if (!pressed) {
if (GetPressPosition(ref pressPosition)) {
pressed = true;
}
} else {
if (Released()) {
pressed = false;
stickOffset = Vector2.zero;
angle = 0;
}else{
Vector2 touchPosition = GetMovePosition();
stickOffset = touchPosition - pressPosition;
if (stickOffset.magnitude > BaseJoystickRadius) {
stickPosition = basePosition + stickOffset.normalized * BaseJoystickRadius;
} else {
stickPosition = basePosition + stickOffset;
}
Vector2 joyDir = Direction;
angle = Mathf.Atan2(joyDir.x, joyDir.y);
angle = (Mathf.PI - Mathf.Abs(angle)) * Mathf.Sign(angle);
}
}
stickRect = new Rect (
stickPosition.x - StickRadius,
stickPosition.y - StickRadius,
StickRadius * 2.0f,
StickRadius * 2.0f);
}
void OnGUI(){
//GUI.DrawTexture (stickRect, circleImage);
if (Event.current.type == EventType.Repaint) {
Mat.SetColor("_TintColor", BaseColor);
Graphics.DrawTexture (baseRect, circleImage, Mat);
Mat.SetColor("_TintColor", StickColor);
Graphics.DrawTexture (stickRect, circleImage, Mat);
}
GUI.Label(new Rect (
baseRect.x,
baseRect.y - 40,
baseRect.width ,
20), (ValueY).ToString("##.###"));
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f84271a8c0fd77c43ad3cf946476e80c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+12
View File
@@ -0,0 +1,12 @@
using UnityEngine;
using System.Collections;
public class Killer : MonoBehaviour {
void OnTriggerEnter (Collider other) {
Debug.Log ("Killing object: " + other.name);
other.gameObject.SendMessage ("OnKill", gameObject);
//Destroy(other.gameObject);
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7745c109e0c6e8c4b80fbfd01d1b92cc
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+55
View File
@@ -0,0 +1,55 @@
using UnityEngine;
using System.Collections;
public class LMath {
public static float frac(float value){
return value - (float)Mathf.FloorToInt(value);
}
}
public class SphericalCoordinate
{
private float polar;
private float elevation;
private Vector3 cartesian;
public float PolarAngle{
get{ return polar; }
set{ polar = value; UpdateCartesian(); }
}
public float ElevationAngle{
get{ return elevation; }
set{ elevation = value; UpdateCartesian(); }
}
public Vector3 Cartesian{
get{ return cartesian; }
set { UpdateSpherical(value); }
}
public SphericalCoordinate(){
UpdateCartesian();
}
private void UpdateCartesian(){
float a = Mathf.Cos(elevation);
cartesian.x = a * Mathf.Cos(polar);
cartesian.y = Mathf.Sin(elevation);
cartesian.z = a * Mathf.Sin(polar);
}
private void UpdateSpherical(Vector3 cartesianCoord){
if (cartesianCoord.x == 0.0f)
cartesianCoord.x = Mathf.Epsilon;
float radius = Mathf.Sqrt((cartesianCoord.x * cartesianCoord.x)
+ (cartesianCoord.y * cartesianCoord.y)
+ (cartesianCoord.z * cartesianCoord.z));
polar = Mathf.Atan(cartesianCoord.z / cartesianCoord.x);
if (cartesianCoord.x < 0.0f)
polar += Mathf.PI;
elevation = Mathf.Asin(cartesianCoord.y / radius);
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 680877b2ff3dc8241bfe8e6972eb3768
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+5
View File
@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 13767c468a2c0fc42a32dbb406afd5f7
folderAsset: yes
DefaultImporter:
userData:
+41
View File
@@ -0,0 +1,41 @@
using UnityEngine;
using System.Collections;
public class AuthorsMenu : MenuLayer {
public override string Name { get {return "AuthorsMenu"; } }
public override void Draw(){
float w = (float)Screen.width;
float h = (float)Screen.height;
float boxWidth = 300;
float boxHeight = 200;
float boxOffsetX = (w - boxWidth) * 0.5f;
float boxOffsetY = (h - boxHeight) * 0.5f;
Rect boxRect = new Rect (boxOffsetX, boxOffsetY, boxWidth, boxHeight);
GUI.Box (boxRect, "");
float buttonHeight = 50;
float buttonWidth = 150;
float buttonMargin = 10;
GUI.Label (new Rect (boxRect.center.x - buttonWidth * 0.5f,
(boxRect.yMax - (buttonHeight + buttonMargin) * 2), buttonWidth, buttonHeight), "L-proger");
if (GUI.Button (new Rect (boxRect.center.x - buttonWidth * 0.5f,
(boxRect.yMax - buttonHeight - buttonMargin), buttonWidth, buttonHeight), "Назад")) {
manager.ActivatePreviousMenu();
}
}
public override void Enter(){
}
public override void Leave(){
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 72c7f2fb5a5a0774b88e12ab79e2f713
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+62
View File
@@ -0,0 +1,62 @@
using UnityEngine;
using System.Collections;
public class MainMenu : MenuLayer {
private GUIStyle style;
public AudioClip clickSound;
public override string Name { get {return "MainMenu"; } }
public override void Draw(){
float w = (float)Screen.width;
float h = (float)Screen.height;
float buttonHeight = 60;
float buttonWidth = 250;
float buttonSpacing = 10;
float buttonOffset = buttonHeight + buttonSpacing;
float buttonBlockHeight = buttonOffset * 5;
float buttonBlockOffset = (h - buttonBlockHeight) * 0.5f;
style = GUI.skin.GetStyle ("button");
style.fontSize = 22;
GUI.enabled = (gameManager != null) && (gameManager.State.currentLevel != 0);
if(GUI.Button (new Rect (0, buttonBlockOffset + buttonOffset * 0, buttonWidth, buttonHeight), "Продолжить", style)){
if(manager != null){
//manager.
}
}
GUI.enabled = true;
if (GUI.Button (new Rect (0, buttonBlockOffset + buttonOffset * 1, buttonWidth, buttonHeight), "Новая игра", style)) {
if(clickSound != null) gameManager.audio.PlayOneShot(clickSound);
gameManager.NewGame();
}
if(GUI.Button (new Rect (0, buttonBlockOffset + buttonOffset * 2, buttonWidth, buttonHeight), "Настройки", style)){
if(clickSound != null) gameManager.audio.PlayOneShot(clickSound);
manager.ActivateMenu("SettingsMenu");
}
if (GUI.Button (new Rect (0, buttonBlockOffset + buttonOffset * 3, buttonWidth, buttonHeight), "Авторы", style)) {
if(clickSound != null) gameManager.audio.PlayOneShot(clickSound);
manager.ActivateMenu("AuthorsMenu");
}
if (GUI.Button (new Rect (0, buttonBlockOffset + buttonOffset * 4, buttonWidth, buttonHeight), "Выход", style)) {
if(clickSound != null) gameManager.audio.PlayOneShot(clickSound);
Application.Quit();
}
}
public override void Enter(){
}
public override void Leave(){
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f0abe46495ed365468451a51a7ec2221
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+24
View File
@@ -0,0 +1,24 @@
using UnityEngine;
using System.Collections;
public abstract class MenuLayer : MonoBehaviour {
public MenuManager manager;
protected GameManager gameManager;
public abstract string Name { get; }
void Start(){
gameManager = GameObject.FindObjectOfType<GameManager> ();
}
public virtual void Draw(){
}
public virtual void Enter(){
}
public virtual void Leave(){
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7d969a2e5701374478473140c4936408
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+34
View File
@@ -0,0 +1,34 @@
using UnityEngine;
using System.Collections;
public class MenuShow : MonoBehaviour {
public Button Predicate;
private MenuManager Manager;
public string MenuName;
public bool ShowOnStart = false;
// Use this for initialization
void Start () {
if (Predicate != null) {
Predicate.EventClick += HandleEventClick;
}
Manager = GameObject.FindObjectOfType<MenuManager> ();
if (ShowOnStart) {
if (Manager != null) {
Manager.ActivateMenu(MenuName);
}
}
}
void HandleEventClick (Button sender)
{
if (Manager != null) {
Manager.ActivateMenu(MenuName);
}
}
// Update is called once per frame
void Update () {
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e1ced3061a6b0e7498f4e350655df028
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+41
View File
@@ -0,0 +1,41 @@
using UnityEngine;
using System.Collections;
public class PauseMenu : MenuLayer {
public override string Name { get {return "PauseMenu"; } }
public override void Draw(){
float w = (float)Screen.width;
float h = (float)Screen.height;
float buttonHeight = 40;
float buttonWidth = 200;
float buttonSpacing = 10;
float buttonOffset = buttonHeight + buttonSpacing;
float buttonBlockHeight = buttonOffset * 4;
float buttonBlockVOffset = (h - buttonBlockHeight) * 0.5f;
float buttonBlockHOffset = (w - buttonWidth) * 0.5f;
if (GUI.Button (new Rect (buttonBlockHOffset, buttonBlockVOffset + buttonOffset * 0, buttonWidth, buttonHeight), "Продолжить")) {
manager.ActivateMenu("");
}
GUI.Button (new Rect (buttonBlockHOffset, buttonBlockVOffset + buttonOffset * 1, buttonWidth, buttonHeight), "Настройки");
if (GUI.Button (new Rect (buttonBlockHOffset, buttonBlockVOffset + buttonOffset * 2, buttonWidth, buttonHeight), "Главное меню")) {
gameManager.MainMenu();
}
if (GUI.Button (new Rect (buttonBlockHOffset, buttonBlockVOffset + buttonOffset * 3, buttonWidth, buttonHeight), "Выход")) {
Application.Quit();
}
}
public override void Enter(){
Debug.Log ("Set time scale to 0");
Time.timeScale = 0.0f;
}
public override void Leave(){
Time.timeScale = 1.0f;
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 98f0ab250b1825c4ea6665a6e75fe3e9
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+51
View File
@@ -0,0 +1,51 @@
using UnityEngine;
using System.Collections;
public class SettingsMenu : MenuLayer {
public override string Name { get {return "SettingsMenu"; } }
public override void Draw(){
float w = (float)Screen.width;
float h = (float)Screen.height;
float boxWidth = 300;
float boxHeight = 200;
float boxOffsetX = (w - boxWidth) * 0.5f;
float boxOffsetY = (h - boxHeight) * 0.5f;
Rect boxRect = new Rect (boxOffsetX, boxOffsetY, boxWidth, boxHeight);
GUI.Box (boxRect, "");
float buttonHeight = 50;
float buttonWidth = 150;
float buttonMargin = 10;
float sliderSize = boxWidth * 0.9f;
float sliderHeight = 20.0f;
float value = gameManager == null ? 50 : gameManager.State.Volume;
value = GUI.HorizontalSlider (new Rect (boxRect.center.x - sliderSize * 0.5f, boxRect.center.y - sliderHeight * 0.5f, sliderSize, sliderHeight), value, 0, 100);
if (gameManager != null) {
gameManager.State.Volume = value;
}
GUI.Label(new Rect (boxRect.center.x - sliderSize * 0.5f, boxRect.center.y - sliderHeight * 0.5f - 30, sliderSize, sliderHeight), "Громкость");
if (GUI.Button (new Rect (boxRect.center.x - buttonWidth * 0.5f,
(boxRect.yMax - buttonHeight - buttonMargin), buttonWidth, buttonHeight), "Назад")) {
gameManager.SaveState();
manager.ActivatePreviousMenu();
}
}
public override void Enter(){
}
public override void Leave(){
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a6d21b57d78ce5945b3d46ba5b1fde4d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+31
View File
@@ -0,0 +1,31 @@
using UnityEngine;
using System.Collections;
using System;
[Serializable]
public class UIPoint{
public bool Relative;
public Vector2 Position;
public Vector2 PixelPosition{
get{
if(Relative){
return new Vector2(Position.x * Screen.width, Position.y * Screen.height);
}else{
return Position;
}
}
}
}
public class UIItem : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fa8eacbb58aa5854a81e4cd830687021
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+15
View File
@@ -0,0 +1,15 @@
using UnityEngine;
using System.Collections;
public class UIPlane : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6cad42e97e167c14eab86cda9f6b9807
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+61
View File
@@ -0,0 +1,61 @@
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class MenuManager : MonoBehaviour {
public MenuLayer activeMenu;
public MenuLayer previousMenu;
private MenuLayer[] menuArray;
// Use this for initialization
void Start () {
menuArray = GameObject.FindObjectsOfType<MenuLayer> ();
foreach (var m in menuArray) {
m.manager = this;
Debug.Log("Found menu: " + m.Name);
}
}
// Update is called once per frame
void Update () {
}
public MenuLayer GetMenu(string menuName){
if (string.IsNullOrEmpty (menuName)) {
return null;
}
foreach (var m in menuArray) {
if(m.Name == menuName){
return m;
}
}
return null;
}
public void ActivateMenu(string menu){
var nextMenu = GetMenu (menu);
if (activeMenu == nextMenu) {
return;
}
if (activeMenu != null) {
activeMenu.Leave();
}
previousMenu = activeMenu;
activeMenu = nextMenu;
if (nextMenu != null) {
nextMenu.Enter();
}
}
public void ActivatePreviousMenu(){
ActivateMenu (previousMenu == null ? "" : previousMenu.Name);
}
/*void OnGUI(){
if (activeMenu == null) {
return;
}
activeMenu.Draw ();
}*/
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4ef676b39b5bc304fb486dc1744de133
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+68
View File
@@ -0,0 +1,68 @@
using UnityEngine;
using System.Collections;
public class Utils {
public static Rect GetCameraRect2D(Camera cam){
float pixWidth = (cam.orthographicSize * Camera.main.aspect) * 2;
float pixHeight = cam.orthographicSize * 2;
return new Rect(
Camera.main.transform.localPosition.x - (pixWidth * 0.5f),
Camera.main.transform.localPosition.y + (pixHeight * 0.5f),
pixWidth, pixHeight);
}
public static Rect RectFromBounds(Bounds b){
return new Rect (b.center.x - b.size.x * 0.5f, b.center.y + b.size.y * 0.5f, b.size.x, b.size.y);
}
}
public class ParallaxBackground : MonoBehaviour {
public float scrollSpeed = 0.5f;
public bool KeepTextureAspect = true;
public Camera cam;
public float Scale = 0.01f;
public float LerpSpeed = 0.5f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Vector2 offset = gameObject.renderer.sharedMaterial.mainTextureOffset;
Vector3 mousePos = Input.mousePosition;
Vector2 screenCenter = new Vector2 (Screen.width / 2, Screen.height / 2);
Vector2 mouseDir = new Vector2 (mousePos.x, mousePos.y) - screenCenter;
Vector2 nextOffset = mouseDir * -Scale;
gameObject.renderer.sharedMaterial.mainTextureOffset = Vector2.Lerp (offset, nextOffset, LerpSpeed * Time.deltaTime);
//offset.x += tcScrollSpeed * Time.deltaTime;
//gameObject.renderer.sharedMaterial.mainTextureOffset =offset;
/*float textureAspect = gameObject.renderer.sharedMaterial.mainTexture.width / gameObject.renderer.sharedMaterial.mainTexture.height;
float textureScale = cam.aspect / textureAspect;
var camRect = Utils.GetCameraRect2D (cam);
float tcScrollSpeed = textureScale * scrollSpeed;
if (Application.isPlaying) {
Vector2 offset = gameObject.renderer.sharedMaterial.mainTextureOffset;
offset.x += tcScrollSpeed * Time.deltaTime;
gameObject.renderer.sharedMaterial.mainTextureOffset =offset;
}
if (KeepTextureAspect) {
gameObject.renderer.sharedMaterial.mainTextureScale = new Vector2(textureScale, 1);
}
transform.localScale = new Vector3 (camRect.width, camRect.height, 1);*/
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 80f7150d5f8f34d458c8766a690578cc
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+15
View File
@@ -0,0 +1,15 @@
using UnityEngine;
using System.Collections;
public class PrintGeometry : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bec8dfa750654ac40accd67ff165d33f
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+16
View File
@@ -0,0 +1,16 @@
using UnityEngine;
using System.Collections;
public class RespawnNotify : MonoBehaviour {
public ISpawner spawner;
public bool destroyOnRespawn = true;
void OnKill(GameObject obj){
if (spawner != null) {
spawner.Respawn();
if(destroyOnRespawn){
Destroy(gameObject);
}
}
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 149f5da6bd210cc409fdf6ea6ccdb610
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+16
View File
@@ -0,0 +1,16 @@
using UnityEngine;
using System.Collections;
public class RotateAxis : MonoBehaviour {
public float speed = 1.0f;
public Vector3 axis = Vector3.up;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.Rotate (axis, speed * Time.deltaTime);
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a8f7514a5bcda0a458994ba9bf05e330
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+32
View File
@@ -0,0 +1,32 @@
using UnityEngine;
using System.Collections;
public interface ISpawner{
void Respawn ();
}
public class Spawner : MonoBehaviour, ISpawner {
public bool spawnOnStart = true;
public GameObject source;
// Use this for initialization
void Start () {
if (spawnOnStart) {
Respawn();
}
}
// Update is called once per frame
void Update () {
}
public void Respawn(){
GameObject obj = (GameObject)Instantiate (source);
RespawnNotify notify = obj.AddComponent<RespawnNotify> ();
notify.spawner = this;
notify.destroyOnRespawn = true;
obj.transform.position = transform.position;
obj.SetActive (true);
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3454a81f038bb9045aca41483d1c20e5
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+20
View File
@@ -0,0 +1,20 @@
using UnityEngine;
using System.Collections;
public class StopForce : MonoBehaviour {
public bool apply = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (apply) {
//float f = rigidbody.mass * (rigidbody.velocity.magnitude / Time.fixedDeltaTime);
//rigidbody.AddForce(-rigidbody.velocity.normalized * f);
float f = (rigidbody.velocity.sqrMagnitude * rigidbody.mass) * 0.5f;
rigidbody.AddForce(-rigidbody.velocity.normalized * f);
}
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5b4c4aa60fd881144a211e6bfda8de5d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+17
View File
@@ -0,0 +1,17 @@
using UnityEngine;
using System.Collections;
public class SwitchLevel : MonoBehaviour {
public string LevelName;
// Use this for initialization
void Start () {
Application.LoadLevel (LevelName);
}
// Update is called once per frame
void Update () {
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f3065281e84fe474fa23ecf0dc8d9d6a
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+5
View File
@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 8991e0e7eb1adc040aa7bf92830a5b28
folderAsset: yes
DefaultImporter:
userData:
+15
View File
@@ -0,0 +1,15 @@
using UnityEngine;
using System.Collections;
public class BlockChain : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f49d8fb4226b03445a6a4f2fef2f88b6
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
+228
View File
@@ -0,0 +1,228 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class WaterField : MonoBehaviour {
public List<GameObject> capturedObjects = new List<GameObject>();
public bool enableDrag = true;
float maxDrag = 0.0f;
float vel = 0.0f;
// Use this for initialization
void Start () {
if (collider == null) {
var c = gameObject.AddComponent<BoxCollider>();
c.center = new Vector3(0, -0.5f, 0);
c.isTrigger = true;
}
}
// Update is called once per frame
void FixedUpdate () {
float envDensity = AdvancedPhysics.Matters.Water.Density;
Plane p = new Plane(transform.up, transform.position);
foreach (var obj in capturedObjects) {
if(obj.collider is SphereCollider){
float objDensity = AdvancedPhysics.Matters.Water.Density * 1.05f;
Vector3 sphereCenter;
float sphereRadius;
SphereCollider c = obj.collider as SphereCollider;
if(c != null){
sphereCenter = c.transform.position;
sphereRadius = c.radius;
}else{
sphereCenter = obj.collider.bounds.center;
Vector3 ext = obj.collider.bounds.extents;
sphereRadius = ext.x > ext.y ? ext.x : (ext.y > ext.z ? ext.y : ext.z);
}
float underwaterVolume = SphereVolumeUnderPlane(p, sphereCenter, sphereRadius);
float forceMagnitude = AdvancedMath.BuoyantForce(underwaterVolume, objDensity, envDensity, Physics.gravity.magnitude);
Vector3 force = Physics.gravity.normalized * -forceMagnitude;
Vector3 sphereDragForce = -obj.rigidbody.velocity.normalized * AdvancedMath.SphereDrag(envDensity, obj.rigidbody.velocity.magnitude, sphereRadius);
float sphereVolume = AdvancedMath.SphereVolume(sphereRadius);
Vector3 speedForce = Vector3.zero;
if(underwaterVolume < sphereVolume){
if(underwaterVolume > 0.0f)
speedForce = Vector3.Cross(obj.rigidbody.angularVelocity, transform.up) * 30;
}else{
speedForce = Vector3.Cross(obj.rigidbody.angularVelocity, transform.up) * 10;
}
obj.rigidbody.AddForce(force + sphereDragForce + speedForce);
}if(obj.collider is BoxCollider){
float objDensity = AdvancedPhysics.Matters.Water.Density * 1.05f;
var mat = obj.GetComponent<AdvancedPhysicsMaterial>();
if(mat != null){
objDensity = mat.matter.Density;
}
var tf = obj.transform.localToWorldMatrix;
Vector3[] vertices;
int[] indices;
var mf = obj.GetComponent<MeshFilter>();
if(mf != null && mf.sharedMesh != null){
vertices = mf.mesh.vertices;
indices = mf.mesh.triangles;
int cnt = vertices.Length;
for(int i = 0; i < cnt; ++i){
vertices[i] = tf.MultiplyPoint3x4(vertices[i]);
}
}else{
AdvancedUtils.CreateMeshCube (obj.transform.localToWorldMatrix, out vertices, out indices);
}
List<Vector3> cuttedTriangles = AdvancedUtils.CutMesh (vertices, indices, p);
//AdvancedGizmo.DrawMesh(cuttedTriangles.ToArray(), true);
float totalVolume = 0;
Vector3 totalBuoyantForce = Vector3.zero;
for (int i = 0; i < cuttedTriangles.Count; i+=3) {
Vector3 v0 = cuttedTriangles[i + 0];
Vector3 v1 = cuttedTriangles[i + 1];
Vector3 v2 = cuttedTriangles[i + 2];
Vector3 normal = AdvancedMath.TriangleNormal(v0, v1, v2);
float dot = Vector3.Dot (normal, p.normal);
if(Mathf.Abs(dot) >= 0.0001f){
float sign = Mathf.Sign(dot);
float h0 = p.GetDistanceToPoint(v0);
float h1 = p.GetDistanceToPoint(v1);
float h2 = p.GetDistanceToPoint(v2);
float avgH = (h0 + h1 + h2) / 3.0f;
Vector3 vp0 = v0 - p.normal * h0;
Vector3 vp1 = v1 - p.normal * h1;
Vector3 vp2 = v2 - p.normal * h2;
float triangleSquare = AdvancedMath.TriangleSquare(vp0, vp1, vp2);
float prismVolume = AdvancedMath.PrismVolume(triangleSquare, avgH) * sign;
float prismBuoyantMagnitude = AdvancedMath.BuoyantForce(prismVolume, objDensity, envDensity, Physics.gravity.magnitude);
Vector3 prismBuoyantForce = Physics.gravity.normalized * -prismBuoyantMagnitude;
totalBuoyantForce += prismBuoyantForce;
totalVolume += prismVolume;
Vector3 com = AdvancedMath.PrismCenterOfMass(vp0, vp1, vp2, p.normal, h0, h1, h2);
obj.rigidbody.AddForceAtPosition(prismBuoyantForce, com, ForceMode.Force);
//obj.rigidbody.d
//Physics.
}
}
if(obj.name == "CubeTest"){
// Debug.Log("Total underwater volume: " + totalVolume);
//Debug.Log("Total buoyant force: " + totalBuoyantForce);
}
Vector3 ext = obj.collider.bounds.extents;
float sphereRadius = ext.x > ext.y ? ext.x : (ext.y > ext.z ? ext.y : ext.z);
float v = obj.rigidbody.velocity.magnitude;
float dragMagnitude = AdvancedMath.Drag(envDensity, v, 1.02f, Mathf.PI * sphereRadius * sphereRadius);
if(v < 0.01f){
dragMagnitude = 0.0f;
}
if( dragMagnitude > v*v*obj.rigidbody.mass){
dragMagnitude = v*v*obj.rigidbody.mass;
}
/* if(dragMagnitude > obj.rigidbody.velocity.magnitude){
dragMagnitude = obj.rigidbody.velocity.magnitude;
}*/
if(enableDrag){
Vector3 sphereDragForce = -obj.rigidbody.velocity.normalized * dragMagnitude;
obj.rigidbody.AddForce(sphereDragForce, ForceMode.Force);
Debug.DrawRay(obj.transform.position,obj.rigidbody.velocity, Color.green);
Debug.DrawRay(obj.transform.position,sphereDragForce, Color.red);
if(obj.name == "CubeTest"){
if(maxDrag < dragMagnitude){
maxDrag = dragMagnitude;
vel = v;
}
}
}
// obj.rigidbody.velocity -= (sphereDragForce / obj.rigidbody.mass) * Time.fixedDeltaTime;
AdvancedGizmo.DrawMesh(cuttedTriangles.ToArray(), true);
}
}
}
void OnGUI(){
GUI.Label (new Rect(0,0,100,100), "Max drag = " + maxDrag);
GUI.Label (new Rect(0,30,100,100), "Vel = " + vel);
}
void OnDrawGizmos(){
Gizmos.matrix = transform.localToWorldMatrix;
Gizmos.DrawWireCube (new Vector3 (0, -0.5f, 0), Vector3.one);
Gizmos.matrix = Matrix4x4.identity;
//AdvancedGizmo.DrawGrid (transform.position, width, height);
int waveLineCount = 5;
int wavesCount = 7;
float hLineOffset = (1.0f / (float)(waveLineCount + 1));
for (int i = 0; i < waveLineCount; ++i) {
float hOffset = -hLineOffset * (float)(i + 1);
AdvancedGizmo.Plot2D (Mathf.Sin, transform.localToWorldMatrix, new Vector3(-0.5f, 0, 0.5f + hOffset), Vector3.right, Vector3.forward, 1, Mathf.PI * wavesCount, 0.05f, 40, Color.blue);
}
}
float SphereVolumeUnderPlane(Plane p, Vector3 sphereCenter, float r){
float distance = p.GetDistanceToPoint (sphereCenter);
if (distance >= r) {
return 0;
} else if (distance <= -r) {
return AdvancedMath.SphereVolume (r);
} else {
float h = Mathf.Abs(distance - r);
return AdvancedMath.SphereSegmentVolume(r, h);
}
}
void OnTriggerEnter(Collider other){
if (other.rigidbody != null && !other.rigidbody.isKinematic) {
capturedObjects.Add(other.gameObject);
}
}
void OnTriggerExit(Collider other){
if (other.rigidbody != null && !other.rigidbody.isKinematic) {
capturedObjects.Remove(other.gameObject);
}
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d47027f2d5930f54aba3542772e2c009
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData: