diff --git a/com.unity.template.hdrp-blank/Assets/Readme.asset b/com.unity.template.hdrp-blank/Assets/Readme.asset index 186e39b3ff6..1a2aa01c80c 100644 --- a/com.unity.template.hdrp-blank/Assets/Readme.asset +++ b/com.unity.template.hdrp-blank/Assets/Readme.asset @@ -12,6 +12,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: fcf7219bab7fe46a1ad266029b2fee19, type: 3} m_Name: Readme m_EditorClassIdentifier: + commonStyle: {fileID: 7433441132597879392, guid: d2c670ece470f4c4fa6712b8dc28a9bb, type: 3} + darkStyle: {fileID: 7433441132597879392, guid: 1f902e57f049a7f47986618de93f5ee1, type: 3} + lightStyle: {fileID: 7433441132597879392, guid: 69e7ab73923f93149821ac3a88b84856, type: 3} icon: {fileID: 2800000, guid: d19680cd422524695938fbe55cc3b3bd, type: 3} title: HDRP Empty Template sections: diff --git a/com.unity.template.hdrp-blank/Assets/TutorialInfo/Scripts/Editor.meta b/com.unity.template.hdrp-blank/Assets/TutorialInfo/Editor.meta similarity index 100% rename from com.unity.template.hdrp-blank/Assets/TutorialInfo/Scripts/Editor.meta rename to com.unity.template.hdrp-blank/Assets/TutorialInfo/Editor.meta diff --git a/com.unity.template.hdrp-blank/Assets/TutorialInfo/Editor/ReadmeEditor.cs b/com.unity.template.hdrp-blank/Assets/TutorialInfo/Editor/ReadmeEditor.cs new file mode 100644 index 00000000000..170d5bd6286 --- /dev/null +++ b/com.unity.template.hdrp-blank/Assets/TutorialInfo/Editor/ReadmeEditor.cs @@ -0,0 +1,128 @@ +using UnityEngine; +using UnityEditor; +using System.IO; +using UnityEngine.UIElements; + +[CustomEditor(typeof(Readme))] +[InitializeOnLoad] +sealed class ReadmeEditor : Editor +{ + const string k_ShowedReadmeSessionStateName = "ReadmeEditor.showedReadme"; + const string k_ReadmeSourceDirectory = "Assets/TutorialInfo"; + + static ReadmeEditor() + => EditorApplication.delayCall += SelectReadmeAutomatically; + + static void SelectReadmeAutomatically() + { + if (!SessionState.GetBool(k_ShowedReadmeSessionStateName, false)) + { + var readme = SelectReadme(); + SessionState.SetBool(k_ShowedReadmeSessionStateName, true); + + if (readme && !readme.loadedLayout) + { + EditorUtility.LoadWindowLayout(Path.Combine(Application.dataPath, "TutorialInfo/Layout.wlt")); + readme.loadedLayout = true; + } + } + } + + static Readme SelectReadme() + { + var ids = AssetDatabase.FindAssets("Readme t:Readme"); + if (ids.Length != 1) + { + Debug.Log("Couldn't find a readme"); + return null; + } + + var readmeObject = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(ids[0])); + Selection.objects = new UnityEngine.Object[] { readmeObject }; + return (Readme)readmeObject; + } + + void RemoveTutorial() + { + if (EditorUtility.DisplayDialog("Remove Readme Assets", + + $"All contents under {k_ReadmeSourceDirectory} will be removed, are you sure you want to proceed?", + "Proceed", + "Cancel")) + { + if (Directory.Exists(k_ReadmeSourceDirectory)) + { + FileUtil.DeleteFileOrDirectory(k_ReadmeSourceDirectory); + FileUtil.DeleteFileOrDirectory(k_ReadmeSourceDirectory + ".meta"); + } + else + { + Debug.Log($"Could not find the Readme folder at {k_ReadmeSourceDirectory}"); + } + + var readmeAsset = SelectReadme(); + if (readmeAsset != null) + { + var path = AssetDatabase.GetAssetPath(readmeAsset); + FileUtil.DeleteFileOrDirectory(path + ".meta"); + FileUtil.DeleteFileOrDirectory(path); + } + + AssetDatabase.Refresh(); + } + } + + //Remove ImGUI + protected sealed override void OnHeaderGUI() { } + public sealed override void OnInspectorGUI() { } + + public override VisualElement CreateInspectorGUI() + { + var readme = (Readme)target; + + VisualElement root = new(); + root.styleSheets.Add(readme.commonStyle); + root.styleSheets.Add(EditorGUIUtility.isProSkin ? readme.darkStyle : readme.lightStyle); + + VisualElement ChainWithClass(VisualElement created, string className) + { + created.AddToClassList(className); + return created; + } + + //Header + VisualElement title = new(); + title.AddToClassList("title"); + title.Add(ChainWithClass(new Image() { image = readme.icon }, "title__icon")); + title.Add(ChainWithClass(new Label(readme.title), "title__text")); + root.Add(title); + + //Content + foreach (var section in readme.sections) + { + VisualElement part = new(); + part.AddToClassList("section"); + + if (!string.IsNullOrEmpty(section.heading)) + part.Add(ChainWithClass(new Label(section.heading), "section__header")); + + if (!string.IsNullOrEmpty(section.text)) + part.Add(ChainWithClass(new Label(section.text), "section__body")); + + if (!string.IsNullOrEmpty(section.linkText)) + { + var link = ChainWithClass(new Label(section.linkText), "section__link"); + link.RegisterCallback(evt => Application.OpenURL(section.url)); + part.Add(link); + } + + root.Add(part); + } + + var button = new Button(RemoveTutorial) { text = "Remove Readme Assets" }; + button.AddToClassList("remove-readme-button"); + root.Add(button); + + return root; + } +} diff --git a/com.unity.template.hdrp-blank/Assets/TutorialInfo/Scripts/Editor/ReadmeEditor.cs.meta b/com.unity.template.hdrp-blank/Assets/TutorialInfo/Editor/ReadmeEditor.cs.meta similarity index 100% rename from com.unity.template.hdrp-blank/Assets/TutorialInfo/Scripts/Editor/ReadmeEditor.cs.meta rename to com.unity.template.hdrp-blank/Assets/TutorialInfo/Editor/ReadmeEditor.cs.meta diff --git a/com.unity.template.hdrp-blank/Assets/TutorialInfo/Scripts/Readme.cs b/com.unity.template.hdrp-blank/Assets/TutorialInfo/Readme.cs similarity index 65% rename from com.unity.template.hdrp-blank/Assets/TutorialInfo/Scripts/Readme.cs rename to com.unity.template.hdrp-blank/Assets/TutorialInfo/Readme.cs index 9b0ae32d4f0..814f0e4f28a 100644 --- a/com.unity.template.hdrp-blank/Assets/TutorialInfo/Scripts/Readme.cs +++ b/com.unity.template.hdrp-blank/Assets/TutorialInfo/Readme.cs @@ -1,8 +1,12 @@ -using System; +using System; using UnityEngine; +using UnityEngine.UIElements; public class Readme : ScriptableObject { + public StyleSheet commonStyle; + public StyleSheet darkStyle; + public StyleSheet lightStyle; public Texture2D icon; public string title; public Section[] sections; diff --git a/com.unity.template.hdrp-blank/Assets/TutorialInfo/Scripts/Readme.cs.meta b/com.unity.template.hdrp-blank/Assets/TutorialInfo/Readme.cs.meta similarity index 100% rename from com.unity.template.hdrp-blank/Assets/TutorialInfo/Scripts/Readme.cs.meta rename to com.unity.template.hdrp-blank/Assets/TutorialInfo/Readme.cs.meta diff --git a/com.unity.template.hdrp-blank/Assets/TutorialInfo/Scripts/Editor/ReadmeEditor.cs b/com.unity.template.hdrp-blank/Assets/TutorialInfo/Scripts/Editor/ReadmeEditor.cs deleted file mode 100644 index f983e049c09..00000000000 --- a/com.unity.template.hdrp-blank/Assets/TutorialInfo/Scripts/Editor/ReadmeEditor.cs +++ /dev/null @@ -1,236 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEditor; -using System; -using System.IO; -using System.Reflection; - -[CustomEditor(typeof(Readme))] -[InitializeOnLoad] -public class ReadmeEditor : Editor -{ - static string s_ShowedReadmeSessionStateName = "ReadmeEditor.showedReadme"; - - static string s_ReadmeSourceDirectory = "Assets/TutorialInfo"; - - const float k_Space = 16f; - - static ReadmeEditor() - { - EditorApplication.delayCall += SelectReadmeAutomatically; - } - - static void RemoveTutorial() - { - if (EditorUtility.DisplayDialog("Remove Readme Assets", - - $"All contents under {s_ReadmeSourceDirectory} will be removed, are you sure you want to proceed?", - "Proceed", - "Cancel")) - { - if (Directory.Exists(s_ReadmeSourceDirectory)) - { - FileUtil.DeleteFileOrDirectory(s_ReadmeSourceDirectory); - FileUtil.DeleteFileOrDirectory(s_ReadmeSourceDirectory + ".meta"); - } - else - { - Debug.Log($"Could not find the Readme folder at {s_ReadmeSourceDirectory}"); - } - - var readmeAsset = SelectReadme(); - if (readmeAsset != null) - { - var path = AssetDatabase.GetAssetPath(readmeAsset); - FileUtil.DeleteFileOrDirectory(path + ".meta"); - FileUtil.DeleteFileOrDirectory(path); - } - - AssetDatabase.Refresh(); - } - } - - static void SelectReadmeAutomatically() - { - if (!SessionState.GetBool(s_ShowedReadmeSessionStateName, false)) - { - var readme = SelectReadme(); - SessionState.SetBool(s_ShowedReadmeSessionStateName, true); - - if (readme && !readme.loadedLayout) - { - LoadLayout(); - readme.loadedLayout = true; - } - } - } - - static void LoadLayout() - { - var assembly = typeof(EditorApplication).Assembly; - var windowLayoutType = assembly.GetType("UnityEditor.WindowLayout", true); - var method = windowLayoutType.GetMethod("LoadWindowLayout", BindingFlags.Public | BindingFlags.Static); - method.Invoke(null, new object[] { Path.Combine(Application.dataPath, "TutorialInfo/Layout.wlt"), false }); - } - - static Readme SelectReadme() - { - var ids = AssetDatabase.FindAssets("Readme t:Readme"); - if (ids.Length == 1) - { - var readmeObject = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(ids[0])); - - Selection.objects = new UnityEngine.Object[] { readmeObject }; - - return (Readme)readmeObject; - } - else - { - Debug.Log("Couldn't find a readme"); - return null; - } - } - - protected override void OnHeaderGUI() - { - var readme = (Readme)target; - Init(); - - var iconWidth = Mathf.Min(EditorGUIUtility.currentViewWidth / 3f - 20f, 128f); - - GUILayout.BeginHorizontal("In BigTitle"); - { - if (readme.icon != null) - { - GUILayout.Space(k_Space); - GUILayout.Label(readme.icon, GUILayout.Width(iconWidth), GUILayout.Height(iconWidth)); - } - GUILayout.Space(k_Space); - GUILayout.BeginVertical(); - { - - GUILayout.FlexibleSpace(); - GUILayout.Label(readme.title, TitleStyle); - GUILayout.FlexibleSpace(); - } - GUILayout.EndVertical(); - GUILayout.FlexibleSpace(); - } - GUILayout.EndHorizontal(); - } - - public override void OnInspectorGUI() - { - var readme = (Readme)target; - Init(); - - foreach (var section in readme.sections) - { - if (!string.IsNullOrEmpty(section.heading)) - { - GUILayout.Label(section.heading, HeadingStyle); - } - - if (!string.IsNullOrEmpty(section.text)) - { - GUILayout.Label(section.text, BodyStyle); - } - - if (!string.IsNullOrEmpty(section.linkText)) - { - if (LinkLabel(new GUIContent(section.linkText))) - { - Application.OpenURL(section.url); - } - } - - GUILayout.Space(k_Space); - } - - if (GUILayout.Button("Remove Readme Assets", ButtonStyle)) - { - RemoveTutorial(); - } - } - - GUIStyle LinkStyle - { - get { return m_LinkStyle; } - } - - [SerializeField] - GUIStyle m_LinkStyle; - - GUIStyle TitleStyle - { - get { return m_TitleStyle; } - } - - [SerializeField] - GUIStyle m_TitleStyle; - - GUIStyle HeadingStyle - { - get { return m_HeadingStyle; } - } - - [SerializeField] - GUIStyle m_HeadingStyle; - - GUIStyle BodyStyle - { - get { return m_BodyStyle; } - } - - [SerializeField] - GUIStyle m_BodyStyle; - - GUIStyle ButtonStyle - { - get { return m_ButtonStyle; } - } - - [SerializeField] - GUIStyle m_ButtonStyle; - - void Init() - { - m_BodyStyle = new GUIStyle(EditorStyles.label); - m_BodyStyle.wordWrap = true; - m_BodyStyle.fontSize = 14; - m_BodyStyle.richText = true; - - m_TitleStyle = new GUIStyle(m_BodyStyle); - m_TitleStyle.fontSize = 26; - - m_HeadingStyle = new GUIStyle(m_BodyStyle); - m_HeadingStyle.fontStyle = FontStyle.Bold; - m_HeadingStyle.fontSize = 18; - - m_LinkStyle = new GUIStyle(m_BodyStyle); - m_LinkStyle.wordWrap = false; - - // Match selection color which works nicely for both light and dark skins - m_LinkStyle.normal.textColor = new Color(0x00 / 255f, 0x78 / 255f, 0xDA / 255f, 1f); - m_LinkStyle.stretchWidth = false; - - m_ButtonStyle = new GUIStyle(EditorStyles.miniButton); - m_ButtonStyle.fontStyle = FontStyle.Bold; - } - - bool LinkLabel(GUIContent label, params GUILayoutOption[] options) - { - var position = GUILayoutUtility.GetRect(label, LinkStyle, options); - - Handles.BeginGUI(); - Handles.color = LinkStyle.normal.textColor; - Handles.DrawLine(new Vector3(position.xMin, position.yMax), new Vector3(position.xMax, position.yMax)); - Handles.color = Color.white; - Handles.EndGUI(); - - EditorGUIUtility.AddCursorRect(position, MouseCursor.Link); - - return GUI.Button(position, label, LinkStyle); - } -} diff --git a/com.unity.template.hdrp-blank/Assets/TutorialInfo/Scripts.meta b/com.unity.template.hdrp-blank/Assets/TutorialInfo/StyleSheets.meta similarity index 100% rename from com.unity.template.hdrp-blank/Assets/TutorialInfo/Scripts.meta rename to com.unity.template.hdrp-blank/Assets/TutorialInfo/StyleSheets.meta diff --git a/com.unity.template.hdrp-blank/Assets/TutorialInfo/StyleSheets/ReadmeEditor.uss b/com.unity.template.hdrp-blank/Assets/TutorialInfo/StyleSheets/ReadmeEditor.uss new file mode 100644 index 00000000000..f2a3b405a98 --- /dev/null +++ b/com.unity.template.hdrp-blank/Assets/TutorialInfo/StyleSheets/ReadmeEditor.uss @@ -0,0 +1,75 @@ +:root { + --link-color: blue; +} + +.title +{ + margin: -2px -6px 0px -15px; + padding: 20px 6px 20px 22px; + flex-direction: row; + align-items: center; + background-color: var(--unity-colors-inspector_titlebar-background); + height: 139px; + border-bottom-width: 1px; + border-bottom-color: var(--unity-colors-inspector_titlebar-border); +} + +.title__icon +{ + max-width: 120px; + max-height: 69px; +} + +.title__text +{ + margin-left: 25px; + padding: 0px 0px 0px 0px; + font-size: 26px; + flex-shrink: 1; + white-space: normal; + overflow: hidden; +} + +.section +{ + align-items:flex-start; + margin-bottom: 16px; +} + +.section__header +{ + font-size: 20px; + white-space: normal; + -unity-font-style: bold; +} + +.section__body +{ + font-size: 14px; + white-space: normal; +} + +.section__link +{ + font-size: 14px; + white-space: nowrap; + overflow: hidden; + border-bottom-width: 0px; + margin-bottom: 0px; + border-bottom-color: var(--link-color); + color: var(--link-color); +} + +.section__link:hover +{ + border-bottom-width: 1px; + margin-bottom: -1px; + cursor: link; +} + +.remove-readme-button +{ + font-size: 13px; + -unity-font-style: bold; + margin: 1px 0px 1px 0px; +} \ No newline at end of file diff --git a/com.unity.template.hdrp-blank/Assets/TutorialInfo/StyleSheets/ReadmeEditor.uss.meta b/com.unity.template.hdrp-blank/Assets/TutorialInfo/StyleSheets/ReadmeEditor.uss.meta new file mode 100644 index 00000000000..cb3639fb639 --- /dev/null +++ b/com.unity.template.hdrp-blank/Assets/TutorialInfo/StyleSheets/ReadmeEditor.uss.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d2c670ece470f4c4fa6712b8dc28a9bb +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} + disableValidation: 0 diff --git a/com.unity.template.hdrp-blank/Assets/TutorialInfo/StyleSheets/ReadmeEditorDark.uss b/com.unity.template.hdrp-blank/Assets/TutorialInfo/StyleSheets/ReadmeEditorDark.uss new file mode 100644 index 00000000000..b9bc823c7d4 --- /dev/null +++ b/com.unity.template.hdrp-blank/Assets/TutorialInfo/StyleSheets/ReadmeEditorDark.uss @@ -0,0 +1,3 @@ +:root { + --link-color: #7DA0FF; +} \ No newline at end of file diff --git a/com.unity.template.hdrp-blank/Assets/TutorialInfo/StyleSheets/ReadmeEditorDark.uss.meta b/com.unity.template.hdrp-blank/Assets/TutorialInfo/StyleSheets/ReadmeEditorDark.uss.meta new file mode 100644 index 00000000000..07fda7218d6 --- /dev/null +++ b/com.unity.template.hdrp-blank/Assets/TutorialInfo/StyleSheets/ReadmeEditorDark.uss.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1f902e57f049a7f47986618de93f5ee1 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} + disableValidation: 0 diff --git a/com.unity.template.hdrp-blank/Assets/TutorialInfo/StyleSheets/ReadmeEditorLight.uss b/com.unity.template.hdrp-blank/Assets/TutorialInfo/StyleSheets/ReadmeEditorLight.uss new file mode 100644 index 00000000000..72fa34b90b6 --- /dev/null +++ b/com.unity.template.hdrp-blank/Assets/TutorialInfo/StyleSheets/ReadmeEditorLight.uss @@ -0,0 +1,3 @@ +:root { + --link-color: #3C28D2; +} \ No newline at end of file diff --git a/com.unity.template.hdrp-blank/Assets/TutorialInfo/StyleSheets/ReadmeEditorLight.uss.meta b/com.unity.template.hdrp-blank/Assets/TutorialInfo/StyleSheets/ReadmeEditorLight.uss.meta new file mode 100644 index 00000000000..d3aa3274595 --- /dev/null +++ b/com.unity.template.hdrp-blank/Assets/TutorialInfo/StyleSheets/ReadmeEditorLight.uss.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 69e7ab73923f93149821ac3a88b84856 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} + disableValidation: 0 diff --git a/com.unity.template.hdrp-blank/Packages/com.unity.template.hdrp-blank/CHANGELOG.md b/com.unity.template.hdrp-blank/Packages/com.unity.template.hdrp-blank/CHANGELOG.md index be8a1ec3219..83ffbfe3124 100644 --- a/com.unity.template.hdrp-blank/Packages/com.unity.template.hdrp-blank/CHANGELOG.md +++ b/com.unity.template.hdrp-blank/Packages/com.unity.template.hdrp-blank/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project template will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [17.0.8] - 2025-01-31 + +### Changed + +- Updated ReadmeEditor to use UITK with more readable link colors + ## [17.0.7] - 2025-01-27 ### Changed diff --git a/com.unity.template.hdrp-blank/Packages/com.unity.template.hdrp-blank/ValidationExceptions.json b/com.unity.template.hdrp-blank/Packages/com.unity.template.hdrp-blank/ValidationExceptions.json index 29831fce5bb..d2f2201c692 100644 --- a/com.unity.template.hdrp-blank/Packages/com.unity.template.hdrp-blank/ValidationExceptions.json +++ b/com.unity.template.hdrp-blank/Packages/com.unity.template.hdrp-blank/ValidationExceptions.json @@ -2,7 +2,7 @@ "ErrorExceptions": [ { "ValidationTest": "Primed Library Validation", - "PackageVersion": "17.0.7" + "PackageVersion": "17.0.8" } ], "WarningExceptions": [] diff --git a/com.unity.template.hdrp-blank/Packages/com.unity.template.hdrp-blank/package.json b/com.unity.template.hdrp-blank/Packages/com.unity.template.hdrp-blank/package.json index 03229708288..f3b5ceab6b6 100644 --- a/com.unity.template.hdrp-blank/Packages/com.unity.template.hdrp-blank/package.json +++ b/com.unity.template.hdrp-blank/Packages/com.unity.template.hdrp-blank/package.json @@ -1,7 +1,7 @@ { "name": "com.unity.template.hdrp-blank", "displayName":"3D HDRP", - "version": "17.0.7", + "version": "17.0.8", "type": "template", "host": "hub", "unity": "2023.3",