/// <summary> /// Checks if this unit needs to update. /// Called by update loop. /// </summary> public void CheckUpdateFow() { int newGridIndex = FowManager.GetGridIndex(this.transform.position); if (newGridIndex != gridIndex) { gridIndex = newGridIndex; fowMan.UpdateFow(this); } }
private void Awake() { //Singleton if (instance != null && instance != this) { Destroy(this.gameObject); } else { fowArrLen = DwarfHeimManager.Instance.OWGrid.WorldWidth * DwarfHeimManager.Instance.OWGrid.WorldHeight; colorArray = new Color32[fowArrLen]; unitFows = new List <UnitFowController>(); unitSet = new HashSet <UnitFowController>(); instance = this; } //copy width and height worldWidth = DwarfHeimManager.Instance.OWGrid.WorldWidth; worldHeight = DwarfHeimManager.Instance.OWGrid.WorldHeight; //init spatial index grid spatialDivisorX = worldWidth / spatialGridWidth; spatialDivisorY = worldHeight / spatialGridHeight; spatialGrid = new List <SpatialGridSquareController>(); Vector3 offset = new Vector3(spatialDivisorX, 0, spatialDivisorY); int index = 0; for (int x = 0; x < spatialGridWidth; x++) { for (int y = 0; y < spatialGridWidth; y++) { GameObject prefab = Instantiate(spatialGridSquarePrefab, this.transform); prefab.transform.position = new Vector3(x * spatialDivisorX * 2, 0, y * spatialDivisorY * 2) + offset; prefab.GetComponent <BoxCollider>().size = new Vector3(spatialDivisorX * 2, 0, spatialDivisorY * 2); prefab.name = "SpatialViz_" + x + "_" + y; SpatialGridSquareController square = prefab.GetComponent <SpatialGridSquareController>(); square.x = x; square.y = y; square.index = index; spatialGrid.Add(square); index++; } } //init DDA Archtypes fowCalcArchetypes = new FowCalcArchetype[viewDists.Length]; for (int i = 0; i < viewDists.Length; i++) { fowCalcArchetypes[i] = new FowCalcArchetype(worldWidth, worldHeight, viewDists[i], seeThroughs[i]); } }
// Start is called before the first frame update void Start() { //find index and update my fow gridIndex = FowManager.GetGridIndex(this.transform.position); fowMan = FowManager.GetInstance(); fowMan.unitFows.Add(this); //init spatial indexing mySquares = new List <SpatialGridSquareController>(); int viewDist = fowMan.fowCalcArchetypes[fowCalcArchetypeID].viewDist; mySpatialCollider.radius = viewDist * 2; //worldsize = 2 //updateMyFOW(); //Deprecated fowMan.UpdateFow(this); }