Beispiel #1
0
        /// <summary>Draws the main editor used for editing rail values</summary>
        /// <param name="rail">The Rail component whose values to display</param>
        /// <param name="heading">The string to display in the EditorHeader</param>
        private void DrawMainEditor(Rail rail, string heading)
        {
            // Default values used when rail == null.
            Color           currentColor       = Color.grey;
            Transform       currentTarget      = null;
            RailOrientation currentOrientation = RailOrientation.Horizontal;
            float           currentLeadIn      = 0f;
            float           currentTrailOut    = 0f;

            if (rail != null)
            {
                currentTarget      = rail.Target;
                currentOrientation = rail.Orientation;
                currentLeadIn      = rail.LeadIn;
                currentTrailOut    = rail.TrailOut;
            }
            else
            {
                GUI.enabled = false;
            }

            // Header - displays name of rail being edited
            GUIUtilities.EditorHeader(heading);

            EditorGUILayout.Space();

            // Target
            _content = new GUIContent("Target", "The target the camera follows while on the rail. If null, the Railcam 2D target is used by default");
            var newTarget = EditorGUILayout.ObjectField(_content, currentTarget, typeof(Transform), true);

            if (rail != null)
            {
                if (rail.Target != (Transform)newTarget)
                {
                    Undo.RecordObject(rail, "Change Rail Target");
                    rail.Target = (Transform)newTarget;
                }
            }

            EditorGUILayout.Space();

            // Orientation
            _content = new GUIContent("Orientation", "The axis used to calculate camera position while on the rail");
            var newOrientation = EditorGUILayout.EnumPopup(_content, currentOrientation);

            if (rail != null)
            {
                if (rail.Orientation != (RailOrientation)newOrientation)
                {
                    Undo.RecordObject(rail, "Change Rail Orientation");
                    rail.Orientation = (RailOrientation)newOrientation;
                }
            }

            EditorGUILayout.Space();

            // Lead-In
            _content = new GUIContent("FX: Lead-In", "The camera leads with reduced velocity between the first two nodes");
            var newLeadIn = EditorGUILayout.Slider(_content, currentLeadIn, 0f, 1f);

            if (rail != null)
            {
                if (rail.LeadIn != newLeadIn)
                {
                    Undo.RecordObject(rail, "Change Rail Lead-In");
                    rail.LeadIn   = newLeadIn;
                    _repaintScene = true;
                }
            }

            // Trail-Out
            _content = new GUIContent("FX: Trail-Out", "The camera trails with reduced velocity between the final two nodes");
            var newTrailOut = EditorGUILayout.Slider(_content, currentTrailOut, 0f, 1f);

            if (rail != null)
            {
                if (rail.TrailOut != newTrailOut)
                {
                    Undo.RecordObject(rail, "Change Rail Trail-Out");
                    rail.TrailOut = newTrailOut;
                    _repaintScene = true;
                }
            }

            EditorGUILayout.Space();

            // Rail Nodes
            if (rail != null)
            {
                ListRailNodes(rail);
            }
        }
Beispiel #2
0
        /// <summary>Draws the main editor for the TriggerManager</summary>
        /// <param name="trigger">The Trigger component whose values to display</param>
        /// <param name="heading">The string to display in the EditorHeader</param>
        private void DrawMainEditor(Trigger trigger, string heading)
        {
            // Default values used when trigger == null.
            Color        currentColor        = Color.grey;
            Transform    currentTarget       = null;
            TriggerEvent currentEvent        = TriggerEvent.Generic;
            float        currentScanInterval = 0f;
            bool         currentStartActive  = false;
            TriggerShape currentShape        = TriggerShape.Circle;
            Vector2      currentPosition     = Vector2.zero;
            float        currentRadius       = 0f;
            Vector2      currentSize         = Vector2.zero;

            if (trigger != null)
            {
                currentTarget       = trigger.Target;
                currentEvent        = trigger.Event;
                currentScanInterval = trigger.ScanInterval;
                currentStartActive  = trigger.StartActive;
                currentShape        = trigger.Shape;
                currentPosition     = trigger.Position;
                currentRadius       = trigger.Radius;
                currentSize         = trigger.Size;
            }
            else
            {
                GUI.enabled = false;
            }

            // Header - displays name of trigger being edited
            GUIUtilities.EditorHeader(heading);

            EditorGUILayout.Space();

            // Target
            _content = new GUIContent("Target", "The target the trigger detects. If null, the Railcam 2D target is used by default");
            var newTarget = EditorGUILayout.ObjectField(_content, currentTarget, typeof(Transform), true);

            if (trigger != null)
            {
                if (trigger.Target != (Transform)newTarget)
                {
                    Undo.RecordObject(trigger, "Change Trigger Target");
                    trigger.Target = (Transform)newTarget;
                }
            }

            EditorGUILayout.Space();

            // Event
            _content = new GUIContent("Event", "The event that occurs when the trigger detects its target");
            var newEvent = EditorGUILayout.EnumPopup(_content, currentEvent);

            if (trigger != null)
            {
                if (trigger.Event != (TriggerEvent)newEvent)
                {
                    Undo.RecordObject(trigger, "Change Trigger Event");
                    trigger.Event = (TriggerEvent)newEvent;
                    _repaintScene = true;
                }
            }

            // Selected Rail
            if (trigger != null && (trigger.Event == TriggerEvent.ConnectToSelectedRail || currentEvent == TriggerEvent.DisconnectFromSelectedRail))
            {
                DrawSelectedRailPopup(trigger);
            }

            EditorGUILayout.Space();

            // Scan Interval
            _content = new GUIContent("Scan Interval", "The time in seconds the trigger waits between each scan for the target (reduces load)");
            var newScanInterval = EditorGUILayout.FloatField(_content, currentScanInterval);

            if (trigger != null)
            {
                if (trigger.ScanInterval != newScanInterval)
                {
                    Undo.RecordObject(trigger, "Change Trigger Scan Interval");
                    if (newScanInterval < 0f)
                    {
                        newScanInterval = 0f;
                    }
                    trigger.ScanInterval = newScanInterval;
                }
            }

            EditorGUILayout.Space();

            // Start Active
            _content = new GUIContent("Start Active", "Determines whether or not the trigger starts the scene with scanning active. Use Activate() and Deactivate() to activate and deactivate the trigger during runtime");
            var newStartActive = EditorGUILayout.Toggle(_content, currentStartActive);

            if (trigger != null)
            {
                if (trigger.StartActive != newStartActive)
                {
                    Undo.RecordObject(trigger, "Change Trigger Start Active");
                    trigger.StartActive = newStartActive;
                }
            }

            EditorGUILayout.Space();

            // Shape
            _content = new GUIContent("Shape", "The shape of the trigger's detection area");
            var newShape = EditorGUILayout.EnumPopup(_content, currentShape);

            if (trigger != null)
            {
                if (trigger.Shape != (TriggerShape)newShape)
                {
                    Undo.RecordObject(trigger, "Change Trigger Shape");
                    trigger.Shape = (TriggerShape)newShape;
                    _repaintScene = true;
                }
            }

            EditorGUILayout.Space();

            // Position
            _content = new GUIContent("Position", "The position of the trigger");
            var newPosition = EditorGUILayout.Vector2Field(_content, currentPosition);

            if (trigger != null)
            {
                if (trigger.Position != newPosition)
                {
                    Undo.RecordObject(trigger, "Move Trigger");
                    trigger.Position = newPosition;
                }
            }

            if (trigger != null)
            {
                if (trigger.Shape == TriggerShape.Circle)
                {
                    // Radius
                    _content = new GUIContent("Radius", "The radius of the trigger when its shape is a circle");
                    var newRadius = EditorGUILayout.FloatField(_content, currentRadius);
                    if (trigger.Radius != newRadius)
                    {
                        Undo.RecordObject(trigger, "Change Trigger Radius");
                        if (newRadius < 0f)
                        {
                            newRadius = 0f;
                        }
                        trigger.Radius = newRadius;
                        _repaintScene  = true;
                    }
                }
                else if (trigger.Shape == TriggerShape.Rectangle)
                {
                    // Size
                    _content = new GUIContent("Size", "The size of the trigger when its shape is a rectangle");
                    var newSize = EditorGUILayout.Vector2Field(_content, currentSize);
                    if (trigger.Size != newSize)
                    {
                        Undo.RecordObject(trigger, "Change Trigger Size");
                        if (newSize.x < 0f)
                        {
                            newSize.x = 0f;
                        }
                        if (newSize.y < 0f)
                        {
                            newSize.y = 0f;
                        }
                        trigger.Size  = newSize;
                        _repaintScene = true;
                    }
                }
            }
        }