private void Awake() { _instance = this; var renderer = GetComponent <Renderer>(); Material fogOfWarMat = null; if (renderer != null) { fogOfWarMat = renderer.material; } if (fogOfWarMat == null) { UnityEngine.Debug.LogError("Material for Fog Of War not found!"); return; } _texture = new Texture2D(_textureSize, _textureSize, TextureFormat.RGBA32, false); _texture.wrapMode = TextureWrapMode.Clamp; _pixels = _texture.GetPixels(); ClearPixels(); fogOfWarMat.mainTexture = _texture; _revealers = new List <FoWRevealer>(); _pixelsPerUnit = Mathf.RoundToInt(_textureSize / transform.lossyScale.x); _centerPixel = new Vector2(_textureSize * 0.5f, _textureSize * 0.5f); }
public void Start() { _demo = (Demo)FindObjectOfType(typeof(Demo)); if (_demo == null) return; if (MinimapTexture == null) return; _fow = FoWManager.FindInstance(); if (_fow == null) return; _texture = new Texture2D(_demo.SizeX * Scale, _demo.SizeZ * Scale, TextureFormat.ARGB32, false, false); ClearTexture(); MinimapTexture.pixelInset = new Rect(-1 * _demo.SizeX * Scale, 0, _demo.SizeX * Scale, _demo.SizeZ * Scale); MinimapTexture.texture = _texture; UpdateMinimap(); _visibleColor = new Color32(255, 255, 255, 255); _exploredColor = new Color32(64, 64, 64, 255); _hiddenColor = new Color32(0, 0, 0, 255); _playerUnitColor = new Color32(32, 32, 255, 255); _playerTowerColor = _playerUnitColor; _enemyUnitColor = new Color32(255, 32, 32, 255); _enemyTowerColor = _enemyUnitColor; _enemyGhostColor = new Color32(255, 200, 32, 255); }
/// <summary> /// Standard Unity method. /// Adds this game object to the FoWManager "viewer" collection /// </summary> public void Start() { _fow = FoWManager.FindInstance(); if (_fow == null) return; _fow.AddViewer(gameObject); }
private void Awake() { if (instance == null) { instance = this; cameraFollow = FindObjectOfType <CameraFollow>(); } else { Destroy(gameObject); } }
/// <summary> /// Standard Unity method. /// </summary> public void Start() { _fow = FoWManager.FindInstance(); }
//////////////////////////////////////////////////////////////////////////////////////////////////// #region PUBLIC METHODS /// <summary> /// Convenience method to find the *single* instance of FoWManager in the game scene. /// </summary> /// <returns>Instance of FoWManager if found</returns> public static FoWManager FindInstance() { return _instance ?? (_instance = FindObjectOfType(typeof(FoWManager)) as FoWManager); }
void Start() { _fowManager = FoWManager.FindInstance(); _fowManager.Initialize(); _minimap = (DemoMinimap)FindObjectOfType(typeof(DemoMinimap)); // // Instantiate the prefabs so we can get the meshes // ... there must be a better way to do this, but I couldn't figure it out! TilePrefabInstances = new GameObject[TilePrefabs.Length]; for (var i = 0; i < TilePrefabs.Length; i++) { TilePrefabInstances[i] = (GameObject)Instantiate(TilePrefabs[i], new Vector3(-1000, -1000, -1000), Quaternion.identity); // TilePrefabInstances[i].SetActive(false); <-- DO NOT DO THIS!!! } // _chunks = new DemoChunk[SizeX / ChunkSize, SizeZ / ChunkSize]; Tiles = new DemoTile[SizeX, SizeZ]; _tilesParent = new GameObject("Tiles"); _unitsParent = new GameObject("Units"); for (var x = 0; x < SizeX; x++) { for (var z = 0; z < SizeZ; z++) { RandomizeTile(x, z, true); } } UpdateDirtyChunks(); // var callbacks = FoWCallbacks.FindInstance(); if (callbacks != null) { callbacks.OnTileBecomesVisible = OnTileBecomesVisible; callbacks.OnTileBecomesExplored = OnTileBecomesExplored; callbacks.OnTileBecomesHidden = OnTileBecomesHidden; // Note: we're using FoWNonPlayerUnit.AutoManagerRenderers so we don't need this... it's here for reference // callbacks.OnNonPlayerUnitBecomesVisible = ShowEnemyUnit; // callbacks.OnNonPlayerUnitBecomesHidden = HideEnemyUnit; // callbacks.OnNonPlayerUnitBecomesExplored = HideEnemyUnit; callbacks.OnAddGhost = AddGhost; callbacks.OnRemoveGhost = RemoveGhost; } SetFoWValues(); UpdatePlayerUnitCount(); UpdatePlayerTowerCount(); UpdateEnemyUnitCount(); UpdateEnemyTowerCount(); }