예제 #1
0
 public void OnAwake(MotionMachine machine, MotionCommander commander)
 {
     Machine   = machine;
     Commander = commander;
     if (machine != null)
     {
         if (machine.Motions != null && machine.Motions.Count > 0 && SequentialMotions != null && SequentialMotions.Count > 0)
         {
             for (int i = 0; i < SequentialMotions.Count; i++)
             {
                 RoleMotionType motionType = SequentialMotions[i];
                 Motion         motion     = machine.GetMotion(motionType);
                 if (motion == null)
                 {
                     continue;
                 }
                 if (Motions == null)
                 {
                     Motions = new List <Motion>();
                 }
                 Motions.Add(motion);
             }
         }
     }
 }
예제 #2
0
        public bool ExecuteMotion(RoleMotionType type)
        {
            //if (CurrentMotion != null)
            //{
            //    if (CurrentMotion.Type == type)
            //    {
            //        if (CurrentMotion.WrapMode == WrapMode.Loop)
            //        {
            //            return false;
            //        }
            //    }
            //}
            //if (LastPlayMotion == RoleMotionType.RMT_Jump)
            //{
            //    int a = 1;
            //}
            //LastPlayMotion = type;

            Motion nextMotion = GetMotion(type);

            if (nextMotion == null)
            {
                return(false);
            }
            NextMotion = nextMotion;
            return(true);
        }
예제 #3
0
        public static CharacterCommand RMT_CC(RoleMotionType type)
        {
            if (type == RoleMotionType.RMT_Idle)
            {
                return(CharacterCommand.CC_Stop);
            }
            else if (type == RoleMotionType.RMT_Run)
            {
                return(CharacterCommand.CC_WalkToPoint);
            }
            else if (type == RoleMotionType.RMT_Jump)
            {
                return(CharacterCommand.CC_JumpToPoint);
            }
            else if (type == RoleMotionType.RMT_Fly)
            {
                return(CharacterCommand.CC_FlyToPoint);
            }
            string[] strArray = type.ToString().Split(new char[] { '_' });
            if (strArray == null || strArray.Length < 2)
            {
                return(CharacterCommand.CC_Stop);
            }
            string rmtStr = "CC_" + strArray[1];

            try
            {
                CharacterCommand cc = (CharacterCommand)System.Enum.Parse(typeof(CharacterCommand), rmtStr);
                return(cc);
            }
            catch
            {
                return(CharacterCommand.CC_Stop);
            }
        }
예제 #4
0
        public To GetTarget(RoleMotionType type, RoleMotionType targetType)
        {
            From from = TryGetRoot(type);

            if (from == null)
            {
                return(null);
            }
            return(from.GetTarget(targetType));
        }
예제 #5
0
        public MotionPlugin GetSpecificPlugin(RoleMotionType type, string pluginName)
        {
            Motion motion = GetMotion(type);

            if (motion == null)
            {
                Utility.LogError("GetSpecificPlugin error caused by null motion named: " + type.ToString());
                return(null);
            }
            return(motion.GetPlugin(pluginName));
        }
예제 #6
0
 public bool HasTarget(RoleMotionType type)
 {
     if (Targets == null || Targets.Count == 0)
     {
         return(false);
     }
     for (int i = 0; i < Targets.Count; i++)
     {
         To target = Targets[i];
         if (target.Motion == type)
         {
             return(true);
         }
     }
     return(false);
 }
예제 #7
0
        public bool IsMotionNameLegal(RoleMotionType type)
        {
            if (Instance == null)
            {
                return(false);
            }
            Motion motion = Instance.GetMotion(type);

            if (motion == null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #8
0
 public Motion TryGetMotion(RoleMotionType type)
 {
     if (Motions == null || Motions.Count == 0)
     {
         return(null);
     }
     for (int i = 0; i < Motions.Count; i++)
     {
         Motion tempMotion = Motions[i];
         if (tempMotion == null)
         {
             continue;
         }
         if (tempMotion.Type == type)
         {
             return(tempMotion);
         }
     }
     return(null);
 }
예제 #9
0
 public From TryGetRoot(RoleMotionType type)
 {
     if (Roots == null || Roots.Count == 0)
     {
         return(null);
     }
     for (int i = 0; i < Roots.Count; i++)
     {
         From tempTree = Roots[i];
         if (tempTree == null)
         {
             continue;
         }
         if (tempTree.Motion == type)
         {
             return(tempTree);
         }
     }
     return(null);
 }
예제 #10
0
 public To GetTarget(RoleMotionType type)
 {
     if (Targets == null || Targets.Count == 0)
     {
         return(null);
     }
     for (int i = 0; i < Targets.Count; i++)
     {
         To target = Targets[i];
         if (target == null)
         {
             continue;
         }
         if (target.Motion == type)
         {
             return(target);
         }
     }
     return(null);
 }
예제 #11
0
 public Motion GetMotion(RoleMotionType type)
 {
     if (Motions == null || Motions.Count == 0)
     {
         return(null);
     }
     for (int i = 0; i < Motions.Count; i++)
     {
         Motion motion = Motions[i];
         if (motion == null)
         {
             continue;
         }
         if (type.Equals(motion.Type))
         {
             return(motion);
         }
     }
     return(null);
 }
예제 #12
0
        public bool ExecuteMotionImmediately(RoleMotionType type)
        {
            if (CurrentMotion != null)
            {
                if (CurrentMotion.Type == type)
                {
                    return(false);
                }
            }
            Motion nextMotion = GetMotion(type);

            if (nextMotion == null)
            {
                return(false);
            }
            if (CurrentMotion != null)
            {
                CurrentMotion.OnEnd(this);
            }
            CurrentMotion = nextMotion;
            CurrentMotion.OnBegin(this);
            return(true);
        }
예제 #13
0
        public static RoleMotionType GenerateRoleMotionTypeByCharacterCommand(CharacterCommand command)
        {
            if (command == CharacterCommand.CC_None)
            {
                return(RoleMotionType.RMT_Idle);
            }
            string[] strArray = command.ToString().Split(new char[] { '_' });
            if (strArray == null || strArray.Length < 2)
            {
                return(RoleMotionType.RMT_Idle);
            }
            string rmtStr = "RMT_" + strArray[1];

            try
            {
                RoleMotionType rmt = (RoleMotionType)System.Enum.Parse(typeof(RoleMotionType), rmtStr);
                return(rmt);
            }
            catch
            {
                return(RoleMotionType.RMT_Idle);
            }
        }
예제 #14
0
        public static CharacterCommand GenerateCharacterCommandByRmt(RoleMotionType varType)
        {
            if (varType == RoleMotionType.RMT_Idle)
            {
                return(CharacterCommand.CC_Stop);
            }
            string[] strArray = varType.ToString().Split(new char[] { '_' });
            if (strArray == null || strArray.Length < 2)
            {
                return(CharacterCommand.CC_None);
            }
            string commandStr = "CC_" + strArray[1];

            try
            {
                CharacterCommand command = (CharacterCommand)System.Enum.Parse(typeof(CharacterCommand), commandStr);
                return(command);
            }
            catch
            {
                return(CharacterCommand.CC_None);
            }
        }
예제 #15
0
        public override void OnInspectorGUI()
        {
            try
            {
                if (Instance == null)
                {
                    return;
                }
                base.OnInspectorGUI();

                #region animator property view
                //GUILayout.Space(5.0f);
                //if (GTAnimatorEditorUtility.DrawHeader("Animator Property", true))
                //{
                //    GTAnimatorEditorUtility.BeginContents();

                //    GUILayout.BeginHorizontal();
                //    if (GUILayout.Button("Preview", GUILayout.Width(100))) { }
                //    if (GUILayout.Button("Clear", GUILayout.Width(100))) { }
                //    GUILayout.EndHorizontal();

                //    GTAnimatorEditorUtility.EndContents();
                //}
                #endregion

                #region animation clip view
                GUILayout.Space(5.0f);
                if (CurrentSelectedMotion != null)
                {
                    OpenMotionHeader = EditorUtility.DrawHeader("Motion: " + CurrentSelectedMotion.Type.ToString() + "  ||  Clip:  " + CurrentSelectedMotion.ClipName, true);
                }
                else
                {
                    OpenMotionHeader = EditorUtility.DrawHeader("Motion", true);
                }
                if (OpenMotionHeader)
                {
                    #region animation clip operation
                    EditorUtility.BeginContents();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Name: ");
                    GonnaCreateMotionType = (RoleMotionType)EditorGUILayout.EnumPopup(GonnaCreateMotionType);
                    if (GUILayout.Button("Add", GUILayout.Width(60), GUILayout.Height(15)))
                    {
                        if (Instance.Motions == null)
                        {
                            Instance.Motions = new List <Motion>();
                        }
                        if (IsMotionNameLegal(GonnaCreateMotionType) == false)
                        {
                            Utility.LogError("motion name is illegal,please try another one"); return;
                        }
                        Instance.Motions.Add(new Motion()
                        {
                            Type = GonnaCreateMotionType
                        });
                    }
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(4.0f);
                    if (GUILayout.Button("Clear", GUILayout.Width(80)))
                    {
                        if (Instance.Motions != null)
                        {
                            Instance.Motions.Clear();
                        }
                    }
                    if (GUILayout.Button("Delete", GUILayout.Width(80)))
                    {
                        if (CurrentSelectedMotion == null)
                        {
                            return;
                        }
                        if (Instance.Motions == null)
                        {
                            return;
                        }
                        Instance.Motions.Remove(CurrentSelectedMotion);
                    }
                    if (GUILayout.Button("Clone", GUILayout.Width(80)))
                    {
                        if (Instance.Motions == null)
                        {
                            Instance.Motions = new List <Motion>();
                        }
                        if (IsMotionNameLegal(GonnaCreateMotionType) == false)
                        {
                            Utility.LogError("motion name is illegal,please try another one"); return;
                        }
                        Motion motion = new Motion();
                        motion.Type = GonnaCreateMotionType;
                        motion.Clone(CurrentSelectedMotion);
                        Instance.Motions.Add(motion);
                    }
                    GUILayout.EndHorizontal();
                    #endregion

                    #region animation clip pop view
                    GUILayout.Space(4.0f);
                    AllMotionNames = new List <string>();
                    if (Instance.Motions != null && Instance.Motions.Count > 0)
                    {
                        for (int i = 0; i < Instance.Motions.Count; i++)
                        {
                            Motion motion = Instance.Motions[i];
                            if (motion == null)
                            {
                                Instance.Motions.RemoveAt(i); i--; continue;
                            }
                            AllMotionNames.Add("Motion: " + motion.Type.ToString() + "  ||  Clip:  " + motion.ClipName);
                        }
                    }
                    CurrentSelectedClipIndex = EditorGUILayout.Popup(CurrentSelectedClipIndex, AllMotionNames.ToArray());
                    if (CurrentSelectedClipIndex < Instance.Motions.Count && CurrentSelectedClipIndex >= 0)
                    {
                        CurrentSelectedMotion = Instance.Motions[CurrentSelectedClipIndex];
                    }
                    else
                    {
                        CurrentSelectedMotion = null;
                    }
                    #endregion

                    #region display clip property
                    GUILayout.Space(4.0f);
                    if (CurrentSelectedMotion != null)
                    {
                        CurrentSelectedMotion.DiaplayEditorView(Instance);
                    }
                    #endregion

                    EditorUtility.EndContents();
                }
                #endregion

                #region animation clip actions view
                GUILayout.Space(5.0f);
                if (EditorUtility.DrawHeader("Plugin", true))
                {
                    if (CurrentSelectedMotion == null)
                    {
                        EditorGUILayout.HelpBox("Please select an motion", MessageType.Warning);
                    }
                    else
                    {
                        #region header
                        GUILayout.BeginHorizontal();
                        GUILayout.Label("Motion: " + CurrentSelectedMotion.Type.ToString());
                        //GUILayout.Space(2.0f);
                        //GUILayout.Label("Time from " + CurrentSelectedMotion.BeginTime + "s to " + CurrentSelectedMotion.EndTime + "s");
                        GUILayout.EndHorizontal();
                        #endregion

                        #region add action
                        EditorUtility.BeginContents();
                        GUILayout.Space(2.0f);
                        GUILayout.BeginHorizontal();
                        if (AllPluginType == null || AllPluginType.Count == 0 || AllPluginTypeName == null || AllPluginTypeName.Count == 0)
                        {
                            AllPluginType = EditorUtility.GetAllSubClass(typeof(MotionPlugin), null);
                            if (AllPluginType != null && AllPluginType.Count > 0)
                            {
                                AllPluginTypeName = new List <string>();
                                for (int i = 0; i < AllPluginType.Count; i++)
                                {
                                    Type type = AllPluginType[i];
                                    if (type == null)
                                    {
                                        continue;
                                    }
                                    string typeName = EditorUtility.GetTypeNameWithoutNamespcae(type.FullName);
                                    AllPluginTypeName.Add(typeName);
                                }
                            }
                        }
                        if (AllPluginTypeName != null && AllPluginTypeName.Count > 0)
                        {
                            GonnaAddPluginIndex = EditorGUILayout.Popup(GonnaAddPluginIndex, AllPluginTypeName.ToArray());
                            if (GonnaAddPluginIndex >= 0 && GonnaAddPluginIndex < AllPluginTypeName.Count)
                            {
                                GonnaCreatePluginType = AllPluginType[GonnaAddPluginIndex];
                            }
                        }
                        GUILayout.FlexibleSpace();
                        GonnaCreateActionName = EditorGUILayout.TextField(GonnaCreateActionName);
                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button("Add", GUILayout.Width(60), GUILayout.Height(15)))
                        {
                            if (CurrentSelectedMotion == null)
                            {
                                return;
                            }
                            if (GonnaCreatePluginType == null)
                            {
                                return;
                            }
                            if (IsPluginNameLegal(GonnaCreateActionName) == false)
                            {
                                Utility.LogError("plugin identify name is illegal,please try another one"); return;
                            }
                            MotionPlugin plugin = CurrentSelectedMotion.AddPlugin(GonnaCreatePluginType);
                            if (plugin != null)
                            {
                                plugin.IdentifyName = GonnaCreateActionName;
                            }
                        }
                        GUILayout.EndHorizontal();
                        #endregion

                        #region operation of action collection

                        GUILayout.Space(3.0f);
                        GUILayout.BeginHorizontal();
                        if (GUILayout.Button("Clear", GUILayout.Width(60)))
                        {
                            if (CurrentSelectedMotion == null)
                            {
                                return;
                            }
                            CurrentSelectedMotion.ClearPlugin();
                        }
                        if (GUILayout.Button("Delete", GUILayout.Width(60)))
                        {
                            if (CurrentSelectedPlugin == null)
                            {
                                return;
                            }
                            if (CurrentSelectedMotion == null)
                            {
                                return;
                            }
                            CurrentSelectedMotion.RemovePlugin(CurrentSelectedPlugin);
                        }
                        if (GUILayout.Button("Clone", GUILayout.Width(60)))
                        {
                        }
                        GUILayout.FlexibleSpace();
                        if (BoolDisplayAllPlugin)
                        {
                            if (GUILayout.Button("Display-Single"))
                            {
                                BoolDisplayAllPlugin = !BoolDisplayAllPlugin;
                            }
                        }
                        else
                        {
                            if (GUILayout.Button("    Display-All  "))
                            {
                                BoolDisplayAllPlugin = !BoolDisplayAllPlugin;
                            }
                        }
                        GUILayout.EndHorizontal();
                        EditorUtility.EndContents();
                        #endregion

                        #region display view
                        EditorUtility.BeginContents();
                        GUILayout.Space(6.0f);
                        if (BoolDisplayAllPlugin == true)
                        {
                            #region all view
                            if (CurrentSelectedMotion == null || CurrentSelectedMotion.GetAllPlugin() == null || CurrentSelectedMotion.GetAllPlugin().Count == null)
                            {
                                return;
                            }
                            for (int i = 0; i < CurrentSelectedMotion.GetAllPlugin().Count; i++)
                            {
                                MotionPlugin plugin = CurrentSelectedMotion.GetAllPlugin()[i];
                                if (plugin == null)
                                {
                                    continue;
                                }
                                EditorUtility.BeginContents();
                                GUILayout.Space(2.0f);
                                plugin.DisplayEditorView(CurrentSelectedMotion);
                                GUILayout.Space(2.0f);
                                EditorUtility.EndContents();
                            }
                            #endregion
                        }
                        else
                        {
                            #region single view
                            AllPluginNames = new List <string>();
                            if (CurrentSelectedMotion.GetAllPlugin() != null && CurrentSelectedMotion.GetAllPlugin().Count > 0)
                            {
                                for (int i = 0; i < CurrentSelectedMotion.GetAllPlugin().Count; i++)
                                {
                                    MotionPlugin plugin = CurrentSelectedMotion.GetAllPlugin()[i];
                                    if (plugin == null)
                                    {
                                        continue;
                                    }
                                    AllPluginNames.Add("From " + plugin.BeginTime + " to " + plugin.EndTime + " || " + plugin.DisplayName);
                                }
                            }
                            CurrentSelectedPluginIndex = EditorGUILayout.Popup(CurrentSelectedPluginIndex, AllPluginNames.ToArray());
                            if (CurrentSelectedPluginIndex >= 0 && CurrentSelectedPluginIndex < CurrentSelectedMotion.GetAllPlugin().Count)
                            {
                                CurrentSelectedPlugin = CurrentSelectedMotion.GetAllPlugin()[CurrentSelectedPluginIndex];
                            }
                            #endregion

                            #region detail property
                            GUILayout.Space(6.0f);
                            if (CurrentSelectedPlugin != null)
                            {
                                CurrentSelectedPlugin.DisplayEditorView(CurrentSelectedMotion);
                            }
                            #endregion
                        }
                        EditorUtility.EndContents();
                        #endregion
                    }
                }
                #endregion
                GUILayout.Space(5.0f);
            }
            catch { }
        }