示例#1
0
        public void OnSceneGUI()
        {
            if (!editMode)
            {
                return;
            }

            CreateParticleMaterials();

            ResizeParticleArrays();

            if (!actor.Initialized)
            {
                return;
            }

            if (Camera.current != null)
            {
                camup      = Camera.current.transform.up;
                camright   = Camera.current.transform.right;
                camforward = Camera.current.transform.forward;
            }

            if (Event.current.type == EventType.Repaint)
            {
                // Update camera facing status and world space positions array:
                UpdateParticleEditorInformation();

                // Generate sorted indices for back-to-front rendering:
                for (int i = 0; i < sortedIndices.Length; i++)
                {
                    sortedIndices[i] = i;
                }

                Array.Sort <int>(sortedIndices, (a, b) => sqrDistanceToCamera[b].CompareTo(sqrDistanceToCamera[a]));

                // Draw custom actor stuff.
                DrawActorInfo();
            }

            // Draw tool handles:
            if (Camera.current != null)
            {
                if (paintBrush)
                {
                    if (ObiClothParticleHandles.ParticleBrush(wsPositions, faceCulling, facingCamera, brushRadius,
                                                              () => {
                        // As RecordObject diffs with the end of the current frame,
                        // and this is a multi-frame operation, we need to use RegisterCompleteObjectUndo instead.
                        Undo.RegisterCompleteObjectUndo(actor, "Paint particles");
                    },
                                                              PaintbrushStampCallback,
                                                              () => {
                        EditorUtility.SetDirty(actor);
                    },
                                                              Resources.Load <Texture2D>("BrushHandle")))
                    {
                        ParticlePropertyChanged();
                    }
                }
                else if (selectionBrush)
                {
                    if (ObiClothParticleHandles.ParticleBrush(wsPositions, faceCulling, facingCamera, brushRadius, null,
                                                              (List <ParticleStampInfo> stampInfo, bool modified) => {
                        foreach (ParticleStampInfo info in stampInfo)
                        {
                            if (actor.active[info.index])
                            {
                                selectionStatus[info.index] = !modified;
                            }
                        }
                    }, null,
                                                              Resources.Load <Texture2D>("BrushHandle")))
                    {
                        SelectionChanged();
                    }
                }
                else
                {
                    if (ObiClothParticleHandles.ParticleSelector(wsPositions, selectionStatus, faceCulling, facingCamera))
                    {
                        SelectionChanged();
                    }
                }
            }

            // Sceneview GUI:
            Handles.BeginGUI();

            GUI.skin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene);

            if (Event.current.type == EventType.Repaint)
            {
                uirect   = GUILayout.Window(0, uirect, DrawUIWindow, "Particle editor");
                uirect.x = Screen.width / EditorGUIUtility.pixelsPerPoint - uirect.width - 10;               //10 and 28 are magic values, since Screen size is not exactly right.
                uirect.y = Screen.height / EditorGUIUtility.pixelsPerPoint - uirect.height - 28;
            }

            GUILayout.Window(0, uirect, DrawUIWindow, "Particle editor");

            Handles.EndGUI();
        }
示例#2
0
        public void OnSceneGUI()
        {
            if (!editMode)
            {
                return;
            }

            CreateParticleMaterial();
            particleMaterial.SetPass(0);

            ResizeParticleArrays();

            if (!actor.Initialized)
            {
                return;
            }

            if (Camera.current != null)
            {
                camup      = Camera.current.transform.up;
                camright   = Camera.current.transform.right;
                camforward = Camera.current.transform.forward;
            }

            if (Event.current.type == EventType.Repaint)
            {
                // Update camera facing status and world space positions array:
                UpdateParticleEditorInformation();

                // Draw 3D stuff: particles, constraints, grid, etc.
                DrawParticles();
            }

            // Draw tool handles:
            if (Camera.current != null)
            {
                switch (tool)
                {
                case EditionTool.SELECT:
                    if (ObiClothParticleHandles.ParticleSelector(wsPositions, selectionStatus, backfaces, facingCamera))
                    {
                        SelectionChanged();
                    }
                    break;

                case EditionTool.SELECTBRUSH:
                    if (ObiClothParticleHandles.ParticleBrush(wsPositions, backfaces, facingCamera, brushRadius, null,
                                                              (List <ParticleStampInfo> stampInfo, bool modified) => {
                        foreach (ParticleStampInfo info in stampInfo)
                        {
                            if (actor.active[info.index])
                            {
                                selectionStatus[info.index] = !modified;
                            }
                        }
                    }, null,
                                                              EditorGUIUtility.Load("BrushHandle.psd") as Texture2D))
                    {
                        SelectionChanged();
                    }
                    break;

                case EditionTool.PAINT:                 //TODO: select mask (paint on selected)
                    if (ObiClothParticleHandles.ParticleBrush(wsPositions, backfaces, facingCamera, brushRadius,
                                                              () => {
                        // As RecordObject diffs with the end of the current frame,
                        // and this is a multi-frame operation, we need to use RegisterCompleteObjectUndo instead.
                        Undo.RegisterCompleteObjectUndo(actor, "Paint particles");
                    },
                                                              PaintbrushStampCallback,
                                                              () => {
                        EditorUtility.SetDirty(actor);
                    },
                                                              EditorGUIUtility.Load("BrushHandle.psd") as Texture2D))
                    {
                        ParticlePropertyChanged();
                    }
                    break;
                }
            }

            // Sceneview GUI:
            Handles.BeginGUI();

            GUI.skin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene);

            if (Event.current.type == EventType.Repaint)
            {
                uirect   = GUILayout.Window(0, uirect, DrawUIWindow, "Particle editor");
                uirect.x = Screen.width - uirect.width - 10;                 //10 and 28 are magic values, since Screen size is not exactly right.
                uirect.y = Screen.height - uirect.height - 28;
            }

            GUILayout.Window(0, uirect, DrawUIWindow, "Particle editor");

            Handles.EndGUI();
        }