Skip to content

Commit ead75cb

Browse files
committedFeb 21, 2025
added readme asset for quick overview on usage and functionality
1 parent 91ce4f1 commit ead75cb

File tree

7 files changed

+265
-0
lines changed

7 files changed

+265
-0
lines changed
 

‎Samples~/Readme.asset

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: fcf7219bab7fe46a1ad266029b2fee19, type: 3}
13+
m_Name: Readme
14+
m_EditorClassIdentifier:
15+
title: How to use Unity Singleton
16+
sections:
17+
- heading: Example Usage
18+
text:
19+
- This is a quick demo on how to use the Unity Singleton Package
20+
- 'To quickly test it out:'
21+
- "\u2022 Go to the Scenes in this Samples folder"
22+
- "\u2022 Add the scenes in the following order"
23+
- " \u2022 _Preload"
24+
- " \u2022 Main Menu"
25+
- "\u2022 Then open the Scenes folder and edit the name parameter on the GameManager component attached to the GameManager object"
26+
- "\u2022 Save and press play"
27+
- "\u2022 The scene will change to the Main Menu, and the log will print out the name provided"
28+
- heading: Functionality overview
29+
text:
30+
- Add using UnityCommunity.UnitySingleton; for using the classes
31+
- "\u2022 Use Singleton<T> for plain C# classes"
32+
- "\u2022 Use MonoSingleton<T> if you want a Scene-based singleton which is not persistent across scenes"
33+
- "\u2022 Use PersistentMonoSingleton<T> if you want a Global and persistent singleton across scenes"

‎Samples~/SamplesGuideInfo/Scripts.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Samples~/SamplesGuideInfo/Scripts/Editor.meta

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
// Copyright (c) Unity Technologies.
2+
// Based on the "URP TutorialInfo ReadmeEditor.cs" script included in URP template projects.
3+
//
4+
// Original asset by Unity Technologies. This version has been modified to display
5+
// a custom Readme.asset in the Inspector about how to use the Singletons package
6+
//
7+
// Modified by github.com/ThatAmuzak - 2025
8+
9+
using UnityEngine;
10+
using UnityEditor;
11+
using System.IO;
12+
13+
[CustomEditor(typeof(Readme))]
14+
public class ReadmeEditor : Editor
15+
{
16+
static string s_ReadmeSourceDirectory = "Assets/Samples/Unity Singleton/3.0.0/Samples/SamplesGuideInfo";
17+
18+
const float k_Space = 8f;
19+
20+
static void RemoveTutorial()
21+
{
22+
if (EditorUtility.DisplayDialog("Remove Readme Assets",
23+
24+
$"All contents under {s_ReadmeSourceDirectory} will be removed, are you sure you want to proceed?",
25+
"Proceed",
26+
"Cancel"))
27+
{
28+
if (Directory.Exists(s_ReadmeSourceDirectory))
29+
{
30+
FileUtil.DeleteFileOrDirectory(s_ReadmeSourceDirectory);
31+
FileUtil.DeleteFileOrDirectory(s_ReadmeSourceDirectory + ".meta");
32+
}
33+
else
34+
{
35+
Debug.Log($"Could not find the Readme folder at {s_ReadmeSourceDirectory}");
36+
}
37+
38+
var readmeAsset = SelectReadme();
39+
if (readmeAsset != null)
40+
{
41+
var path = AssetDatabase.GetAssetPath(readmeAsset);
42+
FileUtil.DeleteFileOrDirectory(path + ".meta");
43+
FileUtil.DeleteFileOrDirectory(path);
44+
}
45+
46+
AssetDatabase.Refresh();
47+
}
48+
}
49+
50+
static Readme SelectReadme()
51+
{
52+
var ids = AssetDatabase.FindAssets("Readme t:Readme");
53+
if (ids.Length == 1)
54+
{
55+
var readmeObject = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(ids[0]));
56+
57+
Selection.objects = new[] { readmeObject };
58+
59+
return (Readme)readmeObject;
60+
}
61+
62+
Debug.Log("Couldn't find a readme");
63+
return null;
64+
}
65+
66+
protected override void OnHeaderGUI()
67+
{
68+
var readme = (Readme)target;
69+
Init();
70+
71+
GUILayout.BeginHorizontal("In BigTitle");
72+
{
73+
GUILayout.Space(k_Space);
74+
GUILayout.BeginVertical();
75+
{
76+
77+
GUILayout.FlexibleSpace();
78+
GUILayout.Label(readme.title, TitleStyle);
79+
GUILayout.FlexibleSpace();
80+
}
81+
GUILayout.EndVertical();
82+
GUILayout.FlexibleSpace();
83+
}
84+
GUILayout.EndHorizontal();
85+
}
86+
87+
public override void OnInspectorGUI()
88+
{
89+
var readme = (Readme)target;
90+
Init();
91+
Rect rect;
92+
foreach (var section in readme.sections)
93+
{
94+
GUILayout.Space(k_Space);
95+
rect = EditorGUILayout.GetControlRect(false, 2 );
96+
rect.height = 2;
97+
EditorGUI.DrawRect(rect, new Color ( 0.5f,0.5f,0.5f, 1 ) );
98+
GUILayout.Space(k_Space);
99+
100+
if (!string.IsNullOrEmpty(section.heading))
101+
{
102+
GUILayout.Label(section.heading, HeadingStyle);
103+
}
104+
105+
foreach (var subtext in section.text)
106+
{
107+
if (!string.IsNullOrEmpty(subtext))
108+
{
109+
GUILayout.Label(subtext, BodyStyle);
110+
}
111+
}
112+
}
113+
GUILayout.Space(k_Space);
114+
rect = EditorGUILayout.GetControlRect(false, 2 );
115+
rect.height = 2;
116+
GUILayout.Space(k_Space);
117+
if (GUILayout.Button("Remove Readme Assets", ButtonStyle))
118+
{
119+
RemoveTutorial();
120+
}
121+
}
122+
123+
bool m_Initialized;
124+
125+
GUIStyle TitleStyle => m_TitleStyle;
126+
127+
[SerializeField]
128+
GUIStyle m_TitleStyle;
129+
130+
GUIStyle HeadingStyle => m_HeadingStyle;
131+
132+
[SerializeField]
133+
GUIStyle m_HeadingStyle;
134+
135+
GUIStyle BodyStyle => m_BodyStyle;
136+
137+
[SerializeField]
138+
GUIStyle m_BodyStyle;
139+
140+
GUIStyle ButtonStyle => m_ButtonStyle;
141+
142+
[SerializeField]
143+
GUIStyle m_ButtonStyle;
144+
145+
void Init()
146+
{
147+
if (m_Initialized)
148+
return;
149+
m_BodyStyle = new GUIStyle(EditorStyles.label);
150+
m_BodyStyle.wordWrap = true;
151+
m_BodyStyle.fontSize = 14;
152+
m_BodyStyle.richText = true;
153+
154+
m_TitleStyle = new GUIStyle(m_BodyStyle);
155+
m_TitleStyle.fontSize = 26;
156+
157+
m_HeadingStyle = new GUIStyle(m_BodyStyle);
158+
m_HeadingStyle.fontStyle = FontStyle.Bold;
159+
m_HeadingStyle.fontSize = 18;
160+
161+
m_ButtonStyle = new GUIStyle(EditorStyles.miniButton);
162+
m_ButtonStyle.fontStyle = FontStyle.Bold;
163+
164+
m_Initialized = true;
165+
}
166+
}

‎Samples~/SamplesGuideInfo/Scripts/Editor/ReadmeEditor.cs.meta

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) Unity Technologies.
2+
// Based on the "URP TutorialInfo ReadmeEditor.cs" script included in URP template projects.
3+
//
4+
// Original asset by Unity Technologies. This version has been modified to display
5+
// a custom Readme.asset in the Inspector about how to use the Singletons package
6+
//
7+
// Modified by ThatAmuzak - 2025
8+
9+
using System;
10+
using System.Collections.Generic;
11+
using UnityEngine;
12+
13+
[CreateAssetMenu(fileName = "Readme", menuName = "ScriptableObjects/Readme", order = 1)]
14+
public class Readme : ScriptableObject
15+
{
16+
public string title;
17+
public Section[] sections;
18+
19+
[Serializable]
20+
public class Section
21+
{
22+
public string heading;
23+
public List<string> text;
24+
}
25+
}

‎Samples~/SamplesGuideInfo/Scripts/Readme.cs.meta

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Failed to load comments.