/// <summary>
        /// 初始化状态管理器
        /// </summary>
        /// <param name="fsmManager">有限状态机管理器.</param>
        /// <param name="states">状态管理器所包含的状态.</param>
        public void Initialize(IFsmManager fsmManager, CharacterControllerBase owner, params CharacterStateBase[] states)
        {
            if (fsmManager == null)
            {
                throw new GameFrameworkException("FSM manager is invalid.");
            }

            if (owner == null)
            {
                throw new GameFrameworkException("FSM Owner is invalid.");
            }

            this.Owner = owner;

            m_FsmManager = fsmManager;
            m_StateFsm   = m_FsmManager.CreateFsm(this, states);
        }
Exemple #2
0
        public ICharacterManager CreateCharacterManager(Type cmType, CharacterControllerBase owner, params CharacterStateBase[] states)
        {
            if (owner == null)
            {
                throw new GameFrameworkException("Invalid Owner to create CharacterManager");
            }

            if (states.Length < 1)
            {
                throw new GameFrameworkException("Must has at least One State to create a CharacterManager");
            }

            string tName = cmType.FullName;

            if (cmType.GetInterface("ICharacterManager") == null)
            {
                throw new GameFrameworkException(string.Format("Invalid Type {0} to create CharacterManager.", tName));
            }

            ICharacterManager ret = null;
            Dictionary <string, ICharacterManager> dict = null;

            if (m_CharacterInstancesDict.TryGetValue(tName, out dict))
            {
                string instName = string.Format("{0}.{1}", owner.name, cmType.Name);
                if (dict.ContainsKey(instName))
                {
                    Log.Warning("{0} already Exists, will be replaced", instName);
                }
                ret = (ICharacterManager)Activator.CreateInstance(cmType);
                ret.Initialize(GameFrameworkEntry.GetModule <IFsmManager>(), owner, states);
                dict [instName] = ret;
            }
            else
            {
                throw new GameFrameworkException(string.Format("Invalid Type {0} to create CharacterManager.", tName));
            }

            return(ret);
        }
Exemple #3
0
        public ICharacterManager CreateCharacterManager <T>(CharacterControllerBase owner, params CharacterStateBase[] states) where T : ICharacterManager
        {
            Type t = typeof(T);

            return(CreateCharacterManager(t, owner, states));
        }