/// <summary> /// Restore recent selection list from editor preferences. /// </summary> private void RestoreRecentSelectionList() { if (s_RecentInstanceIDs == null) { s_RecentInstanceIDs = AssetSettingManagement.GetGroup("Designer").Fetch <string>("RecentInstanceIDs", ""); } if (s_RecentInstanceIDs == "") { return; } foreach (string instanceID in s_RecentInstanceIDs.Value.Split(',')) { try { Object o = EditorUtility.InstanceIDToObject(int.Parse(instanceID, CultureInfo.InvariantCulture)); if (o is IDesignableObject) { this.History.AddToRecent(o as IHistoryObject); } } catch { // Do nothing if an error occurred whilst attempting to parse instance ID. } } }
/// <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); }
private static void PrepareSettingGroup(string key, Action <ISettingStore> prepare) { var group = AssetSettingManagement.GetGroup(key); s_PreferenceGroups.Add(group); prepare(group); group.Seal(); }
static TileSystemInspector() { var settings = AssetSettingManagement.GetGroup("Inspector.TileSystem"); s_setting_ToggleModifyGrid = settings.Fetch <bool>("ExpandModifyGrid", true); s_setting_ToggleStripping = settings.Fetch <bool>("ExpandStripping", false); s_setting_ToggleBuildOptions = settings.Fetch <bool>("ExpandBuildOptions", false); s_setting_ToggleRuntimeOptions = settings.Fetch <bool>("ExpandRuntimeOptions", false); }
static ToolUtility() { EditorApplication.playModeStateChanged += OnPlayModeStateChanged; Undo.undoRedoPerformed += OnUndoRedoPerformed; var group = AssetSettingManagement.GetGroup("ToolUtility"); PrepareSettings(group); group.Seal(); }
public static string[] OnWillSaveAssets(string[] assetPaths) { // We really don't want to crash the Unity asset processor! try { AssetSettingManagement.SaveSettings(); } catch (Exception ex) { Debug.LogException(ex); } return(assetPaths); }
static ToolManagementSettings() { var settingGroup = AssetSettingManagement.GetGroup("ToolManager"); Hidden = settingGroup.Fetch <HashSet <string> >("Hidden", null, filter: (value) => value ?? new HashSet <string>() ); Order = settingGroup.Fetch <string[]>("Order", null, filter: (value) => value ?? new string[0] ); }
private static void AutoInitializeUserSettings() { if (s_HasInitializedUserSettings == true) { return; } var settings = AssetSettingManagement.GetGroup("CreateTileSystemWindow"); s_SelectedPresetGuid = settings.Fetch <string>("SelectedPresetGuid", ""); s_HasInitializedUserSettings = true; }
private static void AutoInitializeUserSettings() { if (s_HasInitializedUserSettings == true) { return; } var settings = AssetSettingManagement.GetGroup("TileSystemPresetInspector"); s_SectionStripping = settings.Fetch <bool>("ExpandStripping", false); s_SectionBuildOptions = settings.Fetch <bool>("ExpandBuildOptions", false); s_SectionRuntimeOptions = settings.Fetch <bool>("ExpandRuntimeOptions", false); s_HasInitializedUserSettings = true; }
private static void OnPlayModeStateChanged(PlayModeStateChange change) { // Ensure that tool is deactivated when switching between play/edit mode. ToolManager.Instance.CurrentTool = null; // Assembly will get reloaded real soon, so let's save user settings // just in case Unity explodes. AssetSettingManagement.SaveSettings(); // Attempt to recover previously active tile system editor preferences. int instanceID = s_setting_ActiveTileSystemInstanceID.Value; ToolUtility.ActiveTileSystem = (instanceID != -1) ? EditorUtility.InstanceIDToObject(instanceID) as TileSystem : null; RepaintScenePalette(); }
static HookAutoHideSceneViewGrid() { // Gain access to the non-public property `AnnotationUtility.showGrid`. // Thanks ShawnWhite! Type tyAnnotationUtility = typeof(SceneView).Assembly.GetType("UnityEditor.AnnotationUtility", false); if (tyAnnotationUtility != null) { s_piAnnotationUtilityShowGrid = tyAnnotationUtility.GetProperty("showGrid", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); } ToolManager.Instance.ToolChanged += ToolManager_ToolChanged; var settingGroup = AssetSettingManagement.GetGroup("ToolManager"); HookEnabled = settingGroup.Fetch <bool>("AutoHideSceneViewGrid", true); HookEnabled.ValueChanged += AutoHideSceneViewGrid_ValueChanged; s_RestoreAnnotationUtilityShowGrid = AnnotationUtilityShowGrid; }
static DesignerView() { var settings = AssetSettingManagement.GetGroup("Designer"); s_setting_DisplayExtendedProperties = settings.Fetch <bool>("DisplayExtendedProperties", false); }