宏管理

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEditor;


public class MacroSetting : EditorWindow
{
	/// <summary>
	/// 宏分类
	/// </summary>
	public enum MacroItemType
	{
		None,
		Develop,
		Product,
		A,
		B
	}

	/// <summary>
	/// 宏批量选择按钮
	/// </summary>
	private void AddButton ()
	{
		if (GUILayout.Button ("A组", GUILayout.Width (100)))
		{
			MultiChoice (MacroItemType.A);
		}

		if (GUILayout.Button ("B组", GUILayout.Width (100)))
		{
			MultiChoice (MacroItemType.B);
		}
	}

	/// <summary>
	/// 宏列表
	/// </summary>
	private void AddMacroItem ()
	{
		ls.Add (new MacroItem () { macroName = "LOCAL_RES", macroDispalyName = "使用本地资源", type = MacroItemType.Develop });  
		ls.Add (new MacroItem () { macroName = "Dev_Jp", macroDispalyName = "使用日本服务器", type = MacroItemType.Product });  
		ls.Add (new MacroItem () { macroName = "A1", macroDispalyName = "A1", type = MacroItemType.A }); 
		ls.Add (new MacroItem () { macroName = "A2", macroDispalyName = "A2", type = MacroItemType.A }); 
		ls.Add (new MacroItem () { macroName = "A3", macroDispalyName = "A3", type = MacroItemType.A }); 
		ls.Add (new MacroItem () { macroName = "B1", macroDispalyName = "B1", type = MacroItemType.B }); 
		ls.Add (new MacroItem () { macroName = "B2", macroDispalyName = "B2", type = MacroItemType.B }); 
		ls.Add (new MacroItem () { macroName = "B3", macroDispalyName = "B3", type = MacroItemType.B }); 
	}

	#region 不需要改动
	class MacroItem
	{
		public string macroName;
		public string macroDispalyName;
		public MacroItemType type;
	}

	private List<MacroItem> ls = new List<MacroItem> ();
	private Dictionary<string, bool> dic = new Dictionary<string, bool> ();
	public  string macroNameStr;

	[MenuItem ("Tools/MacroSetting")]  
	public static void Settings ()
	{  

		MacroSetting sw = (MacroSetting)EditorWindow.GetWindow (typeof(MacroSetting));  
		sw.titleContent = new GUIContent ("宏设置");  
		sw.Show ();  
	}

	void OnEnable ()
	{
		#if UNITY_ANDROID  
		macroNameStr = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android);  
		#elif UNITY_IPHONE  
		macroNameStr = PlayerSettings.GetScriptingDefineSymbolsForGroup (BuildTargetGroup.iOS);  
		#elif UNITY_STANDALONE_WIN||UNITY_STANDALONE_OSX  
		macroNameStr = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone);  
		#endif  
	}

	public MacroSetting ()
	{  
		ls.Clear ();  
		AddMacroItem ();
		for (int i = 0; i < ls.Count; i++)
		{  
			if (!string.IsNullOrEmpty (macroNameStr) && macroNameStr.IndexOf (ls [i].macroName) != -1)
			{  
				dic [ls [i].macroName] = true;  
			} else
			{  
				dic [ls [i].macroName] = false;  
			}  
		}  

	}

	private void OnGUI ()
	{  
		for (int i = 0; i < ls.Count; i++)
		{  

			EditorGUILayout.BeginHorizontal ("box");  
			dic [ls [i].macroName] = GUILayout.Toggle (dic [ls [i].macroName], ls [i].macroDispalyName);  
			EditorGUILayout.EndHorizontal ();  
		}  
		GUILayout.Label ("宏批量选择");
		EditorGUILayout.BeginHorizontal (); 
		AddButton ();
		EditorGUILayout.EndHorizontal ();  
		if (GUILayout.Button ("保存宏", GUILayout.Width (100)))
		{  
			SaveMacro ();  
		}  
	}

	private void MultiChoice (MacroItemType type)
	{
		for (int i = 0; i < ls.Count; i++)
		{  
			if (ls [i].type == type)
			{
				dic [ls [i].macroName] = true;
			} else
			{
				dic [ls [i].macroName] = false;
			}

		}
	}

	private void SaveMacro ()
	{  
		macroNameStr = string.Empty;  
		foreach (var item in dic)
		{  
			if (item.Value)
			{  
				macroNameStr += string.Format ("{0};", item.Key);  
			}  
		}  
		PlayerSettings.SetScriptingDefineSymbolsForGroup (BuildTargetGroup.Android, macroNameStr);  
		PlayerSettings.SetScriptingDefineSymbolsForGroup (BuildTargetGroup.iOS, macroNameStr);  
		PlayerSettings.SetScriptingDefineSymbolsForGroup (BuildTargetGroup.Standalone, macroNameStr);  
		//Close();  
	}

	#endregion

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值