Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
39 changes: 39 additions & 0 deletions Basic/2DSpaceShooter/Assets/Readme.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3c6391202b371bf4f9b33f30f57e6b4c, type: 3}
m_Name: Readme
m_EditorClassIdentifier:
icon: {fileID: 2800000, guid: 6032b1899b04de841b94d52688040780, type: 3}
title: '2DSpaceShooter: A Bitesize Sample'
sections:
- heading: 2DSpaceShooter
text: 'The 2DSpaceShooter sample is a bitesize sample designed to demonstrate
networked 2D and physics-based character movement. This sample leverages Netcode
for GameObject''s (Netcode) NetworkRigidbody2D component and also showcases
object pooling. Read more about the sample from the '
linkText: 2DSpaceShooter bitesize sample documentation page.
url: https://docs-multiplayer.unity3d.com/netcode/current/learn/bitesize/bitesize-spaceshooter/index.html
- heading:
text: The entry scene for this game is the network scene. From there a game can
be hosted or an existing game can be joined.
linkText:
url:
- heading:
text: 'To read more about Netcode and its built-in features, see the '
linkText: Netcode documentation.
url: https://docs-multiplayer.unity3d.com/
- heading:
text: 'For more information about this bitesize sample or our other bitesize
samples, see the GitHub repo Readme from the '
linkText: Bitesize Samples GitHub public repository.
url: https://github.com/Unity-Technologies/com.unity.multiplayer.samples.bitesize
loadedLayout: 1
8 changes: 8 additions & 0 deletions Basic/2DSpaceShooter/Assets/Readme.asset.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Basic/2DSpaceShooter/Assets/Scripts/Readme.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Basic/2DSpaceShooter/Assets/Scripts/Readme/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

184 changes: 184 additions & 0 deletions Basic/2DSpaceShooter/Assets/Scripts/Readme/Editor/ReadmeEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
using UnityEngine;
using UnityEditor;
using System;
using System.IO;
using System.Reflection;

/// <remarks>
/// Custom readme editor window based on the readme created for URP. For more context, see:
/// https://github.com/Unity-Technologies/Graphics/tree/master/com.unity.template-universal
/// </remarks>
[CustomEditor(typeof(Readme))]
[InitializeOnLoad]
public class ReadmeEditor : UnityEditor.Editor
{
const string k_ShowedReadmeSessionStateName = "ReadmeEditor.showedReadme";

const float k_Space = 16f;

bool m_Initialized;

[SerializeField]
GUIStyle m_LinkStyle;

GUIStyle LinkStyle
{
get { return m_LinkStyle; }
}

[SerializeField]
GUIStyle m_TitleStyle;

GUIStyle TitleStyle
{
get { return m_TitleStyle; }
}

[SerializeField]
GUIStyle m_HeadingStyle;

GUIStyle HeadingStyle
{
get { return m_HeadingStyle; }
}

[SerializeField]
GUIStyle m_BodyStyle;

GUIStyle BodyStyle
{
get { return m_BodyStyle; }
}

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)
{
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 });
}

[MenuItem("Sample/Show Sample Instructions")]
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");
{
GUILayout.Label(readme.icon, GUILayout.Width(iconWidth), GUILayout.Height(iconWidth));
GUILayout.Label(readme.title, TitleStyle);
}
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);
}
}



void Init()
{
if (m_Initialized)
return;
m_BodyStyle = new GUIStyle(EditorStyles.label);
m_BodyStyle.wordWrap = true;
m_BodyStyle.fontSize = 14;

m_TitleStyle = new GUIStyle(m_BodyStyle);
m_TitleStyle.fontSize = 26;

m_HeadingStyle = new GUIStyle(m_BodyStyle);
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_Initialized = true;
}

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);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Basic/2DSpaceShooter/Assets/Scripts/Readme/Readme.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using UnityEngine;

/// <remarks>
/// Custom readme class based on the readme created for URP. For more context, see:
/// https://github.com/Unity-Technologies/Graphics/tree/master/com.unity.template-universal
/// </remarks>
[CreateAssetMenu]
public class Readme : ScriptableObject
{
public Texture2D icon;
public string title;
public Section[] sections;
public bool loadedLayout;

[Serializable]
public class Section
{
public string heading;
public string text;
public string linkText;
public string url;
}
}
11 changes: 11 additions & 0 deletions Basic/2DSpaceShooter/Assets/Scripts/Readme/Readme.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions Basic/2DSpaceShooter/Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"dependencies": {
"com.unity.2d.sprite": "1.0.0",
"com.unity.collab-proxy": "1.17.2",
"com.unity.ide.rider": "3.0.15",
"com.unity.collab-proxy": "1.17.7",
"com.unity.ide.rider": "3.0.16",
"com.unity.ide.visualstudio": "2.0.16",
"com.unity.ide.vscode": "1.2.5",
"com.unity.netcode.gameobjects": "1.0.2",
"com.unity.multiplayer.samples.coop": "https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop.git?path=/Packages/com.unity.multiplayer.samples.coop",
"com.unity.netcode.gameobjects": "1.1.0",
"com.unity.postprocessing": "3.2.2",
"com.unity.render-pipelines.universal": "12.1.7",
"com.unity.render-pipelines.universal": "12.1.8",
"com.unity.test-framework": "1.1.31",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.6.4",
Expand Down
Loading