44 lines
797 B
C#
44 lines
797 B
C#
using UnityEngine;
|
|
|
|
[ExecuteInEditMode]
|
|
public class ProjectorMatrix : MonoBehaviour
|
|
{
|
|
public string[] GlobalMatrixNames;
|
|
|
|
public Transform[] ProjectiveTranforms;
|
|
|
|
public bool UpdateOnStart;
|
|
|
|
public bool CanUpdate = true;
|
|
|
|
private Transform t;
|
|
|
|
private void Start()
|
|
{
|
|
t = base.transform;
|
|
if (UpdateOnStart)
|
|
{
|
|
UpdateMatrix();
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!UpdateOnStart)
|
|
{
|
|
UpdateMatrix();
|
|
}
|
|
}
|
|
|
|
public void UpdateMatrix()
|
|
{
|
|
if (CanUpdate && GlobalMatrixNames != null && ProjectiveTranforms != null && GlobalMatrixNames.Length != 0 && ProjectiveTranforms.Length != 0)
|
|
{
|
|
for (int i = 0; i < GlobalMatrixNames.Length; i++)
|
|
{
|
|
Shader.SetGlobalMatrix(GlobalMatrixNames[i], ProjectiveTranforms[i].worldToLocalMatrix * t.localToWorldMatrix);
|
|
}
|
|
}
|
|
}
|
|
}
|