void Start() { tgs = TerrainGridSystem.instance; // setup GUI resizer - only for the demo GUIResizer.Init(800, 500); // setup GUI styles labelStyle = new GUIStyle(); labelStyle.alignment = TextAnchor.MiddleLeft; labelStyle.normal.textColor = Color.black; labelStyleShadow = new GUIStyle(labelStyle); labelStyleShadow.normal.textColor = Color.black; buttonStyle = new GUIStyle(labelStyle); buttonStyle.alignment = TextAnchor.MiddleCenter; buttonStyle.normal.background = Texture2D.whiteTexture; buttonStyle.normal.textColor = Color.black; sliderStyle = new GUIStyle(); sliderStyle.normal.background = Texture2D.whiteTexture; sliderStyle.fixedHeight = 4.0f; sliderThumbStyle = new GUIStyle(); sliderThumbStyle.normal.background = Resources.Load <Texture2D> ("thumb"); sliderThumbStyle.overflow = new RectOffset(0, 0, 8, 0); sliderThumbStyle.fixedWidth = 20.0f; sliderThumbStyle.fixedHeight = 12.0f; StartCoroutine(MoveGrid()); }
void Start() { tgs = TerrainGridSystem.instance; // setup GUI resizer - only for the demo GUIResizer.Init(800, 500); // setup GUI styles labelStyle = new GUIStyle(); labelStyle.alignment = TextAnchor.MiddleLeft; labelStyle.normal.textColor = Color.black; labelStyleShadow = new GUIStyle(labelStyle); labelStyleShadow.normal.textColor = Color.black; buttonStyle = new GUIStyle(labelStyle); buttonStyle.alignment = TextAnchor.MiddleCenter; buttonStyle.normal.background = Texture2D.whiteTexture; buttonStyle.normal.textColor = Color.black; sliderStyle = new GUIStyle(); sliderStyle.normal.background = Texture2D.whiteTexture; sliderStyle.fixedHeight = 4.0f; sliderThumbStyle = new GUIStyle(); sliderThumbStyle.normal.background = Resources.Load <Texture2D> ("thumb"); sliderThumbStyle.overflow = new RectOffset(0, 0, 8, 0); sliderThumbStyle.fixedWidth = 20.0f; sliderThumbStyle.fixedHeight = 12.0f; ball = Resources.Load <GameObject>("Ball"); ballParent = new GameObject("BallParent"); ballParent.transform.position = tgs.terrainCenter + Vector3.up * 200.0f; ResetTerrain(); }
void Start() { tgs = TerrainGridSystem.instance; // setup GUI resizer - only for the demo GUIResizer.Init(800, 500); // setup GUI styles labelStyle = new GUIStyle(); labelStyle.alignment = TextAnchor.MiddleLeft; labelStyle.normal.textColor = Color.black; character = GameObject.Find("Character").GetComponent <Rigidbody>(); }
void Start() { // setup GUI - only for the demo GUIResizer.Init(800, 500); labelStyle = new GUIStyle(); labelStyle.alignment = TextAnchor.MiddleLeft; labelStyle.normal.textColor = Color.white; // Get a reference to TGS system's API grid = TerrainGridSystem.instance; for (int k = 0; k < grid.numCells; k++) { Texture2D fruitTexture = fruits [Random.Range(0, fruits.Length)]; DrawFruit(k, fruitTexture); } grid.OnCellClick += CheckMatchingCells; }
// Use this for initialization void Start() { tgs = TerrainGridSystem.instance; // setup GUI resizer - only for the demo GUIResizer.Init(800, 500); labelStyle = new GUIStyle(); labelStyle.alignment = TextAnchor.MiddleLeft; labelStyle.normal.textColor = Color.white; isSelectingStart = true; #if UNITY_5_4_OR_NEWER Random.InitState(2); #else Random.seed = 2; #endif // Draw some blocked areas for (int i = 0; i < 25; i++) { int row = Random.Range(2, tgs.rowCount - 3); int col = Random.Range(2, tgs.columnCount - 3); for (int j = -2; j <= 2; j++) { for (int k = -2; k <= 2; k++) { int cellIndex = tgs.CellGetIndex(row + j, col + k); tgs.CellSetCanCross(cellIndex, false); tgs.CellToggleRegionSurface(cellIndex, true, Color.white); } } } // Hook into cell click event to toggle start selection or draw a computed path using A* path finding algorithm tgs.OnCellClick += (cellIndex, buttonIndex) => BuildPath(cellIndex); }
// Use this for initialization void Start() { tgs = TerrainGridSystem.instance; // setup GUI resizer - only for the demo GUIResizer.Init(800, 500); labelStyle = new GUIStyle(); labelStyle.alignment = TextAnchor.MiddleLeft; labelStyle.normal.textColor = Color.white; isSelectingStart = true; Random.InitState(2); // Draw some blocked areas for (int i = 0; i < 25; i++) { int row = Random.Range(2, tgs.rowCount - 3); int col = Random.Range(2, tgs.columnCount - 3); for (int j = -2; j <= 2; j++) { for (int k = -2; k <= 2; k++) { int cellIndex = tgs.CellGetIndex(row + j, col + k); tgs.CellSetGroup(cellIndex, CELL_OBSTACLE); tgs.CellToggleRegionSurface(cellIndex, true, Color.white); } } } // Example: sets crossing costs for hexagon sides and draw a line int barrierCost = 10000; Color barrierColor = Color.blue; float barrierWidth = 5f; for (int k = 0; k < 10; k++) { int cellIndex = tgs.CellGetIndex(10, k + 20); if (!tgs.cells [cellIndex].canCross) { continue; } if (tgs.cells [cellIndex].column % 2 == 0) { // Assign a crossing cost to barrier for path-finding purposes tgs.CellSetSideCrossCost(cellIndex, CELL_SIDE.Top, barrierCost); tgs.CellSetSideCrossCost(cellIndex, CELL_SIDE.TopLeft, barrierCost); tgs.CellSetSideCrossCost(cellIndex, CELL_SIDE.TopRight, barrierCost); // Make the barrier block LOS (Line-Of-Sight) tgs.CellSetSideBlocksLOS(cellIndex, CELL_SIDE.Top, true); tgs.CellSetSideBlocksLOS(cellIndex, CELL_SIDE.TopLeft, true); tgs.CellSetSideBlocksLOS(cellIndex, CELL_SIDE.TopRight, true); // Draw the barrier tgs.DrawLine(cellIndex, CELL_SIDE.Top, barrierColor, barrierWidth); tgs.DrawLine(cellIndex, CELL_SIDE.TopLeft, barrierColor, barrierWidth); tgs.DrawLine(cellIndex, CELL_SIDE.TopRight, barrierColor, barrierWidth); } else { // Assign a crossing cost to barrier for path-finding purposes tgs.CellSetSideCrossCost(cellIndex, CELL_SIDE.Top, barrierCost); // Make the barrier block LOS (Line-Of-Sight) tgs.CellSetSideBlocksLOS(cellIndex, CELL_SIDE.Top, true); // Draw the barrier tgs.DrawLine(cellIndex, CELL_SIDE.Top, barrierColor, barrierWidth); } } // Hook into cell click event to toggle start selection or draw a computed path using A* path finding algorithm tgs.OnCellClick += (cellIndex, buttonIndex) => BuildPath(cellIndex); tgs.OnCellEnter += (cellIndex) => ShowLineOfSight(cellIndex); }