using UnityEngine; using System; using System.Linq; using System.Threading; using System.IO; using System.Collections; using System.Collections.Generic; namespace WPM { public partial class WorldMapGlobe : MonoBehaviour { #region Fog of War API [SerializeField] bool _showFogOfWar; /// /// Enables or disables fog of war layer /// public bool showFogOfWar { get { return _showFogOfWar; } set { if (_showFogOfWar != value) { _showFogOfWar = value; DrawFogOfWar(); isDirty = true; } } } [SerializeField] int _fogOfWarResolution = 10; /// /// Resolution for the internal fog of war mask texture /// public int fogOfWarResolution { get { return _fogOfWarResolution; } set { if (_fogOfWarResolution != value) { _fogOfWarResolution = value; DrawFogOfWar(); isDirty = true; } } } [SerializeField] float _fogOfWarElevation = 0.14f; /// /// Elevation for the fog of war layer (scale multiplier) /// public float fogOfWarElevation { get { return _fogOfWarElevation; } set { if (_fogOfWarElevation != value) { _fogOfWarElevation = value; DrawFogOfWar(); isDirty = true; } } } [SerializeField, Range(0,1)] float _fogOfWarNoise = 1f; /// /// Elevation for the fog of war layer (scale multiplier) /// public float fogOfWarNoise { get { return _fogOfWarNoise; } set { if (_fogOfWarNoise != value) { _fogOfWarNoise = value; DrawFogOfWar(); isDirty = true; } } } // [SerializeField] // float _fogOfWarSneak = 0.6f; // // /// // /// Sneak factor (ability to see under fog of war from angled view) // /// // public float fogOfWarSneak { // get { return _fogOfWarSneak; } // set { if (_fogOfWarSneak != value) { // _fogOfWarSneak = value; // DrawFogOfWar(); // isDirty = true; // } // } // } [SerializeField] float _fogOfWarAlpha = 1f; /// /// Alpha for the fog of war layer /// public float fogOfWarAlpha { get { return _fogOfWarAlpha; } set { if (_fogOfWarAlpha != value) { _fogOfWarAlpha = value; DrawFogOfWar(); isDirty = true; } } } [SerializeField] Color _fogOfWarColor1 = new Color(1,1,0); /// /// Enables or disables fog of war layer /// public Color fogOfWarColor1 { get { return _fogOfWarColor1; } set { if (_fogOfWarColor1 != value) { _fogOfWarColor1 = value; DrawFogOfWar(); isDirty = true; } } } [SerializeField] Color _fogOfWarColor2 = new Color(0,1,1); /// /// Enables or disables fog of war layer /// public Color fogOfWarColor2 { get { return _fogOfWarColor2; } set { if (_fogOfWarColor2 != value) { _fogOfWarColor2 = value; DrawFogOfWar(); isDirty = true; } } } /// /// Fills a circle centered on spherePos location with fog using alpha (transparency) and custom width. /// /// Sphere position. /// Alpha in the range 0..1. /// Width in the range 0..1. /// Strength of the brush in the range 0..1. public void SetFogOfWarAlpha(Vector3 spherePos, float alpha, float radius, float strength) { Vector2 latLon = Conversion.GetLatLonFromUnitSpherePoint(spherePos); Vector2 uv = Conversion.GetUVFromLatLon(latLon.x, latLon.y); SetFowAlpha (uv, alpha, radius, strength); } /// /// Assigns an alpha to the entire fog of war layer. /// public void SetFogOfWarAlpha(float alpha) { SetFowAlpha (Misc.Vector2zero, alpha, 2, 1); } /// /// Fills a region with fog using alpha (transparency) and custom width. /// /// Sphere position. /// Alpha in the range 0..1. /// Strength of the brush in the range 0..1. public void SetFogOfWarAlpha(Region region, float alpha, float strength) { if (region==null) return; Rect rect = region.latlonRect2D; float stepX = rect.width * 0.2f; float stepY = rect.height * 0.2f; Vector2 pos = new Vector2(rect.xMin, rect.yMin); float radius = Mathf.Max(Mathf.Max (stepX, stepY) / overlayHeight, 0.001f); while (pos.yrect.xMax) { pos.x = rect.xMin; pos.y += stepY; } } } /// /// Fills a country's main region with fog using alpha (transparency) and custom width. /// /// Country. /// Alpha in the range 0..1. /// Strength of the brush in the range 0..1. public void SetFogOfWarAlpha(Country country, float alpha, float strength) { if (country==null) return; SetFogOfWarAlpha(country.mainRegion, alpha, strength); } /// /// Fills a province's main region with fog using alpha (transparency) and custom width. /// /// Province. /// Alpha in the range 0..1. /// Strength of the brush in the range 0..1. public void SetFogOfWarAlpha(Province province, float alpha, float strength) { if (province==null) return; SetFogOfWarAlpha(province.mainRegion, alpha, strength); } /// /// Fills a cell with fog using alpha (transparency) and custom width. /// /// Cell. /// Alpha in the range 0..1. /// Width in the range 0..1. /// Strength of the brush in the range 0..1. public void SetFogOfWarAlpha(Cell cell, float alpha, float radius, float strength) { if (cell==null) return; SetFogOfWarAlpha(cell.sphereCenter, alpha, radius, strength); } #endregion } }