248 lines
5.9 KiB
C#
Raw Normal View History

2025-05-18 01:04:31 +08:00
// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2020-12-24
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "Cha_Effect" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace G
{
/// <summary>
/// 特效
/// </summary>
public class Cha_Effect : MonoBehaviour
{
#region Field
public Transform ef_arrow_multy;
public Transform ef_arrow_single;
public Transform pt_heal;
public Transform pt_skill_up;
public Transform pt_rising;
public Transform ef_riseattack;
public Transform ef_swordExtreme;
public Transform ef_linehit;
public Transform ef_thump;
public Transform ef_splash;
/// <summary>
///
/// </summary>
public Transform ef_stepfog;
/// <summary>
/// 刺
/// </summary>
public Transform ef_thrustfog;
/// <summary>
/// 转
/// </summary>
public Transform ef_rotfog;
public Transform ef_blur;
public Transform ef_block;
public Transform ef_blockbreak;
public Transform ef_super;
public Transform ef_punch;
public Transform ef_firesplash;
public Transform guide_circle;
public Transform txtef;
private Transform[] c_stepfog = new Transform[4];
private Transform[] c_thrustfog = new Transform[4];
private Txt_effect script_txtef;
private int _nowstep;
private int _nowthrust;
private Ef_twirl script_getitem;
private EntityMainPlayer _scriptCha;
private GameObject _suitFx;
#endregion
#region Method
public void Init()
{
script_getitem = transform.Find("ef_getitem").GetComponent<Ef_twirl>();
script_txtef = txtef.GetComponent<Txt_effect>();
for (int i = 0; i < 4; i++)
{
c_stepfog[i] = Instantiate(ef_stepfog, Vector3.one * 4f, this.transform.root.rotation);
c_thrustfog[i] = Instantiate(ef_thrustfog, Vector3.one * 4f, ef_thrustfog.localRotation);
}
var suitFxAsset = PlayerProxy.Instance.GetCurrEquipmentSuit().suitFxAsset;
if (!string.IsNullOrEmpty(suitFxAsset))
AssetProxy.Instance.TryGetTemporaryAssetAsync<GameObject>($"effect/{suitFxAsset}.prefab").Completed += (handle) =>
{
if (handle.Status == UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationStatus.Succeeded)
{
_suitFx = Instantiate(handle.Result, this.transform);
}
};
}
public void ShowGetItemEffect()
{
script_getitem.TwirlOn(4, 4, 20, false);
}
public void PlayEffect(string ef_name)
{
var ef = transform.Find(ef_name);
if (ef)
{
ef.gameObject.SetActive(true);
}
}
public void PlayEffect(string ef_name, Vector3 position, Quaternion rotaion)
{
var ef = transform.Find(ef_name);
if (ef)
{
ef.SetPositionAndRotation(position, rotaion);
ef.gameObject.SetActive(true);
}
}
public void PlayEffect(string ef_name, float duration)
{
var ef = transform.Find(ef_name);
if (ef)
{
StartCoroutine(StopEffectCO(ef.gameObject, duration, 0f));
}
}
public void PlayEffect(string ef_name, float duration, float delay)
{
var ef = transform.Find(ef_name);
if (ef)
{
StartCoroutine(StopEffectCO(ef.gameObject, duration, delay));
}
}
private IEnumerator StopEffectCO(GameObject go, float duration, float delay)
{
if (delay > 0f)
yield return new WaitForSeconds(delay);
go.SetActive(true);
yield return new WaitForSeconds(duration);
go.SetActive(false);
}
public void FogOn(int kind)
{
switch (kind)
{
case 0:
c_stepfog[_nowstep].gameObject.SetActive(true);
c_stepfog[_nowstep].position = transform.position;
c_stepfog[_nowstep].rotation = transform.rotation;
_nowstep = (_nowstep + 1) % 3;
break;
case 1:
c_thrustfog[_nowthrust].gameObject.SetActive(true);
c_thrustfog[_nowthrust].position = transform.position + transform.forward * 0.2f + Vector3.up * 0.075f;
c_thrustfog[_nowthrust].forward = transform.forward;
//c_thrustfog[_nowthrust].Rotate(transform.forward, Random.Range(0, 360), Space.World);
_nowthrust = (_nowthrust + 1) % 3;
break;
case 2:
c_thrustfog[_nowthrust].gameObject.SetActive(true);
c_thrustfog[_nowthrust].position = transform.position + transform.forward * 0.2f + Vector3.up * 0.075f;
c_thrustfog[_nowthrust].up = transform.forward;
c_thrustfog[_nowthrust].Rotate(transform.forward, GlobalUtils.RndAngle, Space.World);
_nowthrust = (_nowthrust + 1) % 3;
break;
}
}
public void EvadeText()
{
//GlobalNotifier.PostNotification(GlobalDefine.EVENT_SHOW_TEXT_EFFECT, 1);
script_txtef.TxtEfOn(1);
}
public void BlockedText()
{
//GlobalNotifier.PostNotification(GlobalDefine.EVENT_SHOW_TEXT_EFFECT, 3);
script_txtef.TxtEfOn(3);
}
public void CriticalText()
{
script_txtef.TxtEfOn(2);
}
public void OneHitKillText()
{
script_txtef.TxtEfOn(0);
}
public void Flash()
{
StopCoroutine("FlashCO");
StartCoroutine("FlashCO");
}
IEnumerator FlashCO()
{
float ft = Time.time;
var mb = new MaterialPropertyBlock();
while (Time.time - ft < 0.4f)
{
mb.SetFloat("_Flash", 1.2f + (ft - Time.time) * 2f);
_scriptCha.entityView.mainRenderer.SetPropertyBlock(mb);
yield return null;
}
mb.SetFloat("_Flash", 0f);
_scriptCha.entityView.mainRenderer.SetPropertyBlock(mb);
yield return null;
}
#endregion
#region Unity
// Use this for initialization
private void Awake()
{
_scriptCha = GetComponent<EntityMainPlayer>();
Init();
}
//private float _last;
//private void Update()
//{
// if (Time.time - _last > 3f)
// {
// _last = Time.time;
// script_txtef.TxtEfOn(Random.Range(0, 4));
// }
//}
#endregion
}
}