public void CreateFsmMachine(AbsEntity entity, string name,
                                     List <AbsState> stateList, AbsState defaultState, List <AbsTransition> transitionList)
        {
            StateMachine fsm = new StateMachine(entity, name, stateList, defaultState, transitionList);

            _fsmDict.Add(entity, fsm);
        }
Пример #2
0
 public AbsStateMachine(AbsEntity entity)
 {
     Enable       = false;
     Entity       = entity;
     StateList    = new List <AbsState>();
     CurrentState = null;
 }
Пример #3
0
        public void Initialize(AbsEntity entity, bool isAsync = true)
        {
            Entity          = entity;
            IsLoadFinish    = false;
            _isCombineModel = true;

            if (_isCombineModel)
            {
                ModelComponent = Entity.AddComponent <CombineModelComponent>();
            }
            else
            {
                ModelComponent = Entity.AddComponent <CommonModelComponent>();
            }
            ModelComponent.OnLoadFinishHandler = () =>
            {
                gameObject      = ModelComponent.GameObject;
                gameObject.name = Entity.UID.ToString();
                gameObject.transform.localPosition = _position;
                gameObject.transform.localScale    = _scale;
                gameObject.transform.localRotation = Quaternion.Euler(_rotation);
                IsLoadFinish = true;
                Trans        = gameObject.transform;
                _loadFinishHandler?.Invoke(this);
            };
        }
Пример #4
0
 public HumanStateMachine(AbsEntity entity) : base(entity)
 {
     StateList.Add(new IdleState(this));
     StateList.Add(new MoveState(this));
     StateList.Add(new SkillState(this));
     StateList.Add(new SpecialState(this));
     StateList.Add(new DeadState(this));
 }
 public void RemoveStateMachine(AbsEntity entity)
 {
     if (_stateMachineDict.TryGetValue(entity, out var machine))
     {
         machine.UnInitialize();
         _stateMachineDict.Remove(entity);
     }
 }
Пример #6
0
 /// <summary>
 /// 添加Entity;
 /// </summary>
 /// <param name="UID"></param>
 /// <param name="entity"></param>
 /// <returns></returns>
 private bool AddEntity(ulong UID, AbsEntity entity)
 {
     if (_entityDict.ContainsKey(UID))
     {
         return(false);
     }
     _entityList.Add(entity);
     _entityDict[UID] = entity;
     return(true);
 }
 public AbsStateMachine CreateStateMachine(AbsEntity entity)
 {
     if (!_stateMachineDict.TryGetValue(entity, out var machine))
     {
         machine = new HumanStateMachine(entity);
         machine.Initialize();
         _stateMachineDict[entity] = machine;
     }
     return(machine);
 }
Пример #8
0
 /// <summary>
 /// 删除Entity;
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 private bool RemoveEntity(AbsEntity entity)
 {
     if (!_entityDict.ContainsKey(entity.UID))
     {
         return(false);
     }
     _entityList.Remove(entity);
     _entityDict.Remove(entity.UID);
     return(true);
 }
Пример #9
0
        /// <summary>
        /// 获取Entity;
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="uid"></param>
        /// <returns></returns>
        public T GetEntity <T>(ulong uid) where T : AbsEntity, new()
        {
            T         target = null;
            AbsEntity temp   = null;

            if (_entityDict.TryGetValue(uid, out temp))
            {
                target = temp as T;
            }
            return(target);
        }
Пример #10
0
 public BehaviorState Behave(AbsEntity entity, float interval)
 {
     if (!_awake)
     {
         _awake = true;
         Entity = entity;
         Reslut = BehaviorState.Running;
         AwakeEx();
     }
     Update(interval);
     return(Reslut);
 }
Пример #11
0
 public StateMachine(AbsEntity entity, string name,
                     List <AbsState> stateList, AbsState defaultState, List <AbsTransition> transitionList)
 {
     Enable = false;
     Name   = name;
     Entity = entity;
     _stateList.Clear();
     _transitionList.Clear();
     _stateList      = stateList;
     _defaultState   = defaultState;
     CurTrans        = null;
     CurrentState    = _defaultState;
     _transitionList = transitionList;
 }
Пример #12
0
 public void Init(AbsEntity entity, string path, bool isAsync = true)
 {
     Entity       = entity;
     ResPath      = path;
     IsLoadFinish = false;
     proxy        = ResourceMgr.singleton.LoadAssetAsync(ResPath);
     proxy.AddLoadFinishCallBack(() =>
     {
         gameObject      = proxy.GetInstantiateObject <GameObject>();
         gameObject.name = entity.UID.ToString();
         IsLoadFinish    = true;
         Trans           = gameObject.transform;
         _loadFinishHandler?.Invoke(this);
     });
 }
Пример #13
0
 public void RemoveBehaviorTree(AbsEntity entity)
 {
     if (entity == null)
     {
         LogHelper.PrintError("[BehaviorTreeMgr]Remove BehaviorTree error,entity is null!");
         return;
     }
     if (!_treeDict.ContainsKey(entity))
     {
         LogHelper.PrintWarning(string.Format("[BehaviorTreeMgr]can not find a BehaviorTree at EntityName: {0}.", entity.EntityName));
     }
     else
     {
         _treeDict.Remove(entity);
     }
 }
Пример #14
0
        public void CreateBehaviorTree(AbsEntity entity, string path, bool enable = false)
        {
            BehaviorTree tree = BehaviorTreeFactory.CreateBehaviorTree(entity, path);

            if (entity == null)
            {
                LogHelper.PrintError("[BehaviorTreeMgr]Create BehaviorTree error,entity is null!");
                return;
            }
            if (_treeDict.ContainsKey(entity))
            {
                LogHelper.PrintWarning(string.Format("[BehaviorTreeMgr]repeat add BehaviorTree at EntityName: {0}.", entity.EntityName));
            }
            tree.Enable       = enable;
            _treeDict[entity] = tree;
        }
Пример #15
0
 public void Uninit()
 {
     if (_destroyHandler != null)
     {
         _destroyHandler(this);
     }
     if (IsLoadFinish)
     {
         proxy.DestroyUnityObject <GameObject>(gameObject);
     }
     proxy.UnloadProxy();
     Trans              = null;
     _entity            = null;
     _resPath           = string.Empty;
     _loadFinishHandler = null;
     _destroyHandler    = null;
 }
Пример #16
0
        public void Init(AbsEntity entity, string path, bool isAsync = true)
        {
            _entity      = entity;
            _resPath     = path;
            IsLoadFinish = false;
            AsyncAssetProxy proxy = ResourceMgr.Instance.LoadAssetProxy(AssetType.Prefab, _resPath);

            proxy.AddLoadFinishCallBack(() =>
            {
                gameObject      = proxy.LoadUnityObject <GameObject>();
                gameObject.name = entity.UID.ToString();
                IsLoadFinish    = true;
                Trans           = gameObject.transform;
                if (_loadFinishHandler != null)
                {
                    _loadFinishHandler(this);
                }
            });
        }
        public static BehaviorTree CreateBehaviorTree(AbsEntity entity, string path)
        {
            InitDict(path);
            if (_rootBehavior == null)
            {
                LogHelper.PrintError("[BehaviorTreeFactory]Root Behavior is null!");
                return(null);
            }
            GenerateConnect(new List <AbsBehavior>()
            {
                _rootBehavior
            });
            var tree = new BehaviorTree(_rootBehavior, entity);

            _rootBehavior = null;
            _behaviorDict.Clear();
            _connectionDict.Clear();
            return(tree);
        }
Пример #18
0
 public BehaviorTree(AbsBehavior root, AbsEntity entity)
 {
     Root   = root;
     Entity = entity;
     Enable = false;
 }
Пример #19
0
 /// <summary>
 /// 移除Entity;
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="entity"></param>
 public void ReleaseEntity <T>(AbsEntity entity) where T : AbsEntity, new()
 {
     RemoveEntity(entity);
     entity.UnInitialize();
     PoolMgr.Instance.ReleaseCsharpObject <T>(entity as T);
 }
Пример #20
0
 public void Init(AbsEntity entity, bool isAsync = true)
 {
     Entity       = entity;
     IsLoadFinish = false;
     ModelComponent modelComp = entity.GetComponent <ModelComponent>();
 }