LoginSignup
6
3

More than 5 years have passed since last update.

MeshRendererでSortingLayerIDやOrderInLayerを変更する拡張スクリプト

Last updated at Posted at 2019-04-09

おそらく既出でしょうけど作ってみました!

Editor フォルダに下記スクリプトをいれる
MyMeshRendererInspector.cs

using UnityEngine;
using UnityEditor;     
using System.Linq;


[CustomEditor(typeof(MeshRenderer))]
public class MyMeshRendererInspector : Editor
{
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        EditorGUILayout.BeginHorizontal();

        // sorting order
        SerializedProperty sortOrderProperty = serializedObject.FindProperty("m_SortingOrder");
        sortOrderProperty.intValue = EditorGUILayout.IntField("Sort Order", sortOrderProperty.intValue);

        // sorting layer
        SerializedProperty layerIDProperty = serializedObject.FindProperty("m_SortingLayerID");
        var index = System.Array.FindIndex(SortingLayer.layers, layer => layer.id == layerIDProperty.intValue);
        index = EditorGUILayout.Popup(index, (from layer in SortingLayer.layers select layer.name).ToArray());
        layerIDProperty.intValue = SortingLayer.layers[index].id;

        EditorGUILayout.EndHorizontal();
        serializedObject.ApplyModifiedProperties();

        base.OnInspectorGUI();
    }
}

Sorting Layer と Order in Layer が表示されるようになります。

x.PNG

何か問題ありましたら教えてください!

6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3