Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public void Save()
        {
            if (dirty && (!Application.isPlaying || UNSettings.instance.UN_Foliage_RUNTIME_SAVECHANGES))
            {
                #if UNITY_EDITOR
                UNMapGenerators.SaveMap(this);
                #endif

                dirty = false;
            }
        }
Ejemplo n.º 3
0
        public void Save()
        {
            if (dirty)
            {
                #if UNITY_EDITOR
                UNMapGenerators.SaveMap(this);
                #endif

                dirty = false;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Update height on a certain range.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="z"></param>
        /// <param name="sizeX"></param>
        /// <param name="sizeZ"></param>
        public void UpdateHeight_RANGE(float x, float z, int sizeX, int sizeZ, bool save)
        {
            int   mapWidth      = this.mapWidth;
            float resMultiplier = mInstance.transformCordsMultiplier;

            if (x < 0 || z < 0 || x + sizeX > mapWidth || z + sizeZ > mapWidth)
            {
                Debug.Log("Cant generate world map. Out Of Bounds.");
                return;
            }

            Transform managerTransform = mInstance.transform;

            RaycastHit hit;
            Vector3    rayPos = new Vector3(0, managerTransform.position.y + 10000, 0);
            Vector3    vDown  = Vector3.down;

            Vector2 heights;
            Vector3 normals;

            Color32[] colors = mapPixels;

            for (float xIndex = x; xIndex < x + sizeX; xIndex++)
            {
                for (float zIndex = z; zIndex < z + sizeZ; zIndex++)
                {
                    rayPos.x = (xIndex * resMultiplier) + managerTransform.position.x; // transform to world cords
                    rayPos.z = (zIndex * resMultiplier) + managerTransform.position.z; // transform to world cords

                    if (UNMapGenerators.GetMapHit(rayPos, vDown, out hit, Mathf.Infinity))
                    {
                        heights = NormalizeHeight(hit.point.y);
                        normals = UNMapGenerators.TransformNormals(hit.normal);

                        colors[(int)xIndex + (int)zIndex * mapWidth] = new Color32((byte)(normals.x * 255), (byte)(normals.y * 255), (byte)(heights.x), (byte)(heights.y));
                    }
                }
            }

            if (save)
            {
                SetPixels32(colors);
            }
            else
            {
                mapPixels = colors;
            }

            dirty = true;
        }