Пример #1
0
        void Randomize()
        {
            if (r == null || item == null)
            {
                return;
            }

            int amount = Random.Range(r.amount.x, r.amount.y);

            for (int i = 0; i < amount; i++)
            {
                Vector3 pos    = new Vector3(Random.Range(r.posX.x, r.posX.y), 0, Random.Range(r.posZ.x, r.posZ.y));
                float   rotY   = Random.Range(r.rotY.x, r.rotY.y);
                float   scaleX = Random.Range(r.scaleX.x, r.scaleX.y);
                Vector3 scale  = new Vector3(scaleX, Random.Range(r.scaleY.x, r.scaleY.y), scaleX);

                TC_ItemBehaviour newItem = item.Duplicate(item.t.parent);
                newItem.t.position   = pos;
                newItem.t.rotation   = Quaternion.Euler(0, rotY, 0);
                newItem.t.localScale = scale;
                newItem.method       = Method.Max;
            }

            TC.AutoGenerate();
        }
        void MyUpdate()
        {
            transform.Rotate(0, rotSpeed, 0);
            transform.Translate(moveSpeed * 90);
            transform.localScale += new Vector3(scaleSpeed, scaleSpeed, scaleSpeed);

            if (rotSpeed != 0 || moveSpeed.x != 0 || moveSpeed.y != 0 || moveSpeed.z != 0 || scaleSpeed != 0)
            {
                refresh = true;
            }

            if (opacitySpeed != 0)
            {
                if (item != null)
                {
                    item.opacity = Mathf.Abs(Mathf.Sin(Time.realtimeSinceStartup * opacitySpeed));
                    refresh      = true;
                }
            }

            if (refresh)
            {
                TC.repaintNodeWindow = true;
                TC.AutoGenerate();
            }
        }
Пример #3
0
 void UndoRedoPerformed()
 {
     // Debug.Log("Perform undo");
     if (TD.SelectionContainsItemBehaviour())
     {
         TC.RefreshOutputReferences(TC.allOutput);
         TC.AutoGenerate();
     }
 }
Пример #4
0
 void OnDisable()
 {
     if (generateOnDisable)
     {
         TC.AutoGenerate();
     }
     #if UNITY_EDITOR
     UnityEditor.EditorApplication.update -= MyUpdate;
     #endif
 }
Пример #5
0
 public void CheckTransformChange()
 {
     // Debug.Log("check tansform change");
     if (ctOld.hasChanged(this))
     {
         TC.AutoGenerate();
         // Debug.Log(t.name);
         ctOld.Copy(this);
     }
 }
Пример #6
0
 void MyUpdate()
 {
     if (TC_Settings.instance == null)
     {
         return;
     }
     TC_Settings.instance.seed += (Time.realtimeSinceStartup - time) * animateSpeed;
     time = Time.realtimeSinceStartup;
     TC.AutoGenerate();
 }
Пример #7
0
        void MyUpdate()
        {
            // if (repeat) TC.AutoGenerate();

            if (cT.hasChanged(t))
            {
                // Debug.Log("Auto generate");
                cT.Copy(t);
                TC.AutoGenerate();
                // TC_Generate.instance.Generate(true);
            }
        }
Пример #8
0
        void Generate()
        {
            generate = false;

            if (instantGenerate)
            {
                TC_Generate.instance.Generate(true);
            }
            else
            {
                TC.AutoGenerate();
            }
        }
Пример #9
0
        void MyUpdate()
        {
            if (target == null)
            {
                return;
            }

            transform.position = target.position + offset;

            if (refresh)
            {
                TC.repaintNodeWindow = true;
                TC.AutoGenerate();
            }
        }
        void Update()
        {
            if (target == null)
            {
                return;
            }

            if (followPosition)
            {
                t.position = target.position + offset;
            }
            if (followRotation)
            {
                t.rotation = target.rotation;
            }
            if (followScale)
            {
                float scaleY;
                if (followScaleY)
                {
                    scaleY = t.localScale.y;
                }
                else
                {
                    scaleY = target.lossyScale.y;
                }
                t.localScale = new Vector3(target.lossyScale.x, scaleY, target.lossyScale.z);
            }

            if (targetItem != null && item != null)
            {
                if (item.visible != targetItem.visible)
                {
                    item.visible = targetItem.visible;
                    TC.RefreshOutputReferences(item.outputId);
                }
            }

            if (refresh)
            {
                TC.repaintNodeWindow = true;
                TC.AutoGenerate();
            }
        }
Пример #11
0
        public void CalcPreview(bool calcValues = true)
        {
            if (!TC_Settings.instance.hasMasterTerrain)
            {
                return;
            }

            if (itemList.Count > 1)
            {
                int length = TC_Settings.instance.masterTerrain.terrainData.splatPrototypes.Length;

                if (outputId == TC.splatOutput)
                {
                    Texture2D[] texArray = new Texture2D[length];
                    for (int i = 0; i < length; i++)
                    {
                        texArray[i] = TC_Settings.instance.masterTerrain.terrainData.splatPrototypes[i].texture;
                        TC.SetTextureReadWrite(texArray[i]);
                    }
                    CalcPreview(texArray);
                }
                else
                {
                    if (outputId == TC.grassOutput)
                    {
                        for (int i = 0; i < itemList.Count; i++)
                        {
                            TC.SetTextureReadWrite(itemList[i].preview.tex);
                        }
                    }
                    CalcPreview(null);
                }
            }

            CreateMixBuffer();

            // Debug.Log("CalcPreview");
            TC.AutoGenerate();
        }
Пример #12
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();
        }
Пример #13
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);
        }
Пример #14
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();
        }
Пример #15
0
 void OnEnable()
 {
     TC.AutoGenerate();
     UnityEditor.EditorApplication.update += MyUpdate;
 }