void DestroyMe()
        {
            // Debug.Log("Destroy RawImage");
            TC_Settings settings = TC_Settings.instance;

            if (settings == null)
            {
                return;
            }
            if (settings.rawFiles == null)
            {
                return;
            }

            int index = settings.rawFiles.IndexOf(this);

            if (index != -1)
            {
                settings.rawFiles.RemoveAt(index);
            }

                        #if UNITY_EDITOR
            UnityEditor.Undo.DestroyObjectImmediate(gameObject);
                        #else
            Destroy(gameObject);
                        #endif
        }
        public void SetPreviewSplatTexture()
        {
            TC_Settings localSettings = TC_Settings.instance;

            if (localSettings.hasMasterTerrain)
            {
                Texture2D splatTexture;
                int       length = TC.GetTerrainSplatTexture(localSettings.masterTerrain, selectIndex, out splatTexture);

                if (selectIndex < length && selectIndex >= 0)
                {
                    preview.tex = splatTexture;
                    if (preview.tex != null)
                    {
                        name = Mathw.CutString(preview.tex.name, TC.nodeLabelLength);
                    }
                }
                else
                {
                    active = false;
                }
            }
            else
            {
                preview.tex = null;
            }
        }
Exemple #3
0
        static public void DebugMode()
        {
            TC_Settings settings = TC_Settings.instance;

            if (settings.debugMode)
            {
                TC_Reporter.instance.gameObject.hideFlags           = HideFlags.None;
                TC_Generate.instance.gameObject.hideFlags           = HideFlags.None;
                TC_Area2D.current.terrainLayer.gameObject.hideFlags = HideFlags.None;
            }
            else
            {
                TC_Reporter.instance.gameObject.hideFlags = HideFlags.HideInHierarchy;
                TC_Generate.instance.gameObject.hideFlags = HideFlags.HideInHierarchy;
                if (settings.hideTerrainGroup)
                {
                    TC_Area2D.current.terrainLayer.gameObject.hideFlags = HideFlags.HideInHierarchy;
                }
                else
                {
                    TC_Area2D.current.terrainLayer.gameObject.hideFlags = HideFlags.None;
                }
            }

            EditorApplication.RepaintHierarchyWindow();
        }
Exemple #4
0
        void Save()
        {
            TC_Settings settings = TC_Settings.instance;

            string folder = settings.lastPath;

            if (!folder.Contains(Application.dataPath))
            {
                folder = "";
            }
            if (folder == "")
            {
                folder = Application.dataPath + (TC.installPath.Replace("/Assets", "/")) + "/Examples/Presets/TerrainLayer";
            }

            string path = EditorUtility.SaveFilePanel("Save TerrainComposer2 project", folder, "TerrainLayer", "prefab");

            if (path.Length != 0)
            {
                settings.lastPath = TC.GetPath(path);

                string filePath = TC.GetAssetDatabasePath(path);

                if (filePath != "")
                {
                    PrefabUtility.CreatePrefab(filePath, TC_Area2D.current.terrainLayer.gameObject);;
                }
                else
                {
                    TC.AddMessage("Can't find path.");
                }
            }
        }
Exemple #5
0
        public void SetPreviewGrassTexture()
        {
            TC_Settings localSettings = TC_Settings.instance;

            if (localSettings.hasMasterTerrain)
            {
                if (selectIndex < localSettings.masterTerrain.terrainData.detailPrototypes.Length && selectIndex >= 0)
                {
                    DetailPrototype detailPrototype = localSettings.masterTerrain.terrainData.detailPrototypes[selectIndex];
                    if (detailPrototype.usePrototypeMesh)
                    {
                        #if UNITY_EDITOR
                        preview.tex = UnityEditor.AssetPreview.GetAssetPreview(detailPrototype.prototype);
                        #endif
                    }
                    else
                    {
                        preview.tex = detailPrototype.prototypeTexture;
                    }
                    if (preview.tex != null)
                    {
                        name = Mathw.CutString(preview.tex.name, TC.nodeLabelLength);
                    }
                }
                else
                {
                    active = false;
                }
            }
            else
            {
                preview.tex = null;
            }
        }
Exemple #6
0
        void DestroyMe()
        {
            TC_Settings settings = TC_Settings.instance;

            if (settings == null)
            {
                return;
            }
            if (settings.imageList == null)
            {
                return;
            }

            int index = settings.imageList.IndexOf(this);

            if (index != -1)
            {
                settings.imageList.RemoveAt(index);
            }

            TC_Compute.DisposeRenderTexture(ref rt);

            #if UNITY_EDITOR
            UnityEditor.Undo.DestroyObjectImmediate(gameObject);
            #else
            Destroy(gameObject);
            #endif
        }
        public void SetPreviewTreeTexture()
        {
            #if UNITY_EDITOR
            TC_Settings settings = TC_Settings.instance;

            if (settings.hasMasterTerrain)
            {
                TreePrototype[] treePrototypes = settings.masterTerrain.terrainData.treePrototypes;
                if (selectIndex < treePrototypes.Length && selectIndex >= 0)
                {
                    if (treePrototypes[selectIndex].prefab)
                    {
                        preview.tex = UnityEditor.AssetPreview.GetAssetPreview(treePrototypes[selectIndex].prefab);
                        name        = Mathw.CutString(treePrototypes[selectIndex].prefab.name, TC.nodeLabelLength);
                    }
                }
                else
                {
                    active = false;
                }
            }
            else
            {
                preview.tex = null;
            }
            #endif
        }
Exemple #8
0
 void Awake()
 {
     instance = this;
     if (exportPath == "")
     {
         exportPath = Application.dataPath;
     }
 }
Exemple #9
0
 void OnEnable()
 {
     instance = this;
     if (transform.parent != null)
     {
         transform.parent.hideFlags = HideFlags.NotEditable;
     }
 }
 public virtual void OnEnable()
 {
     // preview.Create(128);
     if (TC_Settings.instance == null)
     {
         TC_Settings.GetInstance();
     }
 }
Exemple #11
0
 static public void GetInstance()
 {
     GameObject go = GameObject.Find("Settings");
     if (go != null)
     {
         instance = go.GetComponent<TC_Settings>();
     }
 }
Exemple #12
0
        void Open()
        {
            TC_Settings settings = TC_Settings.instance;

            string folder = settings.lastPath;

            if (!folder.Contains(Application.dataPath))
            {
                folder = "";
            }
            if (folder == "")
            {
                folder = Application.dataPath + TC.installPath.Replace("Assets", "") + "/Examples/Presets/TerrainLayer";
            }

            string path = EditorUtility.OpenFilePanel("Open TerrainComposer2 project", folder, "prefab");

            if (path.Length != 0)
            {
                settings.lastPath = TC.GetPath(path);

                string filePath = TC.GetAssetDatabasePath(path);

                if (TC.FileExists(filePath))
                {
                    GameObject go = Instantiate(AssetDatabase.LoadAssetAtPath(filePath, typeof(GameObject))) as GameObject;
                    if (go != null)
                    {
                        go.transform.hideFlags = HideFlags.HideInInspector;
                        TC_TerrainLayer terrainLayer = go.GetComponent <TC_TerrainLayer>();
                        if (terrainLayer != null)
                        {
                            go.transform.parent = TC_Generate.instance.transform.parent;
                            DestroyImmediate(TC_Area2D.current.terrainLayer.gameObject);
                            TC_Area2D.current.terrainLayer = terrainLayer;
                            DebugMode();
                            TC.AddMessage(TC.GetFileName(path) + " is loaded succesfully.");
                        }
                        else
                        {
                            TC.AddMessage("This is not a TerrainLayer prefab.");
                            DestroyImmediate(go);
                        }
                    }
                }
                else
                {
                    TC.AddMessage("Can't find path.");
                }
            }
        }
Exemple #13
0
        static public void MoveToDustbin(Transform t)
        {
            TC_Settings settings = TC_Settings.instance;

            if (settings.dustbinT == null)
            {
                settings.CreateDustbin();
            }

            t.parent = settings.dustbinT;

            AddMessage(t.name + " is not compatible with the hierarchy of TerrainComposer\n It is moved to the 'Dustbin' GameObject.", 0);
            AddMessage("If you pressed the delete key you can undo it with control-z", 3);
        }
Exemple #14
0
        static public bool LoadGlobalSettings()
        {
#if UNITY_EDITOR
            string file = Application.dataPath.Replace("Assets", "") + installPath + "/Defaults/";
            if (!FileExists(file + "TC_GlobalSettings.asset"))
            {
                UnityEditor.FileUtil.CopyFileOrDirectory(file + "TC_GlobalSettingsDefault.asset", file + "TC_GlobalSettings.asset");
                UnityEditor.AssetDatabase.Refresh();
            }

            GameObject go = GameObject.Find("TerrainComposer2");

            Transform settingsT = go.transform.Find("Settings");
            if (settingsT != null)
            {
                TC_Settings settings = settingsT.GetComponent <TC_Settings>();

                if (settings != null)
                {
                    settings.global = UnityEditor.AssetDatabase.LoadAssetAtPath(installPath + "/Defaults/TC_GlobalSettings.asset", typeof(TC_GlobalSettings)) as TC_GlobalSettings;
                    if (settings.global == null)
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
#endif
            return(true);
        }
Exemple #15
0
        public void SetPreviewSplatTexture()
        {
            TC_Settings localSettings = TC_Settings.instance;

            if (localSettings.hasMasterTerrain)
            {
                if (selectIndex < localSettings.masterTerrain.terrainData.splatPrototypes.Length && selectIndex >= 0)
                {
                    preview.tex = localSettings.masterTerrain.terrainData.splatPrototypes[selectIndex].texture;
                    if (preview.tex != null)
                    {
                        name = Mathw.CutString(preview.tex.name, TC.nodeLabelLength);
                    }
                }
                else
                {
                    active = false;
                }
            }
            else
            {
                preview.tex = null;
            }
        }
Exemple #16
0
        public int GetItemTotalFromTerrain()
        {
            TC_Settings localSettings = TC_Settings.instance;

            if (!localSettings.hasMasterTerrain)
            {
                return(0);
            }

            if (outputId == TC.splatOutput)
            {
                return(localSettings.masterTerrain.terrainData.splatPrototypes.Length);
            }
            if (outputId == TC.grassOutput)
            {
                return(localSettings.masterTerrain.terrainData.detailPrototypes.Length);
            }
            if (outputId == TC.treeOutput)
            {
                return(localSettings.masterTerrain.terrainData.treePrototypes.Length);
            }

            return(0);
        }
Exemple #17
0
 void OnDestroy()
 {
     TC_Reporter.Log("OnDestroy");
     instance = null;
 }
Exemple #18
0
        void DrawMenu()
        {
            TC_Settings settings = TC_Settings.instance;
            float       width    = 55;

            EditorGUILayout.BeginHorizontal();
            if (!TC_Settings.instance.hideMenuBar)
            {
                GUILayout.Space(2);
                if (GUILayout.Button("File", EditorStyles.miniButtonMid, GUILayout.Width(width)))
                {
                    GenericMenu menu = new GenericMenu();
                    DrawFile(menu, false);
                    menu.DropDown(new Rect(1, 17, 1, 1));
                }
                if (GUILayout.Button("Options", EditorStyles.miniButtonMid, GUILayout.Width(width)))
                {
                    GenericMenu menu = new GenericMenu();
                    DrawOptions(menu, false);
                    menu.DropDown(new Rect(1 + width, 17, 1, 1));
                }
                if (GUILayout.Button("Help", EditorStyles.miniButtonMid, GUILayout.Width(width)))
                {
                    GenericMenu menu = new GenericMenu();
                    DrawHelp(menu, false);
                    menu.DropDown(new Rect(1 + width * 2, 17, 1, 1));
                }

                GUILayout.Space(Screen.width - 540 - (width + 5));
            }
            else
            {
                GUILayout.Space(Screen.width - 536 - (width + 5));
            }

            GUI.changed = false;
            float labelWidthOld = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 45;
            settings.seed = EditorGUILayout.FloatField("Seed", settings.seed, GUILayout.Width(100));
            if (GUI.changed)
            {
                EditorUtility.SetDirty(settings);
                TC.AutoGenerate();
            }
            EditorGUIUtility.labelWidth = labelWidthOld;

            for (int i = 0; i < 6; i++)
            {
                TC_LayerGroup layerGroup = terrainLayer.layerGroups[i];
                if (layerGroup == null)
                {
                    break;
                }
                if (layerGroup.visible)
                {
                    if (layerGroup.active)
                    {
                        GUI.backgroundColor = Color.green;
                    }
                    else
                    {
                        GUI.backgroundColor = Color.red;
                    }
                }
                if (GUILayout.Button(TC.outputNames[i][0].ToString(), EditorStyles.miniButtonMid, GUILayout.Width(25)))
                {
                    if (eventCurrent.control)
                    {
                        settings.scrollOffset = -layerGroup.nodePos;
                    }
                    else
                    {
                        TD.ClickOutputButton(layerGroup);
                    }
                }
                GUI.backgroundColor = Color.white;
            }
            GUILayout.Space(5);

            if (GUILayout.Button("Generate", EditorStyles.miniButtonMid, GUILayout.Width(width + 5)))
            {
                ClickMenuMain("Generate");
            }
            if (TC_Generate.instance.autoGenerate)
            {
                GUI.backgroundColor = Color.green;
            }
            else if (TC.autoGenerateCallTimeStart + 0.05f > Time.realtimeSinceStartup)
            {
                GUI.backgroundColor = Color.red;
            }
            if (GUILayout.Button("Auto", EditorStyles.miniButtonMid, GUILayout.Width(width)))
            {
                ClickMenuMain("Auto Generate");
            }
            GUI.backgroundColor = Color.white;

            if (GUILayout.Button("Refresh", EditorStyles.miniButtonMid, GUILayout.Width(width)))
            {
                ClickMenuMain("Refresh");
            }

            EditorGUILayout.EndHorizontal();
        }
Exemple #19
0
        void OnGUI()
        {
            ShowMessages();

            if (correctSetup == -1)
            {
                TC.AddMessage("Close and re-open the TerrainComposer window.");
                return;
            }

            if (correctSetup == -2)
            {
                TC.AddMessage("Can't load default project.\nThis file is needed -> TerrainComposer2/Defaults/TerrainComposer2.prefab.\n\n Please try to close and re-open the TerrainComposer window.");
                return;
            }

            if (correctSetup != 0)
            {
                return;
            }

            if (!TD.Init())
            {
                return;
            }

            settings = TC_Settings.instance;
            TC_Reporter.BenchmarkStart();

            TD.countDrawNode = TD.countDrawNodeCulled = 0;

            TD.hoverItem = null;

            TD.rectWindow = new Rect(0, 0, TC_NodeWindow.window.position.width, TC_NodeWindow.window.position.height);

            settings.selectionOld = Selection.activeTransform;

            if (terrainLayer == null)
            {
                GetLayerLevel();
            }

            Keys();
            ScrollInterface();

            TD.eventCurrent = eventCurrent;

            GUI.DrawTexture(new Rect(0, 0, TC_NodeWindow.window.position.width, TC_NodeWindow.window.position.height), TD.texShelfBackground1);

            settings.HasMasterTerrain();

            TD.showSelectRect = false;

            CaptureWindowEvents();

            TD.scrollMax = Vector2.zero;

            TC_TerrainLayerGUI.Draw(terrainLayer);
            DrawCommand.DrawCommandLists();

            TC_ItemBehaviourEditor.CheckKeyLockOnSelection(eventCurrent);

            TD.DrawCenter(Color.red, 21, 1);
            TD.DrawCenter(Color.red, 11, 3);

            DrawMenu();

            DropDownMenuMain();

            if (settings.showFps)
            {
                if (!EditorGUIUtility.isProSkin)
                {
                    GUI.color = new Color(1, 1, 1, 0.5f);
                    GUI.DrawTexture(new Rect(180, 0, 250, 17), Texture2D.whiteTexture);
                    GUI.color = Color.white;
                }
                string fps = TC_Reporter.BenchmarkStop("| fps ", false);
                EditorGUI.LabelField(new Rect((TC_NodeWindow.window.position.width / 2) - 200, 0, 250, 17), "Node Draw " + TD.countDrawNode + "| Nodes Culled " + TD.countDrawNodeCulled + fps);
            }

            //if (onFocus && correctSetup == 0 && ++frame == 20)
            //{
            //    frame = 0;
            //    Repaint();
            //}
        }
Exemple #20
0
        void DrawMenu()
        {
            TC_Settings settings = TC_Settings.instance;
            float       width    = 55;

            GUI.color = EditorGUIUtility.isProSkin ? new Color(0.2f, 0.2f, 0.2f) : new Color(0.5f, 0.5f, 0.5f);

            GUI.DrawTexture(new Rect(0, 0, TC_NodeWindow.window.position.width, 20), Texture2D.whiteTexture);
            GUI.color = Color.white;

            EditorGUILayout.BeginHorizontal();
            if (!TC_Settings.instance.hideMenuBar)
            {
                GUILayout.Space(2);
                if (GUILayout.Button("File", EditorStyles.miniButtonMid, GUILayout.Width(width)))
                {
                    GenericMenu menu = new GenericMenu();
                    DrawFile(menu, false);
                    menu.DropDown(new Rect(1, 17, 1, 1));
                }
                if (GUILayout.Button("Options", EditorStyles.miniButtonMid, GUILayout.Width(width)))
                {
                    GenericMenu menu = new GenericMenu();
                    DrawOptions(menu, false);
                    menu.DropDown(new Rect(1 + width, 17, 1, 1));
                }
                if (GUILayout.Button("Help", EditorStyles.miniButtonMid, GUILayout.Width(width)))
                {
                    GenericMenu menu = new GenericMenu();
                    DrawHelp(menu, false);
                    menu.DropDown(new Rect(1 + width * 2, 17, 1, 1));
                }
                if (!TC_Settings.instance.global.documentationClicked)
                {
                    GUI.color = new Color(Mathf.Abs(Mathf.Sin(Time.realtimeSinceStartup)), Mathf.Abs(Mathf.Cos(Time.realtimeSinceStartup)), 0);
                }
                else
                {
                    GUI.color = Color.white;
                }

                if (GUILayout.Button("Documentation", EditorStyles.miniButtonMid, GUILayout.Width(width + 40)))
                {
                    if (Event.current.shift)
                    {
                        TC_Settings.instance.global.documentationClicked = false;
                    }
                    else
                    {
                        TC_Settings.instance.global.documentationClicked = true;
                        Application.OpenURL("http://www.terraincomposer.com/terraincomposer2-documentation/");
                    }
                }
                GUI.color = Color.white;

                GUILayout.Space(TC_NodeWindow.window.position.width - 620 - ((width * 2) + 45));
            }
            else
            {
                GUILayout.Space(TC_NodeWindow.window.position.width - 449 - (width + 5));
            }

            GUI.changed = false;
            float labelWidthOld = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 45;
            settings.seed = EditorGUILayout.FloatField("Seed", settings.seed, GUILayout.Width(100));
            if (GUILayout.Button("Random", EditorStyles.miniButtonMid, GUILayout.Width(50)))
            {
                if (eventCurrent.control)
                {
                    TC_Settings.instance.seed = 0;
                }
                else
                {
                    float oldSeed;
                    do
                    {
                        oldSeed = TC_Settings.instance.seed;
                        TC_Settings.instance.seed = Random.Range(-20000.0f, 20000.0f);
                    }while (oldSeed == TC_Settings.instance.seed);
                }
                GUI.changed = true;
            }
            if (GUI.changed)
            {
                EditorUtility.SetDirty(settings);
                TC.AutoGenerate();
            }
            GUILayout.Space(20);
            EditorGUIUtility.labelWidth = labelWidthOld;

            for (int i = 0; i < 6; i++)
            {
                TC_LayerGroup layerGroup = terrainLayer.layerGroups[i];
                if (layerGroup == null)
                {
                    break;
                }
                if (layerGroup.visible)
                {
                    if (layerGroup.active)
                    {
                        GUI.backgroundColor = Color.green;
                    }
                    else
                    {
                        GUI.backgroundColor = Color.red;
                    }
                }
                if (GUILayout.Button(TC.outputNames[i][0].ToString(), EditorStyles.miniButtonMid, GUILayout.Width(25)))
                {
                    if (eventCurrent.control)
                    {
                        settings.scrollOffset = -layerGroup.nodePos;
                    }
                    else
                    {
                        TD.ClickOutputButton(layerGroup);
                    }
                }
                GUI.backgroundColor = Color.white;
            }
            GUILayout.Space(5);

            if (GUILayout.Button("Generate", EditorStyles.miniButtonMid, GUILayout.Width(width + 5)))
            {
                ClickMenuMain("Generate");
            }
            if (TC_Generate.instance.autoGenerate)
            {
                GUI.backgroundColor = Color.green;
            }
            else if (TC.autoGenerateCallTimeStart + 0.05f > Time.realtimeSinceStartup)
            {
                GUI.backgroundColor = Color.red;
            }
            if (GUILayout.Button("Auto", EditorStyles.miniButtonMid, GUILayout.Width(width)))
            {
                ClickMenuMain("Auto Generate");
            }
            GUI.backgroundColor = Color.white;

            if (GUILayout.Button("Refresh", EditorStyles.miniButtonMid, GUILayout.Width(width)))
            {
                ClickMenuMain("Refresh");
            }

            EditorGUILayout.EndHorizontal();
        }
Exemple #21
0
 void Awake()
 {
     instance = this;
 }