using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using DynamicShadowProjector;
|
using vnxbqy.UI;
|
|
|
public class ActorShadowCaster : MonoBehaviour
|
{
|
[SerializeField] Projector m_Projector;
|
[SerializeField] DrawTargetObject m_DrawTargetObject;
|
[SerializeField] Transform m_Target;
|
|
public static ActorShadowCaster Cast(Transform _followTarget, Transform _castTarget)
|
{
|
var shadow = ActorShadowCasterPool.Require();
|
if (shadow != null)
|
{
|
shadow.Follow(_followTarget);
|
shadow.Cast(_castTarget);
|
shadow.SetActive(true);
|
DontDestroyOnLoad(shadow.gameObject);
|
}
|
|
return shadow;
|
}
|
|
public void Follow(Transform _target)
|
{
|
m_Target = _target;
|
this.transform.rotation = Quaternion.identity;
|
|
BossShowModel.Instance.bossShowPreparedEvent -= OnBeginBossShow;
|
BossShowModel.Instance.bossShowCompletedEvent -= OnBossShowCompleted;
|
BossShowModel.Instance.bossShowPreparedEvent += OnBeginBossShow;
|
BossShowModel.Instance.bossShowCompletedEvent += OnBossShowCompleted;
|
}
|
|
public void Cast(Transform _target)
|
{
|
m_DrawTargetObject.target = _target;
|
m_DrawTargetObject.followTarget = false;
|
m_DrawTargetObject.SetCommandBufferDirty();
|
|
if (PlayerDatas.Instance.baseData.MapID > 100)
|
{
|
var dataMapId = MapUtility.GetDataMapId();
|
var lineId = MapUtility.GetLineId();
|
var mapResourcesConfig = MapResourcesConfig.GetConfig(dataMapId, lineId);
|
var config = SceneShadowConfig.Get(mapResourcesConfig.MapResources);
|
if (config != null)
|
{
|
m_Projector.transform.localEulerAngles = config.Rotation;
|
m_Projector.material.SetFloat("_Alpha", config.Intensity);
|
}
|
}
|
}
|
|
public void Stop()
|
{
|
BossShowModel.Instance.bossShowPreparedEvent -= OnBeginBossShow;
|
BossShowModel.Instance.bossShowCompletedEvent -= OnBossShowCompleted;
|
ActorShadowCasterPool.Reycle(this);
|
}
|
|
private void LateUpdate()
|
{
|
if (m_Target == null)
|
{
|
return;
|
}
|
|
this.transform.position = m_Target.position;
|
}
|
|
private void OnBeginBossShow()
|
{
|
if (m_Projector != null)
|
{
|
m_Projector.enabled = false;
|
}
|
}
|
|
private void OnBossShowCompleted()
|
{
|
if (m_Projector != null)
|
{
|
m_Projector.enabled = true;
|
}
|
}
|
|
public static class ActorShadowCasterPool
|
{
|
public static ActorShadowCaster Require()
|
{
|
var prefab = BuiltInLoader.LoadPrefab("ActorShadowCaster");
|
var instance = GameObject.Instantiate(prefab);
|
return instance.GetComponent<ActorShadowCaster>();
|
}
|
|
public static void Reycle(ActorShadowCaster _shadowCaster)
|
{
|
GameObject.Destroy(_shadowCaster.gameObject, 0.1f);
|
}
|
|
}
|
|
|
}
|