Пример #1
0
        public override void GetItems(bool refresh, bool rebuildGlobalLists, bool resetTextures)
        {
            if (resetTextures)
            {
                DisposeTextures();
            }

            itemList.Clear();

            totalActive = 0;

            int listIndex = 0;

            for (int i = t.childCount - 1; i >= 0; i--)
            {
                Transform child = t.GetChild(i);

                TC_SelectItem selectItem = child.GetComponent <TC_SelectItem>();
                if (selectItem == null)
                {
                    TC.MoveToDustbin(child);
                }
                else
                {
                    selectItem.SetParameters(this, listIndex);
                    selectItem.parentItem = this;

                    selectItem.active = selectItem.visible;

                    if (outputId == TC.splatOutput && selectItem.splatCustom)
                    {
                        if (TC_Settings.instance.hasMasterTerrain)
                        {
                            if (selectItem.splatCustomValues.Length != TC_Settings.instance.masterTerrain.terrainData.splatPrototypes.Length)
                            {
                                selectItem.splatCustomValues = Mathw.ResizeArray <float>(selectItem.splatCustomValues, TC_Settings.instance.masterTerrain.terrainData.splatPrototypes.Length);
                            }
                        }
                        selectItem.CalcSplatCustomTotal();
                    }

                    selectItem.SetPreviewItemTexture(); // Put deactive if listIndex is out of bounds

                    if (selectItem.active)
                    {
                        ++totalActive;
                    }

                    if (outputId == TC.treeOutput)
                    {
                        if (selectItem.tree == null)
                        {
                            selectItem.tree = new TC_SelectItem.Tree();
                        }

                        if (selectItem.active)
                        {
                            bool addToList = true;

                            List <TC_SelectItem> treeSelectItems = TC_Area2D.current.terrainLayer.treeSelectItems;

                            if (!rebuildGlobalLists)
                            {
                                int index = treeSelectItems.IndexOf(selectItem);
                                if (index != -1)
                                {
                                    addToList = false; selectItem.globalListIndex = index;
                                }
                            }

                            if (addToList)
                            {
                                treeSelectItems.Add(selectItem);
                                selectItem.globalListIndex = treeSelectItems.Count - 1;
                            }
                        }
                    }
                    else if (outputId == TC.objectOutput)
                    {
                        if (selectItem.spawnObject == null)
                        {
                            selectItem.spawnObject = new TC_SelectItem.SpawnObject();
                        }
                        if (selectItem.spawnObject.go == null)
                        {
                            selectItem.active = false;
                            TC_Area2D.current.terrainLayer.objectSelectItems.Remove(selectItem);
                            // Debug.Log("Remove from list");
                        }

                        if (selectItem.active)
                        {
                            bool addToList = true;

                            List <TC_SelectItem> objectSelectItems = TC_Area2D.current.terrainLayer.objectSelectItems;

                            if (!rebuildGlobalLists)
                            {
                                int index = objectSelectItems.IndexOf(selectItem);
                                if (index != -1)
                                {
                                    addToList = false; selectItem.globalListIndex = index;
                                }
                            }

                            if (addToList)
                            {
                                objectSelectItems.Add(selectItem);
                                selectItem.globalListIndex = objectSelectItems.Count - 1;
                            }
                            selectItem.selectIndex = listIndex;
                        }
                    }

                    selectItem.SetPreviewItemTexture();
                    selectItem.SetPreviewColor();

                    itemList.Add(selectItem);
                    listIndex++;
                }
            }

            if (refreshRangeItem != null || refreshRanges)
            {
                refreshRanges = false;
                RefreshRanges();
                refreshRangeItem = null;
            }
            else if (refresh || TC.refreshPreviewImages)
            {
                CalcPreview();
            }
        }
Пример #2
0
        void ClickMenuMain(object obj)
        {
            string cmd = obj.ToString();

            if (cmd == "New")
            {
                New();
            }
            if (cmd == "Open")
            {
                Open();
            }
            if (cmd == "Save")
            {
                Save();
            }
            else if (cmd == "Settings")
            {
                Selection.activeTransform = TC_Settings.instance.transform;
            }
            else if (cmd == "Generate")
            {
                TC_Generate.instance.Generate(false);
            }
            else if (cmd == "Auto Generate")
            {
                TC_Generate.instance.autoGenerate = !TC_Generate.instance.autoGenerate;
            }
            else if (cmd == "Show Fps")
            {
                TC_Settings.instance.showFps = !TC_Settings.instance.showFps;
            }
            else if (cmd == "Hide Menu Bar")
            {
                TC_Settings.instance.hideMenuBar = !TC_Settings.instance.hideMenuBar;
                if (!TC_Settings.instance.hideMenuBar)
                {
                    TC.AddMessage("The menu bar can be unhided by the popup menu, this can be shown by right clicking in the empty area where the Height/Splat/Color... buttons are.");
                }
            }
            else if (cmd == "Refresh")
            {
                TC_Generate.instance.RefreshOutputReferences(6, true);
                if (TC_Generate.instance.autoGenerate)
                {
                    TC_Generate.instance.Generate(false);
                }
            }
            else if (cmd == "ResetTextures")
            {
                TC.RefreshOutputReferences(7);
            }
            else if (cmd == "Documentation")
            {
                Application.OpenURL("http://www.terraincomposer.com/terraincomposer2-documentation/");
            }
            else if (cmd == "Tooltip")
            {
                TC_Settings.instance.global.tooltip = !TC_Settings.instance.global.tooltip;
            }
            else if (cmd == "About...")
            {
                TC.AddMessage("TerrainComposer version " + TC.GetVersionNumber().ToString(), 0, 4);
            }
        }
Пример #3
0
        static int LoadDefault()
        {
            if (!NewScene())
            {
                return(-1);
            }

            GameObject defaultGo = AssetDatabase.LoadAssetAtPath(TC.installPath + "/Defaults/TerrainComposer2.prefab", typeof(GameObject)) as GameObject;

            if (defaultGo != null)
            {
                GameObject go = Instantiate(defaultGo, Vector3.zero, Quaternion.identity) as GameObject;

                if (go == null)
                {
                    return(-2);
                }
                else
                {
                    go.transform.hideFlags = HideFlags.HideInInspector;
                    go.name = go.name.Replace("(Clone)", "");
                    go.transform.SetAsFirstSibling();
                    DebugMode();

                    if (!TC.LoadGlobalSettings())
                    {
                        return(-2);
                    }

                    Transform generateT = go.transform.Find("Generate");
                    if (generateT != null)
                    {
                        TC_Compute compute = generateT.GetComponent <TC_Compute>();

                        if (compute != null)
                        {
                            compute.enabled = true;
                        }
                        else
                        {
                            return(-2);
                        }
                    }
                    else
                    {
                        return(-2);
                    }
                }
            }
            else
            {
                return(-2);
            }

            if (GameObject.Find("Terrain Area") == null)
            {
                GameObject terrainAreaGo = AssetDatabase.LoadAssetAtPath(TC.installPath + "/Defaults/Terrain Area.prefab", typeof(GameObject)) as GameObject;
                if (terrainAreaGo != null)
                {
                    GameObject go = Instantiate(terrainAreaGo, Vector3.zero, Quaternion.identity) as GameObject;

                    TC_TerrainLayer terrainLayer = TC_Generate.instance.area2D.terrainLayer;

                    terrainLayer.GetItems(false, true, false);

                    // Detect prefab import issue
                    if (terrainLayer.layerGroups[TC.splatOutput].visible)
                    {
                        TC.AddMessage("TerrainComposer2 prefabs did not import correctly.\n\nYou need to be reimport TerrainComposer2 again (So import it twice).\n\nThis happens if ‘Asset Serialization’ is set to ‘Force Text’ in Unity Menu -> Project Settings -> Editor. It is a Unity import bug that can happen on any Asset. If that does not fix it, the ‘Asset Serialization’ can be set to ‘Mixed’ and then reimport TC2 again, then after importing the ‘Asset Serialization’ can be set to ‘Force Text’ again.", 0, 60);
                    }
                    else if (go == null)
                    {
                        TC.AddMessage("Default Terrain Area prefab is missing. Please reimport this prefab.");
                    }
                    go.name = go.name.Replace("(Clone)", "");
                }
                else
                {
                    TC.AddMessage("Default Terrain Area prefab is missing. Please reimport this prefab.");
                }
            }

            TC.AddMessage("Loading default TerrainComposer project.");

            return(0);
        }
Пример #4
0
 public static void ShowWindow()
 {
     window = GetWindow(typeof(TC_NodeWindow)) as TC_NodeWindow;
     window.titleContent = new GUIContent("TC" + TC.GetVersionNumber());
 }
Пример #5
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();
        }
Пример #6
0
 public void Reset()
 {
     TC.DestroyChildrenTransform(t);
 }
Пример #7
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();
            //}
        }
Пример #8
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();
        }
Пример #9
0
        public bool DropTextureEditor(Texture tex)
        {
            #if UNITY_EDITOR
            if (tex != null)
            {
                pathTexStamp = UnityEditor.AssetDatabase.GetAssetPath(tex);
                string path  = pathTexStamp;
                int    index = path.LastIndexOf("/");
                path = path.Insert(index, "/RawFiles");

                index = path.IndexOf("/Resources/");
                isStampInResourcesFolder = (index != -1);

                if (isStampInResourcesFolder)
                {
                    path            = path.Substring(index + 11);
                    path            = path.Remove(path.Length - 4);
                    resourcesFolder = path;
                    // Debug.Log(path);
                }
                else
                {
                    path = path.Remove(path.Length - 3) + "raw";

                    if (!TC.FileExistsPath(path))
                    {
                        path = path.Remove(path.Length - 3) + "r16";
                    }

                    if (!TC.FileExistsPath(path))
                    {
                        // TC.AddMessage("Cannot find the file " + path.Remove(path.Length - 3, 3) + "\n\nThe file extension needs to be .raw or .r16");
                        if (rawImage != null)
                        {
                            rawImage.UnregisterReference();
                        }
                        inputFile = InputFile.Image;
                        stampTex  = tex;
                        TC.AutoGenerate();
                        return(false);
                    }
                }

                TC_RawImage oldRawImage = rawImage;
                if (oldRawImage)
                {
                    oldRawImage.UnregisterReference();
                }

                // Debug.Log(path);

                rawImage = TC_Settings.instance.AddRawFile(path, isStampInResourcesFolder);
            }
            #else
            if (isStampInResourcesFolder)
            {
                rawImage = TC_Settings.instance.AddRawFile(resourcesFolder, isStampInResourcesFolder);
            }
            #endif

            if (rawImage != null)
            {
                stampTex = tex;
                TC.RefreshOutputReferences(outputId, true);

                // TC_Reporter.Log(path);
                TC_Reporter.Log("Node index " + rawImage.name);
                return(true);
            }
            else
            {
                TC.AddMessage("This is not a stamp preview image.\n\nThe raw heightmap file needs to be placed in a 'RawFiles' folder, then TC2 will automatically make a preview image one folder before it.\nThis image needs to be used for dropping on the node.", 0, 4);
            }

            return(false);
        }
Пример #10
0
        public override void GetItems(bool refresh, bool rebuildGlobalLists, bool resetTextures)
        {
            if (resetTextures)
            {
                DisposeTextures();
            }

            int childCount = transform.childCount;

            // Init();
            itemList.Clear();

            active = visible;

            firstActive = lastActive = -1;
            totalActive = 0;

            bool newBounds = true;
            int  listIndex = 0;

            for (int i = childCount - 1; i >= 0; i--)
            {
                Transform child = t.GetChild(i);

                TC_Node node = child.GetComponent <TC_Node>();

                if (node != null)
                {
                    if (resetTextures)
                    {
                        node.DisposeTextures();
                    }
                    node.active = true;
                    node.Init();
                    if (node.inputKind == InputKind.Current && totalActive == 0)
                    {
                        TC.AddMessage("'Current' can only be used if there is active node/s before it.");
                        node.active = false;
                    }
                    if (!node.visible)
                    {
                        node.active = false;
                        // Debug.Log(node.name);
                    }
                    node.SetParameters(this, listIndex);
                    node.nodeGroupLevel = nodeGroupLevel + 1;
                    node.nodeType       = type;

                    node.UpdateVersion();

                    if (node.active)
                    {
                        if (node.clamp)
                        {
                            node.CalcBounds();
                        }
                        if (newBounds)
                        {
                            bounds = node.bounds; newBounds = false;
                        }
                        else
                        {
                            bounds.Encapsulate(node.bounds);
                        }

                        lastActive = listIndex;
                        if (firstActive == -1)
                        {
                            firstActive = lastActive;
                        }
                        ++totalActive;
                    }

                    if (i == childCount - 1) // TODO: Consider hide and do in calculation
                    {
                        if (node.method != Method.Add && node.method != Method.Subtract)
                        {
                            node.method = Method.Add;
                        }
                    }

                    itemList.Add(node);
                    ++listIndex;
                }
                else
                {
                    TC_NodeGroup nodeGroup = child.GetComponent <TC_NodeGroup>();

                    if (nodeGroup != null)
                    {
                        nodeGroup.SetParameters(this, listIndex);
                        nodeGroup.nodeGroupLevel = nodeGroupLevel + 1;
                        itemList.Add(nodeGroup);
                        ++listIndex;
                        nodeGroup.GetItems(refresh, rebuildGlobalLists, resetTextures);

                        if (nodeGroup.active)
                        {
                            lastActive = listIndex;
                            if (firstActive == -1)
                            {
                                firstActive = lastActive;
                            }
                            ++totalActive;
                        }
                    }
                    //else
                    //{
                    //    TC_NodeClone nodeClone = child.GetComponent<TC_NodeClone>();
                    //}
                }
            }

            if (itemList.Count == 1)
            {
                if (itemList[0].active)
                {
                    active = visible = true;
                }
            }

            if (!active)
            {
                totalActive = 0;
            }
            if (totalActive == 0)
            {
                active = false;
            }
        }
Пример #11
0
        static public void ClickMenuInput(object obj)
        {
            int    instanceID;
            string command = TD.ObjectToCommandAndInstanceID(obj, out instanceID);

            TC_Node node = EditorUtility.InstanceIDToObject(instanceID) as TC_Node;

            if (node != null)
            {
                int    index     = command.IndexOf("/");
                string inputKind = command.Substring(0, index);
                string input     = command.Substring(index + 1);
                bool   changed   = false;

                InputKind oldInputKind = node.inputKind;
                node.inputKind = (InputKind)Enum.Parse(typeof(InputKind), inputKind);

                if (node.inputKind != oldInputKind)
                {
                    changed = true;
                }

                if (inputKind == "Terrain")
                {
                    InputTerrain oldInputTerrain = node.inputTerrain;
                    node.inputTerrain = (InputTerrain)Enum.Parse(typeof(InputTerrain), input);
                    if (node.inputTerrain != oldInputTerrain)
                    {
                        changed = true;
                    }
                }
                else if (inputKind == "Noise")
                {
                    InputNoise oldInputNoise = node.inputNoise;
                    node.inputNoise = (InputNoise)Enum.Parse(typeof(InputNoise), input);
                    if (node.inputNoise != oldInputNoise)
                    {
                        changed = true;
                    }
                }
                else if (inputKind == "Shape")
                {
                    InputShape oldInputShape = node.inputShape;
                    node.inputShape = (InputShape)Enum.Parse(typeof(InputShape), input);
                    if (node.inputShape != oldInputShape)
                    {
                        changed = true;
                    }
                }
                else if (inputKind == "File")
                {
                    InputFile oldInputFile = node.inputFile;
                    node.inputFile = (InputFile)Enum.Parse(typeof(InputFile), input);
                    if (node.inputFile != oldInputFile)
                    {
                        changed = true;
                    }
                }
                else if (inputKind == "Current")
                {
                    InputCurrent oldInputCurrent = node.inputCurrent;
                    node.inputCurrent = (InputCurrent)Enum.Parse(typeof(InputCurrent), input);
                    if (node.inputCurrent != oldInputCurrent)
                    {
                        changed = true;
                    }
                }

                if (changed)
                {
                    node.Init();
                    EditorUtility.SetDirty(node);
                    TC.RefreshOutputReferences(node.outputId, true);
                }
            }
        }
Пример #12
0
        public override void GetItems(bool refresh, bool rebuildGlobalLists, bool resetTextures)
        {
            if (resetTextures)
            {
                DisposeTextures();
            }

            active = visible;

            itemList.Clear();

            firstActive = lastActive = -1;
            totalActive = 0;

            bool newBounds = true;
            int  listIndex = 0;

            // Debug.Log(name + " GetItems");

            for (int i = t.childCount - 1; i >= 0; i--)
            {
                Transform child = transform.GetChild(i);
                TC_Layer  layer = child.GetComponent <TC_Layer>();

                if (layer != null)
                {
                    layer.SetParameters(this, listIndex);

                    layer.GetItems(refresh, rebuildGlobalLists, resetTextures);
                    if (layer.active)
                    {
                        ++totalActive;
                        lastActive = listIndex;
                        if (firstActive == -1)
                        {
                            firstActive = lastActive;
                        }
                    }
                    itemList.Add(layer);
                    ++listIndex;

                    if (newBounds)
                    {
                        bounds = layer.bounds; newBounds = false;
                    }
                    else
                    {
                        bounds.Encapsulate(layer.bounds);
                    }
                }
                else
                {
                    TC_LayerGroup layerGroup = child.GetComponent <TC_LayerGroup>();

                    if (layerGroup == null)
                    {
                        TC.MoveToDustbin(child);
                    }
                    else
                    {
                        layerGroup.SetParameters(this, listIndex);
                        layerGroup.GetItems(refresh, rebuildGlobalLists, resetTextures);

                        if (layerGroup.active)
                        {
                            ++totalActive;
                            lastActive = listIndex;
                            if (firstActive == -1)
                            {
                                firstActive = lastActive;
                            }
                        }

                        if (layerGroup.groupResult == null)
                        {
                            TC.MoveToDustbin(child);
                        }
                        else
                        {
                            itemList.Add(layerGroup);
                            listIndex++;
                        }
                        if (newBounds)
                        {
                            bounds = layerGroup.bounds; newBounds = false;
                        }
                        else
                        {
                            bounds.Encapsulate(layerGroup.bounds);
                        }
                    }
                }
            }

            TC_Reporter.Log(TC.outputNames[outputId] + " Level " + level + " activeTotal " + totalActive);

            if (!active)
            {
                totalActive = 0;
            }
            else if (totalActive == 0)
            {
                active = false;
            }
        }
Пример #13
0
 public void SetVersionNumber()
 {
     versionNumber = TC.GetVersionNumber();
 }
Пример #14
0
        public bool SetCurrentArea(TCUnityTerrain tcTerrain, int outputId)
        {
            // Debug.Log(tcTerrain.terrain.name);
            SetCurrentArea(tcTerrain);
            Terrain terrain = currentTerrain;

            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) * TC_Settings.instance.resExpandBorderPercentage);
                resExpandBorderSize = terrain.terrainData.size.x * TC_Settings.instance.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     = TC.GetTerrainSplatTextureLength(currentTerrain);
                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);
        }
        public void LoadRawImage(string path)
        {
            this.path = path;

            string fullPath = Application.dataPath.Replace("Assets", "/") + path;

            // Debug.Log(fullPath);

            if (tex != null)
            {
                return;
            }

            #if UNITY_EDITOR
            if (!isResourcesFolder)
            {
                if (!TC.FileExists(fullPath))
                {
                    return;
                }
            }
            #endif

            TC_Reporter.Log("Load Raw file " + fullPath);

            // Debug.Log(bytes.Length);
            byte[] bytes = null;

            if (isResourcesFolder)
            {
                // Debug.Log("LoadRawImage " + path);
                TextAsset textAsset = Resources.Load <TextAsset>(path);
                if (textAsset != null)
                {
                    bytes = textAsset.bytes;
                }
                else
                {
                    Debug.Log("Can't find file");
                }
            }
            else
            {
                    #if !UNITY_WEBPLAYER
                bytes = File.ReadAllBytes(fullPath);
                    #else
                // TC.AddMessage("You are in Webplayer build mode, loading from disk is protected in this mode and stamp textures don't work.\nThis will be fixed.\n\nFor now another build mode in needed.", 0, 5);
                WWW request = new WWW("file:///" + fullPath);

                while (!request.isDone)
                {
                }
                if (request.error != null)
                {
                    TC.AddMessage(request.error);
                }

                bytes = request.bytes;
                    #endif
            }

            if (bytes == null)
            {
                return;
            }
            if (bytes.Length == 0)
            {
                return;
            }

            GetResolutionFromLength(bytes.Length);

            #if UNITY_EDITOR_OSX
            byte[] bytes1 = new byte[bytes.Length / 2];
            byte[] bytes2 = new byte[bytes.Length / 2];

            for (int i = 0; i < bytes.Length / 2; i++)
            {
                bytes1[i] = bytes[i * 2];
                bytes2[i] = bytes[(i * 2) + 1];
            }

            tex            = new Texture2D(resolution.x, resolution.y, TextureFormat.Alpha8, false, true);
            tex.hideFlags  = HideFlags.DontSave;
            tex2           = new Texture2D(resolution.x, resolution.y, TextureFormat.Alpha8, false, true);
            tex2.hideFlags = HideFlags.DontSave;
            tex2.LoadRawTextureData(bytes2);
            tex2.Apply();
            tex.LoadRawTextureData(bytes1);
            #else
            tex           = new Texture2D(resolution.x, resolution.y, TextureFormat.R16, false, true);
            tex.hideFlags = HideFlags.DontSave;
            tex.LoadRawTextureData(bytes);
            #endif

            tex.Apply();

            // For use of mipmap
            //rt = new RenderTexture(resolution.x, resolution.y, 0, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear);
            //rt.useMipMap = true;
            //rt.hideFlags = HideFlags.DontSave;
            //rt.Create();

            // Graphics.Blit(tex2, rt);
            // Debug.Log("Load");
        }
Пример #16
0
 void OnEnable()
 {
     TC.AutoGenerate();
     UnityEditor.EditorApplication.update += MyUpdate;
 }