211 lines
9.5 KiB
C#
211 lines
9.5 KiB
C#
using Thousandto.Cfg.Data;
|
|
using Thousandto.Code.Global;
|
|
using Thousandto.Code.Logic;
|
|
using Thousandto.Core.Asset;
|
|
using Thousandto.Plugins.Common;
|
|
using UnityEngine;
|
|
|
|
namespace Thousandto.GameUI.Form
|
|
{
|
|
//玩家专用skin组件
|
|
public class UIPlayerSkinCompoent : UIRoleSkinCompoent
|
|
{
|
|
#region//属性
|
|
//切换武器挂节点倒计时
|
|
private float _brightStateTimer = 0f;
|
|
//切换武器挂节点总时间
|
|
private float _brightMaxTime = 38f * Skill.OneFrameTime;
|
|
//武器状态
|
|
private PlayerBrightWeaponState _brightState = PlayerBrightWeaponState.Receive;
|
|
//收武器的缩放
|
|
private Vector3 _receiveWeaponScale = Vector3.one;
|
|
//亮武器的缩放
|
|
private Vector3 _brightWeaponScale = Vector3.one;
|
|
|
|
//切换武器的倒计时
|
|
private float _changeTimer = 10f;
|
|
#endregion
|
|
|
|
#region//属性
|
|
//是否自动切换武器状态
|
|
public bool AutoSwitchWeaponState { get; set; }
|
|
//自动切换武器状态的时间
|
|
public float AutoSwitchWeaponTime { get; set; }
|
|
//默认武器状态
|
|
public PlayerBrightWeaponState NormalWeaponState { get; set; }
|
|
#endregion
|
|
|
|
#region//继承基类
|
|
public override void OnFirstShow(UINormalForm parent, FSkinTypeCode skinType = FSkinTypeCode.Monster, string defaultAnim = "", float animSpeed = 1, bool isUseUIValue = false, bool isUIModel = true)
|
|
{
|
|
base.OnFirstShow(parent, skinType, defaultAnim, animSpeed, isUseUIValue, isUIModel);
|
|
AutoSwitchWeaponState = true;
|
|
AutoSwitchWeaponTime = 10f;
|
|
NormalWeaponState = PlayerBrightWeaponState.Bright;
|
|
Skin.SetDefaultAnim(string.Empty, AnimationPartType.AllBody);
|
|
}
|
|
protected override void OnSkinChange(FSkinBase skin, int part)
|
|
{
|
|
base.OnSkinChange(skin, part);
|
|
|
|
if (part == FSkinPartCode.GodWeaponHead)
|
|
{
|
|
var weaponModelID = Skin.GetSkinPartCfgID(FSkinPartCode.GodWeaponHead);
|
|
var scaleCfg = DeclareWeaponScale.Get(weaponModelID);
|
|
if (scaleCfg != null)
|
|
{
|
|
_receiveWeaponScale = new Vector3(scaleCfg.ReceiveScale / 100f, scaleCfg.ReceiveScale / 100f, scaleCfg.ReceiveScale / 100f);
|
|
_brightWeaponScale = new Vector3(scaleCfg.BrightScale / 100f, scaleCfg.BrightScale / 100f, scaleCfg.BrightScale / 100f);
|
|
}
|
|
else
|
|
{
|
|
_receiveWeaponScale = Vector3.one;
|
|
_brightWeaponScale = Vector3.one;
|
|
}
|
|
ChangeBrightState(NormalWeaponState);
|
|
}
|
|
|
|
if (part == FSkinPartCode.GodWeaponHead || part == FSkinPartCode.Body)
|
|
{
|
|
//SlotUtils.SetSlotLocalScale(Skin.RealTransform, SlotNameDefine.LeftWeapon, _brightWeaponScale);
|
|
SlotUtils.SetSlotLocalScale(Skin.RealTransform, SlotNameDefine.RightWeapon, _brightWeaponScale);
|
|
//SlotUtils.SetSlotLocalScale(Skin.RealTransform, SlotNameDefine.LeftWeaponReceive, _receiveWeaponScale);
|
|
SlotUtils.SetSlotLocalScale(Skin.RealTransform, SlotNameDefine.RightWeaponReceive, _receiveWeaponScale);
|
|
}
|
|
}
|
|
|
|
protected override void OnUpdate(float dt)
|
|
{
|
|
base.OnUpdate(dt);
|
|
if(AutoSwitchWeaponState)
|
|
{
|
|
_changeTimer -= dt;
|
|
if (_changeTimer <= 0f)
|
|
{
|
|
_changeTimer = AutoSwitchWeaponTime;
|
|
switch (_brightState)
|
|
{
|
|
case PlayerBrightWeaponState.Receive:
|
|
ChangeBrightState(PlayerBrightWeaponState.Bright);
|
|
break;
|
|
case PlayerBrightWeaponState.Bright:
|
|
ChangeBrightState(PlayerBrightWeaponState.Receiveing);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
UpdateBrightState(dt);
|
|
}
|
|
|
|
public void ChangeBrightState(PlayerBrightWeaponState state)
|
|
{
|
|
_brightState = state;
|
|
_changeTimer = AutoSwitchWeaponTime;
|
|
switch (_brightState)
|
|
{
|
|
case PlayerBrightWeaponState.Receive:
|
|
{
|
|
//直接切换挂接点
|
|
var body = Skin.GetSkinPart(FSkinPartCode.Body) as FGameObjectBody;
|
|
if (body != null)
|
|
{
|
|
body.BrightWeapon = false;
|
|
//SlotUtils.SetSlotLocalScale(body.RealTransform, SlotNameDefine.LeftWeapon, _receiveWeaponScale);
|
|
SlotUtils.SetSlotLocalScale(body.RealTransform, SlotNameDefine.RightWeapon, _receiveWeaponScale);
|
|
//SlotUtils.SetSlotLocalScale(body.RealTransform, SlotNameDefine.LeftWeaponReceive, _receiveWeaponScale);
|
|
SlotUtils.SetSlotLocalScale(body.RealTransform, SlotNameDefine.RightWeaponReceive, _receiveWeaponScale);
|
|
}
|
|
}
|
|
break;
|
|
case PlayerBrightWeaponState.Receiveing:
|
|
{
|
|
Skin.PlayAnim(AnimClipNameDefine.SwordInIdle, AnimationPartType.AllBody, WrapMode.Once);
|
|
_brightStateTimer = _brightMaxTime;
|
|
//直接切换挂接点
|
|
var body = Skin.GetSkinPart(FSkinPartCode.Body) as FGameObjectBody;
|
|
if (body != null)
|
|
{
|
|
//SlotUtils.SetSlotLocalScale(body.RealTransform, SlotNameDefine.LeftWeapon, _brightWeaponScale);
|
|
SlotUtils.SetSlotLocalScale(body.RealTransform, SlotNameDefine.RightWeapon, _brightWeaponScale);
|
|
}
|
|
}
|
|
break;
|
|
case PlayerBrightWeaponState.Bright:
|
|
{
|
|
_brightStateTimer = _brightMaxTime;
|
|
//直接切换挂接点
|
|
var body = Skin.GetSkinPart(FSkinPartCode.Body) as FGameObjectBody;
|
|
if (body != null)
|
|
{
|
|
body.BrightWeapon = true;
|
|
}
|
|
Skin.PlayAnim(AnimClipNameDefine.SwordOutIdle, AnimationPartType.AllBody, WrapMode.Once);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
public void UpdateBrightState(float dt)
|
|
{
|
|
switch (_brightState)
|
|
{
|
|
case PlayerBrightWeaponState.Receive:
|
|
{
|
|
if(!Skin.IsPlaying())
|
|
{
|
|
Skin.PlayAnim(AnimClipNameDefine.NormalIdle, AnimationPartType.AllBody, WrapMode.Loop);
|
|
}
|
|
}
|
|
break;
|
|
case PlayerBrightWeaponState.Receiveing:
|
|
{
|
|
_brightStateTimer -= dt;
|
|
|
|
var body = Skin.GetSkinPart(FSkinPartCode.Body) as FGameObjectBody;
|
|
if (body != null)
|
|
{
|
|
var sacle = Vector3.Lerp(_receiveWeaponScale, _brightWeaponScale, _brightStateTimer / _brightMaxTime);
|
|
//SlotUtils.SetSlotLocalScale(body.RealTransform, SlotNameDefine.LeftWeapon, sacle);
|
|
SlotUtils.SetSlotLocalScale(body.RealTransform, SlotNameDefine.RightWeapon, sacle);
|
|
}
|
|
|
|
if(!_skin.IsPlaying())
|
|
{
|
|
//切换到收剑状态
|
|
Skin.PlayAnim(AnimClipNameDefine.NormalIdle, AnimationPartType.AllBody, WrapMode.Loop);
|
|
ChangeBrightState(PlayerBrightWeaponState.Receive);
|
|
}
|
|
//if (_brightStateTimer <= 0f)
|
|
//{
|
|
// //切换到收剑状态
|
|
// ChangeBrightState(PlayerBrightWeaponState.Receive);
|
|
//}
|
|
}
|
|
break;
|
|
case PlayerBrightWeaponState.Bright:
|
|
{
|
|
if(_brightStateTimer >= 0f)
|
|
{
|
|
_brightStateTimer -= dt;
|
|
var body = Skin.GetSkinPart(FSkinPartCode.Body) as FGameObjectBody;
|
|
if (body != null)
|
|
{
|
|
var sacle = Vector3.Lerp(_brightWeaponScale, _receiveWeaponScale, _brightStateTimer / _brightMaxTime);
|
|
//SlotUtils.SetSlotLocalScale(body.RealTransform, SlotNameDefine.LeftWeapon, sacle);
|
|
SlotUtils.SetSlotLocalScale(body.RealTransform, SlotNameDefine.RightWeapon, sacle);
|
|
}
|
|
}
|
|
//else
|
|
{
|
|
if (!Skin.IsPlaying())
|
|
{
|
|
Skin.PlayAnim(AnimClipNameDefine.FightIdle, AnimationPartType.AllBody, WrapMode.Loop);
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|