Ejemplo n.º 1
0
        public void GetSplatTextures()
        {
            if (!CheckValidUnityTerrain())
            {
                return;
            }
            splatPrototypes.Clear();

            for (int i = 0; i < terrain.terrainData.splatPrototypes.Length; i++)
            {
                SplatPrototype    s = terrain.terrainData.splatPrototypes[i];
                TC_SplatPrototype d = new TC_SplatPrototype();
                d.texture    = s.texture;
                d.normalMap  = s.normalMap;
                d.metallic   = s.metallic;
                d.smoothness = s.smoothness;
                d.tileOffset = s.tileOffset;
                d.tileSize   = s.tileSize;
                splatPrototypes.Add(d);
            }

            //if (splatColors == null) splatColors = new Color[splatPrototypes.Count];
            //if (splatColors.Length != splatPrototypes.Count) splatColors = new Color[splatPrototypes.Count];
            //Debug.Log("Getsplat texture colors");
            //for (int i = 0; i < splatColors.Length; i++)
            //{
            //    if (splatPrototypes[i].texture != null) splatColors[i] = GetTextureColor(splatPrototypes[i].texture, 1);
            //}
        }
Ejemplo n.º 2
0
 public void SwapSplatTexture(int index1, int index2)
 {
     if (index2 > -1 && index2 < splatPrototypes.Count)
     {
         TC_SplatPrototype splatPrototype2 = splatPrototypes[index1];
         splatPrototypes[index1] = splatPrototypes[index2];
         splatPrototypes[index2] = splatPrototype2;
     }
 }
Ejemplo n.º 3
0
        public void GetSplatTextures(TC_TerrainArea terrainArea)
        {
            if (!CheckValidUnityTerrain())
            {
                return;
            }
            splatPrototypes.Clear();

#if UNITY_5 || UNITY_2017 || UNITY_2018_1 || UNITY_2018_2
            SplatPrototype[] terrainSplatPrototypes = terrain.terrainData.splatPrototypes;
            for (int i = 0; i < terrainSplatPrototypes.Length; i++)
            {
                SplatPrototype    s = terrainSplatPrototypes[i];
                TC_SplatPrototype d = new TC_SplatPrototype();
                d.texture    = s.texture;
                d.normalMap  = s.normalMap;
                d.metallic   = s.metallic;
                d.smoothness = s.smoothness;
                d.tileOffset = s.tileOffset;
                d.tileSize   = s.tileSize;
                splatPrototypes.Add(d);
            }
#else
            TerrainLayer[] terrainLayers = terrain.terrainData.terrainLayers;
            if (terrainLayers == null)
            {
                return;
            }

            for (int i = 0; i < terrainLayers.Length; i++)
            {
                TerrainLayer s = terrainLayers[i];
                if (s == null)
                {
                    continue;
                }

                TC_SplatPrototype d = new TC_SplatPrototype();
                d.texture    = s.diffuseTexture;
                d.normalMap  = s.normalMapTexture;
                d.metallic   = s.metallic;
                d.smoothness = s.smoothness;
                d.tileOffset = s.tileOffset;
                d.tileSize   = s.tileSize;
                splatPrototypes.Add(d);
            }
#endif

            // if (splatColors == null) splatColors = new Color[splatPrototypes.Count];
            // if (splatColors.Length != splatPrototypes.Count) splatColors = new Color[splatPrototypes.Count];
            // Debug.Log("Getsplat texture colors");
            // for (int i = 0; i < splatColors.Length; i++)
            // {
            //     if (splatPrototypes[i].texture != null) splatColors[i] = GetTextureColor(splatPrototypes[i].texture, 1);
            // }
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 6
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
        }