149 lines
5.4 KiB
C#
149 lines
5.4 KiB
C#
using Cal.DataTable;
|
|
using ET;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace ET
|
|
{
|
|
public class UnitViewAwakeSystem: AwakeSystem<UnitView, GameObject>
|
|
{
|
|
public override void Awake(UnitView self, GameObject gameObject)
|
|
{
|
|
self.Awake(gameObject);
|
|
}
|
|
}
|
|
|
|
public class UnitViewDestroySystem: DestroySystem<UnitView>
|
|
{
|
|
public override void Destroy(UnitView self)
|
|
{
|
|
ResourceViewHelper.DestoryPrefabAsync(self.gameObject);
|
|
self.gameObject = null;
|
|
self.transform = null;
|
|
self.spriteRenderer = null;
|
|
self.monoAnimancer = null;
|
|
self.HeadPoint = null;
|
|
self.FootPoint = null;
|
|
self.footEffect = null;
|
|
}
|
|
}
|
|
|
|
public static class UnitViewSystem
|
|
{
|
|
public static void Awake(this UnitView self, GameObject gameObject)
|
|
{
|
|
Unit unit = self.unit = self.GetParent<Unit>();
|
|
self.gameObject = gameObject;
|
|
self.transform = gameObject.transform;
|
|
self.spriteRenderer = gameObject.GetComponent<SpriteRenderer>();
|
|
self.monoAnimancer = gameObject.GetComponent<MonoAnimancer>();
|
|
if (self.monoAnimancer && self.monoAnimancer.Animator == null)
|
|
self.monoAnimancer.Animator = gameObject.GetComponentInChildren<Animator>();
|
|
gameObject.GetOrAddComponent<ComponentView>().Component = self;
|
|
|
|
var children = gameObject.GetComponentsInChildren<Transform>();
|
|
foreach (Transform item in children)
|
|
{
|
|
switch (item.name)
|
|
{
|
|
case "HeadBarPoint":
|
|
self.HeadPoint = item;
|
|
break;
|
|
case "FootPoint":
|
|
self.FootPoint = item;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (self.FootPoint)
|
|
{
|
|
var position = self.transform.position;
|
|
var position1 = self.FootPoint.position;
|
|
self.yDelta = position.y - position1.y;
|
|
self.xDelta = position.x - position1.x;
|
|
}
|
|
|
|
SetColor().Coroutine();
|
|
|
|
async ETVoid SetColor()
|
|
{
|
|
if (self.FootPoint)
|
|
{
|
|
Transform footEffctTran = await ResourceViewHelper.LoadPrefabAsync(Sys_PrefabId.Select);
|
|
footEffctTran.name = "Select";
|
|
footEffctTran.SetParent(self.transform);
|
|
footEffctTran.position = self.FootPoint.position;
|
|
self.footEffect = footEffctTran.GetComponent<SpriteRenderer>();
|
|
self.footEffect.sortingLayerName = "FootEffct";
|
|
}
|
|
|
|
SetFootEffect(self, self.unit.UnitType);
|
|
}
|
|
}
|
|
|
|
public static void SetFootEffcetActive(this UnitView self, bool isActive, Color color)
|
|
{
|
|
if (!self.footEffect) return;
|
|
self.footEffect.gameObject.SetActive(isActive);
|
|
self.footEffect.color = color;
|
|
}
|
|
|
|
public static async ETTask ChangeSkin(this UnitView self, int prefabId)
|
|
{
|
|
HudComponent.Instance.Remove(self.unit);
|
|
DestroyFootEffect(self);
|
|
ResourceViewHelper.DestoryPrefabAsync(self.gameObject);
|
|
self.gameObject = (await ResourceViewHelper.LoadPrefabAsync(prefabId)).gameObject;
|
|
Awake(self, self.gameObject);
|
|
HudComponent.Instance.Init(self.unit);
|
|
NumericComponent num = self.unit.GetComponent<NumericComponent>();
|
|
ClientUnitCharacter clientUnitCharacter = ClientUnitCharacterComponent.Instance.Get(self.unit.Id);
|
|
Game.EventSystem.Publish_Sync(new ET.EventType.SetHudCharacter
|
|
{
|
|
hp = num.GetAsInt(NumericType.Hp),
|
|
maxHp = num.GetAsInt(NumericType.MaxHp),
|
|
jobType = clientUnitCharacter.JobType,
|
|
level = num.GetAsInt(NumericType.Level),
|
|
name = clientUnitCharacter.NickName,
|
|
unit = self.unit,
|
|
progressTitleType = FairyGUI.ProgressTitleType.ValueAndMax
|
|
});
|
|
}
|
|
|
|
private static void DestroyFootEffect(UnitView self)
|
|
{
|
|
if (self.footEffect != null)
|
|
ResourceViewHelper.DestoryPrefabAsync(self.footEffect.gameObject);
|
|
}
|
|
|
|
public static void SetFootEffect(this UnitView self, UnitType unitType)
|
|
{
|
|
Color footEffectColor = Color.white;
|
|
switch (unitType)
|
|
{
|
|
case UnitType.None:
|
|
break;
|
|
case UnitType.Player:
|
|
footEffectColor = Color.white;
|
|
break;
|
|
case UnitType.Monster:
|
|
case UnitType.Enermy:
|
|
case UnitType.MapMonster:
|
|
footEffectColor = Color.red;
|
|
break;
|
|
case UnitType.OtherPlayer:
|
|
footEffectColor = Color.yellow;
|
|
break;
|
|
case UnitType.TeamMember:
|
|
footEffectColor = Color.yellow;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
SetFootEffcetActive(self, true, footEffectColor);
|
|
}
|
|
}
|
|
} |