78 lines
2.4 KiB
C#
78 lines
2.4 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
public class WoodSculpture : MonoBehaviour
|
||
{
|
||
public WoodSculpture_Buildings woodSculpture_Buildings;
|
||
public Type type = Type.Simple;
|
||
public enum Type { Simple, Super, Special};
|
||
public int Value;
|
||
public int avaIndex;
|
||
|
||
private ParticleSystem pc ;
|
||
|
||
private void Start()
|
||
{
|
||
pc = transform.GetChild(0).GetComponent<ParticleSystem>();
|
||
}
|
||
private void OnMouseDown()
|
||
{
|
||
if (type == Type.Special)
|
||
{
|
||
FindObjectOfType<TopBarUI>().EmitFaith(Value*woodSculpture_Buildings.WoodSculpture_to_FaithBuff, transform.position);
|
||
// GameProcedureManager.Instance.FaithCount += Value*woodSculpture_Buildings.WoodSculpture_to_FaithBuff;
|
||
}
|
||
else
|
||
{
|
||
woodSculpture_Buildings.RemoveScuplture(this);
|
||
StartCoroutine(ReleaseFaith(Value * woodSculpture_Buildings.WoodSculpture_to_FaithBuff));
|
||
StartCoroutine(FadeOut());
|
||
}
|
||
}
|
||
private IEnumerator ReleaseFaith(int count)
|
||
{
|
||
var emission = pc.emission;
|
||
emission.rateOverTime = count; // 在1秒内均匀释放n个粒子
|
||
|
||
// 启动粒子系统
|
||
// pc.Play();
|
||
// yield return new WaitForSeconds(0.5f);
|
||
// pc.Stop();
|
||
// 第2阶段:0.5秒内均匀增加x的值
|
||
float xIncreaseInterval = 0.5f / 10;
|
||
int incrementAmount = count / 10;
|
||
|
||
for (int i = 0; i < 10; i++)
|
||
{
|
||
FindObjectOfType<TopBarUI>().EmitFaith(incrementAmount, transform.position);
|
||
// GameProcedureManager.Instance.FaithCount += incrementAmount;
|
||
yield return new WaitForSeconds(xIncreaseInterval);
|
||
}
|
||
Destroy(gameObject);
|
||
}
|
||
|
||
private IEnumerator FadeOut()
|
||
{
|
||
SpriteRenderer sr = GetComponent<SpriteRenderer>();
|
||
float elapsedTime = 0f;
|
||
Color originalColor = sr.color;
|
||
|
||
// 逐渐淡化
|
||
while (elapsedTime < 0.5f)
|
||
{
|
||
elapsedTime += Time.deltaTime;
|
||
float alpha = Mathf.Lerp(1f, 0f, elapsedTime / 0.5f);
|
||
sr.color = new Color(originalColor.r, originalColor.g, originalColor.b, alpha);
|
||
yield return null;
|
||
}
|
||
|
||
// 等待0.5秒
|
||
yield return new WaitForSeconds(1f);
|
||
|
||
// 销毁对象
|
||
Destroy(gameObject);
|
||
}
|
||
}
|