248 lines
5.5 KiB
C#
248 lines
5.5 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2020-12-25
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "EntityGiftBox" company="Kunpo"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
namespace G
|
|
{
|
|
/// <summary>
|
|
/// 无尽宝箱
|
|
/// </summary>
|
|
public class EntityGiftBox : Entity
|
|
{
|
|
public Transform ef_open1;
|
|
public Transform ef_open2;
|
|
public Transform ef_smoke_bossBox;
|
|
public Transform ef_bossBox_light;
|
|
|
|
public AudioClip snd_drop;
|
|
public AudioClip snd_open;
|
|
|
|
private bool _dropImpact;
|
|
private bool _itemRising;
|
|
private bool _isBossLevel;
|
|
|
|
private Collider _collider;
|
|
private AudioSource _audioSource;
|
|
|
|
private Transform _spawnRoot;
|
|
|
|
private Animator _dropBoxAnimator;
|
|
private Animator _bossDropBoxAnimator;
|
|
|
|
#region Method
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public bool canOpen
|
|
{
|
|
get { return _collider.enabled; }
|
|
}
|
|
|
|
private System.Collections.IEnumerator OpenSmoke()
|
|
{
|
|
yield return new WaitForSeconds(0.4f);//间隔多少时间播放烟尘特效
|
|
if (_isBossLevel)
|
|
{
|
|
ef_smoke_bossBox.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private System.Collections.IEnumerator Open()
|
|
{
|
|
PlayOpenAnim();//开启宝箱掉落动画
|
|
|
|
if (_isBossLevel)
|
|
{
|
|
ef_open2.gameObject.SetActive(true);
|
|
yield return new WaitForSeconds(1.65f);//间隔多长时间去播放打开箱子的闪光
|
|
}
|
|
else
|
|
{
|
|
yield return new WaitForSeconds(0.05f);
|
|
ef_open1.gameObject.SetActive(true);
|
|
}
|
|
|
|
_audioSource.PlayOneShot(snd_open);
|
|
_itemRising = true;
|
|
|
|
var dropBox = BoxProxy.Instance.GetBoxInfo(GameLevel.Instance.stageBoxId);
|
|
if (dropBox != null)
|
|
{
|
|
int spIndex = 0;
|
|
int extraWeight = EntityMainPlayer.Instance.dropBoost;
|
|
var items = dropBox.GetRndItems(extraWeight);
|
|
for (int i = 0; i < items.Count; i++)
|
|
{
|
|
if (items[i].id > 0)
|
|
{
|
|
Vector3 a = _spawnRoot.GetChild(spIndex++).position;
|
|
if (spIndex >= _spawnRoot.childCount)
|
|
spIndex = 0;
|
|
//Vector3 a = Random.onUnitSphere * Random.Range(0.18f, 0.26f);
|
|
EnemyHelper.Instance.CreateBox(items[i].id, items[i].count, a);
|
|
}
|
|
}
|
|
|
|
var extra = dropBox.GetExtraItem();
|
|
if (extra.id > 0)
|
|
{
|
|
Vector3 a = _spawnRoot.GetChild(spIndex++).position;
|
|
if (spIndex >= _spawnRoot.childCount)
|
|
spIndex = 0;
|
|
EnemyHelper.Instance.CreateBox(extra.id, extra.count, a);
|
|
}
|
|
}
|
|
|
|
yield return new WaitForSeconds(1f); //boss宝箱播放开启闪光后到打开第二个特效间隔时间
|
|
if (_isBossLevel)
|
|
{
|
|
ef_bossBox_light.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
static int _Drop_I_Hash = Animator.StringToHash("drop_i");
|
|
|
|
bool IsDrop_I()
|
|
{
|
|
if (_isBossLevel)
|
|
{
|
|
return _bossDropBoxAnimator.GetCurrentAnimatorStateInfo(0).shortNameHash == _Drop_I_Hash;
|
|
}
|
|
else
|
|
{
|
|
return _dropBoxAnimator.GetCurrentAnimatorStateInfo(0).shortNameHash == _Drop_I_Hash;
|
|
}
|
|
}
|
|
|
|
void PlayOpenAnim()
|
|
{
|
|
if (_isBossLevel)
|
|
{
|
|
_bossDropBoxAnimator.Play("open_box");
|
|
}
|
|
else
|
|
{
|
|
_dropBoxAnimator.Play("open_box");
|
|
}
|
|
}
|
|
|
|
void PlayOpenFx()
|
|
{
|
|
if (_isBossLevel)
|
|
{
|
|
ef_open1.gameObject.SetActive(false);
|
|
ef_open2.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
ef_open1.gameObject.SetActive(true);
|
|
ef_open2.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Unity
|
|
|
|
public static EntityGiftBox Instance;
|
|
|
|
private void Awake()
|
|
{
|
|
_collider = GetComponent<Collider>();
|
|
_collider.enabled = false;
|
|
_audioSource = GetComponent<AudioSource>();
|
|
|
|
_dropBoxAnimator = transform.GetChild(0).GetComponent<Animator>();
|
|
_bossDropBoxAnimator = transform.GetChild(1).GetComponent<Animator>();
|
|
|
|
_spawnRoot = transform.Find("bbbpoint");
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
SoundProxy.Instance.SetAudioMixer(_audioSource, SoundProxy.FX_LAYER_INDEX);
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
Instance = this;
|
|
|
|
_dropImpact = false;
|
|
_itemRising = false;
|
|
|
|
_isBossLevel = GameLevel.Instance.isBossStage;
|
|
|
|
if (_isBossLevel)
|
|
{
|
|
_dropBoxAnimator.gameObject.SetActive(false);
|
|
_bossDropBoxAnimator.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
_dropBoxAnimator.gameObject.SetActive(true);
|
|
_bossDropBoxAnimator.gameObject.SetActive(false);
|
|
}
|
|
ef_open1.gameObject.SetActive(false);
|
|
ef_open2.gameObject.SetActive(false);
|
|
ef_bossBox_light.gameObject.SetActive(false);
|
|
ef_smoke_bossBox.gameObject.SetActive(false);
|
|
StartCoroutine(OpenSmoke());
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
Instance = null;
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
_collider.enabled = false;
|
|
GameLevel.Instance.OpenPortal();
|
|
StartCoroutine(Open());
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!_dropImpact)
|
|
{
|
|
if (IsDrop_I())
|
|
{
|
|
_dropImpact = true;
|
|
_collider.enabled = true;
|
|
_audioSource.PlayOneShot(snd_drop);
|
|
}
|
|
}
|
|
else if (_itemRising)
|
|
{
|
|
//Vector3 position = ef_risingitem.position;
|
|
//if (position.y < 1f)
|
|
//{
|
|
// ef_risingitem.position += Vector3.up * Time.deltaTime;
|
|
// return;
|
|
//}
|
|
_itemRising = false;
|
|
//ef_risingitem.GetComponent<ParticleSystem>().Stop();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
}
|
|
} |