public void OnSceneGUI() { var currentTrigger = (Trigger)target; if (target == null) { return; } var handleSize = HandleUtility.GetHandleSize(Vector3.zero) * 0.2f; var snapValue = EditorPrefs.GetFloat(EditorPreferences.SnapKey, EditorPreferences.SnapValue); var snapSize = new Vector3(snapValue, snapValue, snapValue); // Draw editable trigger if (currentTrigger.gameObject.transform.parent != null && currentTrigger.gameObject.GetComponentInParent <TriggerManager>() != null) { GUIUtilities.DrawTriggerOnScene(currentTrigger, handleSize, snapSize, true); } // Draw uneditable trigger else { GUIUtilities.DrawTriggerOnScene(currentTrigger, handleSize, snapSize); } }
/// <summary>Creates a Button that adds a child object with a Rail component to the game object</summary> /// <param name="railManager">The RailManager component selected in the Inspector</param> private void AddNewRailButton(RailManager railManager) { // Disallows rails being added when Editor in Play Mode if (EditorApplication.isPlaying) { GUI.enabled = false; } // Button to add a rail _content = new GUIContent("Add New Rail", ""); if (GUILayout.Button(_content, GUILayout.Height(24f))) { // Checks for next available index to append to rail object name var railNames = new List <string>(); for (int i = 0; i < _rails.Count; i++) { railNames.Add(_rails[i].gameObject.name); } var newRailIndex = GUIUtilities.GetUniqueChildObjectIndex(railNames, "Rail "); // Adds the rail object GUIUtilities.AddRailObjectAsChild(railManager.gameObject, newRailIndex); _repaintScene = true; } if (EditorApplication.isPlaying) { GUI.enabled = true; } }
public void OnSceneGUI() { var triggerManager = (TriggerManager)target; if (target == null) { return; } _triggers = Utilities.GetTriggersFromChildren(triggerManager.gameObject, true); var handleSize = HandleUtility.GetHandleSize(Vector3.zero) * 0.2f; var snapValue = EditorPrefs.GetFloat(EditorPreferences.SnapKey, EditorPreferences.SnapValue); var snapSize = new Vector3(snapValue, snapValue, snapValue); // Draw Triggers for (int i = 0; i < _triggers.Count; i++) { var trigger = _triggers[i]; GUIUtilities.DrawTriggerOnScene(trigger, handleSize, snapSize, true); } // Sync editor values with scene if trigger is displayed if (_currentTriggerIndex != -1) { Repaint(); } }
/// <summary>Creates a Button that adds a child object with a Trigger component to the game object</summary> /// <param name="triggerManager">The TriggerManager component selected in the Inspector</param> private void AddNewTriggerButton(TriggerManager triggerManager) { // Disallows triggers being added when Editor in Play Mode if (EditorApplication.isPlaying) { GUI.enabled = false; } // Button to add a trigger _content = new GUIContent("Add New Trigger", ""); if (GUILayout.Button(_content, GUILayout.Height(24f))) { // Checks for next available index to append to trigger object name var triggerNames = new List <string>(); for (int i = 0; i < _triggers.Count; i++) { triggerNames.Add(_triggers[i].gameObject.name); } var newTriggerIndex = GUIUtilities.GetUniqueChildObjectIndex(triggerNames, "Trigger "); // Adds the trigger object GUIUtilities.AddTriggerObjectAsChild(triggerManager.gameObject, newTriggerIndex); _repaintScene = true; } if (EditorApplication.isPlaying) { GUI.enabled = true; } }
/// <summary>Destroys a game object with the specified Rail component attached</summary> /// <param name="rail">The Rail component whose game object to destroy</param> private void RemoveRail(Rail rail) { if (EditorUtility.DisplayDialog("Remove Rail?", "Do you really want to remove " + rail.gameObject.name + " from the scene?", "Remove", "Cancel")) { _currentRailIndex = -1; GUIUtilities.RemoveChildObject(rail.gameObject); } }
/// <summary>Destroys a game object with the specified Trigger component attached</summary> /// <param name="trigger">The Trigger component whose game object to destroy</param> private void RemoveTrigger(Trigger trigger) { if (EditorUtility.DisplayDialog("Remove Trigger?", "Do you really want to remove " + trigger.gameObject.name + " from the scene?", "Remove", "Cancel")) { _currentTriggerIndex = -1; GUIUtilities.RemoveChildObject(trigger.gameObject); } }
public override void OnInspectorGUI() { var trigger = (Trigger)target; if (target == null) { return; } GUIUtilities.ComponentHelpBox(trigger, "Use Trigger Manager on the parent object to edit this trigger."); }
public override void OnInspectorGUI() { var rail = (Rail)target; if (target == null) { return; } GUIUtilities.ComponentHelpBox(rail, "Use Rail Manager on the parent object to edit this rail."); }
public void OnSceneGUI() { var railManager = (RailManager)target; if (target == null) { return; } _rails = Utilities.GetRailsFromChildren(railManager.gameObject, true); var handleSize = HandleUtility.GetHandleSize(Vector3.zero) * 0.2f; var snapValue = EditorPrefs.GetFloat(EditorPreferences.SnapKey, EditorPreferences.SnapValue); var snapSize = new Vector3(snapValue, snapValue, snapValue); // Allows node removal var nodeRemovalActive = false; if (Event.current.shift) { nodeRemovalActive = true; } // Allows new nodes to be snapped to grid when added var snapActive = false; if (Event.current.control) { snapActive = true; } // Draw rails for (int i = 0; i < _rails.Count; i++) { var rail = _rails[i]; if (rail.Nodes.Count < 2) { continue; } GUIUtilities.DrawRailOnScene(rail, handleSize, snapSize, snapActive, nodeRemovalActive, true); } // Sync editor values with scene if rail is displayed in editor if (_currentRailIndex != -1) { Repaint(); } }
public void OnSceneGUI() { var currentRail = (Rail)target; if (target == null) { return; } if (currentRail.Nodes.Count < 2) { return; } var handleSize = HandleUtility.GetHandleSize(Vector3.zero) * 0.2f; var snapValue = EditorPrefs.GetFloat(EditorPreferences.SnapKey, EditorPreferences.SnapValue); var snapSize = new Vector3(snapValue, snapValue, snapValue); // Draw editable rail if (currentRail.gameObject.transform.parent != null && currentRail.gameObject.GetComponentInParent <RailManager>() != null) { // Allows node removal var nodeRemovalIsActive = false; if (Event.current.shift) { nodeRemovalIsActive = true; } // Allows new nodes to be snapped to grid when added var snapActive = false; if (Event.current.control) { snapActive = true; } GUIUtilities.DrawRailOnScene(currentRail, handleSize, snapSize, snapActive, nodeRemovalIsActive, true); } // Draw uneditable rail else { GUIUtilities.DrawRailOnScene(currentRail, handleSize, snapSize); } }
public void OnSceneGUI() { var railcam2DCore = (Railcam2DCore)target; if (target == null) { return; } var handleSize = HandleUtility.GetHandleSize(Vector3.zero) * 0.2f; var snapValue = EditorPrefs.GetFloat(EditorPreferences.SnapKey, EditorPreferences.SnapValue); var snapSize = new Vector3(snapValue, snapValue, snapValue); // If no Rail Manager component on game object, draw uneditable rails if (railcam2DCore.GetComponent <RailManager>() == null) { _rails = Utilities.GetRailsFromChildren(railcam2DCore.gameObject, true); for (int i = 0; i < _rails.Count; i++) { var rail = _rails[i]; if (rail.Nodes.Count < 2) { continue; } GUIUtilities.DrawRailOnScene(rail, handleSize, snapSize); } } // If no Trigger Manager component on game object, draw uneditable triggers if (railcam2DCore.GetComponent <TriggerManager>() == null) { _triggers = Utilities.GetTriggersFromChildren(railcam2DCore.gameObject, true); for (int i = 0; i < _triggers.Count; i++) { var currentTrigger = _triggers[i]; GUIUtilities.DrawTriggerOnScene(currentTrigger, handleSize, snapSize); } } }
/// <summary>Creates Buttons for organising a rail's nodes</summary> /// <param name="rail">The rail whose nodes are being edited</param> /// <param name="i">Index of the node to be edited</param> private void NodeEditorButtons(Rail rail, int i) { var nodes = rail.Nodes; // Shift Up _content = new GUIContent("\u25b2", "Shift up"); if (GUILayout.Button(_content, EditorStyles.miniButtonLeft, GUILayout.Width(20f))) { if (i > 0) { Undo.RecordObject(rail, "Shift Node Up"); var node = nodes[i]; nodes.RemoveAt(i); nodes.Insert(i - 1, node); _repaintScene = true; } } // Shift Down _content = new GUIContent("\u25bc", "Shift down"); if (GUILayout.Button(_content, EditorStyles.miniButtonMid, GUILayout.Width(20f))) { if (i < nodes.Count - 1) { Undo.RecordObject(rail, "Shift Node Down"); var node = nodes[i]; nodes.RemoveAt(i); nodes.Insert(i + 1, node); _repaintScene = true; } } // Insert _content = new GUIContent("\u002b", "Insert"); if (GUILayout.Button(_content, EditorStyles.miniButtonMid, GUILayout.Width(20f))) { Vector2 newNodePos; if (i == 0) { newNodePos = nodes[i].Position - new Vector2(2f, 2f); } else { newNodePos = (nodes[i].Position + nodes[i - 1].Position) * 0.5f; } GUIUtilities.InsertRailNode(rail, i, newNodePos); _repaintScene = true; } // Remove _content = new GUIContent("\u2212", "Remove"); if (GUILayout.Button(_content, EditorStyles.miniButtonRight, GUILayout.Width(20f))) { if (nodes.Count > 2) { GUIUtilities.RemoveRailNode(rail, i); _repaintScene = true; } } }
/// <summary>Displays a list of nodes for the current rail</summary> /// <param name="rail">The Rail component whose nodes to display</param> private void ListRailNodes(Rail rail) { List <RailNode> nodes = rail.Nodes; // Column Labels EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Node #", GUILayout.Width(60f)); EditorGUILayout.LabelField("Position", GUILayout.MinWidth(105f)); _content = new GUIContent("FX: Threshold", "Increased velocity transition effect\n\u2611 to invert"); EditorGUILayout.LabelField(_content, GUILayout.MinWidth(156f), GUILayout.MaxWidth(156f)); EditorGUILayout.EndHorizontal(); for (int i = 0; i < nodes.Count; i++) { var node = nodes[i]; EditorGUILayout.BeginHorizontal(); // Row Label EditorGUILayout.LabelField("Node " + i.ToString(), GUILayout.Width(60f)); // Position var newPosition = EditorGUILayout.Vector2Field(GUIContent.none, node.Position, GUILayout.MinWidth(105f)); if (node.Position != newPosition) { Undo.RecordObject(rail, "Move Node"); node.Position = newPosition; } // Disables editing of the final node's Threshold FX as the value produces no effect if (i == nodes.Count - 1) { GUI.enabled = false; } var newInvertThreshold = EditorGUILayout.Toggle(GUIContent.none, node.InvertThreshold, GUILayout.Width(12f)); if (node.InvertThreshold != newInvertThreshold) { Undo.RecordObject(rail, "Invert Node Threshold"); node.InvertThreshold = newInvertThreshold; } var newThreshold = EditorGUILayout.Slider(GUIContent.none, node.Threshold, 0f, 1f, GUILayout.Width(50f)); if (node.Threshold != newThreshold) { Undo.RecordObject(rail, "Change Node Threshold"); node.Threshold = newThreshold; } if (i == nodes.Count - 1) { GUI.enabled = true; } // Buttons for shifting, inserting, and removing nodes NodeEditorButtons(rail, i); EditorGUILayout.EndHorizontal(); } // Button to add node _content = new GUIContent("\u002b", "Add node"); if (GUILayout.Button(_content)) { Vector2 newNodePos; if (nodes.Count > 0) { newNodePos = nodes[nodes.Count - 1].Position + new Vector2(2f, 2f); } else { newNodePos = GUIUtilities.GetRoundedScenePivot(); } GUIUtilities.AddRailNode(rail, newNodePos); _repaintScene = true; } }
/// <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); } }
/// <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; } } } }