Esempio n. 1
0
        static public void DeleteKey()
        {
            if (Selection.transforms != null)
            {
                for (int i = 0; i < Selection.transforms.Length; i++)
                {
                    Transform t = Selection.transforms[i];

                    TC_LayerGroup       layerGroup      = t.GetComponent <TC_LayerGroup>();
                    TC_LayerGroupResult groupResult     = t.GetComponent <TC_LayerGroupResult>();
                    TC_SelectItemGroup  selectItemGroup = t.GetComponent <TC_SelectItemGroup>();
                    TC_NodeGroup        nodeGroup       = t.GetComponent <TC_NodeGroup>();
                    TC_Node             node            = t.GetComponent <TC_Node>();

                    if (node != null)
                    {
                        if (node.nodeType == NodeGroupType.Select)
                        {
                            TC_NodeGroup nodeGroupParent = (TC_NodeGroup)node.parentItem;
                            if (nodeGroupParent.itemList.Count == 1 && node.outputId != TC.heightOutput)
                            {
                                TC.AddMessage("Select node cannot be deleted as there is always minimum one needed in a Layer."); continue;
                            }
                        }
                    }
                    else if (layerGroup != null)
                    {
                        if (layerGroup.level == 0)
                        {
                            TC.AddMessage("The main " + TC.outputNames[layerGroup.outputId] + " Output Layer Group cannot be deleted. \n\nRight click to clear it."); continue;
                        }
                    }
                    else if (groupResult != null)
                    {
                        TC.AddMessage("A Result Node cannot be deleted. The Layer Group itself needs to be deleted."); continue;
                    }
                    else if (selectItemGroup != null)
                    {
                        selectItemGroup.Clear(true); continue;
                    }
                    else if (nodeGroup != null)
                    {
                        nodeGroup.Clear(true); continue;
                    }

                    Undo.DestroyObjectImmediate(Selection.gameObjects[i]);
                    --i;
                }
            }
        }
Esempio n. 2
0
        static public void DuplicateKey()
        {
            Transform[] transforms = (Transform[])Selection.transforms.Clone();

            if (transforms != null)
            {
                List <GameObject> gos = new List <GameObject>();

                for (int i = 0; i < transforms.Length; i++)
                {
                    Transform t = transforms[i];

                    TC_LayerGroup       layerGroup      = t.GetComponent <TC_LayerGroup>();
                    TC_LayerGroupResult groupResult     = t.GetComponent <TC_LayerGroupResult>();
                    TC_SelectItemGroup  selectItemGroup = t.GetComponent <TC_SelectItemGroup>();
                    TC_NodeGroup        nodeGroup       = t.GetComponent <TC_NodeGroup>();

                    if (layerGroup != null)
                    {
                        if (layerGroup.level == 0)
                        {
                            TC.AddMessage("The main " + TC.outputNames[layerGroup.outputId] + " Output Layer Group cannot be duplicated."); continue;
                        }
                    }
                    else if (groupResult != null)
                    {
                        TC.AddMessage("A Result Node cannot be duplicated."); continue;
                    }
                    else if (selectItemGroup != null)
                    {
                        TC.AddMessage("A " + TC.outputNames[selectItemGroup.outputId] + " Group cannot be directly duplicated.\n\nDrag & drop works with it, while dropping hold the alt key to duplicate it."); continue;
                    }
                    else if (nodeGroup != null)
                    {
                        TC.AddMessage("A " + nodeGroup.type.ToString() + " Group cannot be directly duplicated.\n\nDrag & drop works with it, while dropping hold the alt key to duplicate it."); continue;
                    }

                    TC_ItemBehaviour item = t.GetComponent <TC_ItemBehaviour>();
                    if (item != null)
                    {
                        gos.Add(item.Duplicate(item.transform.parent).gameObject);
                    }
                }
                if (gos.Count > 0)
                {
                    Selection.objects = gos.ToArray();
                }
            }
        }
Esempio n. 3
0
        public void ApplyResolutionTerrainArea(TCUnityTerrain sTerrain)
        {
            for (int i = 0; i < terrains.Count; i++)
            {
                terrains[i].ApplyResolutionTerrain(sTerrain);
            }
            CalcTotalResolutions();

            if (sTerrain.heightmapResolution > 513)
            {
                TC.AddMessage("Heightmap resolution is higher than 513, keep in mind that Auto generate will be too slow to work in realtime.");
            }
            if (sTerrain.splatmapResolution > 1024)
            {
                TC.AddMessage("Splatmap resolution is higher than 1024, keep in mind that Auto generate will be too slow to work in realtime.");
            }
            if (sTerrain.detailResolution > 512)
            {
                TC.AddMessage("Grass resolution is higher than 513, keep in mind that Auto generate will be too slow to work in realtime.");
            }
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
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();
            //}
        }
Esempio n. 6
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);
        }
Esempio n. 7
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;
            }
        }