Skip to content

Instantly share code, notes, and snippets.

@CapnRat
Last active December 20, 2015 01:19
Show Gist options
  • Select an option

  • Save CapnRat/6048145 to your computer and use it in GitHub Desktop.

Select an option

Save CapnRat/6048145 to your computer and use it in GitHub Desktop.

Revisions

  1. CapnRat revised this gist Jul 21, 2013. 3 changed files with 9 additions and 8 deletions.
    6 changes: 6 additions & 0 deletions CompiledShaderBehaviour.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    using UnityEngine;

    public class CompiledShaderBehaviour : MonoBehaviour
    {
    public Shader shader;
    }
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    using UnityEngine;
    using UnityEditor;

    [CustomEditor(typeof(NewBehaviourScript))]
    public class NewBehaviourScriptEditor : Editor
    [CustomEditor(typeof(CompiledShaderBehaviour))]
    public class CompiledShaderBehaviourEditor : Editor
    {
    SerializedProperty shaderProperty;
    SerializedProperty shaderProperty;

    public void OnEnable ()
    {
    5 changes: 0 additions & 5 deletions NewBehaviourScript.cs
    Original file line number Diff line number Diff line change
    @@ -1,5 +0,0 @@
    using UnityEngine;

    public class NewBehaviourScript : MonoBehaviour {
    public Shader shader;
    }
  2. CapnRat created this gist Jul 21, 2013.
    5 changes: 5 additions & 0 deletions NewBehaviourScript.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    using UnityEngine;

    public class NewBehaviourScript : MonoBehaviour {
    public Shader shader;
    }
    30 changes: 30 additions & 0 deletions NewBehaviourScriptEditor.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    using UnityEngine;
    using UnityEditor;

    [CustomEditor(typeof(NewBehaviourScript))]
    public class NewBehaviourScriptEditor : Editor
    {
    SerializedProperty shaderProperty;

    public void OnEnable ()
    {
    shaderProperty = serializedObject.FindProperty ("shader");
    }

    public override void OnInspectorGUI ()
    {
    serializedObject.Update ();

    EditorGUILayout.PropertyField (shaderProperty);

    Shader shader = shaderProperty.objectReferenceValue as Shader;
    if (shader)
    {
    string compiledShaderString = (new SerializedObject(shader)).FindProperty("m_Script").stringValue;

    EditorGUILayout.TextArea (compiledShaderString);
    }

    serializedObject.ApplyModifiedProperties ();
    }
    }