115 lines
3.4 KiB
C#
115 lines
3.4 KiB
C#
using Thousandto.Core.Asset;
|
|
using Thousandto.Core.Base;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Thousandto.Code.Logic.WarningField
|
|
{
|
|
public partial class NewWarningFiled : MonoBehaviour
|
|
{
|
|
#region//私有变量
|
|
private List<GameObject> _instGos = new List<GameObject>();
|
|
private List<Material> _aniMaterials = new List<Material>();
|
|
private List<Material> _innerMaterials = new List<Material>();
|
|
private float _aniTimer = 0f;
|
|
private float _aniMoveTime = 0f;
|
|
private float _innerPercent = 0f;
|
|
#endregion
|
|
|
|
#region//属性
|
|
|
|
private float AniMoveTime
|
|
{
|
|
get
|
|
{
|
|
return _aniMoveTime;
|
|
}
|
|
set
|
|
{
|
|
_aniMoveTime = value;
|
|
_aniTimer = 0f;
|
|
}
|
|
}
|
|
private float InnerPercent
|
|
{
|
|
get
|
|
{
|
|
return _innerPercent;
|
|
}
|
|
set
|
|
{
|
|
_innerPercent = value;
|
|
var offset = Mathf.Lerp(0.5f, -0.4f, _innerPercent);
|
|
for (int i = 0; i < _innerMaterials.Count; ++i)
|
|
{
|
|
var material = _innerMaterials[i];
|
|
if (material != null)
|
|
{
|
|
material.SetTextureOffset("_MainTex", new Vector2(0f, offset));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region//公有函数
|
|
public void AddInstGos(GameObject go)
|
|
{
|
|
_instGos.Add(go);
|
|
var render = go.transform.Find("InSide").GetComponent<MeshRenderer>();
|
|
if (render != null)
|
|
{
|
|
_aniMaterials.Add(render.material);
|
|
}
|
|
render = go.transform.Find("InnerRing").GetComponent<MeshRenderer>();
|
|
if (render != null)
|
|
{
|
|
_innerMaterials.Add(render.material);
|
|
}
|
|
}
|
|
public void DestoryField()
|
|
{
|
|
for (int i = 0; i < _instGos.Count; ++i)
|
|
{
|
|
GameObject.DestroyImmediate(_instGos[i]);
|
|
}
|
|
for (int i = 0; i < _aniMaterials.Count; ++i)
|
|
{
|
|
GameObject.DestroyImmediate(_aniMaterials[i]);
|
|
}
|
|
for (int i = 0; i < _innerMaterials.Count; ++i)
|
|
{
|
|
GameObject.DestroyImmediate(_innerMaterials[i]);
|
|
}
|
|
_instGos.Clear();
|
|
_aniMaterials.Clear();
|
|
_innerMaterials.Clear();
|
|
GameObject.DestroyImmediate(this);
|
|
}
|
|
#endregion
|
|
|
|
#region//私有函数
|
|
private void Update()
|
|
{
|
|
float lerpValue = 1f;
|
|
if (_aniTimer <= _aniMoveTime)
|
|
{
|
|
_aniTimer += Time.deltaTime;
|
|
lerpValue = _aniTimer / _aniMoveTime;
|
|
}
|
|
var startValue = Mathf.Lerp(0.5f, -0.4f, InnerPercent);
|
|
var value = Mathf.Lerp(startValue, -0.4f, lerpValue);
|
|
|
|
for (int i = 0; i < _aniMaterials.Count; ++i)
|
|
{
|
|
var material = _aniMaterials[i];
|
|
if (material != null)
|
|
{
|
|
material.SetTextureOffset("_MainTex", new Vector2(0f, value));
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|