Example #1
0
        public void InitConverter(TerrainLayerArrayConfig config)
        {
            InitParams();
            var terrain = GetComponent <Terrain>();

            ControlArray.Clear();
            ControlArray.AddRange(terrain.terrainData.alphamapTextures);

            DiffuseArray = config.DiffuseArrayConfig.TexArray;
            NormalArray  = config.NormalArrayConfig.TexArray;

            DiffuseIndexes.Clear();
            NormalIndexes.Clear();
            Tillings.Clear();
            NormalScales.Clear();
            for (int i = 0; i < terrain.terrainData.terrainLayers.Length; i++)
            {
                var layer = terrain.terrainData.terrainLayers[i];
                DiffuseIndexes.Add(config.DiffuseArrayConfig.IndexOfTexture(layer.diffuseTexture) + 1);
                NormalIndexes.Add(config.NormalArrayConfig.IndexOfTexture(layer.normalMapTexture) + 1);
                var tilling = new Vector4(terrain.terrainData.size.x / layer.tileSize.x, terrain.terrainData.size.z / layer.tileSize.y, layer.tileOffset.x / layer.tileSize.x, layer.tileOffset.y / layer.tileSize.y);
                Tillings.Add(tilling);
                NormalScales.Add(layer.normalScale);
            }
        }
Example #2
0
        public void Generate()
        {
            if (Config == null)
            {
                var scenePath = SceneManager.GetActiveScene().path;

                var path = EditorUtility.SaveFilePanel("Save Config", Path.GetDirectoryName(scenePath),
                                                       Path.GetFileNameWithoutExtension(scenePath), "asset");
                if (string.IsNullOrEmpty(path))
                {
                    return;
                }

                Config = ScriptableObject.CreateInstance <TerrainLayerArrayConfig>();
                path   = path.Substring(path.IndexOf("Assets/"));
                AssetDatabase.CreateAsset(Config, path);
            }

            Config.Layers.Clear();
            var terrains = GetComponentsInChildren <Terrain>();

            foreach (var terrain in terrains)
            {
                foreach (var layer in terrain.terrainData.terrainLayers)
                {
                    if (!Config.Layers.Contains(layer))
                    {
                        Config.Layers.Add(layer);
                    }
                }
            }

            Config.Generate();
            MarkSceneDirty();
        }
Example #3
0
        public static void GenerateConfig(TerrainLayerArrayConfig config)
        {
            FindOrCreateTextureConfigIfMissing(ref config.DiffuseArrayConfig, GetDiffuseConfigPath(config));
            FindOrCreateTextureConfigIfMissing(ref config.NormalArrayConfig, GetNormalConfigPath(config));

            config.DiffuseArrayConfig.Textures.Clear();
            config.NormalArrayConfig.Textures.Clear();
            foreach (var layer in config.Layers)
            {
                AddTextureToConfig(config.DiffuseArrayConfig, layer.diffuseTexture);
                AddTextureToConfig(config.NormalArrayConfig, layer.normalMapTexture);
            }

            config.DiffuseArrayConfig.UseFirstTextureSettings = config.UseFirstTextureSettings;
            config.DiffuseArrayConfig.IsLinear = false;
            config.NormalArrayConfig.UseFirstTextureSettings = config.UseFirstTextureSettings;
            config.NormalArrayConfig.IsLinear = true;

            config.DiffuseArrayConfig.Generate();
            config.NormalArrayConfig.Generate();

            EditorUtility.SetDirty(config);
            AssetDatabase.SaveAssets();
        }
Example #4
0
        public static string GetNormalConfigPath(TerrainLayerArrayConfig config)
        {
            var path = AssetDatabase.GetAssetPath(config);

            return($"{Path.GetDirectoryName(path)}/{Path.GetFileNameWithoutExtension(path)}_normal.asset");
        }