Skip to content

Commit 4ab59e5

Browse files
feat: ClientDriven readme (#76)
* imported readme, removed starter assets readme files, readme wip * readme cleanup * comment feedback * Updated Readme to have a fancy client driven image Co-authored-by: jilfranco-unity <[email protected]>
1 parent 3bd2a7d commit 4ab59e5

File tree

14 files changed

+404
-249
lines changed

14 files changed

+404
-249
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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: 5ce0e387261ddc34ba81ca7f2f1f7f73, type: 3}
13+
m_Name: Readme
14+
m_EditorClassIdentifier:
15+
icon: {fileID: 2800000, guid: ffb6127603f41ed47963d81c5eb74858, type: 3}
16+
title: 'ClientDriven: A Bitesize Sample'
17+
sections:
18+
- heading: ClientDriven
19+
text: 'The ClientDriven sample is a sample project designed to demonstrate responsive
20+
3rd-person WASD character movements even under unfavourable network conditions.
21+
It also showcases how to interact with shared physics objects in a scene. The
22+
sample leverages Netcode for GameObject''s (Netcode) ClientNetworkTransform
23+
component and moves the owning player client-side, client authoritatively.
24+
Read more about the sample from the '
25+
linkText: ClientDriven bitesize sample documentation.
26+
url: https://docs-multiplayer.unity3d.com/netcode/current/learn/bitesize/bitesize-clientdriven/index.html
27+
- heading:
28+
text: The entry scene for this game is the Bootstrap scene. From there a game
29+
can be hosted or an existing game can be joined.
30+
linkText:
31+
url:
32+
- heading:
33+
text: 'To read more about Netcode and its built-in features, see the '
34+
linkText: Netcode documentation.
35+
url: https://docs-multiplayer.unity3d.com/
36+
- heading:
37+
text: 'For more information about this bitesize sample or our other bitesize
38+
samples, see the GitHub repo Readme from the '
39+
linkText: Bitesize Samples GitHub public repository.
40+
url: https://github.com/Unity-Technologies/com.unity.multiplayer.samples.bitesize
41+
loadedLayout: 1

Basic/ClientDriven/Assets/StarterAssets/Readme.asset.meta renamed to Basic/ClientDriven/Assets/Readme.asset.meta

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Basic/ClientDriven/Assets/Scripts/Readme.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Basic/ClientDriven/Assets/Scripts/Readme/Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
using UnityEngine;
2+
using UnityEditor;
3+
using System;
4+
using System.IO;
5+
using System.Reflection;
6+
7+
/// <remarks>
8+
/// Custom readme editor window based on the readme created for URP. For more context, see:
9+
/// https://github.com/Unity-Technologies/Graphics/tree/master/com.unity.template-universal
10+
/// </remarks>
11+
[CustomEditor(typeof(Readme))]
12+
[InitializeOnLoad]
13+
public class ReadmeEditor : UnityEditor.Editor
14+
{
15+
const string k_ShowedReadmeSessionStateName = "ReadmeEditor.showedReadme";
16+
17+
const float k_Space = 16f;
18+
19+
bool m_Initialized;
20+
21+
[SerializeField]
22+
GUIStyle m_LinkStyle;
23+
24+
GUIStyle LinkStyle
25+
{
26+
get { return m_LinkStyle; }
27+
}
28+
29+
[SerializeField]
30+
GUIStyle m_TitleStyle;
31+
32+
GUIStyle TitleStyle
33+
{
34+
get { return m_TitleStyle; }
35+
}
36+
37+
[SerializeField]
38+
GUIStyle m_HeadingStyle;
39+
40+
GUIStyle HeadingStyle
41+
{
42+
get { return m_HeadingStyle; }
43+
}
44+
45+
[SerializeField]
46+
GUIStyle m_BodyStyle;
47+
48+
GUIStyle BodyStyle
49+
{
50+
get { return m_BodyStyle; }
51+
}
52+
53+
static ReadmeEditor()
54+
{
55+
EditorApplication.delayCall += SelectReadmeAutomatically;
56+
}
57+
58+
static void SelectReadmeAutomatically()
59+
{
60+
if (!SessionState.GetBool(k_ShowedReadmeSessionStateName, false))
61+
{
62+
var readme = SelectReadme();
63+
SessionState.SetBool(k_ShowedReadmeSessionStateName, true);
64+
65+
if (readme && !readme.loadedLayout)
66+
{
67+
LoadLayout();
68+
readme.loadedLayout = true;
69+
}
70+
}
71+
}
72+
73+
static void LoadLayout()
74+
{
75+
var assembly = typeof(EditorApplication).Assembly;
76+
var windowLayoutType = assembly.GetType("UnityEditor.WindowLayout", true);
77+
var method = windowLayoutType.GetMethod("LoadWindowLayout", BindingFlags.Public | BindingFlags.Static);
78+
method?.Invoke(null, new object[] { Path.Combine(Application.dataPath, "TutorialInfo/Layout.wlt"), false });
79+
}
80+
81+
[MenuItem("Sample/Show Sample Instructions")]
82+
static Readme SelectReadme()
83+
{
84+
var ids = AssetDatabase.FindAssets("Readme t:Readme");
85+
if (ids.Length == 1)
86+
{
87+
var readmeObject = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(ids[0]));
88+
89+
Selection.objects = new UnityEngine.Object[] { readmeObject };
90+
91+
return (Readme)readmeObject;
92+
}
93+
else
94+
{
95+
Debug.Log("Couldn't find a readme");
96+
return null;
97+
}
98+
}
99+
100+
protected override void OnHeaderGUI()
101+
{
102+
var readme = (Readme)target;
103+
Init();
104+
105+
var iconWidth = Mathf.Min(EditorGUIUtility.currentViewWidth / 3f - 20f, 128f);
106+
107+
GUILayout.BeginHorizontal("In BigTitle");
108+
{
109+
GUILayout.Label(readme.icon, GUILayout.Width(iconWidth), GUILayout.Height(iconWidth));
110+
GUILayout.Label(readme.title, TitleStyle);
111+
}
112+
GUILayout.EndHorizontal();
113+
}
114+
115+
public override void OnInspectorGUI()
116+
{
117+
var readme = (Readme)target;
118+
Init();
119+
120+
foreach (var section in readme.sections)
121+
{
122+
if (!string.IsNullOrEmpty(section.heading))
123+
{
124+
GUILayout.Label(section.heading, HeadingStyle);
125+
}
126+
127+
if (!string.IsNullOrEmpty(section.text))
128+
{
129+
GUILayout.Label(section.text, BodyStyle);
130+
}
131+
132+
if (!string.IsNullOrEmpty(section.linkText))
133+
{
134+
if (LinkLabel(new GUIContent(section.linkText)))
135+
{
136+
Application.OpenURL(section.url);
137+
}
138+
}
139+
140+
GUILayout.Space(k_Space);
141+
}
142+
}
143+
144+
145+
146+
void Init()
147+
{
148+
if (m_Initialized)
149+
return;
150+
m_BodyStyle = new GUIStyle(EditorStyles.label);
151+
m_BodyStyle.wordWrap = true;
152+
m_BodyStyle.fontSize = 14;
153+
154+
m_TitleStyle = new GUIStyle(m_BodyStyle);
155+
m_TitleStyle.fontSize = 26;
156+
157+
m_HeadingStyle = new GUIStyle(m_BodyStyle);
158+
m_HeadingStyle.fontSize = 18;
159+
160+
m_LinkStyle = new GUIStyle(m_BodyStyle);
161+
m_LinkStyle.wordWrap = false;
162+
163+
// Match selection color which works nicely for both light and dark skins
164+
m_LinkStyle.normal.textColor = new Color(0x00 / 255f, 0x78 / 255f, 0xDA / 255f, 1f);
165+
m_LinkStyle.stretchWidth = false;
166+
167+
m_Initialized = true;
168+
}
169+
170+
bool LinkLabel(GUIContent label, params GUILayoutOption[] options)
171+
{
172+
var position = GUILayoutUtility.GetRect(label, LinkStyle, options);
173+
174+
Handles.BeginGUI();
175+
Handles.color = LinkStyle.normal.textColor;
176+
Handles.DrawLine(new Vector3(position.xMin, position.yMax), new Vector3(position.xMax, position.yMax));
177+
Handles.color = Color.white;
178+
Handles.EndGUI();
179+
180+
EditorGUIUtility.AddCursorRect(position, MouseCursor.Link);
181+
182+
return GUI.Button(position, label, LinkStyle);
183+
}
184+
}
Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using UnityEngine;
3+
4+
/// <remarks>
5+
/// Custom readme class based on the readme created for URP. For more context, see:
6+
/// https://github.com/Unity-Technologies/Graphics/tree/master/com.unity.template-universal
7+
/// </remarks>
8+
[CreateAssetMenu]
9+
public class Readme : ScriptableObject
10+
{
11+
public Texture2D icon;
12+
public string title;
13+
public Section[] sections;
14+
public bool loadedLayout;
15+
16+
[Serializable]
17+
public class Section
18+
{
19+
public string heading;
20+
public string text;
21+
public string linkText;
22+
public string url;
23+
}
24+
}

Basic/ClientDriven/Assets/Scripts/Readme/Readme.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Basic/ClientDriven/Assets/StarterAssets/Readme.asset

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)