using Thousandto.Core.Asset; using Thousandto.Core.Base; using Thousandto.Plugins.Common.UniScene; using System; using System.Collections.Generic; using System.Text; using UnityEngine; using Thousandto.Cfg.Data; using Thousandto.Code.Global; using Thousandto.Code.Center; using Thousandto.Code.Logic.WarningField; using Thousandto.Core.Support; using Thousandto.Core.RootSystem; namespace Thousandto.Code.Logic { //技能对象 public class SkillObject : Entity { #region//私有变量 private SkillVisualInfo _visualCfg = null; private SkillObjectSkill _curSkill = null; private ulong _ownerID = 0; private bool _postDelete = false; private float _moveSpeed = 0f; private float _moveAddSpeed = 0f; #endregion #region//属性 public ulong OwnerID { get { return _ownerID; } } public SkillObjectSkill CurSkill { get { return _curSkill; } } public float MoveSpeed { get { return _moveSpeed; } set { _moveSpeed = value; } } #endregion #region//初始化,加载Skin,卸载处理 protected override FSkinBase OnSetupSkin() { FSkinModel skin = GameCenter.LuaSystem.Adaptor.CreateFSkinModel(FSkinTypeCode.Custom); skin.SetLayer(LayerUtils.SummonObj); return skin; } protected override bool OnInitializeAfter(EntityInitInfo baseInfo) { base.OnInitializeAfter(baseInfo); var info = baseInfo as SkillObjectInitInfo; SyncInfo(info); return true; } protected override void OnUninitializeBefore() { if (_curSkill != null) { _curSkill.Stop(); _curSkill = null; } GameCenter.WarningFiledManager.RemoveFiled(this); base.OnUninitializeBefore(); } //初始化FSM状态 protected override bool OnSetupFSM() { Fsm = new EntityFSM(this); Fsm.AddState(new SkillObjectFSM.Idle()); Fsm.AddState(new SkillObjectFSM.Move()); Fsm.SetDefaultStateId(EntityStateID.Idle); Fsm.Init(this); return true; } public void SyncInfo(SkillObjectInitInfo info) { _ownerID = info.OwnerID; _visualCfg = info.VisualInfo; _moveSpeed = info.MoveSpeed; _moveAddSpeed = info.MoveAddSpeed; //Debug.LogWarning("Skill Object SyncInfo::_curSkill != null:::" + (_curSkill != null)+":::"+this.ID); if (_curSkill != null) { _curSkill.Stop(); _curSkill = null; } _curSkill = new SkillObjectSkill(); _curSkill.DoCreate(_visualCfg, this); _curSkill.Start(); if (info.MovePosList.Count > 1) { SetDirection2d(info.MovePosList[1] - info.MovePosList[0], false, false); Action_MoveTo(info.MovePosList); } else { var owner = GameCenter.GameSceneSystem.FindEntity(_ownerID); if(owner != null) { SetDirection2d(owner.GetFacingDirection2d(), false, false); } Stop_Action(); } _postDelete = false; } //移动到目的--路径点 public bool Action_MoveTo(List targetList) { if (!IsTransAble(EntityStateID.PathMove)) return false; if (targetList != null && targetList.Count >= 2) { PathMoveData data = StateDateCache.Get(EntityStateID.PathMove); data.Path = targetList; bool ret = Fsm.TryTransTo(EntityStateID.PathMove, data); if (ret) { Fsm.Update(0); } return ret; } return false; } //停止活动,也是休闲状态 public bool Stop_Action() { if (Fsm.CurrentState.StateID == EntityStateID.Idle) return true; if (!IsTransAble(EntityStateID.Idle)) return false; bool ret = Fsm.TryTransTo(EntityStateID.Idle, null); if (ret) { Fsm.Update(0); } return ret; } protected override void OnUpdate(float dt) { base.OnUpdate(dt); if (_postDelete) return; _moveSpeed += _moveAddSpeed * dt; if (_curSkill != null) { _curSkill.Update(dt); if (_curSkill.IsEnd) { _curSkill.Stop(); _curSkill = null; PostDelete(); } } } private void PostDelete() { if (!_postDelete) { var baseScene = Scene as BaseScene; if (baseScene != null) { baseScene.DeleteEntity(ID); } _postDelete = true; } } #endregion } }