Files
Main/Assets/GameAssets/Resources/GameUI/Common/UINature/NatureVfxEffect.cs

133 lines
3.3 KiB
C#
Raw Normal View History

2025-01-25 04:38:09 +08:00
using Thousandto.Core.Asset;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 通用造化升级特效脚本
/// </summary>
public class NatureVfxEffect: MonoBehaviour {
private bool _isStart = false;
private float _duraTime = 0.8f;
private float _time = 0f;
private Transform _trans = null;
private Transform _node1 = null;
private Transform _node2 = null;
private TweenScale _scale = null;
private TweenScale _childScale = null;
private TweenAlpha _childAlpha = null;
private FGameObjectVFX _vfx1 = null;
private FGameObjectVFX _vfx2 = null;
public Transform TransFormInst
{
get
{
if (_trans == null)
{
_trans = transform;
}
return _trans;
}
}
public Transform Node2
{
get
{
return _node2;
}
set
{
_node2 = value;
}
}
public void Init()
{
if (TransFormInst)
{
_node1 = TransFormInst.Find("Vfx");
_scale = TransFormInst.RequireComponent<TweenScale>();
_childScale = TransFormInst.Find("Child").RequireComponent<TweenScale>();
_childAlpha = _childScale.transform.RequireComponent<TweenAlpha>();
_scale.gameObject.SetActive(false);
_childScale.gameObject.SetActive(false);
_childAlpha.gameObject.SetActive(false);
}
}
public void Play()
{
_scale.gameObject.SetActive(true);
_childScale.gameObject.SetActive(true);
_childAlpha.gameObject.SetActive(true);
_scale.ResetToBeginning();
_scale.PlayForward();
_childScale.ResetToBeginning();
_childScale.PlayForward();
_childAlpha.ResetToBeginning();
_childAlpha.PlayForward();
//播放特效
if (_vfx1 != null)
{
_vfx1.Destroy();
_vfx1 = null;
}
//_vfx1 = new FGameObjectVFX(ModelTypeCode.UIVFX, 38);
//PlayVfx(_vfx1, _node1);
if (_vfx2 != null)
{
_vfx2.Destroy();
_vfx2 = null;
}
_vfx2 = new FGameObjectVFX(ModelTypeCode.UIVFX, 37);
PlayVfx(_vfx2, Node2);
_isStart = true;
}
private void PlayVfx(FGameObjectVFX vfx, Transform parent)
{
if (vfx == null)
return;
vfx.SetParent(parent.transform, true);
vfx.SetLayer(LayerUtils.UITop, true);
vfx.SetLocalScale(new Vector3(150, 150, 150));
vfx.OnLoadFinishedCallBack = x =>
{
};
vfx.Play(1f);
}
public void Tick(float dt)
{
if (_isStart)
{
if (_time < _duraTime)
{
_time += dt;
}
else
{
_time = 0;
_isStart = false;
_scale.gameObject.SetActive(false);
_childScale.gameObject.SetActive(false);
_childAlpha.gameObject.SetActive(false);
}
}
}
public void Destroy()
{
if (_vfx1 != null)
_vfx1.Destroy();
if (_vfx2 != null)
_vfx2.Destroy();
}
public void OnDestroy()
{
Destroy();
}
}