Exemple #1
0
            /// <summary>
            /// Draw the control point onto Scene view
            /// </summary>
            public void DrawHandles()
            {
#if UNITY_EDITOR
                bool isCtrlKeyHold  = Event.current != null && Event.current.control;
                bool isShiftKeyHold = Event.current != null && Event.current.shift;

                //drag to move control point's position
                EditorHandles.color = Color.blue;
                Vector3 oldPosition = Position;
                Vector3 newPosition = EditorHandles.FreeMoveHandle(
                    Position,
                    Quaternion.identity,
                    HandleUtility.GetHandleSize(Position) * 0.2f,
                    Vector3.zero,
                    EditorHandles.CircleHandleCap);
                newPosition.y = oldPosition.y; //restrict Y-axis movement
                if (newPosition != oldPosition)
                {
                    if (isShiftKeyHold)
                    {
                        newPosition = SnapPosition(newPosition);
                    }
                    if (isCtrlKeyHold)
                    {
                        Translate(newPosition - oldPosition);
                    }
                    else
                    {
                        Position = newPosition;
                    }
                }

                //drag to move handle's position
                EditorHandles.color = Color.red;
                for (int i = 0; i < Handles.Length; ++i)
                {
                    Vector3 handleOldPosition = Handles[i];
                    Vector3 handleNewPosition = EditorHandles.FreeMoveHandle(
                        Handles[i],
                        Quaternion.identity,
                        HandleUtility.GetHandleSize(Handles[i]) * 0.1f,
                        Vector3.zero,
                        EditorHandles.RectangleHandleCap);
                    handleNewPosition.y = handleOldPosition.y; //restrict Y-axis movement

                    if (Handles[i] != handleNewPosition)
                    {
                        if (isShiftKeyHold)
                        {
                            handleNewPosition = SnapHandle(handleNewPosition);
                        }
                        SetHandle(i, handleNewPosition);
                        if (isCtrlKeyHold)
                        {
                            Vector3 reflectedPosition = handleNewPosition + 2 * (Position - handleNewPosition);
                            SetHandle(Handles.Length - 1 - i, reflectedPosition);
                        }
                    }
                    EditorHandles.DrawLine(Handles[i], Position);
                }
#endif
            }
        private void CollisionPlanesSceneGUI()
        {
            if (m_ScenePlanes.Count == 0)
            {
                return;
            }

            Event evt = Event.current;

            Color origCol = Handles.color;
            Color col     = new Color(1, 1, 1, 0.5F);

            for (int i = 0; i < m_ScenePlanes.Count; ++i)
            {
                if (m_ScenePlanes[i] == null)
                {
                    continue;
                }

                Transform  transform          = m_ScenePlanes[i];
                Vector3    position           = transform.position;
                Quaternion rotation           = transform.rotation;
                Vector3    right              = rotation * Vector3.right;
                Vector3    up                 = rotation * Vector3.up;
                Vector3    forward            = rotation * Vector3.forward;
                bool       isPlayingAndStatic = EditorApplication.isPlaying && transform.gameObject.isStatic;
                if (editingPlanes)
                {
                    if (Object.ReferenceEquals(s_SelectedTransform, transform))
                    {
                        EditorGUI.BeginChangeCheck();
                        var newPosition = transform.position;
                        var newRotation = transform.rotation;

                        using (new EditorGUI.DisabledScope(isPlayingAndStatic))
                        {
                            if (isPlayingAndStatic)
                            {
                                Handles.ShowStaticLabel(position);
                            }
                            if (EditMode.editMode == EditMode.SceneViewEditMode.ParticleSystemCollisionModulePlanesMove)
                            {
                                newPosition = Handles.PositionHandle(position, rotation);
                            }
                            else if (EditMode.editMode == EditMode.SceneViewEditMode.ParticleSystemCollisionModulePlanesRotate)
                            {
                                newRotation = Handles.RotationHandle(rotation, position);
                            }
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(transform, s_UndoCollisionPlaneString);
                            transform.position = newPosition;
                            transform.rotation = newRotation;
                            ParticleSystemEditorUtils.PerformCompleteResimulation();
                        }
                    }
                    else
                    {
                        float handleSize = HandleUtility.GetHandleSize(position) * 0.6f;

                        EventType oldEventType = evt.type;

                        // we want ignored mouse up events to check for dragging off of scene view
                        if (evt.type == EventType.Ignore && evt.rawType == EventType.MouseUp)
                        {
                            oldEventType = evt.rawType;
                        }

                        Handles.FreeMoveHandle(position, Quaternion.identity, handleSize, Vector3.zero, Handles.RectangleHandleCap);

                        // Detect selected plane (similar to TreeEditor)
                        if (oldEventType == EventType.MouseDown && evt.type == EventType.Used)
                        {
                            s_SelectedTransform   = transform;
                            oldEventType          = EventType.Used;
                            GUIUtility.hotControl = 0; // Reset hot control or the FreeMoveHandle will prevent input to the new Handles. (case 873514)
                        }
                    }
                }

                Handles.color = col;
                Color color = Handles.s_ColliderHandleColor * 0.9f;
                if (isPlayingAndStatic)
                {
                    color.a *= 0.2f;
                }

                if (m_PlaneVisualizationType == PlaneVizType.Grid)
                {
                    DrawGrid(position, right, forward, up, color);
                }
                else
                {
                    DrawSolidPlane(position, rotation, color, Color.yellow);
                }
            }

            Handles.color = origCol;
        }
Exemple #3
0
 private void CollisionPlanesSceneGUI()
 {
     if (this.m_ScenePlanes.Count != 0)
     {
         Event current = Event.current;
         Color color   = Handles.color;
         Color color2  = new Color(1f, 1f, 1f, 0.5f);
         for (int i = 0; i < this.m_ScenePlanes.Count; i++)
         {
             if (!(this.m_ScenePlanes[i] == null))
             {
                 Transform  transform = this.m_ScenePlanes[i];
                 Vector3    position  = transform.position;
                 Quaternion rotation  = transform.rotation;
                 Vector3    axis      = rotation * Vector3.right;
                 Vector3    normal    = rotation * Vector3.up;
                 Vector3    axis2     = rotation * Vector3.forward;
                 bool       flag      = EditorApplication.isPlaying && transform.gameObject.isStatic;
                 if (this.editingPlanes)
                 {
                     if (object.ReferenceEquals(CollisionModuleUI.s_SelectedTransform, transform))
                     {
                         EditorGUI.BeginChangeCheck();
                         Vector3    position2 = transform.position;
                         Quaternion rotation2 = transform.rotation;
                         using (new EditorGUI.DisabledScope(flag))
                         {
                             if (flag)
                             {
                                 Handles.ShowStaticLabel(position);
                             }
                             if (EditMode.editMode == EditMode.SceneViewEditMode.ParticleSystemCollisionModulePlanesMove)
                             {
                                 position2 = Handles.PositionHandle(position, rotation);
                             }
                             else if (EditMode.editMode == EditMode.SceneViewEditMode.ParticleSystemCollisionModulePlanesRotate)
                             {
                                 rotation2 = Handles.RotationHandle(rotation, position);
                             }
                         }
                         if (EditorGUI.EndChangeCheck())
                         {
                             Undo.RecordObject(transform, "Modified Collision Plane Transform");
                             transform.position = position2;
                             transform.rotation = rotation2;
                             ParticleSystemEditorUtils.PerformCompleteResimulation();
                         }
                     }
                     else
                     {
                         float     num       = HandleUtility.GetHandleSize(position) * 0.6f;
                         EventType eventType = current.type;
                         if (current.type == EventType.Ignore && current.rawType == EventType.MouseUp)
                         {
                             eventType = current.rawType;
                         }
                         Vector3    arg_1F3_0 = position;
                         Quaternion arg_1F3_1 = Quaternion.identity;
                         float      arg_1F3_2 = num;
                         Vector3    arg_1F3_3 = Vector3.zero;
                         if (CollisionModuleUI.< > f__mg$cache0 == null)
                         {
                             CollisionModuleUI.< > f__mg$cache0 = new Handles.CapFunction(Handles.RectangleHandleCap);
                         }
                         Handles.FreeMoveHandle(arg_1F3_0, arg_1F3_1, arg_1F3_2, arg_1F3_3, CollisionModuleUI.< > f__mg$cache0);
                         if (eventType == EventType.MouseDown && current.type == EventType.Used)
                         {
                             CollisionModuleUI.s_SelectedTransform = transform;
                             GUIUtility.hotControl = 0;
                         }
                     }
                 }
                 Handles.color = color2;
                 Color color3 = Handles.s_ColliderHandleColor * 0.9f;
                 if (flag)
                 {
                     color3.a *= 0.2f;
                 }
                 if (CollisionModuleUI.m_PlaneVisualizationType == CollisionModuleUI.PlaneVizType.Grid)
                 {
                     CollisionModuleUI.DrawGrid(position, axis, axis2, normal, color3);
                 }
                 else
                 {
                     CollisionModuleUI.DrawSolidPlane(position, rotation, color3, Color.yellow);
                 }
             }
         }
         Handles.color = color;
     }
 }
        public override void OnSceneGUI(ParticleSystem s, InitialModuleUI initial)
        {
            Event     current   = Event.current;
            EventType eventType = current.type;

            if (current.type == EventType.Ignore && current.rawType == EventType.MouseUp)
            {
                eventType = current.rawType;
            }
            Color color1 = Handles.color;

            Handles.color = new Color(1f, 1f, 1f, 0.5f);
            if (this.m_Type.intValue == 0)
            {
                for (int index = 0; index < this.m_ShownPlanes.Length; ++index)
                {
                    Object objectReferenceValue = this.m_ShownPlanes[index].objectReferenceValue;
                    if (objectReferenceValue != (Object)null)
                    {
                        Transform transform = objectReferenceValue as Transform;
                        if ((Object)transform != (Object)null)
                        {
                            Vector3    position = transform.position;
                            Quaternion rotation = transform.rotation;
                            Vector3    axis1    = rotation * Vector3.right;
                            Vector3    normal   = rotation * Vector3.up;
                            Vector3    axis2    = rotation * Vector3.forward;
                            if (object.ReferenceEquals((object)CollisionModuleUI.m_SelectedTransform, (object)transform))
                            {
                                Tools.s_Hidden = true;
                                EditorGUI.BeginChangeCheck();
                                if (Tools.current == Tool.Move)
                                {
                                    transform.position = Handles.PositionHandle(position, rotation);
                                }
                                else if (Tools.current == Tool.Rotate)
                                {
                                    transform.rotation = Handles.RotationHandle(rotation, position);
                                }
                                if (EditorGUI.EndChangeCheck())
                                {
                                    if (this.m_PlaneVisualizationType == CollisionModuleUI.PlaneVizType.Solid)
                                    {
                                        GameObject plane = ParticleEffectUtils.GetPlane(index);
                                        plane.transform.position   = position;
                                        plane.transform.rotation   = rotation;
                                        plane.transform.localScale = new Vector3(this.m_ScaleGrid, this.m_ScaleGrid, this.m_ScaleGrid);
                                    }
                                    ParticleSystemEditorUtils.PerformCompleteResimulation();
                                }
                            }
                            else
                            {
                                int   keyboardControl = GUIUtility.keyboardControl;
                                float size            = HandleUtility.GetHandleSize(position) * 0.06f;
                                Handles.FreeMoveHandle(position, Quaternion.identity, size, Vector3.zero, new Handles.DrawCapFunction(Handles.RectangleCap));
                                if (eventType == EventType.MouseDown && current.type == EventType.Used && keyboardControl != GUIUtility.keyboardControl)
                                {
                                    CollisionModuleUI.m_SelectedTransform = transform;
                                    eventType = EventType.Used;
                                }
                            }
                            if (this.m_PlaneVisualizationType == CollisionModuleUI.PlaneVizType.Grid)
                            {
                                Color color2 = Handles.s_ColliderHandleColor * 0.9f;
                                if (!this.enabled)
                                {
                                    color2 = new Color(0.7f, 0.7f, 0.7f, 0.7f);
                                }
                                this.DrawGrid(position, axis1, axis2, normal, color2, index);
                            }
                            else
                            {
                                this.DrawSolidPlane(position, rotation, index);
                            }
                        }
                        else
                        {
                            Debug.LogError((object)("Not a transform: " + (object)objectReferenceValue.GetType()));
                        }
                    }
                }
            }
            Handles.color = color1;
        }
Exemple #5
0
        public override void OnSceneGUI(ParticleSystem s, InitialModuleUI initial)
        {
            Event     current = Event.current;
            EventType rawType = current.type;

            if ((current.type == EventType.Ignore) && (current.rawType == EventType.MouseUp))
            {
                rawType = current.rawType;
            }
            Color color  = Handles.color;
            Color color2 = new Color(1f, 1f, 1f, 0.5f);

            Handles.color = color2;
            if (this.m_Type.intValue == 0)
            {
                for (int i = 0; i < this.m_ShownPlanes.Length; i++)
                {
                    Object objectReferenceValue = this.m_ShownPlanes[i].objectReferenceValue;
                    if (objectReferenceValue != null)
                    {
                        Transform objB = objectReferenceValue as Transform;
                        if (objB != null)
                        {
                            Vector3    position = objB.position;
                            Quaternion rotation = objB.rotation;
                            Vector3    vector2  = (Vector3)(rotation * Vector3.right);
                            Vector3    normal   = (Vector3)(rotation * Vector3.up);
                            Vector3    vector4  = (Vector3)(rotation * Vector3.forward);
                            if (object.ReferenceEquals(m_SelectedTransform, objB))
                            {
                                Tools.s_Hidden = true;
                                EditorGUI.BeginChangeCheck();
                                if (Tools.current == Tool.Move)
                                {
                                    objB.position = Handles.PositionHandle(position, rotation);
                                }
                                else if (Tools.current == Tool.Rotate)
                                {
                                    objB.rotation = Handles.RotationHandle(rotation, position);
                                }
                                if (EditorGUI.EndChangeCheck())
                                {
                                    if (this.m_PlaneVisualizationType == PlaneVizType.Solid)
                                    {
                                        GameObject plane = ParticleEffectUtils.GetPlane(i);
                                        plane.transform.position   = position;
                                        plane.transform.rotation   = rotation;
                                        plane.transform.localScale = new Vector3(this.m_ScaleGrid, this.m_ScaleGrid, this.m_ScaleGrid);
                                    }
                                    ParticleSystemEditorUtils.PerformCompleteResimulation();
                                }
                            }
                            else
                            {
                                int   keyboardControl = GUIUtility.keyboardControl;
                                float size            = HandleUtility.GetHandleSize(position) * 0.06f;
                                Handles.FreeMoveHandle(position, Quaternion.identity, size, Vector3.zero, new Handles.DrawCapFunction(Handles.RectangleCap));
                                if (((rawType == EventType.MouseDown) && (current.type == EventType.Used)) && (keyboardControl != GUIUtility.keyboardControl))
                                {
                                    m_SelectedTransform = objB;
                                    rawType             = EventType.Used;
                                }
                            }
                            if (this.m_PlaneVisualizationType == PlaneVizType.Grid)
                            {
                                Color color3 = (Color)(Handles.s_ColliderHandleColor * 0.9f);
                                if (!base.enabled)
                                {
                                    color3 = new Color(0.7f, 0.7f, 0.7f, 0.7f);
                                }
                                this.DrawGrid(position, vector2, vector4, normal, color3, i);
                            }
                            else
                            {
                                this.DrawSolidPlane(position, rotation, i);
                            }
                        }
                        else
                        {
                            Debug.LogError("Not a transform: " + objectReferenceValue.GetType());
                        }
                    }
                }
            }
            Handles.color = color;
        }
Exemple #6
0
            public override void OnToolGUI(EditorWindow window)
            {
                var firstTransform = SyncScenePlanes();

                if (m_ScenePlanes.Count == 0)
                {
                    return;
                }

                // Clear invalid selection (ie when selecting other system)
                if (s_SelectedTransform != null)
                {
                    if (!m_ScenePlanes.Contains(s_SelectedTransform))
                    {
                        s_SelectedTransform = null;
                    }
                }

                // Always try to select first collider if no selection exists
                if (s_SelectedTransform == null)
                {
                    s_SelectedTransform = firstTransform;
                }

                Event evt = Event.current;

                Color origCol   = Handles.color;
                Color col       = new Color(1, 1, 1, 0.5F);
                bool  isPlaying = EditorApplication.isPlaying;

                foreach (var transform in m_ScenePlanes)
                {
                    Vector3    position           = transform.position;
                    Quaternion rotation           = transform.rotation;
                    Vector3    right              = rotation * Vector3.right;
                    Vector3    up                 = rotation * Vector3.up;
                    Vector3    forward            = rotation * Vector3.forward;
                    bool       isPlayingAndStatic = isPlaying && transform.gameObject.isStatic;

                    if (ReferenceEquals(s_SelectedTransform, transform))
                    {
                        EditorGUI.BeginChangeCheck();
                        var newPosition = transform.position;
                        var newRotation = transform.rotation;

                        using (new EditorGUI.DisabledScope(isPlayingAndStatic))
                        {
                            if (isPlayingAndStatic)
                            {
                                Handles.ShowSceneViewLabel(position, Handles.s_StaticLabel);
                            }
                            Handles.TransformHandle(ref newPosition, ref newRotation);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(transform, s_UndoCollisionPlaneString);
                            transform.position = newPosition;
                            transform.rotation = newRotation;
                            ParticleSystemEditorUtils.PerformCompleteResimulation();
                        }
                    }
                    else
                    {
                        float handleSize = HandleUtility.GetHandleSize(position) * 0.6f;

                        EventType oldEventType = evt.type;

                        // we want ignored mouse up events to check for dragging off of scene view
                        if (evt.type == EventType.Ignore && evt.rawType == EventType.MouseUp)
                        {
                            oldEventType = evt.rawType;
                        }

                        Handles.FreeMoveHandle(position, handleSize, Vector3.zero, Handles.RectangleHandleCap);

                        // Detect selected plane (similar to TreeEditor)
                        if (oldEventType == EventType.MouseDown && evt.type == EventType.Used)
                        {
                            s_SelectedTransform   = transform;
                            oldEventType          = EventType.Used;
                            GUIUtility.hotControl = 0; // Reset hot control or the FreeMoveHandle will prevent input to the new Handles. (case 873514)
                        }
                    }

                    Handles.color = col;
                    Color color = Handles.s_ColliderHandleColor * 0.9f;
                    if (isPlayingAndStatic)
                    {
                        color.a *= 0.2f;
                    }

                    if (m_PlaneVisualizationType == PlaneVizType.Grid)
                    {
                        DrawGrid(position, right, forward, up, color);
                    }
                    else
                    {
                        DrawSolidPlane(position, rotation, color, Color.yellow);
                    }
                }

                Handles.color = origCol;
            }
        public override void OnSceneGUI(ParticleSystem s, InitialModuleUI initial)
        {
            Event     current   = Event.current;
            EventType eventType = current.type;

            if (current.type == EventType.Ignore && current.rawType == EventType.MouseUp)
            {
                eventType = current.rawType;
            }
            Color color  = Handles.color;
            Color color2 = new Color(1f, 1f, 1f, 0.5f);

            Handles.color = color2;
            if (this.m_Type.intValue == 0)
            {
                for (int i = 0; i < this.m_ShownPlanes.Length; i++)
                {
                    UnityEngine.Object objectReferenceValue = this.m_ShownPlanes[i].objectReferenceValue;
                    if (objectReferenceValue != null)
                    {
                        Transform transform = objectReferenceValue as Transform;
                        if (transform != null)
                        {
                            Vector3    position = transform.position;
                            Quaternion rotation = transform.rotation;
                            Vector3    axis     = rotation * Vector3.right;
                            Vector3    normal   = rotation * Vector3.up;
                            Vector3    axis2    = rotation * Vector3.forward;
                            if (object.ReferenceEquals(CollisionModuleUI.s_SelectedTransform, transform))
                            {
                                Tools.s_Hidden = true;
                                EditorGUI.BeginChangeCheck();
                                if (Tools.current == Tool.Move)
                                {
                                    transform.position = Handles.PositionHandle(position, rotation);
                                }
                                else if (Tools.current == Tool.Rotate)
                                {
                                    transform.rotation = Handles.RotationHandle(rotation, position);
                                }
                                if (EditorGUI.EndChangeCheck())
                                {
                                    if (this.m_PlaneVisualizationType == CollisionModuleUI.PlaneVizType.Solid)
                                    {
                                        GameObject plane = ParticleEffectUtils.GetPlane(i);
                                        plane.transform.position   = position;
                                        plane.transform.rotation   = rotation;
                                        plane.transform.localScale = new Vector3(this.m_ScaleGrid, this.m_ScaleGrid, this.m_ScaleGrid);
                                    }
                                    ParticleSystemEditorUtils.PerformCompleteResimulation();
                                }
                            }
                            else
                            {
                                int        keyboardControl = GUIUtility.keyboardControl;
                                float      num             = HandleUtility.GetHandleSize(position) * 0.06f;
                                Vector3    arg_1EB_0       = position;
                                Quaternion arg_1EB_1       = Quaternion.identity;
                                float      arg_1EB_2       = num;
                                Vector3    arg_1EB_3       = Vector3.zero;
                                if (CollisionModuleUI.< > f__mg$cache0 == null)
                                {
                                    CollisionModuleUI.< > f__mg$cache0 = new Handles.CapFunction(Handles.RectangleHandleCap);
                                }
                                Handles.FreeMoveHandle(arg_1EB_0, arg_1EB_1, arg_1EB_2, arg_1EB_3, CollisionModuleUI.< > f__mg$cache0);
                                if (eventType == EventType.MouseDown && current.type == EventType.Used && keyboardControl != GUIUtility.keyboardControl)
                                {
                                    CollisionModuleUI.s_SelectedTransform = transform;
                                    eventType = EventType.Used;
                                }
                            }
                            if (this.m_PlaneVisualizationType == CollisionModuleUI.PlaneVizType.Grid)
                            {
                                Color color3 = Handles.s_ColliderHandleColor * 0.9f;
                                if (!base.enabled)
                                {
                                    color3 = new Color(0.7f, 0.7f, 0.7f, 0.7f);
                                }
                                this.DrawGrid(position, axis, axis2, normal, color3, i);
                            }
                            else
                            {
                                this.DrawSolidPlane(position, rotation, i);
                            }
                        }
                        else
                        {
                            Debug.LogError("Not a transform: " + objectReferenceValue.GetType());
                        }
                    }
                }
            }
            Handles.color = color;
        }