Files
Main/Assets/GameAssets/Resources/GameUI/Common/StarMove/StarEffectAttr.cs
2025-01-25 04:38:09 +08:00

319 lines
8.0 KiB
C#

using UnityEngine;
using System.Collections;
using Thousandto.Core.Asset;
using Thousandto.Core.Base;
//星星特效属性
namespace Thousandto.Plugins.Common
{
public class StarEffectAttr
{
#region//私有变量
private int _index = 0;
private FGameObjectVFX _vfxId = null;
private float _startTime = 0;
private float _duration = 0f;
//第二段特效播放时间
private float _secondPlayTime = 0f;
private bool _isStart = false; //是否开始执行动作
private bool _isSetStartPos = false; //是否设置了位移起始位置
private GameObject _go = null;
private GameObject _endGo = null;
private StarMoveManager _manager = null;
//位移世界坐标位置
private Vector3 _startPos = Vector3.zero; //位移起始位置
private Vector3 _endPos = Vector3.zero; //位移结束位置
//当前播放状态
private PlayState _state = PlayState.default_State;
//回调函数
private MyAction _playStarVfxCallBack = null;
#endregion
#region//公共变量
public float Duration
{
get
{
return _duration;
}
set
{
_duration = value;
}
}
public GameObject Go
{
get
{
return _go;
}
set
{
_go = value;
}
}
public Vector3 StartPos
{
get
{
return _startPos;
}
set
{
_startPos = value;
}
}
public Vector3 EndPos
{
get
{
return _endPos;
}
set
{
_endPos = value;
}
}
public GameObject EndGo
{
get
{
return _endGo;
}
set
{
_endGo = value;
}
}
public MyAction PlayStarVfxCallBack
{
get
{
return _playStarVfxCallBack;
}
set
{
_playStarVfxCallBack = value;
}
}
public int Index
{
get
{
return _index;
}
set
{
_index = value;
}
}
#endregion
public StarEffectAttr(GameObject go,GameObject endGo, Vector3 startPos,Vector3 endPos, MyAction func = null)
{
_go = go;
_endGo = endGo;
StartPos = startPos;
EndPos = endPos;
if(PlayStarVfxCallBack == null)
PlayStarVfxCallBack = func;
}
//设置管理
public void SetManager(StarMoveManager manager)
{
_manager = manager;
}
//播放
public void PlayeVfxAction()
{
TweenPosition script = _go.RequireComponent<TweenPosition>();
script.worldSpace = true;
if (!_isSetStartPos)
{
script.from = _startPos;
_isSetStartPos = true;
}
if (_vfxId != null)
{
_vfxId.Destroy();
_vfxId = null;
}
_vfxId = new FGameObjectVFX(ModelTypeCode.UIVFX, 13);
_vfxId.SetParent(script.transform, true);
_vfxId.SetLayer(LayerUtils.UITop, true);
_vfxId.SetLocalScale(new Vector3(150, 150, 150));
_vfxId.OnLoadFinishedCallBack = x =>
{
script.ResetToBeginning();
script.to = _endPos;
script.duration = 0.5f;
_duration = script.duration;
script.PlayForward();
_state = PlayState.frist_State;
_isStart = true;
};
_vfxId.Play(1f);
//_vfxId = VFXPlayer.AsyncPlayOnTransform("VFX/UI/e_ui_013", script.transform, LayerUtils.UIVfx, 1f, false, true, (vfx) =>
//{
// script.ResetToBeginning();
// script.to = _endPos;
// script.duration = 0.5f;
// _duration = script.duration;
// script.PlayForward();
// _state = PlayState.frist_State;
// _isStart = true;
//});
}
//播放第二段特效
private void PlaySecondVfx()
{
if (_vfxId != null)
{
_vfxId.Destroy();
_vfxId = null;
}
_vfxId = new FGameObjectVFX(ModelTypeCode.UIVFX, 3);
_vfxId.SetParent(_go.transform, true);
_vfxId.SetLayer(LayerUtils.UITop, true);
_vfxId.SetLocalScale(new Vector3(150, 150, 150));
_vfxId.OnLoadFinishedCallBack = x =>
{
_state = PlayState.second_State;
};
_vfxId.Play(1.5f);
//_vfxId = VFXPlayer.AsyncPlayOnTransform("VFX/UI/e_ui_003", _go.transform, LayerUtils.UIVfx, 1.5f, false, true, (vfx) =>
//{
// _state = PlayState.second_State;
//});
}
//移除特效
public void ReMoveVfx()
{
if (_vfxId != null)
{
_vfxId.Destroy();
_vfxId = null;
}
if (_go)
{
if (_manager != null)
{
_manager.Pop(this);
_startTime = 0f;
_isStart = false;
}
}
}
//销毁
public void Destory()
{
if (_vfxId != null)
{
_vfxId.Destroy();
_vfxId = null;
}
if (_go != null)
{
GameObject.Destroy(_go);
_go = null;
}
}
//第二段特效播放时间是否结束
private bool IsOverPlaySecondVfx()
{
if (_secondPlayTime < 0.8f)
{
if (_secondPlayTime <= 0.5f)
{
if (_endGo.activeSelf)
{
_endGo.gameObject.SetActive(false);
}
}
_secondPlayTime += Time.deltaTime;
}
else
{
_secondPlayTime = 0f;
_state = PlayState.default_State;
return true;
}
return false;
}
public void Update()
{
if (_isStart)
{
if (_startTime < _duration)
{
_startTime += Time.deltaTime;
}
else
{
_startTime = _duration;
if (_state == PlayState.frist_State)
{
PlaySecondVfx();
_state = PlayState.second_State;
}
else if (_state == PlayState.second_State)
{
if (IsOverPlaySecondVfx())
{
ReMoveVfx();
if (PlayStarVfxCallBack != null && Index == 1)
{
PlayStarVfxCallBack();
}
}
}
}
}
}
#region//enum
private enum PlayState
{
default_State = -1,
frist_State = 0,
second_State ,
}
#endregion
}
}