Some checks failed
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (push) Successful in 5m54s
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (push) Successful in 5m43s
Build project / Publish to itch.io (StandaloneLinux64) (push) Successful in 11s
Build project / Publish to itch.io (StandaloneWindows64) (push) Successful in 9s
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (pull_request) Has been cancelled
Build project / Publish to itch.io (StandaloneLinux64) (pull_request) Has been cancelled
Build project / Publish to itch.io (StandaloneWindows64) (pull_request) Has been cancelled
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (pull_request) Has been cancelled
65 lines
1.4 KiB
C#
65 lines
1.4 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
|
|
[RequireComponent(typeof(Image))]
|
|
public class ScrollDetailTexture : MonoBehaviour
|
|
{
|
|
public bool uniqueMaterial = false;
|
|
public Vector2 scrollPerSecond = Vector2.zero;
|
|
|
|
Matrix4x4 m_Matrix;
|
|
Material mCopy;
|
|
Material mOriginal;
|
|
Image mSprite;
|
|
Material m_Mat;
|
|
|
|
void OnEnable ()
|
|
{
|
|
mSprite = GetComponent<Image>();
|
|
mOriginal = mSprite.material;
|
|
|
|
if (uniqueMaterial && mSprite.material != null)
|
|
{
|
|
mCopy = new Material(mOriginal);
|
|
mCopy.name = "Copy of " + mOriginal.name;
|
|
mCopy.hideFlags = HideFlags.DontSave;
|
|
mSprite.material = mCopy;
|
|
}
|
|
}
|
|
|
|
void OnDisable ()
|
|
{
|
|
if (mCopy != null)
|
|
{
|
|
mSprite.material = mOriginal;
|
|
if (Application.isEditor)
|
|
UnityEngine.Object.DestroyImmediate(mCopy);
|
|
else
|
|
UnityEngine.Object.Destroy(mCopy);
|
|
mCopy = null;
|
|
}
|
|
mOriginal = null;
|
|
}
|
|
|
|
void Update ()
|
|
{
|
|
Material mat = (mCopy != null) ? mCopy : mOriginal;
|
|
|
|
if (mat != null)
|
|
{
|
|
Texture tex = mat.GetTexture("_DetailTex");
|
|
|
|
if (tex != null)
|
|
{
|
|
mat.SetTextureOffset("_DetailTex", scrollPerSecond * Time.time);
|
|
|
|
// TODO: It would be better to add support for MaterialBlocks on UIRenderer,
|
|
// because currently only one Update() function's matrix can be active at a time.
|
|
// With material block properties, the batching would be correctly broken up instead,
|
|
// and would work with multiple widgets using this detail shader.
|
|
}
|
|
}
|
|
}
|
|
}
|