少年修仙传客户端代码仓库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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);
        }
 
    }
 
 
}