Exemplo n.º 1
0
        public static void AddCTSRuntimeWeatherToScene(MenuCommand menuCommand)
        {
            //Add a weather manager
            GameObject ctsWeatherManager = GameObject.Find("CTS Weather Manager");

            if (ctsWeatherManager == null)
            {
                ctsWeatherManager      = new GameObject();
                ctsWeatherManager.name = "CTS Weather Manager";
                ctsWeatherManager.AddComponent <CTSWeatherManager>();
                CompleteTerrainShader.SetDirty(ctsWeatherManager, false, false);
            }
            EditorGUIUtility.PingObject(ctsWeatherManager);

            //And now add weather controllers
            foreach (var terrain in Terrain.activeTerrains)
            {
                CompleteTerrainShader shader = terrain.gameObject.GetComponent <CompleteTerrainShader>();
                if (shader != null)
                {
                    CTSWeatherController controller = terrain.gameObject.GetComponent <CTSWeatherController>();
                    if (controller == null)
                    {
                        controller = terrain.gameObject.AddComponent <CTSWeatherController>();
                        CompleteTerrainShader.SetDirty(terrain, false, false);
                        CompleteTerrainShader.SetDirty(controller, false, false);
                    }
                }
            }
        }
        /// <summary>
        /// Add CTS to a specific terrain
        /// </summary>
        /// <param name="terrain">Terrain to be added to</param>
        public void AddCTSToTerrain(Terrain terrain)
        {
            if (terrain == null)
            {
                return;
            }
            CompleteTerrainShader shader = terrain.gameObject.GetComponent <CompleteTerrainShader>();

            if (shader == null)
            {
                shader = terrain.gameObject.AddComponent <CompleteTerrainShader>();
                CompleteTerrainShader.SetDirty(shader, false, false);
                CompleteTerrainShader.SetDirty(terrain, false, false);
                m_shaderList.Add(shader);
            }
            #if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                if (Terrain.activeTerrain != null)
                {
                    EditorGUIUtility.PingObject(Terrain.activeTerrain);
                }
            }
            #endif
        }
 /// <summary>
 /// Add CTS to all terrains
 /// </summary>
 public void AddCTSToAllTerrains()
 {
     m_shaderList.Clear();
     foreach (var terrain in Terrain.activeTerrains)
     {
         CompleteTerrainShader shader = terrain.gameObject.GetComponent <CompleteTerrainShader>();
         if (shader == null)
         {
             shader = terrain.gameObject.AddComponent <CompleteTerrainShader>();
             CompleteTerrainShader.SetDirty(shader, false, false);
             CompleteTerrainShader.SetDirty(terrain, false, false);
         }
         m_shaderList.Add(shader);
         m_lastShaderListUpdate = DateTime.Now;
     }
     #if UNITY_EDITOR
     //AssetDatabase.SaveAssets();
     if (!Application.isPlaying)
     {
         if (Terrain.activeTerrain != null)
         {
             EditorGUIUtility.PingObject(Terrain.activeTerrain);
         }
     }
     #endif
 }
 public void AddCTSToTerrain(Terrain terrain)
 {
     if (Object.op_Equality((Object)terrain, (Object)null) || !Object.op_Equality((Object)((Component)terrain).get_gameObject().GetComponent <CompleteTerrainShader>(), (Object)null))
     {
         return;
     }
     ((Component)terrain).get_gameObject().AddComponent <CompleteTerrainShader>();
     CompleteTerrainShader.SetDirty((Object)terrain, false, false);
 }
 public void AddCTSToAllTerrains()
 {
     foreach (Terrain activeTerrain in Terrain.get_activeTerrains())
     {
         if (Object.op_Equality((Object)((Component)activeTerrain).get_gameObject().GetComponent <CompleteTerrainShader>(), (Object)null))
         {
             ((Component)activeTerrain).get_gameObject().AddComponent <CompleteTerrainShader>();
             CompleteTerrainShader.SetDirty((Object)activeTerrain, false, false);
         }
     }
 }
Exemplo n.º 6
0
        public static void AddWorldAPIToScene(MenuCommand menuCommand)
        {
            //First - are we even here present
            Type worldAPIType = CompleteTerrainShader.GetType("WAPI.WorldManager");

            if (worldAPIType == null)
            {
                EditorUtility.DisplayDialog("World Manager API", "World Manager is not present in your project. Please go to http://www.procedural-worlds.com/blog/wapi/ to learn about it.", "OK");
                Application.OpenURL("http://www.procedural-worlds.com/blog/wapi/");
                Application.OpenURL("https://github.com/adamgoodrich/WorldManager");
                return;
            }

            //First add a weather manager
            GameObject ctsWeatherManager = GameObject.Find("CTS Weather Manager");

            if (ctsWeatherManager == null)
            {
                ctsWeatherManager      = new GameObject();
                ctsWeatherManager.name = "CTS Weather Manager";
                ctsWeatherManager.AddComponent <CTSWeatherManager>();
                CompleteTerrainShader.SetDirty(ctsWeatherManager, false, false);
            }
            EditorGUIUtility.PingObject(ctsWeatherManager);

            //And now add weather controllers
            foreach (var terrain in Terrain.activeTerrains)
            {
                CompleteTerrainShader shader = terrain.gameObject.GetComponent <CompleteTerrainShader>();
                if (shader != null)
                {
                    CTSWeatherController controller = terrain.gameObject.GetComponent <CTSWeatherController>();
                    if (controller == null)
                    {
                        controller = terrain.gameObject.AddComponent <CTSWeatherController>();
                        CompleteTerrainShader.SetDirty(terrain, false, false);
                        CompleteTerrainShader.SetDirty(controller, false, false);
                    }
                }
            }

            //And now add world API integration component to weather manager
            #if WORLDAPI_PRESENT
            var worldAPIIntegration = ctsWeatherManager.GetComponent <CTSWorldAPIIntegration>();
            if (worldAPIIntegration == null)
            {
                worldAPIIntegration = ctsWeatherManager.AddComponent <CTSWorldAPIIntegration>();
            }
            #endif
        }
Exemplo n.º 7
0
        public void ConstructTerrainReplacementNormals()
        {
            if (Application.get_isPlaying())
            {
                return;
            }
            while (this.m_replacementTerrainNormals.Count > this.m_terrainTextures.Count)
            {
                this.m_replacementTerrainNormals.RemoveAt(this.m_replacementTerrainNormals.Count - 1);
            }
            while (this.m_replacementTerrainNormals.Count < this.m_terrainTextures.Count)
            {
                this.m_replacementTerrainNormals.Add((Texture2D)null);
            }
            string path1 = this.m_ctsDirectory + "Terrains/ReplacementTextures/";

            Directory.CreateDirectory(path1);
            for (int index = 0; index < this.m_terrainTextures.Count; ++index)
            {
                CTSTerrainTextureDetails terrainTexture = this.m_terrainTextures[index];
                if (Object.op_Inequality((Object)terrainTexture.Normal, (Object)null))
                {
                    string path2 = path1 + ((Object)terrainTexture.Normal).get_name() + "_nrm_cts.png";
                    if (!File.Exists(path2))
                    {
                        Texture2D texture2D = CTSProfile.ResizeTexture(terrainTexture.Normal, this.m_normalFormat, this.m_normalAniso, 64, 64, false, true, false);
                        ((Object)texture2D).set_name(((Object)terrainTexture.Normal).get_name() + "_nrm_cts");
                        this.m_replacementTerrainNormals[index] = texture2D;
                        byte[] png = ImageConversion.EncodeToPNG(this.m_replacementTerrainNormals[index]);
                        File.WriteAllBytes(path2, png);
                    }
                }
                else
                {
                    this.m_replacementTerrainNormals[index] = (Texture2D)null;
                }
            }
            CompleteTerrainShader.SetDirty((Object)this, false, true);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Editor UX
        /// </summary>
        public override void OnInspectorGUI()
        {
            //Set the target
            m_shader = (CompleteTerrainShader)target;

            if (m_shader == null)
            {
                return;
            }

            #region Setup and introduction

            //Set up the box style
            if (m_boxStyle == null)
            {
                m_boxStyle = new GUIStyle(GUI.skin.box);
                m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
                m_boxStyle.fontStyle        = FontStyle.Bold;
                m_boxStyle.alignment        = TextAnchor.UpperLeft;
            }

            //Setup the wrap style
            if (m_wrapStyle == null)
            {
                m_wrapStyle           = new GUIStyle(GUI.skin.label);
                m_wrapStyle.fontStyle = FontStyle.Normal;
                m_wrapStyle.wordWrap  = true;
            }

            if (m_wrapHelpStyle == null)
            {
                m_wrapHelpStyle          = new GUIStyle(GUI.skin.label);
                m_wrapHelpStyle.richText = true;
                m_wrapHelpStyle.wordWrap = true;
            }

            //Text intro
            GUILayout.BeginVertical(string.Format("CTS ({0}.{1})", CTSConstants.MajorVersion, CTSConstants.MinorVersion), m_boxStyle);
            if (m_globalHelp)
            {
                Rect rect = EditorGUILayout.BeginVertical();
                rect.x      = rect.width - 10;
                rect.width  = 25;
                rect.height = 20;
                if (GUI.Button(rect, "?-"))
                {
                    m_globalHelp = !m_globalHelp;
                }
                EditorGUILayout.EndVertical();
            }
            else
            {
                Rect rect = EditorGUILayout.BeginVertical();
                //rect.y -= 10f;
                rect.x      = rect.width - 10;
                rect.width  = 25;
                rect.height = 20;
                if (GUI.Button(rect, "?+"))
                {
                    m_globalHelp = !m_globalHelp;
                }
                EditorGUILayout.EndVertical();
            }
            GUILayout.Space(20);
            EditorGUILayout.LabelField("Welcome to CTS. Click ? for help.", m_wrapStyle);
            DrawHelpSectionLabel("Overview");

            if (m_globalHelp)
            {
                if (GUILayout.Button(GetLabel("View Online Tutorials & Docs")))
                {
                    Application.OpenURL("http://www.procedural-worlds.com/cts/");
                }
            }

            GUILayout.EndVertical();
            #endregion

            //Monitor for changes
            EditorGUI.BeginChangeCheck();

            GUILayout.Space(5);

            GUILayout.BeginVertical(m_boxStyle);

            CTSProfile profile = (CTSProfile)EditorGUILayout.ObjectField(GetLabel("Profile"), m_shader.Profile, typeof(CTSProfile), false);
            DrawHelpLabel("Profile");

            EditorGUILayout.LabelField(GetLabel("Global NormalMap"));
            DrawHelpLabel("Global NormalMap");
            EditorGUI.indentLevel++;

            bool autobakeNormalMap = EditorGUILayout.Toggle(GetLabel("AutoBake"), m_shader.AutoBakeNormalMap);
            DrawHelpLabel("AutoBake");

            Texture2D globalNormal = (Texture2D)EditorGUILayout.ObjectField(GetLabel("Normal Map"), m_shader.NormalMap, typeof(Texture2D), false, GUILayout.Height(16f));
            DrawHelpLabel("NormalMap");

            EditorGUI.indentLevel--;

            EditorGUILayout.LabelField(GetLabel("Global ColorMap"));
            DrawHelpLabel("Global ColorMap");
            EditorGUI.indentLevel++;

            bool autobakeColorMap = EditorGUILayout.Toggle(GetLabel("AutoBake"), m_shader.AutoBakeColorMap);
            DrawHelpLabel("AutoBake");
            bool  autoBakeGrassIntoColorMap = m_shader.AutoBakeGrassIntoColorMap;
            float autoBakeGrassMixStrength  = m_shader.AutoBakeGrassMixStrength;
            float autoBakeGrassDarkenAmount = m_shader.AutoBakeGrassDarkenAmount;
            autoBakeGrassIntoColorMap = EditorGUILayout.Toggle(GetLabel("Bake Grass"), autoBakeGrassIntoColorMap);
            DrawHelpLabel("Bake Grass");
            if (autoBakeGrassIntoColorMap)
            {
                EditorGUI.indentLevel++;
                autoBakeGrassMixStrength = EditorGUILayout.Slider(GetLabel("Grass Strength"), autoBakeGrassMixStrength, 0f, 1f);
                DrawHelpLabel("Grass Strength");
                autoBakeGrassDarkenAmount = EditorGUILayout.Slider(GetLabel("Darken Strength"), autoBakeGrassDarkenAmount, 0f, 1f);
                DrawHelpLabel("Darken Strength");
                EditorGUI.indentLevel--;
            }

            Texture2D globalColorMap = (Texture2D)EditorGUILayout.ObjectField(GetLabel("Color Map"), m_shader.ColorMap, typeof(Texture2D), false, GUILayout.Height(16f));
            DrawHelpLabel("ColorMap");

            EditorGUI.indentLevel--;

            bool useCutout = EditorGUILayout.Toggle(GetLabel("Use Cutout"), m_shader.UseCutout);
            DrawHelpLabel("Use Cutout");
            float     heightCutout     = m_shader.CutoutHeight;
            Texture2D globalCutoutMask = m_shader.CutoutMask;
            if (useCutout)
            {
                EditorGUI.indentLevel++;
                heightCutout = EditorGUILayout.FloatField(GetLabel("Cutout Below"), heightCutout);
                DrawHelpLabel("Cutout Below");
                globalCutoutMask = (Texture2D)EditorGUILayout.ObjectField(GetLabel("Cutout Mask"), globalCutoutMask, typeof(Texture2D), false, GUILayout.Height(16f));
                DrawHelpLabel("Cutout Mask");
                EditorGUI.indentLevel--;
            }

            GUILayout.BeginHorizontal();
            if (GUILayout.Button(GetLabel("Bake NormalMap")))
            {
                m_shader.BakeTerrainNormals();
                globalNormal = m_shader.NormalMap;
            }
            if (GUILayout.Button(GetLabel("Bake ColorMap")))
            {
                if (!autoBakeGrassIntoColorMap)
                {
                    m_shader.BakeTerrainBaseMap();
                }
                else
                {
                    m_shader.BakeTerrainBaseMapWithGrass();
                }
                globalColorMap = m_shader.ColorMap;
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            GUILayout.Space(5);

            #region Handle changes

            //Check for changes, make undo record, make changes and let editor know we are dirty
            if (EditorGUI.EndChangeCheck())
            {
                CompleteTerrainShader.SetDirty(m_shader, false, false);
                m_shader.Profile                   = profile;
                m_shader.NormalMap                 = globalNormal;
                m_shader.AutoBakeNormalMap         = autobakeNormalMap;
                m_shader.ColorMap                  = globalColorMap;
                m_shader.AutoBakeColorMap          = autobakeColorMap;
                m_shader.AutoBakeGrassIntoColorMap = autoBakeGrassIntoColorMap;
                m_shader.AutoBakeGrassMixStrength  = autoBakeGrassMixStrength;
                m_shader.AutoBakeGrassDarkenAmount = autoBakeGrassDarkenAmount;
                m_shader.UseCutout                 = useCutout;
                m_shader.CutoutMask                = globalCutoutMask;
                m_shader.CutoutHeight              = heightCutout;
                m_shader.UpdateMaterialAndShader();
            }
            #endregion
        }
Exemplo n.º 9
0
        /// <summary>
        /// Editor UX
        /// </summary>
        public override void OnInspectorGUI()
        {
            #region Setup and introduction

            //Get the target
            m_manager = (CTSWeatherManager)target;

            //Set up the styles
            if (m_boxStyle == null)
            {
                m_boxStyle = new GUIStyle(GUI.skin.box);
                m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
                m_boxStyle.fontStyle        = FontStyle.Bold;
                m_boxStyle.alignment        = TextAnchor.UpperLeft;
            }

            if (m_wrapStyle == null)
            {
                m_wrapStyle           = new GUIStyle(GUI.skin.label);
                m_wrapStyle.fontStyle = FontStyle.Normal;
                m_wrapStyle.wordWrap  = true;
            }

            if (m_wrapHelpStyle == null)
            {
                m_wrapHelpStyle          = new GUIStyle(GUI.skin.label);
                m_wrapHelpStyle.richText = true;
                m_wrapHelpStyle.wordWrap = true;
            }

            //Text intro
            GUILayout.BeginVertical(string.Format("CTS ({0}.{1})", CTSConstants.MajorVersion, CTSConstants.MinorVersion), m_boxStyle);
            if (m_globalHelp)
            {
                Rect rect = EditorGUILayout.BeginVertical();
                //rect.y -= 10f;
                rect.x      = rect.width - 10;
                rect.width  = 25;
                rect.height = 20;
                if (GUI.Button(rect, "?-"))
                {
                    m_globalHelp = !m_globalHelp;
                }
                EditorGUILayout.EndVertical();
            }
            else
            {
                Rect rect = EditorGUILayout.BeginVertical();
                //rect.y -= 10f;
                rect.x      = rect.width - 10;
                rect.width  = 25;
                rect.height = 20;
                if (GUI.Button(rect, "?+"))
                {
                    m_globalHelp = !m_globalHelp;
                }
                EditorGUILayout.EndVertical();
            }

            GUILayout.Space(20);

            EditorGUILayout.LabelField("Welcome to CTS Weather Manager. Click ? for help.", m_wrapStyle);
            DrawHelpSectionLabel("Overview");

            if (m_globalHelp)
            {
                if (GUILayout.Button(GetLabel("View Online Tutorials & Docs")))
                {
                    Application.OpenURL("http://www.procedural-worlds.com/cts/");
                }
            }

            GUILayout.EndVertical();

            #endregion

            //Monitor for changes
            EditorGUI.BeginChangeCheck();

            GUILayout.BeginVertical("Control", m_boxStyle);
            GUILayout.Space(20f);
            DrawHelpSectionLabel("Control");


            GUILayout.BeginVertical(m_boxStyle);
            float rainPower = EditorGUILayout.Slider(GetLabel("Rain Power"), m_manager.RainPower, 0f, 1f);
            DrawHelpLabel("Rain Power");

            float snowPower = EditorGUILayout.Slider(GetLabel("Snow Power"), m_manager.SnowPower, 0f, 1f);
            DrawHelpLabel("Snow Power");

            float season = EditorGUILayout.Slider(GetLabel("Season"), m_manager.Season, 0f, 3.9999f);
            DrawHelpLabel("Season");

            EditorGUI.indentLevel++;
            if (season < 1f)
            {
                EditorGUILayout.LabelField(string.Format("{0:0}% Winter {1:0}% Spring", (1f - season) * 100f, season * 100f));
            }
            else if (season < 2f)
            {
                EditorGUILayout.LabelField(string.Format("{0:0}% Spring {1:0}% Summer", (2f - season) * 100f, (season - 1f) * 100f));
            }
            else if (season < 3f)
            {
                EditorGUILayout.LabelField(string.Format("{0:0}% Summer {1:0}% Autumn", (3f - season) * 100f, (season - 2f) * 100f));
            }
            else
            {
                EditorGUILayout.LabelField(string.Format("{0:0}% Autumn {1:0}% Winter", (4f - season) * 100f, (season - 3f) * 100f));
            }
            EditorGUI.indentLevel--;
            GUILayout.EndVertical();

            GUILayout.EndVertical();


            GUILayout.BeginVertical("Settings", m_boxStyle);
            GUILayout.Space(20f);
            DrawHelpSectionLabel("Settings");

            GUILayout.BeginVertical(m_boxStyle);
            float minSnowHeight = EditorGUILayout.FloatField(GetLabel("Min Snow Height"), m_manager.SnowMinHeight);
            DrawHelpLabel("Min Snow Height");

            float maxSmoothness = EditorGUILayout.Slider(GetLabel("Max Smoothness"), m_manager.MaxRainSmoothness, 0f, 30f);
            DrawHelpLabel("Max Smoothness");

            Color winterTint = EditorGUILayout.ColorField(GetLabel("Winter Tint"), m_manager.WinterTint, true, false, false, null);
            DrawHelpLabel("Winter Tint");

            Color springTint = EditorGUILayout.ColorField(GetLabel("Spring Tint"), m_manager.SpringTint, true, false, false, null);
            DrawHelpLabel("Spring Tint");

            Color summerTint = EditorGUILayout.ColorField(GetLabel("Summer Tint"), m_manager.SummerTint, true, false, false, null);
            DrawHelpLabel("Summer Tint");

            Color autumnTint = EditorGUILayout.ColorField(GetLabel("Autumn Tint"), m_manager.AutumnTint, true, false, false, null);
            DrawHelpLabel("Autumn Tint");

            GUILayout.EndVertical();

            GUILayout.EndVertical();

            //Handle changes
            if (EditorGUI.EndChangeCheck())
            {
                CompleteTerrainShader.SetDirty(m_manager, false, false);

                //UX Settings
                m_manager.SnowPower         = snowPower;
                m_manager.SnowMinHeight     = minSnowHeight;
                m_manager.RainPower         = rainPower;
                m_manager.Season            = season;
                m_manager.MaxRainSmoothness = maxSmoothness;
                m_manager.WinterTint        = winterTint;
                m_manager.SpringTint        = springTint;
                m_manager.SummerTint        = summerTint;
                m_manager.AutumnTint        = autumnTint;
            }
        }