2024-12-14 21:15:57 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using DG.Tweening;
|
|
|
|
|
|
|
|
|
|
public class SnowHpControl : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public Vector3 minScale = new Vector3(0f, 0.1f, 1f); // <20><>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
|
|
|
|
|
public Vector3 maxScale = new Vector3(1f, 0.1f, 1f); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-12-16 17:46:38 +08:00
|
|
|
|
public float duration = 1f; // <20>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵij<C5B5><C4B3><EFBFBD>ʱ<EFBFBD><CAB1>
|
2024-12-14 21:15:57 +08:00
|
|
|
|
public float moveSpeed = 0.005f; // <20><><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
|
|
|
|
public float fadeDuration = 0f; // <20><>ʧʱ<CAA7>䣨<EFBFBD><E4A3A8><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ʵ<EFBFBD>ּ<EFBFBD>ʱ<EFBFBD><CAB1>ʧ<EFBFBD><CAA7>
|
2024-12-16 17:46:38 +08:00
|
|
|
|
public float moveDistance = 1f; // <20><><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-12-14 21:15:57 +08:00
|
|
|
|
public Canvas targetCanvas; // Ŀ<>껭<EFBFBD><EABBAD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7>UIԪ<49><D4AA><EFBFBD>ڸû<DAB8><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>
|
|
|
|
|
|
|
|
|
|
private Renderer rend; // <20><><EFBFBD>ڻ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Renderer<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><CDB8><EFBFBD><EFBFBD>
|
|
|
|
|
private Vector3 initialPosition;
|
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
targetCanvas = transform.parent.GetComponent<Canvas>();
|
|
|
|
|
|
|
|
|
|
// <20><>ȡRenderer
|
|
|
|
|
rend = GetComponent<Renderer>();
|
|
|
|
|
|
|
|
|
|
// ȷ<><C8B7>Ѫ<EFBFBD><D1AA><EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>Ŀ<EFBFBD>껭<EFBFBD><EABBAD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷλ<C8B7><CEBB><EFBFBD><EFBFBD>
|
|
|
|
|
if (targetCanvas.renderMode == RenderMode.WorldSpace)
|
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>Ŀ<EFBFBD>껭<EFBFBD><EABBAD><EFBFBD><EFBFBD>WorldSpaceģʽ<C4A3><CABD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
initialPosition = transform.position;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ScreenSpaceģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫת<D2AA><D7AA><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD>굽<EFBFBD><EAB5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
initialPosition = targetCanvas.worldCamera.ScreenToWorldPoint(transform.position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><>ʼ<EFBFBD><CABC>Ѫ<EFBFBD><D1AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
transform.localScale = minScale;
|
|
|
|
|
|
2024-12-16 17:46:38 +08:00
|
|
|
|
// ʹ<><CAB9>DOTween<65><6E><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŷ<EFBFBD><C5B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>minScale<6C><EFBFBD><F0BDA5B1><EFBFBD>
|
|
|
|
|
Sequence sequence = DOTween.Sequence();
|
2024-12-14 21:15:57 +08:00
|
|
|
|
|
2024-12-16 17:46:38 +08:00
|
|
|
|
// 1. <20><><EFBFBD>ƶ<EFBFBD><C6B6>Ĺ<EFBFBD><C4B9><EFBFBD><EFBFBD>д<EFBFBD>minScale<6C><EFBFBD><F0BDA5B1><EFBFBD><EFBFBD><EFBFBD>maxScale
|
|
|
|
|
sequence.Append(transform.DOMoveY(initialPosition.y + moveDistance, 0.3f)
|
|
|
|
|
.SetEase(Ease.InOutQuad) // <20>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
);
|
|
|
|
|
sequence.Join(transform.DOScale(maxScale, 0.3f)
|
|
|
|
|
.SetEase(Ease.InOutQuad) // ͬ<><CDAC><EFBFBD><EFBFBD><EFBFBD>Ŷ<EFBFBD><C5B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>minScale<6C><65>maxScale
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// 2. <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŵ<C5B4>maxScale<6C><65><EFBFBD><EFBFBD>
|
|
|
|
|
sequence.Append(transform.DOScale(maxScale * 1.5f, 0.3f)
|
|
|
|
|
.SetEase(Ease.OutBack) // <20>յ<EFBFBD><D5B5>Ŵ<EFBFBD><C5B4><EFBFBD>ʹ<EFBFBD><CAB9>OutBackʹ<6B>÷Ŵ<C3B7><C5B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
//// 3. <20><><EFBFBD>ص<EFBFBD>maxScale
|
|
|
|
|
//sequence.Append(transform.DOScale(maxScale, 0.3f)
|
|
|
|
|
// .SetEase(Ease.InOutQuad) // <20><><EFBFBD><EFBFBD>ʱʹ<CAB1><CAB9>InBack<63><6B>ʹ<EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD>Ȼ
|
|
|
|
|
//);
|
|
|
|
|
|
|
|
|
|
// 4. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD><EFBFBD>
|
|
|
|
|
sequence.OnComplete(() => StartFading());
|
2024-12-14 21:15:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void StartFading()
|
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>fadeDurationΪ<6E>㣬ֱ<E3A3AC><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if (fadeDuration == 0f)
|
|
|
|
|
{
|
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>fadeDuration<6F><6E><EFBFBD><EFBFBD><EFBFBD>㣬<EFBFBD><E3A3AC>ʹ<EFBFBD><CAB9>DOTween
|
|
|
|
|
// ͨ<><CDA8>DOTween<65><6E><EFBFBD><EFBFBD><EFBFBD><CDB8><EFBFBD>Ƚ<EFBFBD><C8BD>䵽<EFBFBD>㣬<EFBFBD><E3A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD>
|
|
|
|
|
DOTween.ToAlpha(() => rend.material.color, x => rend.material.color = x, 0f, fadeDuration).OnComplete(() =>
|
|
|
|
|
{
|
|
|
|
|
Destroy(gameObject); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD>
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|