Skip to content

Instantly share code, notes, and snippets.

@Suzeep
Last active November 18, 2017 09:25
Show Gist options
  • Save Suzeep/8da11dcce3902b749a24f8fc6eac3a99 to your computer and use it in GitHub Desktop.
Save Suzeep/8da11dcce3902b749a24f8fc6eac3a99 to your computer and use it in GitHub Desktop.
DEBUG, RELEASE, MASTERといったプリプロセッサを追加・切り替えするメニュー
using UnityEditor;
using UnityEngine;
using System;
using System.Collections.Generic;
using System.Linq;
//================================================================================
// class DefineSymbolSwitcher
//================================================================================
public static class DefineSymbolSwitcher
{
//================================================================================
// constant
//================================================================================
// 設定対象のBuildTargetGroupテーブル
private static readonly BuildTargetGroup[] _targetGroupTbl =
{
BuildTargetGroup.Standalone,
BuildTargetGroup.Android,
BuildTargetGroup.iOS,
// ...
};
// ツールメニューのタイトル
public const string STR_MENU_TITLE = "FW Tools/DefineSwitch/";
// 現在選択中のプラットフォームグループを取得
//private static BuildTargetGroup CurrentPlatform = EditorUserBuildSettings.selectedBuildTargetGroup;
//--------------------------------------------------------------------------------
// 共通定義
//--------------------------------------------------------------------------------
public const string STR_FW_DEBUG = "FW_DEBUG";
public const string STR_FW_RELEASE = "FW_RELEASE";
public const string STR_FW_MASTER = "FW_MASTER";
//--------------------------------------------------------------------------------
// FW_DEBUG
//--------------------------------------------------------------------------------
[MenuItem(STR_MENU_TITLE + "Framework/DEBUG")]
public static void Add_FW_DEBUG()
{
foreach( var group in _targetGroupTbl )
{
deleteSymbol( group, STR_FW_RELEASE );
deleteSymbol( group, STR_FW_MASTER );
addSymbol( group, STR_FW_DEBUG );
}
}
//--------------------------------------------------------------------------------
// FW_RELEASE
//--------------------------------------------------------------------------------
[MenuItem(STR_MENU_TITLE + "Framework/RELEASE")]
public static void Add_FW_RELEASE()
{
foreach( var group in _targetGroupTbl )
{
deleteSymbol( group, STR_FW_DEBUG );
deleteSymbol( group, STR_FW_MASTER );
addSymbol( group, STR_FW_RELEASE );
}
}
//--------------------------------------------------------------------------------
// FW_MASTER
//--------------------------------------------------------------------------------
[MenuItem(STR_MENU_TITLE + "Framework/MASTER")]
public static void Add_FW_MASTER()
{
foreach( var group in _targetGroupTbl )
{
deleteSymbol( group, STR_FW_DEBUG );
deleteSymbol( group, STR_FW_RELEASE );
addSymbol( group, STR_FW_MASTER );
}
}
//--------------------------------------------------------------------------------
// 指定したシンボルを削除
//--------------------------------------------------------------------------------
private static void deleteSymbol( BuildTargetGroup group, string str_target )
{
var sds_list = getSymbolList( group );
if( sds_list.Contains( str_target ) ){
sds_list.Remove( str_target );
PlayerSettings.SetScriptingDefineSymbolsForGroup( group, string.Join(";", sds_list.ToArray()) );
}
}
//--------------------------------------------------------------------------------
// 指定したシンボルを追加
//--------------------------------------------------------------------------------
private static void addSymbol( BuildTargetGroup group, string str_target )
{
var sds_list = getSymbolList( group );
if( !sds_list.Contains( str_target ) ){
sds_list.Insert( 0, str_target );
PlayerSettings.SetScriptingDefineSymbolsForGroup( group, string.Join(";", sds_list.ToArray()) );
}
}
//--------------------------------------------------------------------------------
// シンボルをリストで取得
//--------------------------------------------------------------------------------
private static List<string> getSymbolList( BuildTargetGroup group )
{
return PlayerSettings.GetScriptingDefineSymbolsForGroup( group ).Split( ';' ).Select( s => s.Trim() ).ToList();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment