Skip to content

Commit ccda515

Browse files
committed
From Unity-CrypticCabinet (41a0e75eb099f02eb1a538f942464b7347c9971f)
1 parent 409b42f commit ccda515

124 files changed

Lines changed: 7749 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

com.meta.tutorial.framework/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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "Meta.Tutorial.Framework.Editor",
3+
"rootNamespace": "",
4+
"references": [
5+
"Meta.Tutorial.Framework.Runtime",
6+
"Meta.XR.Guides.Editor",
7+
"Oculus.VR"
8+
],
9+
"includePlatforms": [
10+
"Editor"
11+
],
12+
"excludePlatforms": [],
13+
"allowUnsafeCode": false,
14+
"overrideReferences": false,
15+
"precompiledReferences": [],
16+
"autoReferenced": true,
17+
"defineConstraints": [],
18+
"versionDefines": [],
19+
"noEngineReferences": false
20+
}

com.meta.tutorial.framework/Editor/Meta.Tutorial.Framework.Editor.asmdef.meta

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

com.meta.tutorial.framework/Editor/Scripts.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.

com.meta.tutorial.framework/Editor/Scripts/Contexts.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
using System.IO;
4+
using Meta.Tutorial.Framework.Hub.Attributes;
5+
using Meta.Tutorial.Framework.Hub.Pages;
6+
using Meta.Tutorial.Framework.Hub.Utilities;
7+
using Meta.Tutorial.Framework.Hub.Windows;
8+
using Meta.Tutorial.Framework.Windows;
9+
using UnityEditor;
10+
using UnityEngine;
11+
12+
namespace Meta.Tutorial.Framework.Hub.Contexts
13+
{
14+
[MetaHubContext(TutorialFrameworkHub.CONTEXT)]
15+
public abstract class BaseTutorialHubContext : MetaHubContext
16+
{
17+
[SerializeField] private TutorialConfig m_tutorialConfig; // The name of the tutorial this context falls under
18+
[SerializeField] private bool m_showBanner;
19+
20+
private bool m_isInstance;
21+
22+
public TutorialConfig TutorialConfig => m_tutorialConfig;
23+
public string TutorialName => m_tutorialConfig?.Name;
24+
25+
public override string ProjectName => TutorialName;
26+
27+
public override string TelemetryContext => Telemetry.TUTORIAL_HUB_CONTEXT;
28+
29+
protected TutorialConfig.Banner Banner => m_tutorialConfig.BannerConfig;
30+
31+
protected bool ShowBanner => m_showBanner;
32+
33+
protected string GetCurrentDirectory()
34+
=> Path.GetDirectoryName(AssetDatabase.GetAssetPath(this));
35+
36+
protected string GetRootPageAssetPath()
37+
=> Path.Combine(GetCurrentDirectory(), "pages", $"{Title}.asset");
38+
39+
protected string GetChildPageAssetPath(string childName)
40+
=> Path.Combine(GetCurrentDirectory(), "pages", $"{Title}_{childName}.asset");
41+
42+
protected void EnsureDirectoryExists(string path)
43+
{
44+
if (string.IsNullOrEmpty(path))
45+
{
46+
return;
47+
}
48+
49+
var directory = Path.GetDirectoryName(path);
50+
if (!Directory.Exists(directory))
51+
{
52+
_ = Directory.CreateDirectory(directory);
53+
}
54+
}
55+
56+
/// <inheritdoc cref="MetaHubContext.ShowDefaultWindow"/>
57+
public override MetaHubBase ShowDefaultWindow() => TutorialFrameworkHub.ShowWindow();
58+
59+
/// <summary>
60+
/// Create or load an instance of a ScriptableObject. When in edit mode, it will create a new instance
61+
/// </summary>
62+
/// <param name="assetPath">The path to the asset. When in edit mode, it will create the asset at this path.</param>
63+
/// <param name="result">Loaded or instantiated object.</param>
64+
/// <param name="forceCreate">Pass true to force the creation of an instance.</param>
65+
/// <returns>True if the instance was created, false if it was loaded.
66+
/// </returns>
67+
protected bool CreateOrLoadInstance<T>(string assetPath, out T result, bool forceCreate = false) where T : ScriptableObject
68+
{
69+
#if META_EDIT_TUTORIALS
70+
if (!forceCreate && File.Exists(assetPath))
71+
{
72+
result = AssetDatabase.LoadAssetAtPath<T>(assetPath);
73+
m_isInstance = false;
74+
return m_isInstance;
75+
}
76+
else
77+
{
78+
result = CreateInstance<T>();
79+
m_isInstance = true;
80+
}
81+
return m_isInstance;
82+
#else
83+
// when not in edit mode, we shouldn't create assets, just load them.
84+
result = AssetDatabase.LoadAssetAtPath<T>(assetPath);
85+
m_isInstance = false;
86+
return m_isInstance;
87+
#endif
88+
}
89+
90+
protected T InstanceToAsset<T>(T instance, string assetPath) where T : ScriptableObject
91+
{
92+
#if META_EDIT_TUTORIALS
93+
if (m_isInstance)
94+
{
95+
EditorUtility.SetDirty(instance);
96+
EnsureDirectoryExists(assetPath);
97+
AssetDatabase.CreateAsset(instance, assetPath);
98+
m_isInstance = false;
99+
return AssetDatabase.LoadAssetAtPath<T>(assetPath);
100+
}
101+
#endif
102+
// this already is an asset when not in edit mode
103+
return instance;
104+
}
105+
106+
/// <summary>
107+
/// Create the page references for the tutorial hub
108+
/// </summary>
109+
/// <param name="forceCreate">Force the regeneration of the pages.</param>
110+
/// <returns>An array with the created page references. When more than one page is returned,
111+
/// the first page should be considered as the parent, although its foldout path will not reflect that.</returns>
112+
public abstract PageReference[] CreatePageReferences(bool forceCreate = false);
113+
114+
public override int CompareTo(MetaHubContext other)
115+
{
116+
if (other is BaseTutorialHubContext)
117+
{
118+
return base.CompareTo(other);
119+
}
120+
121+
return 1; // TutorialHubContexts are always greater than other contexts
122+
}
123+
}
124+
}

com.meta.tutorial.framework/Editor/Scripts/Contexts/BaseTutorialHubContext.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.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
using System;
4+
using Meta.Tutorial.Framework.Hub.Utilities;
5+
using Meta.Tutorial.Framework.Hub.Windows;
6+
using UnityEditor;
7+
using UnityEngine;
8+
9+
namespace Meta.Tutorial.Framework.Hub.Contexts
10+
{
11+
/// <summary>
12+
/// A documentation context that contains pages.
13+
/// </summary>
14+
public abstract class MetaHubContext : ScriptableObject, IComparable<MetaHubContext>
15+
{
16+
private const string GLOBAL_SHOW_ON_STARTUP_KEY = "Meta_Hub_Show_On_Startup_";
17+
18+
/// <summary>
19+
/// A page that is part of a context.
20+
/// </summary>
21+
[Serializable]
22+
public class ScriptableObjectReflectionPage
23+
{
24+
[Tooltip("The type of scriptable object to reflect.")]
25+
public string ScriptableObjectType;
26+
27+
[Tooltip("The foldout hierarchy name for this object.")]
28+
public string HierarchyName;
29+
30+
[Tooltip("A modifier the priority of all pages of this type.")]
31+
public int PriorityModifier;
32+
}
33+
34+
35+
[Header("Context Configuration")]
36+
37+
38+
[SerializeField, Tooltip("The title of the context")]
39+
private string m_title;
40+
41+
[SerializeField, Tooltip("The priority of this context. Lower number means higher probability that this will be the primary context.")]
42+
private int m_priority = 1000;
43+
44+
/// <summary>
45+
/// Whether to show any context on startup.
46+
/// </summary>
47+
public static bool GlobalShowOnStartup
48+
{
49+
get => EditorPrefs.GetBool(GLOBAL_SHOW_ON_STARTUP_KEY + Application.productName, true);
50+
set => EditorPrefs.SetBool(GLOBAL_SHOW_ON_STARTUP_KEY + Application.productName, value);
51+
}
52+
53+
/// <summary>
54+
/// The name of the context.
55+
/// </summary>
56+
public virtual string Name => name;
57+
58+
/// <summary>
59+
/// The priority of the context. Lower number means higher probability that this will be the primary context.
60+
/// </summary>
61+
public virtual int Priority => m_priority;
62+
63+
/// <summary>
64+
/// The title of the window if this is the primary context.
65+
/// </summary>
66+
public virtual string Title => m_title;
67+
68+
/// <summary>
69+
/// The name of the project if this is the primary context.
70+
/// </summary>
71+
public virtual string ProjectName => m_title;
72+
73+
public virtual string TelemetryContext => Telemetry.META_HUB_CONTEXT;
74+
75+
/// <summary>
76+
/// Whether the user has chosen to show this context on startup.
77+
/// </summary>
78+
public virtual bool ShowOnStartup
79+
{
80+
get => GlobalShowOnStartup;// && EditorPrefs.GetBool(StartupKey, true);
81+
set => EditorPrefs.SetBool(StartupKey, value);
82+
}
83+
84+
/// <summary>
85+
/// The key to use for startup preference.
86+
/// </summary>
87+
private string StartupKey => $"{Name}_Startup";
88+
89+
/// <inheritdoc cref="IComparable{T}.CompareTo"/>
90+
public virtual int CompareTo(MetaHubContext other)
91+
{
92+
return ReferenceEquals(this, other) ? 0 : other is null ? 1 : m_priority.CompareTo(other.m_priority);
93+
}
94+
95+
/// <summary>
96+
/// Show the default window for this context.
97+
/// </summary>
98+
public virtual MetaHubBase ShowDefaultWindow()
99+
=> MetaHubBase.ShowWindow<MetaHubBase>(Name);
100+
}
101+
}

com.meta.tutorial.framework/Editor/Scripts/Contexts/MetaHubContext.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.

0 commit comments

Comments
 (0)