From 38a2c8844fa029ce71334375830d7c33cedb99a8 Mon Sep 17 00:00:00 2001 From: Andy Baker Date: Thu, 19 Dec 2024 11:17:17 +0000 Subject: [PATCH 1/2] Runtime switching for experimental brushes --- Assets/Editor/BuildTiltBrush.cs | 4 +- Assets/Scenes/Main.unity | 2 +- Assets/Scripts/App.cs | 37 ++++++++------ Assets/Scripts/BrushCatalog.cs | 15 +++--- Assets/Scripts/Config.cs | 19 ++------ Assets/Scripts/EnvironmentCatalog.cs | 2 +- Assets/Scripts/GUI/AppSettingsPanel.cs | 3 +- Assets/Scripts/GUI/BrushTypeButton.cs | 2 +- Assets/Scripts/GUI/LocalePopUpWindow.cs | 2 +- Assets/Scripts/Rendering/IconTextureAtlas.cs | 2 +- Assets/Scripts/UserConfig.cs | 48 ++++++++----------- .../Localization/Strings/Strings_en.asset | 2 +- 12 files changed, 62 insertions(+), 76 deletions(-) diff --git a/Assets/Editor/BuildTiltBrush.cs b/Assets/Editor/BuildTiltBrush.cs index a8af77a93d..a63f6ed928 100644 --- a/Assets/Editor/BuildTiltBrush.cs +++ b/Assets/Editor/BuildTiltBrush.cs @@ -1435,7 +1435,7 @@ static void ShowBrushExportTextures() using (var unused = new TempHookUpSingletons()) { // Set consultUserConfig = false to keep user config from affecting the build output. - TiltBrushManifest manifest = App.Instance.GetMergedManifest(forceExperimental: true); + TiltBrushManifest manifest = App.Instance.ManifestFull; StringBuilder s = new StringBuilder(); foreach (BrushDescriptor desc in manifest.UniqueBrushes()) @@ -1547,7 +1547,7 @@ public static void DoBuild(TiltBuildOptions tiltOptions) // to be run at build-time (ie when nobody has called Start(), Awake()). // TempHookupSingletons() has done just enough initialization to make it happy. // Also set consultUserConfig = false to keep user config from affecting the build output. - TiltBrushManifest manifest = App.Instance.GetMergedManifest(forceExperimental: true); + TiltBrushManifest manifest = App.Instance.ManifestFull; // Some sanity checks { diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index 55c188aed8..0fad55d57e 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -10198,7 +10198,7 @@ MonoBehaviour: m_FadeFromBlackDuration: 3 m_QuickLoadHintDelay: 2 m_GpuIntersector: {fileID: 165291219} - m_Manifest: {fileID: 11400000, guid: 0be87170c871bfc4f91119634daa9c79, type: 2} + m_ManifestStandard: {fileID: 11400000, guid: 0be87170c871bfc4f91119634daa9c79, type: 2} m_ManifestExperimental: {fileID: 11400000, guid: 1121701af0c4d7145af70356f0ac2a83, type: 2} m_ZapboxManifest: {fileID: 11400000, guid: 7be45b23483e18347a0170a596bf2867, type: 2} diff --git a/Assets/Scripts/App.cs b/Assets/Scripts/App.cs index c26e70c583..d2bf9ba7bc 100644 --- a/Assets/Scripts/App.cs +++ b/Assets/Scripts/App.cs @@ -23,6 +23,7 @@ using UnityEngine; using Newtonsoft.Json; using TMPro; +using UnityEngine.Serialization; #if USD_SUPPORTED using Unity.Formats.USD; #endif @@ -191,11 +192,22 @@ public static void Log(string msg) [SerializeField] GpuIntersector m_GpuIntersector; - public TiltBrushManifest m_Manifest; - - // Previously Experimental-Mode only + [SerializeField] private TiltBrushManifest m_ManifestStandard; [SerializeField] private TiltBrushManifest m_ManifestExperimental; [SerializeField] private TiltBrushManifest m_ZapboxManifest; + private TiltBrushManifest m_ManifestFull; + + public TiltBrushManifest ManifestFull + { + get + { + if (m_ManifestFull == null) + { + m_ManifestFull = MergeManifests(); + } + return m_ManifestFull; + } + } [SerializeField] private SelectionEffect m_SelectionEffect; @@ -552,8 +564,6 @@ void Awake() gameObject.AddComponent(); } - m_Manifest = GetMergedManifest(); - m_HttpServer = GetComponentInChildren(); if (!Config.IsMobileHardware) { @@ -2201,19 +2211,16 @@ void OnPlaybackComplete() } } - public TiltBrushManifest GetMergedManifest(bool forceExperimental = false) + private TiltBrushManifest MergeManifests() { - var manifest = m_Manifest; - if (Config.IsExperimental || forceExperimental) +#if ZAPBOX_SUPPORTED + var manifest = m_ZapboxManifest; +#else + var manifest = Instantiate(m_ManifestStandard); + if (m_ManifestExperimental != null) { - if (m_ManifestExperimental != null) - { - manifest = Instantiate(m_Manifest); - manifest.AppendFrom(m_ManifestExperimental); - } + manifest.AppendFrom(m_ManifestExperimental); } -#if ZAPBOX_SUPPORTED - manifest = m_ZapboxManifest; #endif return manifest; } diff --git a/Assets/Scripts/BrushCatalog.cs b/Assets/Scripts/BrushCatalog.cs index 86a44c4a2e..13bdfe354a 100644 --- a/Assets/Scripts/BrushCatalog.cs +++ b/Assets/Scripts/BrushCatalog.cs @@ -189,19 +189,22 @@ public void BeginReload() m_GuiBrushList.Clear(); foreach (var brush in m_GuidToBrush.Values) { - if (brush.m_HiddenInGui) + // Some brushes are hardcoded as hidden + if (brush.m_HiddenInGui) continue; + // Always include if experimental mode is on + if (Config.IsExperimental || !App.Instance.IsBrushExperimental(brush)) { - continue; + m_GuiBrushList.Add(brush); } - m_GuiBrushList.Add(brush); } + BrushCatalogChanged?.Invoke(); } public Brush[] GetTagFilteredBrushList() { - List includeTags = App.UserConfig.Brushes.IncludeTags.ToList(); - List excludeTags = App.UserConfig.Brushes.ExcludeTags.ToList(); + List includeTags = App.UserConfig.Brushes.IncludeTags?.ToList(); + List excludeTags = App.UserConfig.Brushes.ExcludeTags?.ToList(); if (includeTags == null || includeTags.Count == 0) { @@ -288,7 +291,7 @@ Brush _FindBrushByDescription(string brushDescription) static private List LoadBrushesInManifest() { List output = new List(); - var manifest = App.Instance.m_Manifest; + var manifest = App.Instance.ManifestFull; foreach (var desc in manifest.Brushes) { if (desc != null) diff --git a/Assets/Scripts/Config.cs b/Assets/Scripts/Config.cs index efadeeb3db..8b63d49b81 100644 --- a/Assets/Scripts/Config.cs +++ b/Assets/Scripts/Config.cs @@ -113,9 +113,6 @@ private class UserConfigChange // The sdk mode indicates which SDK that we're using to drive the display. public SdkMode m_SdkMode; - // Stores the value of IsExperimental at startup time - [NonSerialized] public bool m_WasExperimentalAtStartup; - // Whether or not to just do an automatic profile and then exit. public bool m_AutoProfile; // How long to wait before starting to profile. @@ -126,7 +123,7 @@ private class UserConfigChange public string[] m_SketchFiles = new string[0]; [NonSerialized] public bool m_QuickLoad = true; - public SecretsConfig.ServiceAuthData GoogleSecrets => Secrets[SecretsConfig.Service.Google]; + public SecretsConfig.ServiceAuthData GoogleSecrets => Secrets?[SecretsConfig.Service.Google]; public SecretsConfig.ServiceAuthData SketchfabSecrets => Secrets[SecretsConfig.Service.Sketchfab]; public SecretsConfig.ServiceAuthData OculusSecrets => Secrets[SecretsConfig.Service.Oculus]; public SecretsConfig.ServiceAuthData OculusMobileSecrets => Secrets[SecretsConfig.Service.OculusMobile]; @@ -530,12 +527,6 @@ public bool GeometryShaderSuppported } } - // Non-Static version of above - public bool GetIsExperimental() - { - return PlayerPrefs.HasKey("ExperimentalMode") && PlayerPrefs.GetInt("ExperimentalMode") == 1; - } - public void SetIsExperimental(bool active) { PlayerPrefs.SetInt("ExperimentalMode", active ? 1 : 0); @@ -546,7 +537,6 @@ public void SetIsExperimental(bool active) void Awake() { m_SingletonState = this; - m_WasExperimentalAtStartup = GetIsExperimental(); #if UNITY_EDITOR if (!string.IsNullOrEmpty(m_FakeCommandLineArgsInEditor)) @@ -580,12 +570,9 @@ void Awake() #endif m_BrushReplacement = new Dictionary(); - if (IsExperimental) + foreach (var brush in m_BrushReplacementMap) { - foreach (var brush in m_BrushReplacementMap) - { - m_BrushReplacement.Add(new Guid(brush.FromGuid), new Guid(brush.ToGuid)); - } + m_BrushReplacement.Add(new Guid(brush.FromGuid), new Guid(brush.ToGuid)); } } diff --git a/Assets/Scripts/EnvironmentCatalog.cs b/Assets/Scripts/EnvironmentCatalog.cs index ffe69c8924..827a4d194a 100644 --- a/Assets/Scripts/EnvironmentCatalog.cs +++ b/Assets/Scripts/EnvironmentCatalog.cs @@ -107,7 +107,7 @@ void Update() static void LoadEnvironmentsInManifest(List output) { - var manifest = App.Instance.m_Manifest; + var manifest = App.Instance.ManifestFull; foreach (var asset in manifest.Environments) { if (asset != null) diff --git a/Assets/Scripts/GUI/AppSettingsPanel.cs b/Assets/Scripts/GUI/AppSettingsPanel.cs index ffe5450a9a..d26c00abcf 100644 --- a/Assets/Scripts/GUI/AppSettingsPanel.cs +++ b/Assets/Scripts/GUI/AppSettingsPanel.cs @@ -24,7 +24,7 @@ public class AppSettingsPanel : BasePanel public override void InitPanel() { base.InitPanel(); - m_ExperimentalModeToggle.IsToggledOn = App.Config.GetIsExperimental(); + m_ExperimentalModeToggle.IsToggledOn = Config.IsExperimental; } public void HandleToggleHandedness() @@ -43,7 +43,6 @@ public void HandleResetFirstUse() public void HandleToggleExperimentalMode(ToggleButton btn) { App.Config.SetIsExperimental(btn.IsToggledOn); - RestartNotification(); } private void RestartNotification() diff --git a/Assets/Scripts/GUI/BrushTypeButton.cs b/Assets/Scripts/GUI/BrushTypeButton.cs index 359b404a0e..37abc24f32 100644 --- a/Assets/Scripts/GUI/BrushTypeButton.cs +++ b/Assets/Scripts/GUI/BrushTypeButton.cs @@ -114,7 +114,7 @@ public void SetButtonProperties(BrushDescriptor rBrush) VisualizerManager.m_Instance.VisualsRequested); // Play standard click sound if brush doesn't have a custom button sound m_ButtonHasPressedAudio = (rBrush.m_ButtonAudio == null); - if (App.Config.m_WasExperimentalAtStartup) + if (Config.IsExperimental) { m_ExperimentalIcon.SetActive(App.Instance.IsBrushExperimental(rBrush)); } diff --git a/Assets/Scripts/GUI/LocalePopUpWindow.cs b/Assets/Scripts/GUI/LocalePopUpWindow.cs index f4344858cb..0a907810f1 100644 --- a/Assets/Scripts/GUI/LocalePopUpWindow.cs +++ b/Assets/Scripts/GUI/LocalePopUpWindow.cs @@ -47,7 +47,7 @@ override public void Init(GameObject rParent, string sText) //build list of locale presets we're going to show Locale currentSelectedLocale = LocalizationSettings.SelectedLocale; - m_Locales = App.Instance.m_Manifest.Locales; + m_Locales = App.Instance.ManifestFull.Locales; int iPresetIndex = -1; m_CurrentPresetIdCode = currentSelectedLocale.Identifier.Code; diff --git a/Assets/Scripts/Rendering/IconTextureAtlas.cs b/Assets/Scripts/Rendering/IconTextureAtlas.cs index f0fb2db86b..01520f088f 100644 --- a/Assets/Scripts/Rendering/IconTextureAtlas.cs +++ b/Assets/Scripts/Rendering/IconTextureAtlas.cs @@ -56,7 +56,7 @@ public Material GetAppropriateMaterial(bool activated, bool focus) void AtlasIconTextures() { // Load the appropriate catalog from Resources. - string catalogPath = App.Config.GetIsExperimental() ? m_ExperimentalCatalogPath : m_CatalogPath; + string catalogPath = m_ExperimentalCatalogPath; m_Catalog = Resources.Load(catalogPath); Debug.Assert(m_Catalog != null); diff --git a/Assets/Scripts/UserConfig.cs b/Assets/Scripts/UserConfig.cs index 313c82fdc6..1a811652b8 100644 --- a/Assets/Scripts/UserConfig.cs +++ b/Assets/Scripts/UserConfig.cs @@ -232,14 +232,7 @@ public string[] IncludeTags { if (m_IncludeTags == null) { - if (App.Config.GetIsExperimental()) - { - m_IncludeTags = new[] { "default", "experimental" }; - } - else - { - m_IncludeTags = new[] { "default" }; - } + m_IncludeTags = new[] { "default", "experimental" }; } return m_IncludeTags; } @@ -550,37 +543,34 @@ public Dictionary BrushReplacementMap get { Dictionary results = new Dictionary(); - if (Config.IsExperimental) + if (string.IsNullOrEmpty(BrushReplacements)) { - if (string.IsNullOrEmpty(BrushReplacements)) - { - return results; - } - var replacements = BrushReplacements.Split(','); - foreach (string replacement in replacements) + return results; + } + var replacements = BrushReplacements.Split(','); + foreach (string replacement in replacements) + { + string[] pair = replacement.Split('='); + if (pair.Length == 2) { - string[] pair = replacement.Split('='); - if (pair.Length == 2) + if (pair[0] == "*") { - if (pair[0] == "*") - { - Guid guid = new Guid(pair[1]); - foreach (var brush in App.Instance.m_Manifest.Brushes) - { - results.Add(brush.m_Guid, guid); - } - } - else + Guid guid = new Guid(pair[1]); + foreach (var brush in App.Instance.ManifestFull.Brushes) { - results.Add(new Guid(pair[0]), new Guid(pair[1])); + results.Add(brush.m_Guid, guid); } } else { - OutputWindowScript.Error("BrushReplacement should be of the form:\n" + - "brushguidA=brushguidB,brushguidC=brushguidD"); + results.Add(new Guid(pair[0]), new Guid(pair[1])); } } + else + { + OutputWindowScript.Error("BrushReplacement should be of the form:\n" + + "brushguidA=brushguidB,brushguidC=brushguidD"); + } } return results; } diff --git a/Assets/Settings/Localization/Strings/Strings_en.asset b/Assets/Settings/Localization/Strings/Strings_en.asset index 0c50b585da..d5841d6ce2 100644 --- a/Assets/Settings/Localization/Strings/Strings_en.asset +++ b/Assets/Settings/Localization/Strings/Strings_en.asset @@ -3081,7 +3081,7 @@ MonoBehaviour: m_Metadata: m_Items: [] - m_Id: 89093153698373632 - m_Localized: (Restart required) + m_Localized: Less compatibility when exported. See our docs. m_Metadata: m_Items: [] - m_Id: 89093320602312704 From f6bbc948b9094cc70e35d0551a752643760fbb29 Mon Sep 17 00:00:00 2001 From: Andy Baker Date: Thu, 19 Dec 2024 12:06:14 +0000 Subject: [PATCH 2/2] Icon experimental badges need to update all the time --- Assets/Scripts/GUI/BrushTypeButton.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Assets/Scripts/GUI/BrushTypeButton.cs b/Assets/Scripts/GUI/BrushTypeButton.cs index 37abc24f32..dd63934f8b 100644 --- a/Assets/Scripts/GUI/BrushTypeButton.cs +++ b/Assets/Scripts/GUI/BrushTypeButton.cs @@ -114,10 +114,7 @@ public void SetButtonProperties(BrushDescriptor rBrush) VisualizerManager.m_Instance.VisualsRequested); // Play standard click sound if brush doesn't have a custom button sound m_ButtonHasPressedAudio = (rBrush.m_ButtonAudio == null); - if (Config.IsExperimental) - { - m_ExperimentalIcon.SetActive(App.Instance.IsBrushExperimental(rBrush)); - } + m_ExperimentalIcon.SetActive(App.Instance.IsBrushExperimental(rBrush)); } override protected void OnDescriptionActivated()