少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
namespace vnxbqy.UI
{
    public class TreasureSkyEffect : MonoBehaviour
    {
        [SerializeField] BoxArea m_RandomArea;
        [SerializeField, Header("间隔时间")] float repeatTime = 1.0f;
        [SerializeField] int effect = 0;
        float timer = 0;
 
        private void OnEnable()
        {
            timer = 0f;
        }
 
        private void LateUpdate()
        {
            timer += Time.deltaTime;
            if (timer >= repeatTime)
            {
                timer = 0;
                Display();
            }
        }
 
        void Display()
        {
            if (effect == 0)
            {
                return;
            }
            var sfx = SFXPlayUtility.Instance.Play(effect, m_RandomArea.RandomPosition(transform.position), Vector3.forward);
            if (sfx != null)
            {
                LayerUtility.SetLayer(sfx.gameObject, LayerUtility.UILayer, true);
            }
        }
 
#if UNITY_EDITOR
        private void OnDrawGizmos()
        {
            Gizmos.color = Color.yellow;
            Gizmos.DrawWireCube(m_RandomArea.position + transform.position, m_RandomArea.size);
        }
#endif
    }
 
    [Serializable]
    public struct BoxArea
    {
        public Vector3 position;
        public Vector3 size;
 
        public Vector3 RandomPosition(Vector3 _pos)
        {
            var realpos = position + _pos;
            var random_x = realpos.x + UnityEngine.Random.Range(-size.x, size.x) / 2;
            var random_y = realpos.y + UnityEngine.Random.Range(-size.y, size.y) / 2;
            var random_z = realpos.z + UnityEngine.Random.Range(-size.z, size.z) / 2;
            return new Vector3(random_x, random_y, random_z);
        }
    }
}