diff --git a/Assets/Scripts/Editor/EditorHelper.cs b/Assets/Scripts/Editor/EditorHelper.cs new file mode 100644 index 00000000..e836ae73 --- /dev/null +++ b/Assets/Scripts/Editor/EditorHelper.cs @@ -0,0 +1,64 @@ +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Editor +{ + using System.Linq; + using UnityEditor; + using UnityEditor.Build; + + public static class EditorHelper + { + public static BuildTargetGroup[] GetAllSupportedTargetGroups() + { + return new[] + { + BuildTargetGroup.Android, + BuildTargetGroup.Standalone, + BuildTargetGroup.iOS, + }; + } + + public static NamedBuildTarget[] GetAllSupportedNamedBuildTargets() + { + return new[] + { + NamedBuildTarget.Android, + NamedBuildTarget.Standalone, + NamedBuildTarget.iOS, + }; + } + + public static void AddSymbol(string symbolToAdd) + { + foreach (BuildTargetGroup targetGroup in GetAllSupportedTargetGroups()) + { + var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup); + var allDefines = defines.Split(';').ToList(); + if (!allDefines.Any(_ => string.Equals(_, symbolToAdd))) + { + allDefines.Add(symbolToAdd); + } + allDefines.Sort(); + PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, + string.Join(";", allDefines.ToArray())); + } + } + + public static void RemoveSymbol(string symbolToDelete) + { + foreach (BuildTargetGroup targetGroup in GetAllSupportedTargetGroups()) + { + var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup); + var allDefines = defines.Split(';').ToList(); + var newDefines = allDefines + .Where(_ => !string.Equals(_, symbolToDelete)).ToList(); + newDefines.Sort(); + PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, + string.Join(";", newDefines.ToArray())); + } + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Editor/EditorHelper.cs.meta b/Assets/Scripts/Editor/EditorHelper.cs.meta new file mode 100644 index 00000000..051e264c --- /dev/null +++ b/Assets/Scripts/Editor/EditorHelper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: cf514aeafd514072afb9dc35e364cf81 +timeCreated: 1667895294 \ No newline at end of file diff --git a/Assets/Scripts/Editor/FeatureEnablement.cs b/Assets/Scripts/Editor/FeatureEnablement.cs new file mode 100644 index 00000000..45efb85a --- /dev/null +++ b/Assets/Scripts/Editor/FeatureEnablement.cs @@ -0,0 +1,34 @@ +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Editor +{ + using UnityEditor; + using UnityEngine; + + public static class FeatureEnablement + { + [MenuItem("Pal3/Extra Features/Realtime lighting and shadow/Enable")] + public static void EnableRealtimeLightingAndShadow() + { + if (Resources.Load("Materials/Toon") != null) + { + EditorHelper.AddSymbol("RTX_ON"); + AssetDatabase.SaveAssets(); + } + else + { + Debug.LogError("Failed to enable realtime lighting and shadow since RealToon material was not found."); + } + } + + [MenuItem("Pal3/Extra Features/Realtime lighting and shadow/Disable")] + public static void DisableRealtimeLightingAndShadow() + { + EditorHelper.RemoveSymbol("RTX_ON"); + AssetDatabase.SaveAssets(); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Editor/FeatureEnablement.cs.meta b/Assets/Scripts/Editor/FeatureEnablement.cs.meta new file mode 100644 index 00000000..350679f6 --- /dev/null +++ b/Assets/Scripts/Editor/FeatureEnablement.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 29ac446b76204a4cbbaf5369808bf028 +timeCreated: 1667894961 \ No newline at end of file diff --git a/Assets/Scripts/Editor/GameVariantSwitcher.cs b/Assets/Scripts/Editor/GameVariantSwitcher.cs index f9d968fe..3575a1e0 100644 --- a/Assets/Scripts/Editor/GameVariantSwitcher.cs +++ b/Assets/Scripts/Editor/GameVariantSwitcher.cs @@ -17,45 +17,25 @@ namespace Editor [MenuItem("Pal3/Switch Variant/PAL3")] public static void SwitchToPal3() { - RemoveSymbol("PAL3A"); - AddSymbol("PAL3"); + EditorHelper.RemoveSymbol("PAL3A"); + EditorHelper.AddSymbol("PAL3"); ApplyPlayerSettingsForVariant("PAL3"); } [MenuItem("Pal3/Switch Variant/PAL3A")] public static void SwitchToPal3A() { - RemoveSymbol("PAL3"); - AddSymbol("PAL3A"); + EditorHelper.RemoveSymbol("PAL3"); + EditorHelper.AddSymbol("PAL3A"); ApplyPlayerSettingsForVariant("PAL3A"); } - - private static BuildTargetGroup[] GetAllSupportedTargetGroups() - { - return new[] - { - BuildTargetGroup.Android, - BuildTargetGroup.Standalone, - BuildTargetGroup.iOS, - }; - } - - private static NamedBuildTarget[] GetAllSupportedNamedBuildTargets() - { - return new[] - { - NamedBuildTarget.Android, - NamedBuildTarget.Standalone, - NamedBuildTarget.iOS, - }; - } - + private static void ApplyPlayerSettingsForVariant(string appName) { PlayerSettings.productName = appName; PlayerSettings.companyName = GameConstants.CompanyName; - foreach (BuildTargetGroup targetGroup in GetAllSupportedTargetGroups()) + foreach (BuildTargetGroup targetGroup in EditorHelper.GetAllSupportedTargetGroups()) { PlayerSettings.SetApplicationIdentifier(targetGroup, $"{GameConstants.AppIdentifierPrefix}.{appName}"); @@ -65,7 +45,7 @@ namespace Editor var gameIcon = Resources.Load(gameIconPath); if (gameIcon == null) throw new Exception($"Game icon not found: {gameIconPath}"); - foreach (NamedBuildTarget buildTarget in GetAllSupportedNamedBuildTargets()) + foreach (NamedBuildTarget buildTarget in EditorHelper.GetAllSupportedNamedBuildTargets()) { // Set app icon var iconSizes = PlayerSettings.GetIconSizes(buildTarget, IconKind.Application); @@ -85,35 +65,5 @@ namespace Editor AssetDatabase.SaveAssets(); } - - private static void AddSymbol(string symbolToAdd) - { - foreach (BuildTargetGroup targetGroup in GetAllSupportedTargetGroups()) - { - var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup); - var allDefines = defines.Split(';').ToList(); - if (!allDefines.Any(_ => string.Equals(_, symbolToAdd))) - { - allDefines.Add(symbolToAdd); - } - allDefines.Sort(); - PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, - string.Join(";", allDefines.ToArray())); - } - } - - private static void RemoveSymbol(string symbolToDelete) - { - foreach (BuildTargetGroup targetGroup in GetAllSupportedTargetGroups()) - { - var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup); - var allDefines = defines.Split(';').ToList(); - var newDefines = allDefines - .Where(_ => !string.Equals(_, symbolToDelete)).ToList(); - newDefines.Sort(); - PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, - string.Join(";", newDefines.ToArray())); - } - } } } \ No newline at end of file