Exemplo n.º 1
0
        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="handleOnLoadComplete"></param>
        /// <returns></returns>
        public IEnumerator AsynLoad(Action <Object> handleOnLoadComplete)
        {
            while (true)
            {
                if (m_GameObject != null)
                {
                    if (handleOnLoadComplete != null)
                    {
                        handleOnLoadComplete(m_GameObject);
                    }
                    yield break;
                }

                try
                {
                    m_GameObject = Resources.LoadAssetAtPath(m_strPath, typeof(GameObject)) as GameObject;
                    if (m_GameObject == null)
                    {
                        BTDebug.Warning(string.Format("Editor Load {0} Failed, Record Path:{1}", m_strName, m_strPath), "RESOURCE");
                    }
                }
                catch (System.Exception ex)
                {
                    BTDebug.ExceptionEx(ex);
                }
                yield return(null);

                if (handleOnLoadComplete != null)
                {
                    handleOnLoadComplete(m_GameObject);
                }

                yield break;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 从配置创建状态机
        /// </summary>
        /// <param name="fsmXMLEntity"></param>
        /// <returns></returns>
        public bool CreateFromFSMXML(CFSMXMLEntity fsmXMLEntity)
        {
            if (fsmXMLEntity == null)
            {
                return(false);
            }
            m_uEnteranceStateId = fsmXMLEntity.m_uEntranceStateId;
            m_uAnyStateId       = fsmXMLEntity.m_uAnyStateId;
            Int32 nStateSize = fsmXMLEntity.m_FSMStateList == null ? 0 : fsmXMLEntity.m_FSMStateList.Count;

            for (Int32 i = 0; i < nStateSize; ++i)
            {
                CFSMXMLState xmlState = fsmXMLEntity.m_FSMStateList[i];
                if (xmlState == null)
                {
                    continue;
                }
                CFSMExecutableState fsmState = new CFSMExecutableState();
                if (fsmState.CreateFromXML(xmlState) == false)
                {
                    BTDebug.Warning("<BTFSM> Create FSM State Failed");
                    continue;
                }
                AddState(fsmState);
            }
            return(true);
        }
Exemplo n.º 3
0
        // 从xml数据创建动作列表
        private List <CFSMAction> CreateActionListFromXML(CFSMXMLActionArray actionxmlList)
        {
            if (actionxmlList == null)
            {
                return(null);
            }
            List <CFSMAction> actionList = new List <CFSMAction>();
            Int32             nSize      = actionxmlList.m_ActionList == null ? 0 : actionxmlList.m_ActionList.Count;

            for (Int32 i = 0; i < nSize; ++i)
            {
                CFSMXMLAction actionxml = actionxmlList.m_ActionList[i];
                if (actionxml == null)
                {
                    continue;
                }
                CFSMAction newAction = new CFSMAction();
                if (newAction.CreateFromXML(actionxml) == false)
                {
                    BTDebug.Warning("<BTFSM> Create FSM Action Failed");
                    continue;
                }
                actionList.Add(newAction);
            }
            return(actionList);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 帧更新
        /// </summary>
        public void Update()
        {
            while (m_ListenedEvent.IsEmpty() == false)
            {
                System.Object objInfo = null;
                if (m_ListenedEvent.Pop(ref objInfo) == false || objInfo == null)
                {
                    continue;
                }
                CEventInfo info = objInfo as CEventInfo;
                if (info == null)
                {
                    continue;
                }
                UInt32        uEventId = info.GetEventId();
                System.Object objParam = info.GetEventParam();

                m_EventInfoPool.GiveBackObject(info);

                CHandleInfo handleInfo = null;
                if (m_EventActionList.QuickFind(uEventId, ref handleInfo) == false || handleInfo == null)
                {
                    continue;
                }
                bool bTriggerRet = handleInfo.TriggerHandle(objParam);
                if (bTriggerRet == false)
                {
                    BTDebug.Warning(string.Format("Trigger Event:{0} With Param:{2} Failed", uEventId, objParam), "ACTION");
                }
            }
        }
Exemplo n.º 5
0
 // 更新
 public void OnUpdateConnect()
 {
     while (m_QueMsgReceive.IsEmpty() == false)
     {
         System.Object refObj = null;
         if (m_QueMsgReceive.Pop(ref refObj) == false)
         {
             break;
         }
         if (refObj == null)
         {
             continue;
         }
         Byte[] receByteArray = refObj as Byte[];
         if (receByteArray == null)
         {
             BTDebug.Warning("Receive Data Not Packed as Byte Array", "NET");
             continue;
         }
         if (m_HandleOnReceiveMsg != null)
         {
             m_HandleOnReceiveMsg(receByteArray);
         }
     }
 }
Exemplo n.º 6
0
        // 更新当前状态
        protected virtual void UpdateCurrentState()
        {
            if (m_CurrentState == null)
            {
                return;
            }
            // 获取下一个状态, 如果没有则循环执行当前状态
            UInt32 uNextStateId = m_CurrentState.GetFSMTransState(this);

            if (uNextStateId == CFSMState.cuInvalieStateId)
            {
                if (m_CurrentState.Process(this, null) == false)
                {
                    BTDebug.Warning(string.Format("<BTFSM> State:{0} Process Failed", m_CurrentState.GetStateName()));
                }
                return;
            }
            // 切换到下一状态
            bool bChangeRet = ChangeToState(uNextStateId, null);

            if (bChangeRet == false)
            {
                BTDebug.Warning(string.Format("<BTFSM> FSM Trans From:{0} To:{1} Failed", m_CurrentState.GetStateID(), uNextStateId));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 设置FSM调试开关
        /// 仅对BTDEBUG下的BTCore有效
        /// </summary>
        /// <param name="bOpen"></param>
        public void SetOpenFSMDebug(bool bOpen)
        {
#if BTDEBUG
            m_bOpenDebug = bOpen;
#else
            BTDebug.Warning("<BTFSM> BTCore On Release Mode Not Support FSM Debug");
#endif
        }
Exemplo n.º 8
0
        // 加载 由GameDataManager管理
        private static bool Load(Action handleOnLoadComplete, Action <string> handleOnLoadError)
        {
            Action <string> tmpActionOnError = (strInfo) =>
            {
                if (handleOnLoadError != null)
                {
                    handleOnLoadError(strInfo);
                }
            };

            if (m_DataSingleton != null)             // 重复加载
            {
                string strErrorInfo = string.Format("Duplicate Load:{0}", typeof(U));
                BTDebug.Warning(strErrorInfo, "DATA");
                tmpActionOnError(strErrorInfo);
                return(false);
            }
            m_DataSingleton = new GameData <T>();
            string strDataFileKey = GetDataFileKey();

            if (string.IsNullOrEmpty(strDataFileKey) == true)
            {
                string strErrorInfo = string.Format("GameData:{0} Has No DataFileKey", typeof(U).ToString());
                BTDebug.Exception(strErrorInfo, "DATA");
                tmpActionOnError(strErrorInfo);
                return(false);
            }

            if (GameDataManager.Instance.AsynLoadGameDataFile(strDataFileKey, (errorInfo, dataArray) =>
            {
                if (string.IsNullOrEmpty(errorInfo) == false)
                {
                    BTDebug.Exception(string.Format("GameData:{0} Load File Error:{1}", typeof(U), errorInfo), "DATA");
                    tmpActionOnError(errorInfo);
                    return;
                }
                if (m_DataSingleton.ReadFromXML(PackageSetting.cTextFileEncoding.GetString(dataArray)) == false)
                {
                    string info = string.Format("GameData:{0} Parse Failed", typeof(U).ToString());
                    BTDebug.Exception(info, "DATA");
                    tmpActionOnError(errorInfo);
                    return;
                }
                if (handleOnLoadComplete != null)
                {
                    handleOnLoadComplete();
                }
            }
                                                              ) == false)
            {
                string strInfo = string.Format("GameData:{0} Load File Failed", typeof(U).ToString());
                BTDebug.Exception(strInfo, "DATA");
                tmpActionOnError(strInfo);
                return(false);
            }

            return(true);
        }
Exemplo n.º 9
0
    /// <summary>
    /// 加载数据
    /// </summary>
    /// <param name="dataType"></param>
    /// <param name="handleOnLoadComplete"></param>
    /// <param name="handleOnLoadError"></param>
    /// <param name="bClearIfLoaded"></param>
    /// <returns></returns>
    public bool StartLoadData(Type dataType, Action handleOnLoadComplete, Action <string> handleOnLoadError, bool bClearIfLoaded = false)
    {
        if (dataType == null)
        {
            return(false);
        }
        bool bRet         = false;
        Type gameDataType = GetGameDataCollectionType(dataType.BaseType);

        if (gameDataType == null)
        {
            BTDebug.Warning(string.Format("Load DataType:{0} Not AssignableFrom GameData", dataType.Name), "DATA");
            return(false);
        }

        if (mLoadedGameDataList.Contains(dataType))
        {
            if (bClearIfLoaded == true)
            {
                ClearData(dataType);
            }
            else
            {
                BTDebug.Warning(string.Format("Dup Load DataType:{0} ", dataType.Name), "DATA");
                return(false);
            }
        }

        System.Reflection.MethodInfo methodInfo = gameDataType.GetMethod(
            cStrGameDataLoadMethodName,
            System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);

        if (methodInfo == null)
        {
            BTDebug.Warning(string.Format("DataType:{0} No {1} Method", dataType.Name, cStrGameDataLoadMethodName), "DATA");
            return(false);
        }
        try
        {
            Object[] paramArray = { handleOnLoadComplete, handleOnLoadError };
            bRet = (bool)methodInfo.Invoke(null, paramArray);
        }
        catch (System.Exception ex)
        {
            BTDebug.ExceptionEx(ex);
            bRet = false;
        }
        if (bRet == true)
        {
            mLoadedGameDataList.Add(dataType);
        }
        return(bRet);
    }
Exemplo n.º 10
0
        /// <summary>
        /// 触发事件
        /// </summary>
        /// <param name="uEventId"></param>
        /// <param name="objParam"></param>
        /// <returns></returns>
        public bool TriggerAction(UInt32 uEventId, System.Object objParam)
        {
            CEventInfo eventInfo = m_EventInfoPool.RentObject() as CEventInfo;

            if (eventInfo == null)
            {
                BTDebug.Warning(string.Format("Action {0} Trigger Failed, Event Info NULL", uEventId), "ACTION");
                return(false);
            }
            eventInfo.Set(uEventId, objParam);
            if (m_ListenedEvent.Push(eventInfo) == false)
            {
                BTDebug.Warning(string.Format("Action {0} Trigger Failed, Event Info Push Failed", uEventId), "ACTION");
                return(false);
            }
            return(true);
        }
Exemplo n.º 11
0
    /// <summary>
    /// 清除数据
    /// </summary>
    /// <param name="dataType"></param>
    /// <returns></returns>
    public bool ClearData(Type dataType)
    {
        if (mLoadedGameDataList == null)
        {
            return(false);
        }
        if (mLoadedGameDataList.Contains(dataType) == false)
        {
            return(false);
        }
        Type gameDataType = GetGameDataCollectionType(dataType.BaseType);

        if (gameDataType == null)
        {
            return(false);
        }
        System.Reflection.MethodInfo methodInfo = gameDataType.GetMethod(
            cStrGameDataClearMethodName,
            System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);

        if (methodInfo == null)
        {
            BTDebug.Warning(string.Format("DataType:{0} No {1} Method", dataType.Name, cStrGameDataClearMethodName), "DATA");
            return(false);
        }

        bool bRet = false;

        try
        {
            bRet = (bool)methodInfo.Invoke(null, null);
        }
        catch (System.Exception ex)
        {
            BTDebug.ExceptionEx(ex);
            bRet = false;
        }
        if (bRet == true)
        {
            mLoadedGameDataList.Remove(dataType);
        }
        return(bRet);
    }
Exemplo n.º 12
0
        /// <summary>
        /// 切换到一个状态
        /// </summary>
        /// <param name="uNextState"></param>
        /// <param name="fsmEvent"></param>
        /// <returns></returns>
        public bool ChangeToState(UInt32 uNextState, CFSMEvent fsmEvent)
        {
            CFSMState nextFSMState = GetState(uNextState);

            if (nextFSMState == null)
            {
                BTDebug.Warning(string.Format("Found NO State With ID:{0}, Change State Failed", uNextState), "FSM");
                return(false);
            }

            if (m_CurrentState != null)
            {
                if (m_CurrentState.GetStateID() == uNextState)
                {
                    return(true);
                }

                if (m_CurrentState.OnExit(this, fsmEvent) == false)
                {
                    BTDebug.Warning(string.Format("State:{0} Exit Failed", m_CurrentState.GetStateName()), "FSM");
                }
            }

#if BTDEBUG
            if (m_bOpenDebug)
            {
                string strLog = string.Format("FSM Trans From:{0} To:{1}",
                                              m_CurrentState == null ? "NULL" : m_CurrentState.GetStateName(),
                                              nextFSMState.GetStateName());

                BTDebug.Log(strLog, "BTFSM");
            }
#endif

            m_CurrentState = nextFSMState;

            if (nextFSMState.OnEnter(this, fsmEvent) == false)
            {
                BTDebug.Warning(string.Format("State:{0} Enter Failed", nextFSMState.GetStateName()), "FSM");
            }

            return(true);
        }
Exemplo n.º 13
0
    /// <summary>
    /// 释放GameObject实体
    /// </summary>
    /// <param name="go"></param>
    /// <returns></returns>
    public bool ReleaseInstance(Object go)
    {
        if (go == null)
        {
            return(false);
        }
        Int32  guid    = go.GetInstanceID();
        string strName = string.Empty;

        if (m_InstanceMap.TryGetValue(guid, out strName) == false)
        {
            BTDebug.Warning(string.Format("Release Game Object:{0} No Record in Map", go.name), "RESOURCE");
            return(false);
        }

        m_InstanceMap.Remove(guid);
        m_AssetsLoader.ReleaseAsset(strName);
        GameObject.Destroy(go);
        return(true);
    }
Exemplo n.º 14
0
        // 更新公共状态
        protected virtual void UpdateAnyState()
        {
            if (m_AnyState == null)
            {
                return;
            }
            // 获取下一个状态, 如果没有则循环执行当前状态
            UInt32 uNextStateId = m_AnyState.GetFSMTransState(this);

            if (uNextStateId != CFSMState.cuInvalieStateId)
            {
                ChangeToState(uNextStateId, null);
                return;
            }
            if (m_AnyState.Process(this, null) == false)
            {
                BTDebug.Warning(string.Format("<BTFSM> State:{0} Process Failed", m_CurrentState.GetStateName()));
            }
            return;
        }
Exemplo n.º 15
0
        /// <summary>
        /// 切换到一个状态
        /// </summary>
        /// <param name="uNextState"></param>
        /// <param name="fsmEvent"></param>
        /// <returns></returns>
        public bool ChangeToState(UInt32 uNextState, CFSMEvent fsmEvent)
        {
            CFSMState nextFSMState = GetState(uNextState);

            if (nextFSMState == null)
            {
                return(false);
            }

            if (m_CurrentState != null)
            {
                if (m_CurrentState.GetStateID() == uNextState)
                {
                    return(true);
                }

                if (m_CurrentState.OnExit(this, fsmEvent) == false)
                {
                    BTDebug.Warning(string.Format("<BTFSM> State:{0} Exit Failed", m_CurrentState.GetStateName()));
                }
            }

#if BTDEBUG
            if (m_bOpenDebug)
            {
                BTDebug.Log(string.Format("<BTFSM> FSM Trans From:{0} To:{1}",
                                          m_CurrentState == null ? "NULL" : m_CurrentState.GetStateName(),
                                          nextFSMState.GetStateName()));
            }
#endif

            if (nextFSMState.OnEnter(this, fsmEvent) == false)
            {
                BTDebug.Warning(string.Format("<BTFSM> State:{0} Enter Failed", nextFSMState.GetStateName()));
            }

            m_CurrentState = nextFSMState;

            return(true);
        }
Exemplo n.º 16
0
            /// <summary>
            /// 触发回调
            /// </summary>
            /// <param name="objParam"></param>
            /// <returns></returns>
            public bool TriggerHandle(System.Object objParam)
            {
                if (CheckEventParamType(objParam) == false)
                {
                    BTDebug.Warning("Trigger Event With An Param Not Fit", "ACTION");
                    return(false);
                }

#if BTDEBUG
                m_cpuProfiler.StartNewCall();
#endif
                if (m_Handle == null)
                {
                    return(true);
                }
                Delegate[] delArray = m_Handle.GetInvocationList();
                Int32      nSize    = delArray == null ? 0 : delArray.Length;
                for (Int32 i = 0; i < nSize; ++i)
                {
                    try
                    {
                        HandleObjectAction handle = (HandleObjectAction)delArray[i];
                        if (handle == null)
                        {
                            continue;
                        }
                        handle(objParam);
                    }
                    catch (System.Exception ex)
                    {
                        BTDebug.ExceptionEx(ex);
                    }
                }
#if BTDEBUG
                m_cpuProfiler.EndCall();
#endif
                return(true);
            }
Exemplo n.º 17
0
    /// <summary>
    /// 加载资源
    /// </summary>
    /// <param name="strName"></param>
    /// <param name="handleOnLoaded"></param>
    /// <param name="fProgress"></param>
    public void LoadAsset(string strName, Action <Object> handleOnLoaded, Action <float> fProgress)
    {
        AssetInfo4EditorLoad info = null;

        if (m_LoadedResourceInfoMap.TryGetValue(strName, out info) == false ||
            info == null)
        {
            string strPath = string.Empty;
            if (Data_EditorObjectList.TryGetFilePath(strName, out strPath) == false)
            {
                BTDebug.Warning(string.Format("Resource:{0} Not Found In Path Info Map", strName), "RESOURCE");
                if (handleOnLoaded != null)
                {
                    handleOnLoaded(null);
                    return;
                }
            }
            info = new AssetInfo4EditorLoad(strName, strPath);
            m_LoadedResourceInfoMap.Add(strName, info);
        }
        info.AddRefCount();
        StartCoroutine(info.AsynLoad(handleOnLoaded));
    }