Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions com.unity.template.hdrp-blank/Assets/Readme.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ClickEvent>(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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

This file was deleted.

Loading