/// <summary> /// Register custom tool with tile system editor. /// </summary> /// <example> /// <para>Register custom tool by creating a custom editor script with a class /// that implements <see cref="ToolBase"/>. The custom tool must be registered /// with the <see cref="ToolManager"/> which can be achieved easily by adding /// the attribute <c>InitializeOnLoad</c> and a static initializer function.</para> /// <para>See <a href="http://unity3d.com/support/documentation/Manual/RunningEditorCodeOnLaunch.html">Running Editor Script Code on Launch</a> /// for more information regarding <c>InitializeOnLoad</c>.</para> /// <code language="csharp"><![CDATA[ /// using Rotorz.Tile; /// using Rotorz.Tile.Editor; /// using UnityEditor; /// using UnityEngine; /// /// [InitializeOnLoad] /// public class MagicTool : ToolBase /// { /// static MagicTool() /// { /// ToolManager.Instance.RegisterTool<MagicTool>(); /// } /// /// /// public override string Label { /// get { return "Magic"; } /// } /// /// /// public override void OnTool(ToolEvent e, IToolContext context) /// { /// // Do something magical! /// } /// /// public override void OnToolInactive(ToolEvent e, IToolContext context) /// { /// // Do something magical! /// } /// } /// ]]></code> /// </example> /// <returns> /// Instance of registered tool. /// </returns> /// <typeparam name="T">Type of tool</typeparam> public ToolBase RegisterTool <T>() where T : ToolBase, new() { // Has a tool already been registered with this name? if (this.registeredTools.ContainsKey(typeof(T))) { Debug.LogError("A tool has already been registered of type '" + typeof(T).FullName + "'"); return(null); } ToolBase tool = new T(); // Prepare settings for tool. var group = AssetSettingManagement.GetGroup("Tool[" + typeof(T).FullName + "]"); tool.PrepareSettings(group); group.Seal(); this.registeredTools[typeof(T)] = tool; this.toolsInOrderRegistered.Add(tool); // Restore visibility of tool from user settings but bypass property // setter to avoid immediately marking tool ordering dirty. tool._visible = !ToolManagementSettings.IsToolHidden(tool); // Restore user preferred ordering of tools. ToolManagementSettings.LoadToolOrdering(); return(tool); }
/// <summary> /// Reset user preferences. /// </summary> public static void ResetToDefaultValues() { foreach (var group in s_PreferenceGroups) { group.RestoreDefaultValues(); } ToolManagementSettings.RestoreToolVisibility(); ToolManagementSettings.ResetToolOrdering(); }
private void DrawToolsTab() { EditorGUI.BeginChangeCheck(); ReorderableListGUI.Title(TileLang.Text("Tool Palette:")); ReorderableListGUI.ListField(this.toolsAdaptor, ReorderableListFlags.HideAddButton | ReorderableListFlags.HideRemoveButtons); if (EditorGUI.EndChangeCheck()) { ToolManagementSettings.SaveToolOrdering(); ToolUtility.RepaintToolPalette(); } ExtraEditorGUI.TrailingTip(TileLang.Text("Specify which tools appear in the tools palette.")); GUILayout.Space(5); RtsPreferences.AutoShowToolPalette.Value = EditorGUILayout.ToggleLeft(TileLang.Text("Automatically show tool palette upon activating tool"), RtsPreferences.AutoShowToolPalette); GUILayout.Space(5); }