hellbound/Assets/Sources/Lean/Common/Documentation/LeanGuide.cs

191 lines
22 KiB
C#
Raw Normal View History

2021-11-26 11:16:25 +03:00
using UnityEngine;
namespace Lean.Common
{
/// <summary>This class defines documentation data that can be viewed in the inspector.</summary>
public class LeanGuide : ScriptableObject
{
public string LongName;
public string ShortName;
public TextAsset Documentation;
[System.NonSerialized]
private Texture2D icon;
[System.NonSerialized]
private string version;
public Texture2D Icon
{
get
{
if (icon == null)
{
icon = new Texture2D(1, 1);
icon.LoadImage(System.Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAgAElEQVR4Ae2dffBkVZnfe5gZGGAG5UVgGEARBAEXFBd3haIUXF9KqdIYNUnpJrtozBpfSogVquJGsWqtFP+gBaW1tVakysQ/NGJEWaNRFBPU6KrLiMsoMFiiwyAOrzO8DjOT8+3f79Pz7afPud19+/bLDPepuv19nue8P+d8+9zbt2/3ij179nRaaSPQRiAfgQPy7tbbRqCNgCLQEqRdB20EKiLQEqQiOG1SG4GWIO0aaCNQEYGWIBXBaZPaCLQEaddAG4GKCLQEqQhOm9RGoCVIuwbaCFREYFVFWpu0/0RgRYNDeUbdWW4J0uDKmXFVTS76cbo+rN39ikAtQcZZGrPPO2wxeo/Gyevl6uolIsR+lPLVbXem5VqCzDTc2cbigspmWnaW8pb81DUsnXyOpYWNP9aJ3+uQTr5Sesy/UPaK9suKM5kPFsmwxqry5dJG9cV2Y7lhizemD7PVXsxDH0p+0hcKW4I0Nx1x0ZVqrsqXS4u+cW3vRyxLWmnRun8UXfV5vpxd8sm/cNISZLwpKS2wWEtVvlxa9FXZ46SpXzF/7KvbVYubtBKqHtKqdNrzvPgWDluCDE7JqAuqKl8uLfqq7FHSPE9JZ3Sejs8xLlbsSVFtUEfUc7Z8CyXP1Iv0YQuGSarKl0uLviq7lOb+nD6qb5QxkCe3iPE5Rl19wUddjkrzPK4rX7S97ELo+zNBFPxRpCpfLi36qmxPG0fP5cVXQo2VtKiPE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return icon;
}
}
public string Version
{
get
{
if (version == null && Documentation != null)
{
var text = Documentation.text;
var a = text.IndexOf("Documentation - ");
var b = text.IndexOf("</title>");
if (a > 0 && b > 0)
{
version = text.Substring(a + 16, b - a - 16);
}
}
return version;
}
}
}
}
#if UNITY_EDITOR
namespace Lean.Common.Editor
{
using UnityEditor;
[CustomEditor(typeof(LeanGuide))]
public class LeanGuide_Editor : UnityEditor.Editor
{
private static GUIStyle titleStyle;
private static GUIStyle headerStyle;
private static GUIStyle bodyStyle;
private static GUIStyle rateStyle;
public static void UpdateStyles()
{
if (bodyStyle == null)
{
bodyStyle = new GUIStyle(EditorStyles.label);
bodyStyle.wordWrap = true;
bodyStyle.fontSize = 14;
titleStyle = new GUIStyle(bodyStyle);
titleStyle.fontSize = 26;
titleStyle.alignment = TextAnchor.MiddleCenter;
headerStyle = new GUIStyle(bodyStyle);
headerStyle.fontSize = 18 ;
rateStyle = new GUIStyle(EditorStyles.toolbarButton);
rateStyle.fontSize = 20;
}
}
public override void OnInspectorGUI()
{
var tgt = (LeanGuide)target;
UpdateStyles();
EditorGUILayout.LabelField("Thank You For Using " + tgt.LongName + "!", headerStyle);
EditorGUILayout.LabelField("The documentation can be opened below. To understand how this asset works I also recommend you run the example scenes, and read their description text.", bodyStyle);
if (GUILayout.Button(new GUIContent("Local Documentation", "Open In Web Browser")) == true)
{
System.Diagnostics.Process.Start(Application.dataPath + AssetDatabase.GetAssetPath(tgt.Documentation).Remove(0, "Assets".Length));
}
if (GUILayout.Button(new GUIContent("Online Documentation", "Open In Web Browser")) == true)
{
Application.OpenURL("https://CarlosWilkes.com/Documentation/" + tgt.ShortName);
}
EditorGUILayout.Separator();
EditorGUILayout.Separator();
EditorGUILayout.LabelField("Need Help?", headerStyle);
EditorGUILayout.LabelField("If you have questions, feel free to ask!", bodyStyle);
if (GUILayout.Button(new GUIContent("Forum Thread", "Unity Forums")) == true)
{
Application.OpenURL("https://CarlosWilkes.com/Forum/" + tgt.ShortName);
}
if (GUILayout.Button(new GUIContent("E-Mail Me", "carlos.wilkes@gmail.com")) == true)
{
Application.OpenURL("mailto:carlos.wilkes@gmail.com");
}
if (GUILayout.Button(new GUIContent("Private Message", "Unity Forum Profile")) == true)
{
Application.OpenURL("https://forum.unity.com/members/41960");
}
EditorGUILayout.Separator();
EditorGUILayout.Separator();
EditorGUILayout.LabelField("You're Awesome!", headerStyle);
EditorGUILayout.LabelField("If you haven't already, consider rating this asset. It really helps me out!", bodyStyle);
if (GUILayout.Button(new GUIContent("Rate This Asset", tgt.LongName + " Asset Page")) == true)
{
Application.OpenURL("https://CarlosWilkes.com/Get/" + tgt.ShortName);
}
EditorGUILayout.Separator();
EditorGUILayout.Separator();
EditorGUILayout.LabelField("Made Something Cool?", headerStyle);
EditorGUILayout.LabelField("Let me know so I can shout your project out!", bodyStyle);
if (GUILayout.Button(new GUIContent("E-Mail Me", "carlos.wilkes@gmail.com")) == true)
{
Application.OpenURL("mailto:carlos.wilkes@gmail.com");
}
EditorGUILayout.Separator();
EditorGUILayout.Separator();
EditorGUILayout.LabelField("Want More?", headerStyle);
EditorGUILayout.LabelField("I've released a range of assets to speed up your project development, check them out:", bodyStyle);
if (GUILayout.Button(new GUIContent("My Website", "CarlosWilkes.com")) == true)
{
Application.OpenURL("https://CarlosWilkes.com");
}
}
protected override void OnHeaderGUI()
{
var tgt = (LeanGuide)target;
UpdateStyles();
GUILayout.BeginHorizontal("In BigTitle");
{
var iconWidth = Mathf.Min(EditorGUIUtility.currentViewWidth/3f - 20f, 128f);
var content = new GUIContent("Version\n" + tgt.Version);
var height = Mathf.Max(titleStyle.CalcHeight(content, EditorGUIUtility.currentViewWidth - iconWidth), iconWidth);
if (tgt.Icon != null)
{
GUILayout.Label(tgt.Icon, EditorStyles.centeredGreyMiniLabel, GUILayout.Width(iconWidth), GUILayout.Height(iconWidth));
}
GUILayout.Label(content, titleStyle, GUILayout.Height(height));
}
GUILayout.EndHorizontal();
}
}
}
#endif