예제 #1
0
//		private static string[] syncChannelOptions = new string[]{ "None", "Splat", "Node Targets", "Node Children" };

        public void OnEnable()
        {
            painter = (NodePainter)target;
            if (painter.painter == null)
            {
                throw new Exception("Painter not initialized!");
            }
            editor = new PaintingEditor(painter.painter);
            editor.MultiChannelSyncGUI = DrawMultiChannelSyncGUI;

            //GetPreviewTextures ();

            painter.UpdateTerrains();
            GlobalPainting.UpdateTerrainBrush();
            GlobalPainting.HideCanvasProjection();

            if (!System.IO.Directory.Exists(Settings.paintingResourcesFolder))
            {
                Debug.LogWarning("Resource folder does not exist! Please select a valid path in the settings!");
                return;
            }
        }
        public void OnGUI()
        {
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

            #region Settings GUI

            GUILayout.Label("Paint Behaviour", EditorStyles.boldLabel);

            Settings.targetPaintInterval      = EditorGUILayout.Slider(ContentPaintInterval, Settings.targetPaintInterval, 0, 1);
            Settings.targetGenerationInterval = EditorGUILayout.Slider(ContentGenerationInterval, Settings.targetGenerationInterval, 0, 1);
            Settings.autoGenerate             = EditorGUILayout.Toggle(ContentAutoGenerate, Settings.autoGenerate);
//			Settings.enablePartialGeneration = EditorGUILayout.Toggle (ContentPartialGeneration, Settings.enablePartialGeneration);
            Settings.continuousPaint = EditorGUILayout.Toggle(ContentContinuousPainting, Settings.continuousPaint);


            GUILayout.Label("Undo", EditorStyles.boldLabel);

            Settings.enableUndo    = EditorGUILayout.Toggle(ContentEnableUndo, Settings.enableUndo);
            Settings.undoStackSize = Mathf.Clamp(EditorGUILayout.IntField(ContentUndoStackSize, Settings.undoStackSize), 5, 50);


            GUILayout.Label("GUI", EditorStyles.boldLabel);

            Settings.imgPreviewTexSize    = Mathf.Clamp(EditorGUILayout.IntField(ContentBrushPreviewSize, Settings.imgPreviewTexSize), 16, 128);
            Settings.maxCanvasPreviewSize = Mathf.Clamp(EditorGUILayout.IntField(ContentMaxCanvasSize, Settings.maxCanvasPreviewSize), 128, 2048);

//			Settings.relativeCanvasPaintBorder = EditorGUILayout.Slider (ContentRelativeCanvasBorder, Settings.relativeCanvasPaintBorder, 0, 1);
            Settings.fixedCanvasPaintBorder = EditorGUILayout.IntSlider(ContentFixedCanvasBorder, Settings.fixedCanvasPaintBorder, 0, 100);

            EditorGUI.BeginChangeCheck();
            Settings.terrainCanvasOverlayStrength = EditorGUILayout.Slider(ContentCanvasOverlayStrength, Settings.terrainCanvasOverlayStrength, 0, 1);
            if (EditorGUI.EndChangeCheck())
            {
                GlobalPainting.UpdateCanvasProjection();
                Repaint();
            }

            GUILayout.Label("Folder Locations", EditorStyles.boldLabel);

            GUILayout.BeginHorizontal();
            Settings.paintingResourcesFolder = EditorGUILayout.TextField(ContentResourceFolder, Settings.paintingResourcesFolder);
            if (GUILayout.Button("Select", GUILayout.ExpandWidth(false)))
            {
                string newPath = EditorUtility.OpenFolderPanel("Select Folder containing all resources.", Settings.paintingResourcesFolder, "");
                if (!string.IsNullOrEmpty(newPath))
                {
                    if (!newPath.StartsWith(Application.dataPath) || !Directory.Exists(newPath))
                    {
                        ShowNotification(new GUIContent("Selected resource folder does not exist or is not located in the Asset folder! Please re-select!"));
                    }
                    else
                    {
                        Settings.paintingResourcesFolder = newPath;
                    }
                }
            }
            GUILayout.EndHorizontal();

            EditorGUI.BeginChangeCheck();
            GUILayout.BeginHorizontal();
            Settings.brushStampsFolder = EditorGUILayout.TextField(ContentBrushStampsFolder, Settings.brushStampsFolder);
            if (GUILayout.Button("Select", GUILayout.ExpandWidth(false)))
            {
                string newPath = EditorUtility.OpenFolderPanel("Select Folder containing all brush stamps.", Settings.brushStampsFolder, "");
                if (!string.IsNullOrEmpty(newPath))
                {
                    if (!Directory.Exists(newPath))
                    {
                        ShowNotification(new GUIContent("Selected brush stamps folder does not exist! Please re-select!"));
                    }
                    else
                    {
                        Settings.brushStampsFolder = newPath;
                    }
                }
            }
            GUILayout.EndHorizontal();
            if (EditorGUI.EndChangeCheck())
            {
                GlobalPainting.ReloadBrushTextures();
            }

            GUILayout.BeginHorizontal();
            Settings.lastSessionCacheFolder = EditorGUILayout.TextField(ContentCacheFolder, Settings.lastSessionCacheFolder);
            if (GUILayout.Button("Select", GUILayout.ExpandWidth(false)))
            {
                string newPath = EditorUtility.OpenFolderPanel("Select Folder to store the last session cache in.", Settings.lastSessionCacheFolder, "");
                if (!string.IsNullOrEmpty(newPath))
                {
                    if (!Directory.Exists(newPath))
                    {
                        ShowNotification(new GUIContent("Selected cache folder does not exist! Please re-select!"));
                    }
                    else
                    {
                        Settings.lastSessionCacheFolder = newPath;
                    }
                }
            }
            GUILayout.EndHorizontal();


//			GUILayout.Label ("Internal Settings", EditorStyles.boldLabel);
//
//			Settings.enableDebug = EditorGUILayout.ToggleLeft (ContentEnableDebug, Settings.enableDebug);
//			Settings.enableGPUUniformBranching = EditorGUILayout.ToggleLeft (ContentUniformBranching, Settings.enableGPUUniformBranching);


            #endregion

            EditorGUILayout.EndScrollView();

            EditorGUILayout.Space();

            if (GUILayout.Button("Reset All to Default Values"))
            {
                Settings.ResetAll();
            }
        }
예제 #3
0
        public void OnSceneGUI()
        {
            if (!painter.painter.hasCanvas)
            {
                return;
            }

            if (!editor.isMouseInWindow || Event.current.modifiers == EventModifiers.Alt)
            {
                GlobalPainting.UpdateTerrainBrush();
                return;
            }

            if (vizCanvasOnTerrain)
            {
                GlobalPainting.ShowCanvasProjection(painter.transform.position + Vector3.up * painter.canvasSize.y, painter.transform.rotation,
                                                    new Vector2(painter.transform.lossyScale.x * painter.canvasSize.x, painter.transform.lossyScale.z * painter.canvasSize.z),
                                                    painter.painter.vizCanvas, painter.painter.canvasFormat == Painting.Format.Value);
            }

            if (debugGenerateRect)
            {
                Vector2 totalAreaSize = new Vector2(painter.areaSize.x * painter.areaTiles.x, painter.areaSize.z * painter.areaTiles.y);
                Rect    rect          = new Rect(Vector2.Scale(painter.generateRect.position, totalAreaSize) - totalAreaSize / 2, Vector2.Scale(painter.generateRect.size, totalAreaSize));
                rect.position += new Vector2(painter.areaPos.x, painter.areaPos.z);
                Handles.DrawSolidRectangleWithOutline(new Vector3[] { new Vector3(rect.xMin, 0, rect.yMin), new Vector3(rect.xMax, 0, rect.yMin), new Vector3(rect.xMax, 0, rect.yMax), new Vector3(rect.xMin, 0, rect.yMax) }, new Color(1, 1, 1, 0), Color.green);
            }

            if (debugNodeRect)
            {
                Rect rect = painter.nodeRect;
                Handles.DrawSolidRectangleWithOutline(new Vector3[] { new Vector3(rect.xMin, 0, rect.yMin), new Vector3(rect.xMax, 0, rect.yMin), new Vector3(rect.xMax, 0, rect.yMax), new Vector3(rect.xMin, 0, rect.yMax) }, new Color(1, 1, 1, 0), Color.red);
            }

            painter.painter.blockPainting = Tools.current != Tool.None;

            if ((Event.current.type == EventType.MouseUp && Event.current.button == 0) || Event.current.button != 0)
            {
                painter.painter.StopPainting(SceneViewID);
            }

            editor.controlID = GUIUtility.GetControlID(FocusType.Passive);
            HandleUtility.AddDefaultControl(editor.controlID);
            if (Event.current.GetTypeForControl(editor.controlID) == EventType.MouseDown)
            {             // Block left-click in scene view
                GUIUtility.hotControl = editor.controlID;
//				Event.current.Use ();
            }

            Vector2 brushPos;
            Vector3 worldPos;

            if (painter.CalcBrushWorldPos(out brushPos, out worldPos))
            {
                if (Event.current.type != EventType.Repaint && Event.current.type != EventType.Layout)
                {
                    Undo.RecordObject(painter, "Node Painter Shortcut");
                }
                string undoRecord;
                bool   blockPainting = editor.HandleShortcuts(out undoRecord) || painter.painter.blockPainting;
                if (!string.IsNullOrEmpty(undoRecord))
                {
                    Undo.FlushUndoRecordObjects();
                }

                if (Event.current.type == EventType.Layout)
                {
                    if (blockPainting)
                    {
                        GlobalPainting.UpdateTerrainBrush();
                    }
                    else if (painter.TCNodeTarget != null)
                    {
                        GlobalPainting.ShowTerrainBrush(painter.painter, worldPos, painter.painter.curBrush.size * painter.TCNodeTarget.size.x * painter.transform.lossyScale.x);
                    }
                    else
                    {
                        GlobalPainting.ShowTerrainBrush(painter.painter, worldPos, painter.painter.curBrush.size * TC_Area2D.current.bounds.size.x * painter.transform.lossyScale.x);
                    }
                }

                float expand     = painter.painter.curBrush.size;
                bool  isInCanvas = (brushPos.x >= -expand && brushPos.x <= 1 + expand) && (brushPos.y >= -expand && brushPos.y <= 1 + expand);

                if (painter.painter.PaintUpdate(SceneViewID, editor.controlID, isInCanvas, blockPainting, brushPos))
                {
                    Repaint();
                }
            }
            else
            {
                if (GUIUtility.hotControl == editor.controlID)
                {
                    GUIUtility.hotControl = 0;
                }
                GlobalPainting.UpdateTerrainBrush();
            }

            if (editor.isMouseInWindow)
            {
                HandleUtility.Repaint();
            }
        }
예제 #4
0
 public void OnDisable()
 {
     editor.Close();
     GlobalPainting.UpdateTerrainBrush();
     GlobalPainting.HideCanvasProjection();
 }
예제 #5
0
        public override void OnInspectorGUI()
        {
            if (editor == null)
            {
                return;
            }

            if ((Event.current.type == EventType.MouseUp && Event.current.button == 0) || Event.current.button != 0)
            {
                painter.painter.StopPainting(GUIWindowID);
            }

            editor.GUIWindowID = GUIWindowID;

            if (Event.current.type != EventType.Repaint && Event.current.type != EventType.Layout)
            {
                Undo.RecordObject(painter, "Node Painter Settings");
            }
            string undoRecord;

            editor.DoPainterGUI(out undoRecord);
            if (!string.IsNullOrEmpty(undoRecord))
            {
                Undo.FlushUndoRecordObjects();
                //Debug.Log ("Recording " + undoRecord + " over " + Undo.GetCurrentGroupName () + "!");
            }

            if (painter.painter.hasCanvas)
            {
                expandTargets = EditorGUILayout.Foldout(expandTargets, "Node Targets", PaintingEditor.headerFoldout);
                if (expandTargets)
                {
                    painter.TCArea = (TC_Area2D)EditorGUILayout.ObjectField("TC2 Area 2D", painter.TCArea, typeof(TC_Area2D), true);
                    if (painter.painter.canvasFormat != Painting.Format.Multi && painter.TCNode != null)
                    {
                        GUILayout.Label("Current node: " + painter.TCNode.name);
                    }
                    while (painter.channelTargets.Count < painter.painter.canvasChannelCount || painter.channelTargets.Count < 1)
                    {
                        painter.channelTargets.Add(new NodePainter.ChannelNodeTargets());
                    }
//					painter.painter.curChannelIndex = Mathf.Clamp (painter.painter.curChannelIndex, 0, painter.painter.canvasChannelCount-1);
                    DrawNodeTargetList(painter.channelTargets[painter.painter.curChannelIndex].targets);

                    if (painter.channelTargets.Count == 0)
                    {
                        GUILayout.Label("No node targets specified!");
                    }
                }
            }

            AdditionalGUIUtility.Seperator();

            if (GUILayout.Button("Show Settings", EditorStyles.toolbarButton))
            {
                SettingsWindow.Open();
            }

//			GUILayout.Label ("Painter's control ID: " + editor.controlID);
//			GUILayout.Label ("Active control ID: " + GUIUtility.hotControl);

            EditorGUILayout.Space();

            if (editor.isMouseInWindow)
            {
                Repaint();
            }

            if (vizCanvasOnTerrain != painter.painter.vizCanvasExternally)
            {
                vizCanvasOnTerrain = painter.painter.vizCanvasExternally;
                if (vizCanvasOnTerrain)
                {
                    GlobalPainting.ShowCanvasProjection(painter.transform.position + Vector3.up * TC_Area2D.current.bounds.size.y, painter.transform.rotation,
                                                        new Vector2(painter.transform.localScale.x * painter.TCNodeTarget.size.x, painter.transform.localScale.z * painter.TCNodeTarget.size.z),
                                                        painter.painter.vizCanvas, painter.painter.canvasFormat == Painting.Format.Value);
                }
                else
                {
                    GlobalPainting.HideCanvasProjection();
                }
                HandleUtility.Repaint();
                SceneView.RepaintAll();
            }
        }