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);
|
}
|
}
|
}
|