コード例 #1
0
        public static void SetActionFieldValue(SkillStateAction action, string fieldName, object value)
        {
            if (action == null)
            {
                Debug.LogError(Strings.get_Error_Action_is_null_());
                return;
            }
            FieldInfo field = action.GetType().GetField(fieldName, 20);

            if (field != null)
            {
                if (field.get_FieldType().IsInstanceOfType(value))
                {
                    field.SetValue(action, value);
                    return;
                }
                if (!ActionUtility.TrySetValue(action, field, value))
                {
                    Debug.LogError(string.Format(Strings.get_Error_Could_Not_Set_Action_Field_Value(), fieldName));
                    return;
                }
            }
            else
            {
                Debug.LogError(string.Format(Strings.get_Error_Could_Not_Find_Action_Field(), fieldName));
            }
        }
コード例 #2
0
        public static SkillStateAction AddPlayAnimationAction(Skill targetFsm, SkillState state, AnimationClip anim, SkillStateAction beforeAction = null)
        {
            SkillStateAction fsmStateAction = ActionUtility.AddAction(state, "HutongGames.PlayMaker.Actions.PlayAnimation", beforeAction);

            if (fsmStateAction == null)
            {
                return(null);
            }
            if (!ActionUtility.GameObjectHasAnimationClip(targetFsm.get_GameObject(), anim.get_name()) && Dialogs.YesNoDialog(Strings.get_ActionUtility_Add_Animation_Clip_to_GameObject()))
            {
                ActionUtility.AddAnimationClip(targetFsm.get_GameObject(), anim);
            }
            FieldInfo field = fsmStateAction.GetType().GetField("animName", 20);

            if (field != null)
            {
                FieldInfo   arg_68_0  = field;
                object      arg_68_1  = fsmStateAction;
                SkillString fsmString = new SkillString();
                fsmString.set_Value(anim.get_name());
                arg_68_0.SetValue(arg_68_1, fsmString);
            }
            SkillEditor.SetFsmDirty(targetFsm, true, false, true);
            SkillEditor.SaveActions(targetFsm);
            return(fsmStateAction);
        }
コード例 #3
0
        public static List <SkillInfo> FindStatesUsingAction(Skill fsm, Type actionType)
        {
            List <SkillInfo> list = new List <SkillInfo>();

            SkillState[] states = fsm.get_States();
            for (int i = 0; i < states.Length; i++)
            {
                SkillState fsmState = states[i];
                if (fsmState.get_ActionsLoaded())
                {
                    int num = 0;
                    SkillStateAction[] actions = fsmState.get_Actions();
                    for (int j = 0; j < actions.Length; j++)
                    {
                        SkillStateAction fsmStateAction = actions[j];
                        if (fsmStateAction.GetType() == actionType)
                        {
                            list.Add(new SkillInfo
                            {
                                fsm         = fsm,
                                state       = fsmState,
                                action      = fsmStateAction,
                                actionIndex = num
                            });
                        }
                        num++;
                    }
                }
            }
            return(list);
        }
コード例 #4
0
 public static Object GetAsset(SkillStateAction action)
 {
     if (action != null)
     {
         return(ActionScripts.GetAsset(action.GetType()));
     }
     return(null);
 }
コード例 #5
0
 public static string GetActionLabel(SkillStateAction action)
 {
     if (action == null)
     {
         return(Strings.get_Label_None_Action());
     }
     if (string.IsNullOrEmpty(action.get_Name()))
     {
         return(Labels.GetActionLabel(action.GetType()));
     }
     return(action.get_Name());
 }
コード例 #6
0
        public static CustomActionEditor GetCustomEditor(SkillStateAction action)
        {
            CustomActionEditor customActionEditor;

            CustomActionEditors.customEditors.TryGetValue(action, ref customActionEditor);
            if (customActionEditor == null)
            {
                Type customEditor = CustomActionEditors.GetCustomEditor(action.GetType());
                if (customEditor != null)
                {
                    customActionEditor        = (CustomActionEditor)Activator.CreateInstance(customEditor);
                    customActionEditor.target = action;
                    customActionEditor.OnEnable();
                    CustomActionEditors.customEditors.Add(action, customActionEditor);
                }
                else
                {
                    Debug.LogError("Could not get Custom Action Editor for: " + action.GetType());
                }
            }
            return(customActionEditor);
        }
コード例 #7
0
        public static void SetOwnerDefault(Skill fsm, SkillStateAction action, GameObject targetGO, string fieldName = "gameObject")
        {
            FieldInfo field = action.GetType().GetField(fieldName, 20);

            if (field != null && fsm.get_GameObject() != targetGO)
            {
                FieldInfo         arg_3C_0        = field;
                SkillOwnerDefault fsmOwnerDefault = new SkillOwnerDefault();
                fsmOwnerDefault.set_OwnerOption(1);
                fsmOwnerDefault.set_GameObject(targetGO);
                arg_3C_0.SetValue(action, fsmOwnerDefault);
            }
        }
コード例 #8
0
        public static SkillStateAction AddPlaySoundAction(Skill targetFsm, SkillState state, AudioClip audioClip, SkillStateAction beforeAction = null)
        {
            SkillStateAction fsmStateAction = ActionUtility.AddAction(state, "HutongGames.PlayMaker.Actions.PlaySound", beforeAction);

            if (fsmStateAction == null)
            {
                return(null);
            }
            FieldInfo field = fsmStateAction.GetType().GetField("clip", 20);

            if (field != null)
            {
                FieldInfo   arg_38_0  = field;
                object      arg_38_1  = fsmStateAction;
                SkillObject fsmObject = new SkillObject();
                fsmObject.set_Value(audioClip);
                arg_38_0.SetValue(arg_38_1, fsmObject);
            }
            SkillEditor.SetFsmDirty(targetFsm, true, false, true);
            SkillEditor.SaveActions(targetFsm);
            return(fsmStateAction);
        }
コード例 #9
0
        public static string UpdateTooltip(SkillStateAction action)
        {
            Actions.tooltipLookup.Remove(action);
            string text = Actions.GetTooltip(action);

            text = string.Format(Strings.get_Tooltip_Action(), Labels.NicifyVariableName(Labels.StripNamespace(action.GetType().ToString())), text);
            Actions.tooltipLookup.Add(action, text);
            return(text);
        }
コード例 #10
0
        private static void CheckActionForErrors(SkillState state, SkillStateAction action)
        {
            if (action == null)
            {
                FsmErrorChecker.AddError(new FsmError(state, null, Strings.get_FsmErrorChecker_MissingActionError()));
                return;
            }
            action.Init(state);
            FsmErrorChecker.fsmEventTargetContext = null;
            string actionLabel = Labels.GetActionLabel(action);

            if (FsmEditorSettings.CheckForMissingActions && action is MissingAction)
            {
                FsmErrorChecker.AddError(new FsmError(state, action, Strings.get_FsmErrorChecker_StateHasMissingActionError()));
                return;
            }
            if (FsmEditorSettings.CheckForObsoleteActions)
            {
                string obsoleteMessage = CustomAttributeHelpers.GetObsoleteMessage(action.GetType());
                if (!string.IsNullOrEmpty(obsoleteMessage))
                {
                    FsmErrorChecker.AddError(new FsmError(state, action, obsoleteMessage));
                }
            }
            Type type = action.GetType();

            FieldInfo[] fields = ActionData.GetFields(type);
            FieldInfo[] array  = fields;
            for (int i = 0; i < array.Length; i++)
            {
                FieldInfo fieldInfo = array[i];
                Type      fieldType = fieldInfo.get_FieldType();
                object    value     = fieldInfo.GetValue(action);
                if (fieldType == typeof(SkillEventTarget))
                {
                    SkillEventTarget fsmEventTarget = (SkillEventTarget)value;
                    if (actionLabel == "Set Event Target")
                    {
                        FsmErrorChecker.fsmEventTargetContextGlobal = fsmEventTarget;
                    }
                    else
                    {
                        FsmErrorChecker.fsmEventTargetContext = fsmEventTarget;
                    }
                }
                FsmErrorChecker.CheckActionParameter(state, action, fieldInfo);
            }
            string text = "";

            try
            {
                text = action.ErrorCheck();
            }
            catch (Exception ex)
            {
                Debug.Log(string.Concat(new object[]
                {
                    "Bad ErrorCheck: ",
                    type,
                    "\n",
                    ex
                }));
            }
            if (!string.IsNullOrEmpty(text))
            {
                FsmErrorChecker.AddError(new FsmError(state, action, text));
            }
        }
コード例 #11
0
        public static void OpenWikiPage(SkillStateAction action)
        {
            HelpUrlAttribute attribute = CustomAttributeHelpers.GetAttribute <HelpUrlAttribute>(action.GetType());

            if (attribute != null)
            {
                Application.OpenURL(attribute.get_Url());
                return;
            }
            string topic = Labels.StripNamespace(action.ToString());

            if (!EditorCommands.OpenWikiPage(topic))
            {
                EditorCommands.SearchWikiHelp(action);
            }
        }