2024-05-13 04:19:55 +08:00
|
|
|
|
#region
|
|
|
|
|
|
|
|
|
|
using System;
|
2022-10-23 04:31:10 +08:00
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2024-05-13 04:19:55 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
2022-11-11 12:39:58 +08:00
|
|
|
|
namespace nadena.dev.modular_avatar.core.editor
|
2022-10-23 04:31:10 +08:00
|
|
|
|
{
|
|
|
|
|
internal static class LogoDisplay
|
|
|
|
|
{
|
2023-01-19 20:32:44 +08:00
|
|
|
|
internal static readonly Texture2D LOGO_ASSET;
|
2024-08-26 11:19:04 +08:00
|
|
|
|
internal static float TARGET_HEIGHT
|
|
|
|
|
{
|
|
|
|
|
get {
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return (EditorStyles.label?.lineHeight ?? 0) * 3;
|
|
|
|
|
}
|
2024-09-28 10:24:19 +08:00
|
|
|
|
catch (NullReferenceException)
|
2024-08-26 11:19:04 +08:00
|
|
|
|
{
|
|
|
|
|
// This can happen in early initialization...
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-23 04:31:10 +08:00
|
|
|
|
|
2023-01-19 20:32:44 +08:00
|
|
|
|
internal static float ImageWidth(float height)
|
|
|
|
|
{
|
|
|
|
|
return (height / (float) LOGO_ASSET.height) * LOGO_ASSET.width;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-23 04:31:10 +08:00
|
|
|
|
private static GUIStyle STYLE => new GUIStyle()
|
|
|
|
|
{
|
|
|
|
|
fixedHeight = TARGET_HEIGHT,
|
2022-11-11 12:30:10 +08:00
|
|
|
|
fixedWidth = TARGET_HEIGHT * (LOGO_ASSET.width / (float) LOGO_ASSET.height),
|
2022-10-23 04:31:10 +08:00
|
|
|
|
stretchHeight = false,
|
|
|
|
|
stretchWidth = false,
|
|
|
|
|
imagePosition = ImagePosition.ImageOnly
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static LogoDisplay()
|
|
|
|
|
{
|
|
|
|
|
var placeholderPath = AssetDatabase.GUIDToAssetPath("2a2bb4e0b8e906743890ef10c778e65c");
|
2022-11-11 12:30:10 +08:00
|
|
|
|
|
2022-10-23 04:31:10 +08:00
|
|
|
|
var path = placeholderPath.Substring(0, placeholderPath.LastIndexOf("/", StringComparison.Ordinal));
|
|
|
|
|
path += "/ma_logo.png";
|
|
|
|
|
|
|
|
|
|
var real_logo = AssetDatabase.LoadAssetAtPath<Texture2D>(path);
|
|
|
|
|
if (real_logo != null) LOGO_ASSET = real_logo;
|
|
|
|
|
else LOGO_ASSET = AssetDatabase.LoadAssetAtPath<Texture2D>(placeholderPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static void DisplayLogo()
|
|
|
|
|
{
|
2024-05-13 04:19:55 +08:00
|
|
|
|
if (LOGO_ASSET == null || EditorStyles.label == null) return;
|
2022-10-23 04:31:10 +08:00
|
|
|
|
|
|
|
|
|
var height = TARGET_HEIGHT;
|
2023-01-19 20:32:44 +08:00
|
|
|
|
var width = ImageWidth(height);
|
2022-10-23 04:31:10 +08:00
|
|
|
|
var rect = GUILayoutUtility.GetRect(width, height);
|
2022-11-11 12:30:10 +08:00
|
|
|
|
|
2022-10-23 04:31:10 +08:00
|
|
|
|
GUI.DrawTexture(rect, LOGO_ASSET, ScaleMode.ScaleToFit);
|
2022-11-11 12:30:10 +08:00
|
|
|
|
GUILayoutUtility.GetRect(width, EditorStyles.label.lineHeight / 2);
|
2022-10-23 04:31:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|