You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
152 lines
5.4 KiB
152 lines
5.4 KiB
3 years ago
|
using Animancer;
|
||
|
using DG.Tweening;
|
||
|
using ET.FUIBattle;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.EventSystems;
|
||
|
|
||
|
namespace ET
|
||
|
{
|
||
|
public class BattleUnitViewComponentAwakeSystem : AwakeSystem<BattleUnitViewComponent>
|
||
|
{
|
||
|
public override void Awake(BattleUnitViewComponent self)
|
||
|
{
|
||
|
self.Awake();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public class BattleUnitViewComponentDestroySystem : DestroySystem<BattleUnitViewComponent>
|
||
|
{
|
||
|
public override void Destroy(BattleUnitViewComponent self)
|
||
|
{
|
||
|
self.Destroy();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static class BattleAnimName
|
||
|
{
|
||
|
public const string Idle = "Battle_Idle";
|
||
|
public const string Run = "Battle_Run";
|
||
|
public const string Attack = "Battle_Attack";
|
||
|
public const string BeHit = "BeHit";
|
||
|
}
|
||
|
|
||
|
[FriendClass(typeof(BattleUnitViewComponent))]
|
||
|
[FriendClass(typeof(BattleSceneViewComponent))]
|
||
|
[FriendClass(typeof(Fighter))]
|
||
|
public static class BattleUnitViewComponentSystem
|
||
|
{
|
||
|
public static void Awake(this BattleUnitViewComponent self)
|
||
|
{
|
||
|
self.Fighter = self.GetParent<Fighter>();
|
||
|
}
|
||
|
|
||
|
public static void Init(this BattleUnitViewComponent self, int index, bool left)
|
||
|
{
|
||
|
var battleSceneView = self.ZoneScene().CurrentScene().GetComponent<BattleSceneViewComponent>();
|
||
|
|
||
|
GameObject peopleGO = self.InstantiateSync("People_1001", battleSceneView.PeopleRoot);
|
||
|
self.DisplayGameObject = peopleGO;
|
||
|
|
||
|
ReferenceCollector rc = peopleGO.GetComponent<ReferenceCollector>();
|
||
|
self.ThrowPoint = rc.Get<GameObject>("bone_12").transform;
|
||
|
|
||
|
var pos = battleSceneView.GetUnitPosByIndex(index, left);
|
||
|
peopleGO.transform.position = pos;
|
||
|
self.Index = index;
|
||
|
self.Left = left;
|
||
|
|
||
|
if (!left)
|
||
|
{
|
||
|
var scale = peopleGO.transform.localScale;
|
||
|
peopleGO.transform.localScale = new Vector3(-scale.x, scale.y, scale.z);
|
||
|
}
|
||
|
|
||
|
var model = self.DisplayGameObject.transform.Find("Body/Model");
|
||
|
self.AnimancerComp = model.GetComponent<AnimancerComponent>();
|
||
|
self.AnimancerComp.TryPlay(BattleAnimName.Idle);
|
||
|
self.SEventReceiver = model.GetComponent<SimpleAnimEventHandler>();
|
||
|
|
||
|
// init click event
|
||
|
EventTrigger trigger = self.DisplayGameObject.transform.Find("SpriteClick").GetComponent<EventTrigger>();
|
||
|
EventTrigger.Entry entry = new EventTrigger.Entry();
|
||
|
entry.eventID = EventTriggerType.PointerClick;
|
||
|
entry.callback.AddListener((data) =>
|
||
|
{
|
||
|
self.OnSpriteClicked();
|
||
|
});
|
||
|
trigger.triggers.Add(entry);
|
||
|
}
|
||
|
|
||
|
public static void OnSpriteClicked(this BattleUnitViewComponent self)
|
||
|
{
|
||
|
Log.Info(self.Index.ToString());
|
||
|
|
||
|
var fuiBattleMain = (FUIBattleMainComponent)self.ZoneScene().GetComponent<FUIComponent>().GetUI(FUI_BattleMain.UIResName);
|
||
|
fuiBattleMain.ShowBuffDesc(FUIHelper.ConvertToUIPos(self.GetTopPos()));
|
||
|
}
|
||
|
|
||
|
public static Vector3 GetTopPos(this BattleUnitViewComponent self)
|
||
|
{
|
||
|
return self.DisplayGameObject.transform.position + Vector3.up * 2;
|
||
|
}
|
||
|
|
||
|
public static void BeHit(this BattleUnitViewComponent self)
|
||
|
{
|
||
|
var prefab = YooAssetComponent.Instance.LoadAssetSync<GameObject>("Hit_Blood");
|
||
|
GameObject fxGO = Util.GameObjectPoolHelper.SpawnGameObject(prefab);
|
||
|
|
||
|
fxGO.transform.position = self.DisplayGameObject.transform.position + Vector3.up;
|
||
|
ParticleController pc = fxGO.GetComponent<ParticleController>();
|
||
|
pc.Play();
|
||
|
pc.OnParticleEnd = () =>
|
||
|
{
|
||
|
Util.GameObjectPoolHelper.ReturnObjectToPool(fxGO);
|
||
|
};
|
||
|
|
||
|
var state = self.AnimancerComp.TryPlay(BattleAnimName.BeHit);
|
||
|
// state.Events.OnEnd = () =>
|
||
|
// {
|
||
|
// self.AnimancerComp.TryPlay(BattleAnimName.Idle);
|
||
|
// };
|
||
|
state.Events.endEvent = new AnimancerEvent(1.0f, () =>
|
||
|
{
|
||
|
self.AnimancerComp.TryPlay(BattleAnimName.Idle);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public static void CheckState(this BattleUnitViewComponent self)
|
||
|
{
|
||
|
if (!self.Fighter.IsAlive)
|
||
|
{
|
||
|
var sprs = self.DisplayGameObject.transform.GetComponentsInChildren<SpriteRenderer>();
|
||
|
foreach (SpriteRenderer spriteRenderer in sprs)
|
||
|
{
|
||
|
spriteRenderer.color = Color.black;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static void ShowStateMsg(this BattleUnitViewComponent self, string msg)
|
||
|
{
|
||
|
var fuiComp = self.ZoneScene().GetComponent<FUIComponent>();
|
||
|
var battleComp = fuiComp.GetUI(FUI_BattleMain.UIResName) as FUIBattleMainComponent;
|
||
|
battleComp.UpdateUnitStateInfo(self.Fighter, msg);
|
||
|
}
|
||
|
|
||
|
// 是否需要移动到目标前去攻击
|
||
|
public static bool NeedMoveToAttack(this BattleUnitViewComponent self)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public static void Destroy(this BattleUnitViewComponent self)
|
||
|
{
|
||
|
if (self.Parent == null)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
GameObject.Destroy(self.DisplayGameObject);
|
||
|
}
|
||
|
}
|
||
|
}
|