Skip to content

Instantly share code, notes, and snippets.

@kankikuchi
Created February 12, 2015 20:00
Show Gist options
  • Save kankikuchi/5c310de007eb2dc594af to your computer and use it in GitHub Desktop.
Save kankikuchi/5c310de007eb2dc594af to your computer and use it in GitHub Desktop.
Sorting Layer名を定数で管理するクラスを作成するエディタ拡張【Unity】
using System;
using System.IO;
using System.Text;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
/// <summary>
/// ソーティングレイヤー名を定数で管理するクラスを自動で作成するスクリプト
/// </summary>
public class SortingLayerNameCreator : AssetPostprocessor{
private const string COMMAND_NAME = "Tools/Create/Sorting Layer Name"; // コマンド名
//スクリプトを作成します
[MenuItem(COMMAND_NAME)]
private static void Create()
{
Dictionary<string, string> sortingLayerNameDic = GetSortingLayerNames ().ToDictionary(value => value);
ConstantsClassCreator.Create ("SortingLayerName", "ソーティングレイヤー名を定数で管理するクラス", sortingLayerNameDic);
}
//sortinglayerの名前一覧を取得
private static string[] GetSortingLayerNames() {
Type internalEditorUtilityType = typeof(InternalEditorUtility);
PropertyInfo sortingLayersProperty = internalEditorUtilityType.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
return (string[])sortingLayersProperty.GetValue(null, new object[0]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment