public BrushModuleEditor(PrefabPainterEditor editor)
        {
            this.editor       = editor;
            this.editorTarget = editor.GetPainter();

            brushDistribution = new BrushDistribution(this);

            brushSize     = editor.FindProperty(x => x.brushSettings.brushSize);
            brushRotation = editor.FindProperty(x => x.brushSettings.brushRotation);

            sizeGuide     = editor.FindProperty(x => x.brushSettings.sizeGuide);
            normalGuide   = editor.FindProperty(x => x.brushSettings.normalGuide);
            rotationGuide = editor.FindProperty(x => x.brushSettings.rotationGuide);

            alignToTerrain = editor.FindProperty(x => x.brushSettings.alignToTerrain);

            distribution = editor.FindProperty(x => x.brushSettings.distribution);

            poissonDiscSize          = editor.FindProperty(x => x.brushSettings.poissonDiscSize);
            poissonDiscRaycastOffset = editor.FindProperty(x => x.brushSettings.poissonDiscRaycastOffset);
            fallOffCurve             = editor.FindProperty(x => x.brushSettings.fallOffCurve);
            fallOff2dCurveX          = editor.FindProperty(x => x.brushSettings.fallOff2dCurveX);
            fallOff2dCurveZ          = editor.FindProperty(x => x.brushSettings.fallOff2dCurveZ);
            curveSamplePoints        = editor.FindProperty(x => x.brushSettings.curveSamplePoints);
            allowOverlap             = editor.FindProperty(x => x.brushSettings.allowOverlap);
            layerMask = editor.FindProperty(x => x.brushSettings.layerMask);

            // initialize integrated applications
            vegetationStudioProIntegration = new VegetationStudioProIntegration(editor);
        }
        public void Layout(string[] guiInfo)
        {
            int controlId = GUIUtility.GetControlID(GetHashCode(), FocusType.Passive);

            if (Event.current.type == EventType.Layout)
            {
                HandleUtility.AddDefaultControl(controlId);
            }


            // examples about how to show ui info
            // note: Handles.BeginGUI and EndGUI are important, otherwise the default gizmos aren't drawn
            Handles.BeginGUI();

            /* disabling this, never needed it so far
             * if (raycastHitValid)
             * {
             *  ShowHandleInfo(raycastHit.point);
             * }
             */

            PrefabPainterEditor.ShowGuiInfo(guiInfo);

            Handles.EndGUI();
        }
#pragma warning restore 0414

        public AntiGravityInteraction(PrefabPainterEditor editor)
        {
            this.editor       = editor;
            this.editorTarget = editor.GetPainter();

            antiGravityStrength = editor.FindProperty(x => x.interactionSettings.antiGravity.strength);
        }
Exemple #4
0
        public SplineModuleEditor(PrefabPainterEditor editor)
        {
            this.editor       = editor;
            this.editorTarget = editor.GetPainter();

            spawnMechanism = editor.FindProperty(x => x.splineSettings.spawnMechanism);

            curveResolution = editor.FindProperty(x => x.splineSettings.curveResolution);
            loop            = editor.FindProperty(x => x.splineSettings.loop);

            separation         = editor.FindProperty(x => x.splineSettings.separation);
            separationDistance = editor.FindProperty(x => x.splineSettings.separationDistance);

            separationDistanceMin = editor.FindProperty(x => x.splineSettings.separationDistanceMin);
            separationDistanceMax = editor.FindProperty(x => x.splineSettings.separationDistanceMax);

            lanes          = editor.FindProperty(x => x.splineSettings.lanes);
            laneDistance   = editor.FindProperty(x => x.splineSettings.laneDistance);
            skipCenterLane = editor.FindProperty(x => x.splineSettings.skipCenterLane);

            instanceRotation     = editor.FindProperty(x => x.splineSettings.instanceRotation);
            controlPointRotation = editor.FindProperty(x => x.splineSettings.controlPointRotation);
            attachMode           = editor.FindProperty(x => x.splineSettings.attachMode);

            reusePrefabs = editor.FindProperty(x => x.splineSettings.reusePrefabs);

            snap  = editor.FindProperty(x => x.splineSettings.snap);
            debug = editor.FindProperty(x => x.splineSettings.debug);

            controlPoints = editor.FindProperty(x => x.splineSettings.controlPoints);

            dirty = editor.FindProperty(x => x.splineSettings.dirty);
        }
        public void RemoveContainerChildren()
        {
            GameObject container = editorTarget.container as GameObject;

            if (!container)
            {
                return;
            }

            List <Transform> list = new List <Transform>();

            foreach (Transform child in container.transform)
            {
                list.Add(child);
            }

            foreach (Transform child in list)
            {
                GameObject go = child.gameObject;

                PrefabPainterEditor.DestroyImmediate(go);
            }

            // remove spline instances
            editorTarget.splineSettings.prefabInstances.Clear();
        }
Exemple #6
0
#pragma warning restore 0414

        public MagnetInteraction(PrefabPainterEditor editor)
        {
            this.editor       = editor;
            this.editorTarget = editor.GetPainter();

            strength = editor.FindProperty(x => x.interactionSettings.magnet.strength);
        }
        public PrefabModuleEditor(PrefabPainterEditor editor)
        {
            this.editor       = editor;
            this.editorTarget = editor.GetPainter();

            LoadTemplateCollection();
        }
Exemple #8
0
        public SpawnExtension(PrefabPainterEditor editor)
        {
            this.editor       = editor;
            this.editorTarget = editor.GetPainter();

            autoSimulationType         = editor.FindProperty(x => x.spawnSettings.autoSimulationType);
            autoSimulationHeightOffset = editor.FindProperty(x => x.spawnSettings.autoSimulationHeightOffset);
        }
Exemple #9
0
        public UnityTerrainTreesIntegration(PrefabPainterEditor editor)
        {
            this.editor = editor;

            terrainTreeManager = new UnityTerrainTreeManager(editor);

            targetTerrain = editor.FindProperty(x => x.brushSettings.targetTerrain);
        }
        public FilterExtension(PrefabPainterEditor editor)
        {
            this.editor       = editor;
            this.editorTarget = editor.GetPainter();

            layerFilterEnabled = editor.FindProperty(x => x.filterSettings.layerFilterEnabled);
            includeTextures    = editor.FindProperty(x => x.filterSettings.includes);
            excludesTextures   = editor.FindProperty(x => x.filterSettings.excludes);
        }
Exemple #11
0
        private bool needsPhysicsApplied = false; // TODO property


        public InteractionModuleEditor(PrefabPainterEditor editor)
        {
            this.editor       = editor;
            this.editorTarget = editor.GetPainter();

            interactionType     = editor.FindProperty(x => x.interactionSettings.interactionType);
            antiGravityStrength = editor.FindProperty(x => x.interactionSettings.antiGravityStrength);
            magnetStrength      = editor.FindProperty(x => x.interactionSettings.magnetStrength);
        }
        public ChangeScaleInteraction(PrefabPainterEditor editor)
        {
            this.editor       = editor;
            this.editorTarget = editor.GetPainter();

            terrainTreeManager = new UnityTerrainTreeManager(editor);

            changeScaleStrength = editor.FindProperty(x => x.interactionSettings.changeScale.changeScaleStrength);
        }
Exemple #13
0
        public SetScaleInteraction(PrefabPainterEditor editor)
        {
            this.editor       = editor;
            this.editorTarget = editor.GetPainter();

            terrainTreeManager = new UnityTerrainTreeManager(editor);

            setScaleValue = editor.FindProperty(x => x.interactionSettings.setScale.setScaleValue);
        }
        public InteractionModuleEditor(PrefabPainterEditor editor)
        {
            this.editor       = editor;
            this.editorTarget = editor.GetPainter();

            interactionType = editor.FindProperty(x => x.interactionSettings.interactionType);

            antiGravityModule = new AntiGravityInteraction(editor);
            magnetModule      = new MagnetInteraction(editor);
            changeScaleModule = new ChangeScaleInteraction(editor);
            setScaleModule    = new SetScaleInteraction(editor);
        }
Exemple #15
0
        public PhysicsExtension(PrefabPainterEditor editor)
        {
            this.editor       = editor;
            this.editorTarget = editor.GetPainter();

            forceApplyType      = editor.FindProperty(x => x.physicsSettings.forceApplyType);
            maxIterations       = editor.FindProperty(x => x.physicsSettings.maxIterations);
            forceMinMax         = editor.FindProperty(x => x.physicsSettings.forceMinMax);
            forceAngleInDegrees = editor.FindProperty(x => x.physicsSettings.forceAngleInDegrees);
            randomizeForceAngle = editor.FindProperty(x => x.physicsSettings.randomizeForceAngle);
            simulationTime      = editor.FindProperty(x => x.physicsSettings.simulationTime);
            simulationSteps     = editor.FindProperty(x => x.physicsSettings.simulationSteps);
        }
Exemple #16
0
        public void OnEnable()
        {
            this.editor = this;

            container = FindProperty(x => x.container);
            mode      = FindProperty(x => x.mode);

            this.editorTarget = target as PrefabPainter;

            this.brushModule       = new BrushModuleEditor(this);
            this.splineModule      = new SplineModuleEditor(this);
            this.interactionModule = new InteractionModuleEditor(this);
            this.containerModule   = new ContainerModuleEditor(this);
            this.prefabModule      = new PrefabModuleEditor(this);
            this.physicsModule     = new PhysicsExtension(this);
            this.copyPasteModule   = new CopyPasteExtension(this);
            this.selectionModule   = new SelectionExtension(this);
            this.toolsModule       = new ToolsExtension(this);
            this.spawnModule       = new SpawnExtension(this);
            this.filterModule      = new FilterExtension(this);

            modeButtons = new GUIContent[]
            {
                // TODO: icons
                new GUIContent("Brush", "Paint prefabs using a brush"),
                new GUIContent("Spline", "Align prefabs along a spline"),
                new GUIContent("Interaction", "Brush interaction on the container children"),
                new GUIContent("Operations", "Operations on the container"),
            };

            // subscribe to play mode state changes
            EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
            EditorApplication.playModeStateChanged += OnPlayModeStateChanged;

            // subscribe to scene gui changes
            SceneView.duringSceneGui -= OnSceneGUI;
            SceneView.duringSceneGui += OnSceneGUI;

            brushModule.OnEnable();
            splineModule.OnEnable();
            interactionModule.OnEnable();
            containerModule.OnEnable();
        }
 public CopyPasteExtension(PrefabPainterEditor editor)
 {
     this.editor       = editor;
     this.editorTarget = editor.GetPainter();
 }
Exemple #18
0
        // About the position handle see example https://docs.unity3d.com/ScriptReference/Handles.PositionHandle.html
        public void OnSceneGUI()
        {
            int controlId = GUIUtility.GetControlID(GetHashCode(), FocusType.Passive);

            Ray        ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            RaycastHit hit;



            if (Physics.Raycast(ray.origin, ray.direction, out hit, Mathf.Infinity))
            {
                mousePos      = hit.point;
                mousePosValid = true;

                ///
                /// process mouse & keyboard events
                ///

                //if (EditorWindow.focusedWindow)
                {
                    switch (Event.current.type)
                    {
                    case EventType.KeyDown:
                    {
                        // toggle add mode
                        if (Event.current.shift && Event.current.keyCode == KeyCode.A)
                        {
                            // toggle add mode

                            SplineSettings.AttachMode selectedAttachMode = editorTarget.splineSettings.attachMode;

                            /*
                             * SplineSettings.AttachMode selectedAttachMode = (SplineSettings.AttachMode)System.Enum.GetValues(typeof(SplineSettings.AttachMode)).GetValue(attachMode.enumValueIndex);
                             *
                             * int boundsIndex = ArrayUtility.IndexOf((SplineSettings.AttachMode[])System.Enum.GetValues(typeof(SplineSettings.AttachMode)), SplineSettings.AttachMode.Bounds);
                             * int betweenIndex = ArrayUtility.IndexOf((SplineSettings.AttachMode[])System.Enum.GetValues(typeof(SplineSettings.AttachMode)), SplineSettings.AttachMode.Between);
                             */

                            if (selectedAttachMode == SplineSettings.AttachMode.Bounds)
                            {
                                editorTarget.splineSettings.attachMode = SplineSettings.AttachMode.Between;
                            }
                            else
                            {
                                editorTarget.splineSettings.attachMode = SplineSettings.AttachMode.Bounds;
                            }

                            // trigger repaint, so that the enumpopup will be updated
                            editor.Repaint();
                        }
                        ;

                        break;
                    }
                    }
                }

                // control key pressed
                if (Event.current.shift)
                {
                    mousePos      = hit.point;
                    mousePosValid = true;

                    // shift + ctrl = delete
                    bool deleteMode = Event.current.control;

                    int addControlPointIndex = FindClosestControlPoint(mousePos);

                    //Handles.DrawSphere(controlId, mousePos, Quaternion.identity, 0.3f);
                    Color handleColor;
                    if (deleteMode)
                    {
                        handleColor = Color.red; // red = delete
                    }
                    // draw attachment line
                    else
                    {
                        handleColor = Color.gray; // gray = add
                    }

                    // draw gray circle
                    float radius = 0.1f;
                    Handles.color = handleColor;
                    Handles.DrawWireDisc(mousePos, hit.normal, radius);

                    // draw line to closest point
                    if (editorTarget.splineSettings.controlPoints.Count > 0)
                    {
                        // draw indicator line to closest control point
                        Vector3 lineStartPosition = editorTarget.splineSettings.controlPoints.ElementAt(addControlPointIndex).position;
                        Vector3 lineEndPosition   = mousePos;

                        Handles.DrawLine(lineStartPosition, lineEndPosition);

                        // draw additional indicator line to the control point which is next in the list after the closest control point
                        if (!deleteMode)
                        {
                            int neighbourIndex;
                            if (addControlPointIndex > 0)
                            {
                                neighbourIndex = addControlPointIndex - 1;
                            }
                            else
                            {
                                neighbourIndex = addControlPointIndex + 1;
                            }

                            if (editorTarget.splineSettings.attachMode == SplineSettings.AttachMode.Between && neighbourIndex >= 0 && neighbourIndex <= editorTarget.splineSettings.controlPoints.Count - 1)
                            {
                                Vector3 neighbourLineStartPosition = editorTarget.splineSettings.controlPoints.ElementAt(neighbourIndex).position;
                                Vector3 neighbourLineEndPosition   = mousePos;

                                Handles.DrawLine(neighbourLineStartPosition, neighbourLineEndPosition);
                            }
                        }
                    }

                    if (Event.current.type == EventType.MouseDown)
                    {
                        // delete node
                        if (deleteMode)
                        {
                            bool canDelete = editorTarget.splineSettings.controlPoints.Count > 0;

                            if (Event.current.button == 0 && canDelete)
                            {
                                Vector3 mousePosition = new Vector3(mousePos.x, mousePos.y, mousePos.z);

                                int controlPointIndex = FindClosestControlPoint(mousePosition);

                                // remove the closest point
                                if (controlPointIndex != -1)
                                {
                                    RemoveControlPoint(controlPointIndex);
                                }


                                Event.current.Use();
                            }
                        }
                        // add new node
                        else
                        {
                            // left button = 0; right = 1; middle = 2
                            if (Event.current.button == 0)
                            {
                                Vector3 position = new Vector3(mousePos.x, mousePos.y, mousePos.z);

                                AddControlPoint(position, addControlPointIndex);

                                Event.current.Use();
                            }
                        }
                    }
                }
            }
            else
            {
                mousePosValid = false;
            }

            if (Event.current.type == EventType.Layout)
            {
                HandleUtility.AddDefaultControl(controlId);
            }

            DrawSplineGizmos();

            // create gameobjects
            bool placeObjects = mousePosValid && spawnMechanism.enumValueIndex == (int)SpawnMechanism.Automatic;

            if (placeObjects)
            {
                PerformEditorAction();
            }

            // show info
            Handles.BeginGUI();

            string[] info = new string[] { "Add Control Point: shift + click", "Remove control point: shift + ctrl + click", "Change Attach Mode: shift + A, Current: " + editorTarget.splineSettings.attachMode };
            PrefabPainterEditor.ShowGuiInfo(info);

            Handles.EndGUI();
        }
 public ToolsExtension(PrefabPainterEditor editor)
 {
     this.editor       = editor;
     this.editorTarget = editor.GetPainter();
 }
Exemple #20
0
 public SelectionExtension(PrefabPainterEditor editor)
 {
     this.editor       = editor;
     this.editorTarget = editor.GetPainter();
 }
 public VegetationStudioProIntegration(PrefabPainterEditor editor)
 {
     this.editor = editor;
 }
Exemple #22
0
#pragma warning restore 0414

        public UnityTerrainTreeManager(PrefabPainterEditor editor)
        {
            this.editor = editor;
        }
Exemple #23
0
        public VegetationStudioProIntegration(PrefabPainterEditor editor)
        {
            this.editor = editor;

            spawnToVSPro = editor.FindProperty(x => x.brushSettings.spawnToVSPro);
        }
Exemple #24
0
        #pragma warning restore 0414

        public ContainerModuleEditor(PrefabPainterEditor editor)
        {
            this.editor       = editor;
            this.editorTarget = editor.GetPainter();
        }