static public void Clear() { s_CurrentTarget = Target.None; s_CurrentRule = null; s_CurrentCondition = null; s_CurrentAction = null; }
private void RenderActionListElement(Rect rect, int index, bool isActive, bool isFocused) { RSActionData action = m_SelectionState.Rule.Actions[index]; Rect labelRect = rect; labelRect.width -= CLONE_BUTTON_WIDTH + CLONE_BUTTON_SPACING; string labelText = action.GetPreviewString(GetCurrentTrigger(), m_Context.Library); using (new RSGUI.ColorScope(action.Enabled ? Color.white : Color.gray)) { EditorGUI.LabelField(labelRect, labelText); } Rect cloneRect = rect; cloneRect.width = CLONE_BUTTON_WIDTH; cloneRect.height -= 4; cloneRect.x = labelRect.xMax + CLONE_BUTTON_SPACING; using (new EditorGUI.DisabledScope(EditorApplication.isPlaying)) { if (GUI.Button(cloneRect, "Clone")) { RSActionData clone = action.Clone(); InsertAction(clone, index + 1); } } if (DetectContextClick(rect)) { ShowActionElementContextMenu(action, index); } }
static public void CopyAction(RSActionData inActionData) { Clear(); s_CurrentTarget = Target.Action; s_CurrentAction = inActionData.Clone(); }
/// <summary> /// Renders editor for Action info. /// </summary> static public void ActionData(UndoTarget inUndo, RSActionData ioAction, RSValidationFlags inFlags, RSValidationContext inContext) { string preview = ioAction.GetPreviewString(inContext.Trigger, inContext.Library); GUILayout.Label(preview, RSGUIStyles.RuleHeaderStyle); EditorGUILayout.Space(); // Enabled bool bEnabled = EditorGUILayout.Toggle("Enabled", ioAction.Enabled); if (bEnabled != ioAction.Enabled) { inUndo.MarkDirty("Changed Action Enabled"); ioAction.Enabled = bEnabled; } EditorGUILayout.Space(); using (new EditorGUI.DisabledGroupScope(!bEnabled)) { EntityScopedIdentifier action = ValueGUILayout.ActionField(EditorGUIUtility.TrTempContent("Action"), ioAction.Action, inFlags, inContext); RSActionInfo actionInfo = inContext.Library.GetAction(action.Id); if (action != ioAction.Action) { bool bChangedId = ioAction.Action.Id != action.Id; inUndo.MarkDirty("Changed Action", true); ioAction.Action = action; if (bChangedId) { if (actionInfo != null) { actionInfo.PopulateDefaultArguments(ioAction); } else { ioAction.Arguments = null; } } } if (actionInfo != null && ioAction.Arguments != null && ioAction.Arguments.Length > 0) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Arguments", RSGUIStyles.SubHeaderStyle); for (int i = 0; i < ioAction.Arguments.Length; ++i) { ParameterData(inUndo, actionInfo.Parameters[i], ioAction.Arguments[i], inFlags, inContext); } } } }
public void ClearSelections() { RuleIndex = -1; ConditionIndex = -1; ActionIndex = -1; Rule = null; Condition = null; Action = null; }
static public void PasteAction(RSActionData ioTarget) { if (!HasAction()) { Debug.LogError("No action copied"); return; } ioTarget.CopyFrom(s_CurrentAction); }
private void OnAddNewAction(ReorderableList list) { RSActionData actionData = new RSActionData(); int index = list.index; if (index >= 0) { ++index; } InsertAction(actionData, index); }
/// <summary> /// Performs an action on entities. /// </summary> public MultiReturn <ActionResult> PerformAction(RSActionData inAction) { RSActionInfo actionInfo = m_Environment.Library.GetAction(inAction.Action.Id); MultiReturn <IRSRuntimeEntity> targets = ResolveEntity(inAction.Action.Scope); ResolveArgsArray(inAction.Arguments, actionInfo.TempArgStorage); if (targets.Set != null) { return(new MultiReturn <ActionResult>(m_Environment.PerformActions(targets.Set, actionInfo, actionInfo.TempArgStorage, this))); } return(new MultiReturn <ActionResult>(m_Environment.PerformAction(targets.Single, actionInfo, actionInfo.TempArgStorage, this))); }
private void InsertAction(RSActionData inAction, int inIndex = -1) { m_TargetState.UndoTarget.MarkDirty("Added Action", true); if (inIndex < 0 || inIndex >= m_SelectionState.Rule.Actions.Length) { ArrayUtility.Add(ref m_SelectionState.Rule.Actions, inAction); inIndex = m_SelectionState.Rule.Actions.Length - 1; } else { ArrayUtility.Insert(ref m_SelectionState.Rule.Actions, inIndex, inAction); } SelectAction(inIndex); }
public void PopulateDefaultArguments(RSActionData ioData) { if (Parameters == null || Parameters.Length == 0) { ioData.Arguments = null; } else { Array.Resize(ref ioData.Arguments, Parameters.Length); for (int i = 0; i < Parameters.Length; ++i) { RSResolvableValueData.SetAsValue(ref ioData.Arguments[i], Parameters[i].Default); } } }
private void ShowActionElementContextMenu(RSActionData inActionData, int inIndex) { GenericMenu menu = new GenericMenu(); menu.AddItem(s_ContextMenuCopyLabel, false, () => RSEditorClipboard.CopyAction(inActionData)); if (RSEditorClipboard.HasAction()) { menu.AddItem(s_ContextMenuPasteOverwriteLabel, false, () => { m_TargetState.UndoTarget.MarkDirty("Paste action (overwrite)"); RSEditorClipboard.PasteAction(inActionData); }); if (EditorApplication.isPlaying) { menu.AddDisabledItem(s_ContextMenuPasteInsertLabel, false); } else { menu.AddItem(s_ContextMenuPasteInsertLabel, false, () => { RSActionData clone = RSEditorClipboard.PasteAction(); InsertAction(clone, inIndex + 1); }); } } else { menu.AddDisabledItem(s_ContextMenuPasteOverwriteLabel, false); menu.AddDisabledItem(s_ContextMenuPasteInsertLabel, false); } if (EditorApplication.isPlaying) { menu.AddDisabledItem(s_ContextMenuDeleteLabel, false); } else { menu.AddItem(s_ContextMenuDeleteLabel, false, () => DeleteAction(inIndex)); } menu.ShowAsContext(); }
public void Refresh() { if (Source == null) { ClearSelections(); return; } if (Source.TableData == null) { Table = null; ClearSelections(); return; } Table = Source.TableData; Rule = Select(Table?.Rules, RuleIndex); Condition = Select(Rule?.Conditions, ConditionIndex); Action = Select(Rule?.Actions, ActionIndex); }
private void ShowActionHeaderContextMenu() { GenericMenu menu = new GenericMenu(); if (EditorApplication.isPlaying) { menu.AddDisabledItem(s_ContextMenuPasteAddToEndLabel, false); menu.AddDisabledItem(s_ContextMenuDeleteAllLabel, false); } else { if (RSEditorClipboard.HasAction()) { menu.AddItem(s_ContextMenuPasteAddToEndLabel, false, () => { RSActionData clone = RSEditorClipboard.PasteAction(); InsertAction(clone, -1); }); } else { menu.AddDisabledItem(s_ContextMenuPasteAddToEndLabel, false); } if (m_SelectionState.Rule.Actions.Length > 0) { menu.AddItem(s_ContextMenuDeleteAllLabel, false, () => { SelectAction(-1); m_TargetState.UndoTarget.MarkDirty("Removed all Actions", true); m_SelectionState.Rule.Actions = new RSActionData[0]; }); } else { menu.AddDisabledItem(s_ContextMenuDeleteAllLabel, false); } } menu.ShowAsContext(); }
static private void ValidateAction(RSActionData inAction, RSValidationState ioState, RSValidationContext inContext) { ioState.PushContext("Action Id"); RSActionInfo actionInfo = ValidateActionId(inAction.Action, RSValidationFlags.None, ioState, inContext); ioState.PopContext(); ioState.PushContext("Arguments"); if (actionInfo != null) { int argCount = actionInfo.Parameters.Length; if (argCount <= 0) { if (inAction.Arguments != null && inAction.Arguments.Length > 0) { ioState.Error("Arguments provided for action {0} but none required", actionInfo.Name); } } else { if (inAction.Arguments == null) { ioState.Error("No arguments provided for action {0} but {1} required", actionInfo.Name, argCount); } else if (inAction.Arguments.Length != argCount) { ioState.Error("Argument count mismatch for action {0} - {1} required but {2} provided", actionInfo.Name, argCount, inAction.Arguments.Length); } else { for (int i = 0; i < argCount; ++i) { ValidateParameter(actionInfo.Parameters[i], inAction.Arguments[i], ioState, inContext); } } } } ioState.PopContext(); }