Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
スプライトアニメーションが使用するテクスチャを上書きする
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(SpriteRenderer))]
public class OverrideSprite : MonoBehaviour
{
private SpriteRenderer sr;
private static int idMainTex = Shader.PropertyToID("_MainTex");
private MaterialPropertyBlock block;
[SerializeField]
private Texture texture = null;
public Texture overrideTexture{
get{ return texture; }
set{
texture = value;
if (block == null) {
Init ();
}
block.SetTexture (idMainTex, texture);
}
}
void Awake()
{
Init ();
overrideTexture = texture;
}
void LateUpdate()
{
sr.SetPropertyBlock (block);
}
void OnValidate()
{
overrideTexture = texture;
}
void Init()
{
block = new MaterialPropertyBlock ();
sr = GetComponent<SpriteRenderer> ();
sr.GetPropertyBlock (block);
}
}
@tsubaki
Copy link
Author

tsubaki commented Jan 7, 2018

animation 98

@tsubaki
Copy link
Author

tsubaki commented Jan 9, 2018

animation 102

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment