You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/Plugins/Animancer/Examples/Code/ShowReadMeOnStartup.cs

59 lines
1.8 KiB
C#

// Animancer // Copyright 2020 Kybernetik //
#if UNITY_EDITOR
using UnityEditor;
namespace Animancer.Editor
{
/// <summary>[Editor-Only] [Internal] Automatically selects the <see cref="ReadMe"/> on startup.</summary>
/// <remarks>This script is in the Examples folder so that it gets deleted along with them.</remarks>
[InitializeOnLoad]
internal static class ShowReadMeOnStartup
{
/************************************************************************************************************************/
static ShowReadMeOnStartup()
{
const string SessionStateKey = "Animancer.HasShownReadMe";
if (SessionState.GetBool(SessionStateKey, false))
return;
EditorApplication.delayCall += () =>
{
var asset = FindReadMe();
if (asset == null ||
asset.DontShowOnStartup)
return;
SessionState.SetBool(SessionStateKey, true);
EditorApplication.delayCall += () =>
Selection.activeObject = asset;
};
}
/************************************************************************************************************************/
private static ReadMe FindReadMe()
{
var guids = AssetDatabase.FindAssets("t:ReadMe");
for (int i = 0; i < guids.Length; i++)
{
var assetPath = AssetDatabase.GUIDToAssetPath(guids[i]);
var asset = AssetDatabase.LoadAssetAtPath<ReadMe>(assetPath);
if (asset != null)
return asset;
}
return null;
}
/************************************************************************************************************************/
}
}
#endif