Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active January 21, 2018 13:58
Show Gist options
  • Select an option

  • Save tsubaki/85f82045c5bb4ebfbbeab8f8018e3db5 to your computer and use it in GitHub Desktop.

Select an option

Save tsubaki/85f82045c5bb4ebfbbeab8f8018e3db5 to your computer and use it in GitHub Desktop.
スプライトアニメーションが使用するテクスチャを上書きする
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

tsubaki commented Jan 7, 2018

Copy link
Copy Markdown
Author

animation 98

@tsubaki

tsubaki commented Jan 9, 2018

Copy link
Copy Markdown
Author

animation 102

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