Skip to content

Instantly share code, notes, and snippets.

@arun02139
Created August 6, 2015 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arun02139/ab5fea17fe8b10d7b816 to your computer and use it in GitHub Desktop.
Save arun02139/ab5fea17fe8b10d7b816 to your computer and use it in GitHub Desktop.
using UnityEngine;
// LINK: http://docs.unity3d.com/Manual/SL-SubshaderTags.html
public enum RenderOrderType { None = 0, Background = 1000, Geometry = 2000, PhoenixGround = 2010, PhoenixGroundShadow = 2020,
PhoenixEnvironProp = 2030, AlphaTest = 2450, Transparent = 3000, Overlay = 4000 }
public class RenderOrder : MonoBehaviour
{
public int Order;
Material material;
void Awake()
{
if(GetComponent<Renderer>() != null)
material = GetComponent<Renderer>().sharedMaterial;
else if(GetComponent<CanvasRenderer>() != null)
material = GetComponent<CanvasRenderer>().GetMaterial();
else
NUnit.Framework.Assert.Fail();
}
void Start()
{
if(material != null && Order != 0)
{
// Debug.Log(string.Format("Setting {0}'s render order to {1} ({2})", gameObject.name, (RenderOrderType)material.renderQueue, Order));
material.renderQueue = Order;
}
else
{
Debug.Log(string.Format("RenderOrder.Start {0}: m_Material is {1}, Order = {2}", name, material == null ? "null" : "not null", this.Order));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment