68 lines
2.2 KiB
C#
68 lines
2.2 KiB
C#
|
using UnityEngine;
|
|||
|
|
|||
|
public class LightningLinkFxController : LinkFxController
|
|||
|
{
|
|||
|
public float interval = 1f;
|
|||
|
|
|||
|
// 最大帧数
|
|||
|
public int maxCount = 8;
|
|||
|
private Transform _child;
|
|||
|
private int _currentCount = -1;
|
|||
|
private float _nextFrame;
|
|||
|
|
|||
|
protected override bool isBillboard
|
|||
|
{
|
|||
|
get { return true; }
|
|||
|
}
|
|||
|
|
|||
|
protected override MeshRenderer RegisterMeshMaterials()
|
|||
|
{
|
|||
|
_child = transform.Find("effect");
|
|||
|
materialRecords = new LinkFxMaterialRecord[1];
|
|||
|
var meshRenderer0 = _child.GetComponent<MeshRenderer>();
|
|||
|
materialRecords[0] = new LinkFxMaterialRecord(meshRenderer0.material, new[] {"_MainTex"});
|
|||
|
return meshRenderer0;
|
|||
|
}
|
|||
|
|
|||
|
//private void OnEnable()
|
|||
|
//{
|
|||
|
// EventListenerSystem.Instance.AddMessageOne(Games.Events.MessageID.PostMainCameraMove, OnCameraMove);
|
|||
|
//}
|
|||
|
//
|
|||
|
//private void OnDisable()
|
|||
|
//{
|
|||
|
// EventListenerSystem.Instance.RemoveMessageOne(Games.Events.MessageID.PostMainCameraMove, OnCameraMove);
|
|||
|
//}
|
|||
|
|
|||
|
// Uv动画
|
|||
|
public override bool TryUpdateLink()
|
|||
|
{
|
|||
|
if (Time.time > _nextFrame)
|
|||
|
{
|
|||
|
_currentCount++;
|
|||
|
if (_currentCount >= maxCount)
|
|||
|
_currentCount = 0;
|
|||
|
var offsetV = (float) _currentCount / maxCount;
|
|||
|
_nextFrame = Time.time + interval;
|
|||
|
for (var i = 0; i < materialRecords.Length; i++)
|
|||
|
materialRecords[i].material
|
|||
|
.SetTextureOffset(materialRecords[i].textures[i].propertyName, new Vector2(0f, offsetV));
|
|||
|
//if (SceneLogic.CameraController != null && SceneLogic.CameraController.MainCamera != null)
|
|||
|
//{
|
|||
|
// var cameraTrans = SceneLogic.CameraController.MainCamera.transform;
|
|||
|
// var z = cameraTrans.position - _child.position;
|
|||
|
// if (z != Vector3.zero)
|
|||
|
// {
|
|||
|
// var y = Vector3.Cross(z, transform.right);
|
|||
|
// if (y != Vector3.zero)
|
|||
|
// {
|
|||
|
// z = Vector3.Cross(transform.right, y);
|
|||
|
// _child.rotation = Quaternion.LookRotation(z, y);
|
|||
|
// }
|
|||
|
// }
|
|||
|
//}
|
|||
|
}
|
|||
|
|
|||
|
return base.TryUpdateLink();
|
|||
|
}
|
|||
|
}
|