Esempio n. 1
0
 public void ApplyResolutionTerrainAreas(TCUnityTerrain sTerrain)
 {
     for (int i = 0; i < terrainAreas.Length; i++)
     {
         terrainAreas[i].ApplyResolutionTerrainArea(sTerrain);
     }
 }
Esempio n. 2
0
        public void ApplyResolutionTerrain(TCUnityTerrain sTerrain)
        {
            SetTerrainResolutionFromList();
            if (!CheckValidUnityTerrain())
            {
                return;
            }

            //Debug.Log(sTerrain.heightmapResolution);
            //Debug.Log(sTerrain.splatmapResolution);
            //Debug.Log(sTerrain.detailResolution);
            //Debug.Log(sTerrain.detailResolutionPerPatch);
            //Debug.Log(sTerrain.basemapResolution);

            if (terrain.terrainData.heightmapResolution != sTerrain.heightmapResolution)
            {
                Vector3 oldSize = terrain.terrainData.size;
                terrain.terrainData.heightmapResolution = sTerrain.heightmapResolution;
                terrain.terrainData.size = oldSize;
            }
            if (terrain.terrainData.alphamapResolution != sTerrain.splatmapResolution)
            {
                terrain.terrainData.alphamapResolution = sTerrain.splatmapResolution;
            }
            if (terrain.terrainData.baseMapResolution != sTerrain.basemapResolution)
            {
                terrain.terrainData.baseMapResolution = sTerrain.basemapResolution;
            }

            if (terrain.terrainData.detailResolution != sTerrain.detailResolution || sTerrain.detailResolutionPerPatch != sTerrain.appliedResolutionPerPatch)
            {
                terrain.terrainData.SetDetailResolution(sTerrain.detailResolution, sTerrain.detailResolutionPerPatch);
                sTerrain.appliedResolutionPerPatch = sTerrain.detailResolutionPerPatch;
            }
        }
Esempio n. 3
0
 public void ApplySplatTexturesTerrainAreas(TCUnityTerrain sTerrain)
 {
     for (int i = 0; i < terrainAreas.Length; i++)
     {
         terrainAreas[i].ApplySplatTextures(sTerrain);
     }
 }
Esempio n. 4
0
 public void SetCurrentArea(TCUnityTerrain tcTerrain)
 {
     currentTerrain        = tcTerrain.terrain;
     currentTCUnityTerrain = tcTerrain;
     currentTCTerrain      = tcTerrain;
     currentTerrainArea    = terrainAreas[0];
 }
Esempio n. 5
0
        float SampleTerrainHeight(Vector3 pos)
        {
            TC_TerrainArea terrainArea = TC_Generate.instance.area2D.terrainAreas[0];

            for (int i = 0; i < terrainArea.terrains.Count; i++)
            {
                TCUnityTerrain tcTerrain = terrainArea.terrains[i];
                if (tcTerrain.terrain == null)
                {
                    continue;
                }
                if (tcTerrain.terrain.terrainData == null)
                {
                    continue;
                }

                Vector3 posTerrain  = tcTerrain.terrain.transform.position;
                Vector3 sizeTerrain = tcTerrain.terrain.terrainData.size;

                Rect rect = new Rect(posTerrain.x, posTerrain.z, sizeTerrain.x, sizeTerrain.z);

                if (rect.Contains(pos))
                {
                    return(tcTerrain.terrain.SampleHeight(pos));
                }
            }

            return(-1);
        }
Esempio n. 6
0
        public void ApplyTrees(TCUnityTerrain sTerrain = null)
        {
            if (!CheckValidUnityTerrain())
            {
                return;
            }
            if (sTerrain == null)
            {
                sTerrain = this;
            }

            if (sTerrain.treePrototypes.Count == 0)
            {
                ResetTrees();
            }

            List <TreePrototype> treePrototypesCleaned = new List <TreePrototype>();

            for (int i = 0; i < sTerrain.treePrototypes.Count; i++)
            {
                TC_TreePrototype s = sTerrain.treePrototypes[i];

                if (s.prefab == null)
                {
                    continue;
                }

                TreePrototype d = new TreePrototype();
                d.bendFactor = s.bendFactor;
                d.prefab     = s.prefab;
                treePrototypesCleaned.Add(d);
            }

            terrain.terrainData.treePrototypes = treePrototypesCleaned.ToArray();
        }
 public void ApplySplatTextures(TCUnityTerrain sTerrain)
 {
     for (int i = 0; i < terrains.Count; i++)
     {
         terrains[i].ApplySplatTextures(sTerrain);
     }
 }
Esempio n. 8
0
        public void ApplyGrass(TCUnityTerrain sTerrain = null)
        {
            if (!CheckValidUnityTerrain())
            {
                return;
            }
            if (sTerrain == null)
            {
                sTerrain = this;
            }

            CleanGrassPrototypes(sTerrain);

            List <DetailPrototype> detailPrototypesCleaned = new List <DetailPrototype>();
            float multi = sTerrain.grassScaleMulti;

            bool tooManyGrassMessage = false;

            for (int i = 0; i < sTerrain.detailPrototypes.Count; i++)
            {
                if (detailPrototypesCleaned.Count >= TC.grassLimit)
                {
                    tooManyGrassMessage = true; break;
                }

                TC_DetailPrototype s = sTerrain.detailPrototypes[i];
                DetailPrototype    d = new DetailPrototype();

                d.bendFactor   = s.bendFactor;
                d.dryColor     = s.dryColor;
                d.healthyColor = s.healthyColor;

                d.minHeight = s.minHeight * multi;
                d.maxHeight = s.maxHeight * multi;
                d.minWidth  = s.minWidth * multi;
                d.maxWidth  = s.maxWidth * multi;

                d.noiseSpread      = s.noiseSpread;
                d.usePrototypeMesh = s.usePrototypeMesh;
                d.prototype        = s.prototype;
                d.prototypeTexture = s.prototypeTexture;
                d.renderMode       = s.renderMode;
                TC.SetTextureReadWrite(d.prototypeTexture);
                detailPrototypesCleaned.Add(d);
            }

            if (tooManyGrassMessage)
            {
                TC.AddMessage("TC2 supports generating maximum " + TC.grassLimit + " grass textures."); Debug.Log("TC2 supports generating maximum " + TC.grassLimit + " grass textures.");
            }

            terrain.terrainData.detailPrototypes = detailPrototypesCleaned.ToArray();
        }
        public void ResetNeighbors()
        {
            for (int i = 0; i < terrains.Count; i++)
            {
                TCUnityTerrain t = terrains[i];
                if (!t.CheckValidUnityTerrain())
                {
                    continue;
                }

                t.terrain.SetNeighbors(null, null, null, null);
            }
        }
Esempio n. 10
0
 public void CleanSplatTextures(TCUnityTerrain sTerrain = null)
 {
     if (sTerrain == null)
     {
         sTerrain = this;
     }
     for (int i = 0; i < sTerrain.splatPrototypes.Count; i++)
     {
         if (sTerrain.splatPrototypes[i].texture == null)
         {
             sTerrain.EraseSplatTexture(i); --i;
         }
     }
 }
Esempio n. 11
0
        public void ResetNeighbors()
        {
#if UNITY_5 || UNITY_2017 || UNITY_2018_1 || UNITY_2018_2
            for (int i = 0; i < terrains.Count; i++)
            {
                TCUnityTerrain t = terrains[i];
                if (!t.CheckValidUnityTerrain())
                {
                    continue;
                }

                t.terrain.SetNeighbors(null, null, null, null);
            }
#endif
        }
Esempio n. 12
0
        public void CleanGrassPrototypes(TCUnityTerrain sTerrain)
        {
            if (sTerrain == null)
            {
                sTerrain = this;
            }

            for (int i = 0; i < sTerrain.detailPrototypes.Count; i++)
            {
                if (sTerrain.detailPrototypes[i].prototypeTexture == null && sTerrain.detailPrototypes[i].prototype == null)
                {
                    sTerrain.EraseDetailPrototype(i); --i;
                }
            }
        }
Esempio n. 13
0
        public void ApplySplatTextures(TCUnityTerrain sTerrain = null)
        {
            if (!CheckValidUnityTerrain())
            {
                return;
            }
            if (sTerrain == null)
            {
                sTerrain = this;
            }

            // CleanSplatTextures(sTerrain);

            List <SplatPrototype> splatPrototypesCleaned = new List <SplatPrototype>();
            bool tooManySplatsMessage = false;

            for (int i = 0; i < sTerrain.splatPrototypes.Count; i++)
            {
                if (splatPrototypesCleaned.Count >= TC.splatLimit)
                {
                    tooManySplatsMessage = true; break;
                }

                TC_SplatPrototype s = sTerrain.splatPrototypes[i];

                if (s.texture != null)
                {
                    SplatPrototype d = new SplatPrototype();
                    d.texture    = s.texture;
                    d.normalMap  = s.normalMap;
                    d.metallic   = s.metallic;
                    d.smoothness = s.smoothness;
                    d.tileOffset = s.tileOffset;
                    float tileSize = sTerrain.terrain.terrainData.size.x / Mathf.Round(sTerrain.terrain.terrainData.size.x / s.tileSize.x);
                    d.tileSize = new Vector2(tileSize, tileSize);

                    splatPrototypesCleaned.Add(d);
                    TC.SetTextureReadWrite(s.texture);
                }
            }

            if (tooManySplatsMessage)
            {
                TC.AddMessage("TC2 supports generating maximum " + TC.splatLimit + " splat textures."); Debug.Log("TC2 supports generating maximum " + TC.splatLimit + " splat textures.");
            }

            terrain.terrainData.splatPrototypes = splatPrototypesCleaned.ToArray();
        }
Esempio n. 14
0
        public void SetNeighbors()
        {
            for (int i = 0; i < terrains.Count; i++)
            {
                TCUnityTerrain t = terrains[i];
                if (!t.CheckValidUnityTerrain())
                {
                    continue;
                }

                Terrain top    = GetTerrainTile(t.tileX, t.tileZ + 1);
                Terrain right  = GetTerrainTile(t.tileX + 1, t.tileZ);
                Terrain bottom = GetTerrainTile(t.tileX, t.tileZ - 1);
                Terrain left   = GetTerrainTile(t.tileX - 1, t.tileZ);

                t.terrain.SetNeighbors(left, top, right, bottom);
            }
        }
Esempio n. 15
0
        public TCUnityTerrain CopyTerrain(TCUnityTerrain tcTerrain)
        {
            GameObject   go = new GameObject();
            SaveTemplate s  = go.AddComponent <SaveTemplate>();

            s.tcTerrain = tcTerrain;

            GameObject go2 = (GameObject)Instantiate(go);

            DestroyImmediate(go);
            s                     = go2.GetComponent <SaveTemplate>();
            tcTerrain             = s.tcTerrain;
            tcTerrain.rtHeight    = null;
            tcTerrain.texHeight   = null;
            tcTerrain.texColormap = null;
            DestroyImmediate(go2);

            return(tcTerrain);
        }
        void UpdateTerrainPositionsZ()
        {
            for (int i = 0; i < tcTerrains.Count; i++)
            {
                TCUnityTerrain tcTerrain = tcTerrains[i];
                Terrain        terrain   = tcTerrain.terrain;

                relativePos = mainCamera.position.z - initPos[i].z;
                newPos      = (Mathf.Round((relativePos - offset) / totalSize) * totalSize) + initPos[i].z;

                if (terrain.transform.position.z != newPos)
                {
                    if (newPos > terrain.transform.position.z)
                    {
                        tcTerrain.tileZ = terrainArea.tiles.y - 1;
                        for (int z = 1; z < terrainArea.tiles.y; z++)
                        {
                            terrainArea.GetTCUnityTerrainTile(tcTerrain.tileX, z).tileZ = z - 1;
                        }
                    }
                    else
                    {
                        tcTerrain.tileZ = 0;
                        for (int z = 0; z < terrainArea.tiles.y - 1; z++)
                        {
                            terrainArea.GetTCUnityTerrainTile(tcTerrain.tileX, z).tileZ = z + 1;
                        }
                    }

                    // terrain.gameObject.SetActive(false);
                    tcTerrain.newPos           = new Vector3(terrain.transform.position.x, terrain.transform.position.y, newPos);
                    tcTerrain.updateTerrainPos = true;
                    // terrains.Add(terrains[i]);
                    tcTerrain.active = true;
                    if (!taskList.Contains(tcTerrain))
                    {
                        taskList.Add(tcTerrain);
                    }
                }
            }
            oldPos.z = Mathf.Round(mainCamera.position.z / terrainSize) * terrainSize;
        }
Esempio n. 17
0
        public void ApplyGrass(TCUnityTerrain sTerrain = null)
        {
            if (!CheckValidUnityTerrain())
            {
                return;
            }
            if (sTerrain == null)
            {
                sTerrain = this;
            }

            CleanGrassPrototypes(sTerrain);

            List <DetailPrototype> DetailPrototypesCleaned = new List <DetailPrototype>();
            float multi = sTerrain.grassScaleMulti;

            for (int i = 0; i < sTerrain.detailPrototypes.Count; i++)
            {
                TC_DetailPrototype s = sTerrain.detailPrototypes[i];
                DetailPrototype    d = new DetailPrototype();

                d.bendFactor   = s.bendFactor;
                d.dryColor     = s.dryColor;
                d.healthyColor = s.healthyColor;

                d.minHeight = s.minHeight * multi;
                d.maxHeight = s.maxHeight * multi;
                d.minWidth  = s.minWidth * multi;
                d.maxWidth  = s.maxWidth * multi;

                d.noiseSpread      = s.noiseSpread;
                d.usePrototypeMesh = s.usePrototypeMesh;
                d.prototype        = s.prototype;
                d.prototypeTexture = s.prototypeTexture;
                d.renderMode       = s.renderMode;
                TC.SetTextureReadWrite(d.prototypeTexture);
                DetailPrototypesCleaned.Add(d);
            }

            terrain.terrainData.detailPrototypes = DetailPrototypesCleaned.ToArray();
        }
Esempio n. 18
0
        public void ApplyResolutionTerrainArea(TCUnityTerrain sTerrain)
        {
            for (int i = 0; i < terrains.Count; i++)
            {
                terrains[i].ApplyResolutionTerrain(sTerrain);
            }
            CalcTotalResolutions();

            if (sTerrain.heightmapResolution > 513)
            {
                TC.AddMessage("Heightmap resolution is higher than 513, keep in mind that Auto generate will be too slow to work in realtime.");
            }
            if (sTerrain.splatmapResolution > 1024)
            {
                TC.AddMessage("Splatmap resolution is higher than 1024, keep in mind that Auto generate will be too slow to work in realtime.");
            }
            if (sTerrain.detailResolution > 512)
            {
                TC.AddMessage("Grass resolution is higher than 513, keep in mind that Auto generate will be too slow to work in realtime.");
            }
        }
        void UpdateTerrainPositionsX()
        {
            for (int i = 0; i < tcTerrains.Count; i++)
            {
                TCUnityTerrain tcTerrain = tcTerrains[i];
                Terrain        terrain   = tcTerrain.terrain;

                relativePos = mainCamera.position.x - initPos[i].x;
                newPos      = (Mathf.Round((relativePos - offset) / totalSize) * totalSize) + initPos[i].x;

                if (terrain.transform.position.x != newPos)
                {
                    if (newPos > terrain.transform.position.x)
                    {
                        // Debug.Log("->");

                        // terrainArea.terrainArray[terrainArea.tiles.x - 1, tcTerrain.tileZ] =
                        // tcTerrain.tileX = terrainArea.tiles.x - 1;
                        // for (int x = 1; x < terrainArea.tiles.x; x++) terrainArea.GetTCUnityTerrainTile(x, tcTerrain.tileZ).tileX = x - 1;
                        // tcTerrains.RemoveAt(i);
                        // tcTerrains.Insert(i + 1, tcTerrain);
                    }
                    else
                    {
                        // Debug.Log("<-");
                        // tcTerrain.tileX = 0;
                        // for (int x = 0; x < terrainArea.tiles.x - 1; x++) terrainArea.GetTCUnityTerrainTile(x, tcTerrain.tileZ).tileX = x + 1;
                    }

                    // terrain.gameObject.SetActive(false);
                    tcTerrain.newPos           = new Vector3(newPos, terrain.transform.position.y, terrain.transform.position.z);
                    tcTerrain.updateTerrainPos = true;
                    // terrains.Add(terrains[i]);
                    tcTerrain.active = true;
                    taskList.Add(tcTerrain);
                }
            }

            oldPos.x = Mathf.Round(mainCamera.position.x / terrainSize) * terrainSize;
        }
Esempio n. 20
0
        public void ApplySplatTextures(TCUnityTerrain sTerrain = null)
        {
            if (!CheckValidUnityTerrain())
            {
                return;
            }
            if (sTerrain == null)
            {
                sTerrain = this;
            }

            // CleanSplatTextures(sTerrain);

            List <SplatPrototype> splatPrototypesCleaned = new List <SplatPrototype>();

            for (int i = 0; i < sTerrain.splatPrototypes.Count; i++)
            {
                TC_SplatPrototype s = sTerrain.splatPrototypes[i];

                if (s.texture != null)
                {
                    SplatPrototype d = new SplatPrototype();
                    d.texture    = s.texture;
                    d.normalMap  = s.normalMap;
                    d.metallic   = s.metallic;
                    d.smoothness = s.smoothness;
                    d.tileOffset = s.tileOffset;
                    float tileSize = sTerrain.terrain.terrainData.size.x / Mathf.Round(sTerrain.terrain.terrainData.size.x / s.tileSize.x);
                    d.tileSize = new Vector2(tileSize, tileSize);

                    splatPrototypesCleaned.Add(d);
                    TC.SetTextureReadWrite(s.texture);
                }
            }

            terrain.terrainData.splatPrototypes = splatPrototypesCleaned.ToArray();
        }
Esempio n. 21
0
        public bool SetCurrentArea(TCUnityTerrain tcTerrain, int outputId)
        {
            // Debug.Log(tcTerrain.terrain.name);
            Terrain terrain = currentTerrain = tcTerrain.terrain;

            currentTCUnityTerrain = tcTerrain;
            currentTCTerrain      = tcTerrain;
            currentTerrainArea    = terrainAreas[0];

            if (!currentTCUnityTerrain.active)
            {
                return(false);
            }

            intResolution = new Int2();
            Int2 resolution2 = new Int2();

            if (terrain.terrainData.heightmapResolution > 2049)
            {
                resExpandBorder     = 0;
                resExpandBorderSize = 0;
            }
            else
            {
                resExpandBorder     = Mathf.RoundToInt((terrain.terrainData.heightmapResolution - 1) * resExpandBorderPercentage);
                resExpandBorderSize = terrain.terrainData.size.x * resExpandBorderPercentage;
            }

            // Debug.Log(resExpandBorder);
            // Debug.Log(resExpandBorderSize);

            if (outputId == TC.heightOutput)
            {
                intResolution.x = intResolution.y = (terrain.terrainData.heightmapResolution) + (resExpandBorder * 2);
                resolution2     = new Int2(terrain.terrainData.heightmapResolution, terrain.terrainData.heightmapResolution);
            }
            else if (outputId == TC.splatOutput)
            {
                intResolution.x = intResolution.y = terrain.terrainData.alphamapResolution;
                resolution2     = intResolution;
                splatLength     = currentTerrain.terrainData.splatPrototypes.Length;
                splatmapLength  = currentTerrain.terrainData.alphamapTextures.Length;
            }
            else if (outputId == TC.treeOutput)
            {
                intResolution.x = intResolution.y = (int)(terrain.terrainData.size.x / terrainLayer.treeResolutionPM); resolution2 = intResolution;
            }
            else if (outputId == TC.grassOutput)
            {
                intResolution.x = intResolution.y = terrain.terrainData.detailResolution; resolution2 = intResolution;
            }
            else if (outputId == TC.objectOutput)
            {
                intResolution.x = intResolution.y = (int)(terrain.terrainData.size.x / terrainLayer.objectResolutionPM); resolution2 = intResolution;
                //if (false)
                //{
                //    area.center = new Vector2((int)terrainLayer.objectTransform.position.x, (int)terrainLayer.objectTransform.position.z);
                //    area.size = new Vector2(terrainLayer.objectResolutionPM, terrainLayer.objectResolutionPM);
                //    totalArea.position = area.position;
                //    totalArea.size = terrainLayer.objectAreaSize;
                //    resolutionPM = new Vector2(terrainLayer.objectAreaSize.x / (resolution2.x), terrainLayer.objectAreaSize.y / (resolution2.y));
                //}
            }
            else if (outputId == TC.colorOutput)
            {
                intResolution.x = intResolution.y = terrainLayer.colormapResolution; resolution2 = intResolution;
            }

            outputOffsetV2 = new Vector2(terrainLayer.layerGroups[outputId].t.position.x, terrainLayer.layerGroups[outputId].t.position.z);
            outputOffsetV3 = new Vector3(outputOffsetV2.x, 0, outputOffsetV2.y);

            resolution = intResolution.ToVector2();

            if (intResolution.x < TC_Settings.instance.previewResolution)
            {
                previewResolution = intResolution.x; TC_Reporter.Log("From " + TC_Settings.instance.previewResolution + " To " + previewResolution);
            }
            else
            {
                previewResolution = TC_Settings.instance.previewResolution;
            }

            resToPreview = new Vector2((previewResolution - 0) / (totalArea.width + 0), (previewResolution - 0) / (totalArea.height + 0));

            if (outputId == TC.heightOutput || outputId == TC.splatOutput)
            {
                resolutionPM = new Vector2(terrain.terrainData.size.x / (resolution2.x - 1), terrain.terrainData.size.z / (resolution2.y - 1));
            }
            else
            {
                resolutionPM = new Vector2(terrain.terrainData.size.x / (resolution2.x - 0), terrain.terrainData.size.z / (resolution2.y - 0));
            }

            // if (outputId == TC.objectOutput) Debug.Log(resolutionPM);

            // resolutionPM = new Vector2(terrain.terrainData.size.x / (resolution2.x - 1), terrain.terrainData.size.z / (resolution2.y - 1));

            if (outputId == TC.heightOutput)
            {
                // area = new Rect(terrain.transform.position.x - resolutionPM.x, terrain.transform.position.z - resolutionPM.y, intResolution.x - 0, intResolution.y - 0);
                area = new Rect(terrain.transform.position.x - (resolutionPM.x * resExpandBorder), terrain.transform.position.z - (resolutionPM.y * resExpandBorder), intResolution.x - 0, intResolution.y - 0);
            }
            else
            {
                // resolutionPM = new Vector2(terrain.terrainData.size.x / (resolution2.x), terrain.terrainData.size.z / (resolution2.y));
                Vector2 posSnap;
                posSnap.x = Mathw.Snap(terrain.transform.position.x, resolutionPM.x);
                posSnap.y = Mathw.Snap(terrain.transform.position.z, resolutionPM.y);

                if (outputId == TC.treeOutput || outputId == TC.objectOutput)
                {
                    // posSnap += resolutionPM / 2;
                }
                area = new Rect(posSnap.x, posSnap.y, intResolution.x, intResolution.y);

                snapOffsetUV    = (new Vector2(terrain.transform.position.x, terrain.transform.position.z) - posSnap);
                snapOffsetUV.x /= terrain.terrainData.size.x;
                snapOffsetUV.y /= terrain.terrainData.size.z;

                // Debug.Log(area);
            }

            bounds      = new Bounds(terrain.transform.position + terrain.terrainData.size / 2, terrain.terrainData.size);
            startPos    = new Vector3(area.xMin, terrain.transform.position.y, area.yMin);
            terrainSize = terrain.terrainData.size;

            return(true);
        }
Esempio n. 22
0
        public void ApplySplatTextures(TC_TerrainArea terrainArea, TCUnityTerrain sTerrain = null)
        {
            if (!CheckValidUnityTerrain())
            {
                return;
            }
            if (sTerrain == null)
            {
                sTerrain = this;
            }

            // CleanSplatTextures(sTerrain);

            #if UNITY_5 || UNITY_2017 || UNITY_2018_1 || UNITY_2018_2
            List <SplatPrototype> splatPrototypesCleaned = new List <SplatPrototype>();
            bool tooManySplatsMessage = false;

            for (int i = 0; i < sTerrain.splatPrototypes.Count; i++)
            {
                if (splatPrototypesCleaned.Count >= TC.splatLimit)
                {
                    tooManySplatsMessage = true; break;
                }

                TC_SplatPrototype s = sTerrain.splatPrototypes[i];

                if (s.texture != null)
                {
                    SplatPrototype d = new SplatPrototype();
                    d.texture    = s.texture;
                    d.normalMap  = s.normalMap;
                    d.metallic   = s.metallic;
                    d.smoothness = s.smoothness;
                    d.tileOffset = s.tileOffset;
                    float tileSize = sTerrain.terrain.terrainData.size.x / Mathf.Round(sTerrain.terrain.terrainData.size.x / s.tileSize.x);
                    d.tileSize = new Vector2(tileSize, tileSize);

                    splatPrototypesCleaned.Add(d);
                    TC.SetTextureReadWrite(s.texture);
                }
            }

            if (tooManySplatsMessage)
            {
                TC.AddMessage("TC2 supports generating maximum " + TC.splatLimit + " splat textures."); Debug.Log("TC2 supports generating maximum " + TC.splatLimit + " splat textures.");
            }


            terrain.terrainData.splatPrototypes = splatPrototypesCleaned.ToArray();
            #else
            List <TerrainLayer> splatPrototypesCleaned = new List <TerrainLayer>();
            bool tooManySplatsMessage = false;

            for (int i = 0; i < sTerrain.splatPrototypes.Count; i++)
            {
                if (splatPrototypesCleaned.Count >= TC.splatLimit)
                {
                    tooManySplatsMessage = true; break;
                }

                TC_SplatPrototype s = sTerrain.splatPrototypes[i];

                if (s.texture != null)
                {
                    TerrainLayer d = new TerrainLayer();
                    d.diffuseTexture   = s.texture;
                    d.normalMapTexture = s.normalMap;
                    d.normalScale      = s.normalScale;
                    d.metallic         = s.metallic;
                    d.smoothness       = s.smoothness;
                    d.tileOffset       = s.tileOffset;
                    float tileSize = sTerrain.terrain.terrainData.size.x / Mathf.Round(sTerrain.terrain.terrainData.size.x / s.tileSize.x);
                    d.tileSize = new Vector2(tileSize, tileSize);

                    splatPrototypesCleaned.Add(d);
                    TC.SetTextureReadWrite(s.texture);
                }
            }

            if (tooManySplatsMessage)
            {
                TC.AddMessage("TC2 supports generating maximum " + TC.splatLimit + " splat textures."); Debug.Log("TC2 supports generating maximum " + TC.splatLimit + " splat textures.");
            }

            TerrainLayer[] newTerrainLayers = splatPrototypesCleaned.ToArray();

                #if UNITY_EDITOR
            string terrainPath = "Assets" + terrainArea.terrainDataPath.Replace(Application.dataPath, String.Empty);

            for (int i = 0; i < newTerrainLayers.Length; i++)
            {
                string path;
                if (terrainArea.useSameTerrainLayersForAllTerrains)
                {
                    path = terrainPath + "/" + terrainArea.terrainName + "_TerrainLayer_" + i + ".asset";
                }
                else
                {
                    path = terrainPath + "/" + terrain.name + "_TerrainLayer_" + i + ".asset";
                }

                TerrainLayer terrainLayer = UnityEditor.AssetDatabase.LoadAssetAtPath(path, typeof(TerrainLayer)) as TerrainLayer;

                if (terrainLayer == null)
                {
                    UnityEditor.AssetDatabase.DeleteAsset(path);
                    UnityEditor.AssetDatabase.CreateAsset(newTerrainLayers[i], path);
                }
                else
                {
                    CopyTerrainLayer(newTerrainLayers[i], terrainLayer);
                    newTerrainLayers[i] = terrainLayer;
                }
            }
                #endif

            terrain.terrainData.terrainLayers = newTerrainLayers;
                #endif
        }
Esempio n. 23
0
 public void ApplyAllSettings(TCUnityTerrain terrain, bool settingsEditor)
 {
     ApplyResolutionTerrain(terrain);
     ApplySettings(terrain, settingsEditor);
 }
Esempio n. 24
0
        public void ApplySettings(TCUnityTerrain sTerrain, bool settingsEditor)
        {
            if (!CheckValidUnityTerrain())
            {
                return;
            }

            terrain.drawHeightmap = sTerrain.drawHeightmap;
            #if UNITY_EDITOR
            terrain.bakeLightProbesForTrees = sTerrain.bakeLightProbesForTrees;
            #endif
            terrain.collectDetailPatches = sTerrain.collectDetailPatches;
            terrain.legacyShininess      = sTerrain.legacyShininess;
            terrain.legacySpecular       = sTerrain.legacySpecular;
            terrain.reflectionProbeUsage = sTerrain.reflectionProbeUsage;
            terrain.materialType         = sTerrain.materialType;
            // terrain.materialTemplate = sTerrain.materialTemplate;
            terrain.terrainData.thickness           = sTerrain.thickness;
            terrain.basemapDistance                 = sTerrain.basemapDistance;
            terrain.castShadows                     = sTerrain.castShadows;
            terrain.treeCrossFadeLength             = sTerrain.treeCrossFadeLength;
            terrain.terrainData.wavingGrassSpeed    = sTerrain.wavingGrassSpeed;
            terrain.terrainData.wavingGrassAmount   = sTerrain.wavingGrassAmount;
            terrain.terrainData.wavingGrassStrength = sTerrain.wavingGrassStrength;
            terrain.terrainData.wavingGrassTint     = sTerrain.wavingGrassTint;

            if (settingsEditor)
            {
                terrain.drawTreesAndFoliage = sTerrain.drawTreesAndFoliage;

                terrain.heightmapPixelError = sTerrain.heightmapPixelError;
                terrain.heightmapMaximumLOD = sTerrain.heightmapMaximumLOD;

                terrain.detailObjectDistance    = sTerrain.detailObjectDistance;
                terrain.detailObjectDensity     = sTerrain.detailObjectDensity;
                terrain.treeDistance            = sTerrain.treeDistance;
                terrain.treeBillboardDistance   = sTerrain.treeBillboardDistance;
                terrain.treeMaximumFullLODCount = sTerrain.treeMaximumFullLODCount;
            }
            else
            {
                if (terrainSettingsScript == null)
                {
                    terrainSettingsScript = terrain.gameObject.GetComponent <TC_TerrainSettings>();

                    if (terrainSettingsScript == null)
                    {
                        terrainSettingsScript = terrain.gameObject.AddComponent <TC_TerrainSettings>();
                    }
                }

                terrainSettingsScript.heightmapPixelError     = sTerrain.heightmapPixelError;
                terrainSettingsScript.heightmapMaximumLOD     = sTerrain.heightmapMaximumLOD;
                terrainSettingsScript.drawTreesAndFoliage     = sTerrain.drawTreesAndFoliage;
                terrainSettingsScript.treeDistance            = sTerrain.treeDistance;
                terrainSettingsScript.detailObjectDistance    = sTerrain.detailObjectDistance;
                terrainSettingsScript.detailObjectDensity     = sTerrain.detailObjectDensity;
                terrainSettingsScript.treeBillboardDistance   = sTerrain.treeBillboardDistance;
                terrainSettingsScript.treeMaximumFullLODCount = sTerrain.treeMaximumFullLODCount;
            }
        }