Skip to content

Commit 4fff9ad

Browse files
committed
Initial files.
1 parent 34e9275 commit 4fff9ad

File tree

164 files changed

+2991
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+2991
-0
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "Assets/UnitySteer"]
2+
path = Assets/UnitySteer
3+
url = [email protected]:ricardojmendez/UnitySteer.git

Assets/Materials.meta

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Materials/Ground.mat

4.9 KB
Binary file not shown.

Assets/Materials/Ground.mat.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Materials/Iron.mat

5.21 KB
Binary file not shown.

Assets/Materials/Iron.mat.meta

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Materials/Stone.mat

5.21 KB
Binary file not shown.

Assets/Materials/Stone.mat.meta

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Prefabs.meta

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Prefabs/Capsule.prefab

8.32 KB
Binary file not shown.

Assets/Prefabs/Capsule.prefab.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Prefabs/FencePost.prefab

7.53 KB
Binary file not shown.

Assets/Prefabs/FencePost.prefab.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Prefabs/FenceWall.prefab

6.66 KB
Binary file not shown.

Assets/Prefabs/FenceWall.prefab.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scene.unity

50.8 KB
Binary file not shown.

Assets/Scene.unity.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts.meta

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/BlockController.cs

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using UnityEngine;
2+
using System.Collections;
3+
4+
using DigitalRuby.Tween;
5+
6+
public class BlockController : MonoBehaviour {
7+
8+
private Vector3 initialPos;
9+
10+
public float initialY;
11+
12+
// Use this for initialization
13+
void Start () {
14+
15+
}
16+
17+
// Called from GridController
18+
public void Spawn(float delay, bool randomDelay)
19+
{
20+
if (randomDelay) StartCoroutine(WaitAndSpawn(Random.Range(0.0f, delay)));
21+
else StartCoroutine(WaitAndSpawn(delay));
22+
}
23+
24+
// Update is called once per frame
25+
void Update () {
26+
27+
}
28+
29+
private IEnumerator WaitAndSpawn(float waitTime)
30+
{
31+
GetComponent<MeshRenderer>().enabled = false;
32+
yield return new WaitForSeconds(waitTime);
33+
GetComponent<MeshRenderer>().enabled = true;
34+
TweenSpawn();
35+
}
36+
37+
private void TweenSpawn()
38+
{
39+
initialPos = transform.position;
40+
gameObject.Tween("Move" + GetInstanceID(),
41+
initialY,
42+
0.5f,
43+
0.3f,
44+
TweenScaleFunctions.Linear, (t) =>
45+
{
46+
float yPos = t.CurrentValue;
47+
transform.position = new Vector3(initialPos.x, yPos, initialPos.z);
48+
}, (t) =>
49+
{
50+
//Debug.Log("Finished move.");
51+
});
52+
}
53+
54+
}

Assets/Scripts/BlockController.cs.meta

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/CapsuleController.cs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using UnityEngine;
2+
using System.Collections;
3+
4+
public class CapsuleController : MonoBehaviour {
5+
6+
public GameObject bloodSplatter;
7+
8+
// Use this for initialization
9+
void Start () {
10+
11+
}
12+
13+
// Update is called once per frame
14+
void Update () {
15+
16+
}
17+
18+
void OnCollisionEnter(Collision collision)
19+
{
20+
if (collision.gameObject.tag == "WallBlock")
21+
{
22+
Debug.Log("Splat");
23+
24+
ContactPoint contact = collision.contacts[0];
25+
Quaternion rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
26+
Vector3 pos = contact.point;
27+
28+
Debug.DrawRay(pos, contact.normal * 10.0f, Color.green, 2.0f);
29+
30+
GameObject splatter = (GameObject) Instantiate(bloodSplatter, pos, rot);
31+
splatter.transform.parent = gameObject.transform;
32+
splatter.SetActive(true);
33+
float duration = splatter.GetComponent<ParticleSystem>().duration;
34+
Destroy(splatter, duration);
35+
}
36+
}
37+
}

Assets/Scripts/CapsuleController.cs.meta

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/GridController.cs

+180
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
using UnityEngine;
2+
using System.Collections;
3+
4+
using DigitalRuby.Tween;
5+
6+
public enum WallDirection
7+
{
8+
xAxis, zAxis
9+
}
10+
11+
public class GridController : MonoBehaviour {
12+
13+
public GameObject gridBlock;
14+
15+
public GameObject testCapsule;
16+
17+
private GameObject[] grid;
18+
19+
public Vector2 gridSize = new Vector2(40, 40);
20+
21+
public float gridSpacing = 3.0f;
22+
23+
private int gridWidth;
24+
private int gridHeight;
25+
26+
public float brickSpawnInterval = 1.0f;
27+
28+
// Use this for initialization
29+
void Start () {
30+
gridWidth = (int)gridSize.x;
31+
gridHeight = (int)gridSize.y;
32+
33+
gameObject.transform.position = new Vector3(-gridSize.x / 2 + 0.5f, 0.0f, -gridSize.y / 2 + 0.5f);
34+
35+
grid = new GameObject[gridWidth * gridHeight];
36+
37+
if (testCapsule != null) SpawnSomeCapsules(50);
38+
39+
if (gridBlock == null) return;
40+
41+
StartCoroutine(SpawnSomeWalls(10, 2.0f));
42+
//SpawnAllRandom();
43+
44+
}
45+
46+
void SpawnSomeCapsules(int count)
47+
{
48+
for (int i = 0; i < count; i++)
49+
{
50+
SpawnRandomCapsule();
51+
}
52+
}
53+
54+
void SpawnRandomCapsule()
55+
{
56+
int randX = Random.Range(0, gridWidth);
57+
int randZ = Random.Range(0, gridHeight);
58+
59+
SpawnCapsule(randX, randZ);
60+
}
61+
62+
void SpawnRandomWall()
63+
{
64+
float rand = Random.Range(0.0f, 1.0f);
65+
WallDirection dir = rand < 0.5f ? WallDirection.xAxis : WallDirection.zAxis;
66+
67+
int randX = Random.Range(0, gridWidth);
68+
int randZ = Random.Range(0, gridHeight);
69+
70+
SpawnWall(randX, randZ, dir);
71+
}
72+
73+
IEnumerator SpawnSomeWalls(int count, float waitTime)
74+
{
75+
for (int i = 0; i < count; i++)
76+
{
77+
SpawnRandomWall();
78+
yield return new WaitForSeconds(waitTime);
79+
}
80+
}
81+
82+
void SpawnAllRandom()
83+
{
84+
for (int i = 0; i < gridHeight; i++)
85+
{
86+
for (int j = 0; j < gridWidth; j++)
87+
{
88+
SpawnBrick(j, i, 5.0f, true);
89+
}
90+
}
91+
}
92+
93+
void SpawnCapsule (int x, int z)
94+
{
95+
GameObject capsule = (GameObject)Instantiate(testCapsule);
96+
capsule.transform.parent = gameObject.transform;
97+
// Unity is Z-forward
98+
float initialY = 1.4f;
99+
//float initialY = 40.0f;
100+
capsule.transform.localPosition = new Vector3(gridSpacing * x, initialY, gridSpacing * z);
101+
capsule.SetActive(true);
102+
}
103+
104+
void SpawnBrick (int x, int z, float delay, bool randomDelay)
105+
{
106+
int index = gridWidth * z + x;
107+
//Debug.Log(string.Format("X: {0}, Z: {1}, Index: {2}", x, z, index));
108+
grid[index] = (GameObject)Instantiate(gridBlock);
109+
grid[index].transform.parent = gameObject.transform;
110+
// Unity is Z-forward
111+
float initialY = 40.0f - (x + z) / 3.0f;
112+
//float initialY = 40.0f;
113+
grid[index].transform.localPosition = new Vector3(gridSpacing * x, initialY, gridSpacing * z);
114+
grid[index].GetComponent<BlockController>().initialY = initialY;
115+
grid[index].SetActive(true);
116+
grid[index].GetComponent<BlockController>().Spawn(delay, randomDelay);
117+
}
118+
119+
void SpawnWall (int startX, int startZ, WallDirection wallDirection)
120+
{
121+
if (wallDirection == WallDirection.xAxis)
122+
{
123+
// X forward
124+
for (int i = startX; i < gridWidth; i++)
125+
{
126+
int index = gridWidth * startZ + i;
127+
// Stop on block
128+
if (grid[index] != null) break;
129+
130+
float delayFactor = i - startX;
131+
132+
SpawnBrick(i, startZ, brickSpawnInterval * delayFactor, false);
133+
}
134+
if (startX - 1 >= 0)
135+
{
136+
// X backward
137+
for (int j = startX - 1; j >= 0; j--)
138+
{
139+
int index = gridWidth * startZ + j;
140+
// Stop on block
141+
if (grid[index] != null) break;
142+
143+
float delayFactor = (startX - j) + 1.0f;
144+
SpawnBrick(j, startZ, brickSpawnInterval * delayFactor, false);
145+
}
146+
}
147+
} else
148+
{
149+
// Z forward
150+
for (int k = startZ; k < gridWidth; k++)
151+
{
152+
int index = gridWidth * k + startX;
153+
// Stop on block
154+
if (grid[index] != null) break;
155+
156+
float delayFactor = k - startX;
157+
158+
SpawnBrick(startX, k, brickSpawnInterval * delayFactor, false);
159+
}
160+
if (startZ - 1 >= 0)
161+
{
162+
// Z backward
163+
for (int l = startZ - 1; l >= 0; l--)
164+
{
165+
int index = gridWidth * l + startX;
166+
// Stop on block
167+
if (grid[index] != null) break;
168+
169+
float delayFactor = (startZ - l) + 1.0f;
170+
SpawnBrick(startX, l, brickSpawnInterval * delayFactor, false);
171+
}
172+
}
173+
}
174+
}
175+
176+
// Update is called once per frame
177+
void Update () {
178+
179+
}
180+
}

0 commit comments

Comments
 (0)