223 lines
6.4 KiB
C#
223 lines
6.4 KiB
C#
using Thousandto.Plugins.Common.UniScene;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using Thousandto.Core.Asset;
|
||
using Thousandto.Code.Center;
|
||
using Thousandto.Code.Global;
|
||
using PathEditor.Proxy.Plugin;
|
||
using Thousandto.Plugins.PathGrid;
|
||
|
||
namespace Thousandto.Code.Logic
|
||
{
|
||
/// <summary>
|
||
/// lua角色类,用于扩展
|
||
/// </summary>
|
||
public class LuaCharacter : Entity
|
||
{
|
||
#region members
|
||
//角色所在场景
|
||
private GameScene _sceneEx = null;
|
||
//模型信息
|
||
private FSkinModel _roleSkin = null;
|
||
//是否被屏蔽模型
|
||
protected bool _isShowModel = true;
|
||
#endregion
|
||
|
||
#region //属性接口
|
||
public new GameScene Scene
|
||
{
|
||
get
|
||
{
|
||
if (_sceneEx == null)
|
||
{
|
||
_sceneEx = base.Scene as GameScene;
|
||
}
|
||
return _sceneEx;
|
||
}
|
||
set
|
||
{
|
||
_sceneEx = value;
|
||
base.Scene = value;
|
||
}
|
||
|
||
}
|
||
public new FSkinModel Skin
|
||
{
|
||
get
|
||
{
|
||
if (_roleSkin == null)
|
||
{
|
||
_roleSkin = base.Skin as FSkinModel;
|
||
}
|
||
return _roleSkin;
|
||
}
|
||
set
|
||
{
|
||
base.Skin = value;
|
||
_roleSkin = value;
|
||
}
|
||
}
|
||
//是否被屏蔽模型
|
||
public bool IsShowModel
|
||
{
|
||
get
|
||
{
|
||
return _isShowModel;
|
||
}
|
||
set
|
||
{
|
||
_isShowModel = value;
|
||
if (_isShowModel != Skin.IsActive())
|
||
{
|
||
Skin.SetActive(_isShowModel);
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region//lua回调
|
||
public Action SetupFSMBeforeHandle = null;
|
||
public Action SetupFSMHandle = null;
|
||
public Action<LuaCharInitInfo> InitializeAfterHandle = null;
|
||
public Action<LuaCharInitInfo> SyncInfoHandle = null;
|
||
public Action UninitializeBeforeHandle = null;
|
||
#endregion
|
||
|
||
#region//初始化和卸载 -- 重写父类函数
|
||
//加载Skin
|
||
protected override FSkinBase OnSetupSkin()
|
||
{
|
||
FSkinModel skin = GameCenter.LuaSystem.Adaptor.CreateFSkinModel(FSkinTypeCode.Custom);
|
||
skin.SetLayer(LayerUtils.RemotePlayer);
|
||
skin.SetMipmapLevel(0.5f);
|
||
return skin;
|
||
}
|
||
//创建FSM之前的处理
|
||
protected override bool OnSetupFSMBefore()
|
||
{
|
||
ResetDirection();
|
||
if(SetupFSMBeforeHandle != null)
|
||
{
|
||
SetupFSMBeforeHandle();
|
||
}
|
||
return base.OnSetupFSMBefore();
|
||
}
|
||
//设置FSM
|
||
protected override bool OnSetupFSM()
|
||
{
|
||
Fsm = new EntityFSM(this);
|
||
if(SetupFSMHandle != null)
|
||
{
|
||
SetupFSMHandle();
|
||
}
|
||
Fsm.Init(this);
|
||
return true;
|
||
}
|
||
public void AddState(LuaCharState state)
|
||
{
|
||
Fsm.AddState(state);
|
||
}
|
||
public void SetDefaultState(int stateId)
|
||
{
|
||
Fsm.SetDefaultStateId((EntityStateID)stateId);
|
||
}
|
||
//初始化完成
|
||
protected override bool OnInitializeAfter(EntityInitInfo baseInfo)
|
||
{
|
||
RefreshSkinQuality();
|
||
var initInfo = baseInfo as LuaCharInitInfo;
|
||
if(InitializeAfterHandle != null && initInfo != null)
|
||
{
|
||
InitializeAfterHandle(initInfo);
|
||
}
|
||
return base.OnInitializeAfter(baseInfo);
|
||
}
|
||
//同步数据
|
||
public void SyncInfo(EntityInitInfo baseInfo)
|
||
{
|
||
var initInfo = baseInfo as LuaCharInitInfo;
|
||
if (SyncInfoHandle != null && initInfo != null)
|
||
{
|
||
SyncInfoHandle(initInfo);
|
||
}
|
||
}
|
||
//卸载之前
|
||
protected override void OnUninitializeBefore()
|
||
{
|
||
if(UninitializeBeforeHandle != null)
|
||
{
|
||
UninitializeBeforeHandle();
|
||
}
|
||
base.Scene = null;
|
||
_sceneEx = null;
|
||
}
|
||
#endregion
|
||
|
||
#region//判断当前角色处于那种状态
|
||
//判断当前是否处于某个状态
|
||
public bool IsXState(int state)
|
||
{
|
||
bool retval = false;
|
||
if (Fsm != null)
|
||
{
|
||
retval = (int)Fsm.CurrentState.StateID == state;
|
||
}
|
||
return retval;
|
||
}
|
||
#endregion
|
||
|
||
#region//状态改变
|
||
//状态改变
|
||
public bool ChangeAction(int stateId, object userData)
|
||
{
|
||
if (!IsTransAble((EntityStateID)stateId))
|
||
return false;
|
||
var data = StateDateCache.Get<LuaCharStateData>(EntityStateID.LuaCharState);
|
||
data.LuaData = userData;
|
||
bool ret = Fsm.TryTransTo((EntityStateID)stateId, data);
|
||
if (ret)
|
||
{
|
||
Fsm.Update(0);
|
||
}
|
||
return ret;
|
||
}
|
||
#endregion
|
||
|
||
#region//其他公共接口
|
||
//刷新skin品质
|
||
public void RefreshSkinQuality()
|
||
{
|
||
var setCode = GameCenter.GameSetting.GetSetting(GameSettingKeyCode.OtherBonesCount);
|
||
switch (setCode)
|
||
{
|
||
case 1:
|
||
SkinQuality = SkinQuality.Bone1;
|
||
break;
|
||
case 2:
|
||
SkinQuality = SkinQuality.Bone2;
|
||
break;
|
||
case 4:
|
||
SkinQuality = SkinQuality.Bone4;
|
||
break;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region//重写父类的一些处理 ---- 播放动作等
|
||
//播放
|
||
protected override bool OnPlayAnim(string anim, AnimationPartType partType = AnimationPartType.AllBody, WrapMode wrapMode = WrapMode.Default, bool isCrossFade = true, float crossFadeTime = 0.2f, float speed = 1f, float normalizedTime = 0.0f)
|
||
{
|
||
return Skin.PlayAnim(anim, partType, wrapMode, isCrossFade, crossFadeTime, speed, normalizedTime);
|
||
}
|
||
#endregion
|
||
|
||
#region //阻挡判定
|
||
public bool IsBlocked(float x, float y)
|
||
{
|
||
return Scene.navigator.IsBlocked(new Vector2(x, y));
|
||
}
|
||
#endregion
|
||
}
|
||
}
|