public static void FadeOut(TerrainGridSystem tgs, GameObject surface, Region region, Color color, float duration) { SurfaceFader fader = surface.GetComponent <SurfaceFader>(); if (fader != null) { DestroyImmediate(fader); } fader = surface.AddComponent <SurfaceFader>(); fader.tgs = tgs; fader.startTime = Time.time; fader.duration = duration + 0.0001f; fader.color = color; fader.region = region; }
/// <summary> /// Colors a cell and fades it out during "duration" in seconds. /// </summary> public void CellFadeOut(int cellIndex, Color color, float duration) { if (cellIndex < 0 || cellIndex >= cells.Count) { return; } CellToggleRegionSurface(cellIndex, true, color, false); int cacheIndex = GetCacheIndexForCellRegion(cellIndex); if (surfaces.ContainsKey(cacheIndex)) { GameObject cellSurface = surfaces[cacheIndex]; Material mat = Instantiate(cellSurface.GetComponent <Renderer>().sharedMaterial); mat.color = color; mat.hideFlags = HideFlags.DontSave; cellSurface.GetComponent <Renderer>().sharedMaterial = mat; cells[cellIndex].region.customMaterial = mat; SurfaceFader.FadeOut(this, cellSurface, cells[cellIndex].region, color, duration); } }
/// <summary> /// Colors a territory and fades it out during "duration" in seconds. /// </summary> public void TerritoryFadeOut(int territoryIndex, Color color, float duration) { if (_territoryHighlightedIndex == territoryIndex) { return; } TerritoryToggleRegionSurface(territoryIndex, true, color); int cacheIndex = GetCacheIndexForTerritoryRegion(territoryIndex); if (surfaces.ContainsKey(cacheIndex)) { GameObject territorySurface = surfaces[cacheIndex]; Material mat = Instantiate(territorySurface.GetComponent <Renderer>().sharedMaterial); mat.color = color; mat.hideFlags = HideFlags.DontSave; territorySurface.GetComponent <Renderer>().sharedMaterial = mat; territories[territoryIndex].region.customMaterial = mat; SurfaceFader.FadeOut(this, territorySurface, territories[territoryIndex].region, color, duration); // fader = territorySurface.GetComponent<SurfaceFader>() ?? territorySurface.AddComponent<SurfaceFader>(); } }
public static void Animate(FADER_STYLE style, TerrainGridSystem grid, GameObject surface, Region region, Material fadeMaterial, Color color, float duration, int repetitions) { SurfaceFader fader = surface.GetComponent <SurfaceFader>(); if (fader != null) { fader.Finish(0); DestroyImmediate(fader); } fader = surface.AddComponent <SurfaceFader>(); fader.grid = grid; fader.startTime = Time.time; fader.duration = duration + 0.0001f; fader.color = color; fader.region = region; fader.fadeMaterial = fadeMaterial; fader.style = style; fader.initialColor = fadeMaterial.color; fader.repetitions = repetitions; }