示例#1
0
        /// <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);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Performs an action with static scope.
        /// </summary>
        public object PerformAction(IRSRuntimeEntity inEntity, string inActionId, params object[] inArgs)
        {
            RSActionInfo   actionInfo = Library.GetAction(inActionId);
            ExecutionScope scope      = CreateScope(inEntity, RSValue.Null, TableUtils.GetRuleFlags(actionInfo.Flags));

            using (new SharedRef <ExecutionScope>(scope))
            {
                return(PerformAction(inEntity, actionInfo, InternalScriptUtils.Convert(inArgs), scope).Value);
            }
        }
示例#3
0
        static private RuleFlags GetRuleFlags(RSActionInfo inInfo)
        {
            RuleFlags flags = 0;

            if (inInfo != null)
            {
                flags |= GetRuleFlags(inInfo.Flags);
            }

            return(flags);
        }
示例#4
0
        /// <summary>
        /// Performs an action with static scope.
        /// </summary>
        public object PerformAction(string inActionId, params object[] inArgs)
        {
            RSActionInfo   actionInfo = Library.GetAction(inActionId);
            ExecutionScope scope      = m_StaticScope;

            CloneScopeIfNecessary(scope, TableUtils.GetRuleFlags(actionInfo.Flags), out scope);

            using (new SharedRef <ExecutionScope>(scope))
            {
                return(PerformAction(null, actionInfo, InternalScriptUtils.Convert(inArgs), scope).Value);
            }
        }
示例#5
0
        /// <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)));
        }
示例#6
0
        static private RSActionInfo ValidateActionId(EntityScopedIdentifier inIdentifier, RSValidationFlags inFlags, RSValidationState ioState, RSValidationContext inContext)
        {
            ValidateEntityScope(inIdentifier.Scope, inFlags.ForMethodScope(), ioState, inContext);

            if (inIdentifier.Id == 0)
            {
                ioState.Error("Null action not allowed");
                return(null);
            }
            else
            {
                RSActionInfo actionInfo = inContext.Library.GetAction(inIdentifier.Id);
                if (actionInfo == null)
                {
                    ioState.Error("Action {0} does not exist", inIdentifier.Id);
                }
                else
                {
                    switch (inIdentifier.Scope.Type)
                    {
                    case EntityScopeType.Global:
                    {
                        if (actionInfo.OwnerType != null)
                        {
                            ioState.Error("Action {0} is bound to type {1} but was specified as a global action", actionInfo.Name, actionInfo.OwnerType.Name);
                        }
                        break;
                    }

                    case EntityScopeType.Null:
                    case EntityScopeType.Invalid:
                        break;

                    default:
                    {
                        if (actionInfo.OwnerType == null)
                        {
                            ioState.Error("Action {0} is bound to global scope but was specified as a local action", actionInfo.Name);
                        }
                        break;
                    }
                    }
                }

                return(actionInfo);
            }
        }
示例#7
0
        public string GetPreviewString(RSTriggerInfo inTriggerContext, RSLibrary inLibrary)
        {
            using (PooledStringBuilder psb = PooledStringBuilder.Alloc())
            {
                var sb = psb.Builder;

                if (!Enabled)
                {
                    sb.Append("[Disabled] ");
                }

                sb.Append(Action.GetPreviewStringAsAction(inTriggerContext, inLibrary));

                if (Arguments != null && Arguments.Length > 0)
                {
                    sb.Append("(");

                    RSActionInfo actionInfo = inLibrary.GetAction(Action.Id);
                    for (int i = 0; i < Arguments.Length; ++i)
                    {
                        if (i > 0)
                        {
                            sb.Append("; ");
                        }

                        if (actionInfo != null && i < actionInfo.Parameters.Length)
                        {
                            sb.Append(actionInfo.Parameters[i].Name);
                        }
                        else
                        {
                            sb.Append(i);
                        }

                        sb.Append(": ");

                        sb.Append(Arguments[i].GetPreviewString(inTriggerContext, inLibrary));
                    }

                    sb.Append(")");
                }

                return(sb.ToString());
            }
        }
示例#8
0
        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();
        }
示例#9
0
 internal IEnumerable <ActionResult> PerformActions(IEnumerable <IRSRuntimeEntity> inEntities, RSActionInfo inAction, RSValue[] inArguments, ExecutionScope inContext)
 {
     inAction.PrepArguments(inArguments, inContext);
     foreach (var entity in inEntities)
     {
         yield return(inAction.InvokeWithCachedArgs(entity, inContext));
     }
 }
示例#10
0
 internal ActionResult PerformAction(IRSRuntimeEntity inEntity, RSActionInfo inAction, RSValue[] inArguments, ExecutionScope inContext)
 {
     return(inAction.Invoke(inEntity, inArguments, inContext));
 }