Пример #1
0
        protected UNMap(Texture2D texture, Color32[] pixels, FoliageManagerInstance mInstance)
        {
            _map       = texture;
            _mInstance = mInstance;

            Apply(pixels);
        }
Пример #2
0
        /// <summary>
        /// This method will make sure that the map exists and if it doesnt it will create it.
        ///
        /// Used mainly for the rendering so if the user accidently/ purposely removed the grass map it will automatically generate a new one so it wont affect the system.
        /// </summary>
        /// <param name="manager"></param>
        /// <returns></returns>
        public Texture2D SafeGetMap(FoliagePrototype prototype, FoliageManagerInstance instance)
        {
            if (map == null)
            {
                map = UNMapGenerators.GenerateGrassMap(prototype.id, instance);
                UpdateMap();
            }

            return(map);
        }
Пример #3
0
        public static FoliageGrassMap CreateGrassMap(int prototypeIndex, FoliageManagerInstance mInstance)
        {
            FoliagePrototype prototype = FoliageDB.sortedPrototypes[prototypeIndex];

            FoliageGrassMap grassMap = new FoliageGrassMap(GenerateGrassMap(prototypeIndex, mInstance), prototype, mInstance);

            grassMap.UpdateMap();

            return(grassMap);
        }
Пример #4
0
        /// <summary>
        /// Update all of the availble grass maps
        /// (pixels)
        /// </summary>
        /// <param name="size"></param>
        public static void UpdateGrassMaps(FoliageManagerInstance mInstance)
        {
            if (FoliageDB.unSortedPrototypes.Count == 0)
            {
                return;
            }

            for (int i = 0; i < FoliageDB.unSortedPrototypes.Count; i++)
            {
                mInstance.grassMaps[FoliageDB.unSortedPrototypes[i]].UpdateMap();
            }
        }
Пример #5
0
        public static void ApplyAreaSizeChange(FoliageManagerInstance mInstance)
        {
            FoliageGrassMap grassMap;

            for (int i = 0; i < FoliageDB.unSortedPrototypes.Count; i++)
            {
                grassMap = mInstance.grassMaps[FoliageDB.unSortedPrototypes[i]];

                grassMap.Resize(mInstance.foliageAreaResolutionIntegral);
            }

            UNSettings.Log("Grass maps updated succesfully after modifying resolution.");
        }
Пример #6
0
        public static void SaveGrassMaps(FoliageManagerInstance mInstance)
        {
            FoliagePrototype prototype;

            for (int i = 0; i < FoliageDB.unSortedPrototypes.Count; i++)
            {
                prototype = FoliageDB.unSortedPrototypes[i];

                if (mInstance.grassMaps.ContainsKey(prototype))
                {
                    SaveMap(mInstance.grassMaps[prototype]);
                }
            }
        }
Пример #7
0
        /// <summary>
        /// This will generate the texture itself instead of the whole FoliageGrassMap like the "CreateGrassMap" method.
        /// </summary>
        /// <param name="prototypeIndex"></param>
        /// <param name="mInstance"></param>
        /// <returns></returns>
        public static Texture2D GenerateGrassMap(int prototypeIndex, FoliageManagerInstance mInstance)
        {
            int size = mInstance.foliageAreaResolutionIntegral;

            Texture2D map;

            string path;

            try
            {
                map = new Texture2D(size, size, TextureFormat.ARGB32, false, true);
                Color32[] colors = new Color32[size * size];

                map.SetPixels32(colors); // set pixels to black so it wont be a white texture.
                map.filterMode = FilterMode.Point;

                path = GetGrassMapPath(prototypeIndex, mInstance);

                if (!Application.isPlaying)
                {
                    CreateAndSaveTexture(path, map);
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }

            #if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                UnityEditor.EditorUtility.SetDirty(mInstance);

                #if UNITY_5_3_OR_NEWER
                UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty();
                #else
                UnityEditor.EditorApplication.MarkSceneDirty();
                #endif
            }
            #endif

            return(map);
        }
Пример #8
0
 public FoliageWorldMap(Texture2D texture, FoliageManagerInstance mInstance) : base(texture, texture.GetPixels32(), mInstance)
 {
 }
Пример #9
0
 public FoliageGrassMap(Texture2D texture, Color32[] pixels, FoliagePrototype prototype, FoliageManagerInstance mInstance) : base(texture, pixels, mInstance)
 {
     _prototypeID = prototype.id;
 }
Пример #10
0
 public FoliageGrassMap(Texture2D texture, FoliagePrototype prototype, FoliageManagerInstance mInstance) : this(texture, texture.GetPixels32(), prototype, mInstance)
 {
 }
Пример #11
0
        public static FoliageWorldMap GenerateWorldMap(FoliageManagerInstance mInstance)
        {
            List <Terrain> dirtyTerrains = new List <Terrain>();

            var     terrains = GameObject.FindObjectsOfType <Terrain>();
            Terrain terrain;

            for (int i = 0; i < terrains.Length; i++)
            {
                terrain = terrains[i];

                if (terrain.drawTreesAndFoliage)
                {
                    terrain.drawTreesAndFoliage = false;
                    dirtyTerrains.Add(terrain);
                }
            }

            int mapResolution = mInstance.foliageAreaResolutionIntegral;

            string path = GetWorldMapPath(mapResolution, mInstance);

            FoliageWorldMap worldMap;

            try
            {
                Texture2D map    = new Texture2D(mapResolution, mapResolution, TextureFormat.ARGB32, false, true);
                Color32[] colors = new Color32[mapResolution * mapResolution];

                map.filterMode = FilterMode.Point;

                map.SetPixels32(colors); // set pixels to black so it wont be a white texture.

                if (!Application.isPlaying)
                {
                    /*
                     * byte[] bytes = map.EncodeToPNG();
                     *
                     * GameObject.DestroyImmediate(map);
                     *
                     * CreateAndSaveTexture(path, bytes);
                     *
                     * map = Resources.Load<Texture2D>(path);
                     */

                    CreateAndSaveTexture(path, map);
                }

                worldMap = new FoliageWorldMap(map, mInstance);
                worldMap.UpdateHeight_RANGE(0, 0, mapResolution, mapResolution, true);

                worldMap.Save();
            }
            catch (System.Exception ex)
            {
                for (int i = 0; i < dirtyTerrains.Count; i++)
                {
                    terrain = dirtyTerrains[i];

                    terrain.drawTreesAndFoliage = true;
                }

                throw ex;
            }

            for (int i = 0; i < dirtyTerrains.Count; i++)
            {
                terrain = dirtyTerrains[i];

                terrain.drawTreesAndFoliage = true;
            }

            #if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                UnityEditor.EditorUtility.SetDirty(mInstance);

                #if UNITY_5_3_OR_NEWER
                UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty();
                #else
                UnityEditor.EditorApplication.MarkSceneDirty();
                #endif
            }
            #endif

            return(worldMap);
        }
Пример #12
0
 public static string GetWorldMapPath(int size, FoliageManagerInstance mInstance)
 {
     return("GrassMaps/" + string.Format("WorldMap_{0}_{1}", mInstance.guid, size));
 }
Пример #13
0
 public static string GetGrassMapPath(int prototypeIndex, FoliageManagerInstance mInstance)
 {
     return("GrassMaps/" + string.Format("GrassMap_{0}_{1}_Prototype_{2}", mInstance.guid, mInstance.foliageAreaResolutionIntegral, prototypeIndex));
 }
Пример #14
0
        public static void ApplyAreaSizeChange(FoliageManagerInstance mInstance)
        {
            mInstance.worldMap.Resize(mInstance.foliageAreaResolutionIntegral);

            UNSettings.Log("World map updated succesfully after modifying resolution.");
        }