using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering; using Sirenix.OdinInspector; using DG.Tweening; namespace BITKit.Entities { public class EntityCharacter : EntityComponent { [Header(Constant.Header.Components)] public List fpvRenderer = new(); public List tpvRenderer = new(); [Header(Constant.Header.Reference)] [SerializeReference, SubclassSelector] public References _isAlive; [SerializeReference, SubclassSelector] public References _getDamage; public override void OnStart() { entity.AddListener(nameof(OnSetAlive), OnSetAlive); entity.AddListener(nameof(OnSetHP), OnSetHP); } public override void OnSpawn() { if (isLocalPlayer) { OnSetAlive(true); } else { SetFPV(false); } } public override void OnDespawn() { SetFPV(false); } void OnSetAlive(bool alive) { SetFPV(isLocalPlayer ? alive : false); } void OnSetHP(int hp) { entity.Invoke(Constant.Animation.Play, _getDamage); } void SetFPV(bool isFpv) { var shadowMode = isFpv ? ShadowCastingMode.ShadowsOnly : ShadowCastingMode.On; foreach (var x in fpvRenderer) { x.enabled = isFpv; } foreach (var x in tpvRenderer) { x.shadowCastingMode = shadowMode; } } } }