Files
ft/Client/Assets/Scripts/EventCubeMelt/Weapon/WeaponController.cs
2026-06-29 21:18:33 +08:00

69 lines
1.8 KiB
C#

//
// WeaponController
// 控制颜色和 透明度
using System;
using DG.Tweening;
using EventCubeMelt;
using UnityEngine;
namespace EventCubeMelt.Weapon
{
public class WeaponController : MonoBehaviour
{
private static readonly int LightNumID = Shader.PropertyToID("_LightNum");
private static readonly int OpacityID = Shader.PropertyToID("_Opacity");
// 进度
// private float progress;
// 透明度
// private float Opacity; //[0,1]
private Material _material;
private readonly float _duration = 0.5f * 0.01f;
private void Awake()
{
var renderer = GetComponent<Renderer>();
if (renderer)
{
_material = renderer.material;
}
// SetProgress(0.8f);
// SetOpacity(0.5f);
}
public void SetProgress(float percent)
{
ELog($"SetProgress-> {percent}");
_material.SetFloat(LightNumID,percent);
}
//-更新进度
public void UpdateToProgress(float percent)
{
ELog($"UpdateToProgress-> {percent}");
var startValue= _material.GetFloat(LightNumID);
var df = _duration * 100 * (percent - startValue);
_material.DOFloat(percent, LightNumID, df);
}
public void SetOpacity(float percent)
{
_material.SetFloat(OpacityID,percent);
}
#region LOG
private static void ELog(string message)
{
#if UNITY_EDITOR
if (!EventCubeMeltLogPolicy.EnableELog) return;
Debug.Log($"<color=orange> WeaponController => {message} </color>");
#endif
}
#endregion
}
}