mirror of
https://github.com/0x7c13/Pal3.Unity.git
synced 2026-11-26 17:38:10 +08:00
Add editor function to enable/disable lighting feature flag
This commit is contained in:
1 parent
1f9e2b10f9
commit
78678024d5
5 files changed
+111
-57
No files matched your search
@@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf514aeafd514072afb9dc35e364cf81
|
||||
timeCreated: 1667895294
|
||||
@@ -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<Material>("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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29ac446b76204a4cbbaf5369808bf028
|
||||
timeCreated: 1667894961
|
||||
@@ -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<Texture2D>(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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user