Add: AlchemySettings

This commit is contained in:
AnnulusGames 2024-02-16 19:49:46 +09:00
parent f9d099985b
commit 5de738d459
8 changed files with 260 additions and 25 deletions

View File

@ -0,0 +1,38 @@
using System.IO;
using UnityEngine;
using Alchemy.Hierarchy;
namespace Alchemy.Editor
{
public sealed class AlchemySettings : ScriptableObject
{
static readonly string SettingsPath = "ProjectSettings/AlchemySettings.json";
static AlchemySettings instance;
public static AlchemySettings GetOrCreateSettings()
{
if (instance != null) return instance;
if (File.Exists(SettingsPath))
{
instance = CreateInstance<AlchemySettings>();
JsonUtility.FromJsonOverwrite(File.ReadAllText(SettingsPath), instance);
}
else
{
instance = CreateInstance<AlchemySettings>();
}
return instance;
}
public static void SaveSettings()
{
File.WriteAllText(SettingsPath, JsonUtility.ToJson(instance, true));
}
[SerializeField] HierarchyObjectMode hierarchyObjectMode = HierarchyObjectMode.RemoveInBuild;
public HierarchyObjectMode HierarchyObjectMode => hierarchyObjectMode;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: be6c5afdb20ff4718b97d2eeeb1787e2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,69 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace Alchemy.Editor
{
internal static class AlchemySettingsProvider
{
static readonly string MenuName = "Project/Alchemy";
[SettingsProvider]
public static SettingsProvider CreateSettingsProvider()
{
static Label CreateHeader(string text)
{
return new Label(text)
{
style = {
unityFontStyleAndWeight = FontStyle.Bold,
marginLeft = 2f,
marginTop = 3f,
}
};
}
return new SettingsProvider(MenuName, SettingsScope.Project)
{
keywords = new HashSet<string>(new[] { "Alchemy, Inspector, Hierarchy" }),
activateHandler = (searchContext, rootElement) =>
{
var serializedObject = new SerializedObject(AlchemySettings.GetOrCreateSettings());
var root = new VisualElement
{
style = {
marginLeft = 10f
}
};
rootElement.Add(root);
var label = new Label("Alchemy")
{
style = {
unityFontStyleAndWeight = FontStyle.Bold,
fontSize = 20,
marginTop = 3f,
marginBottom = 5f
}
};
root.Add(label);
var hierarchyHeader = CreateHeader("Hierarchy");
root.Add(hierarchyHeader);
var hierarchyObjectModeField = new PropertyField(serializedObject.FindProperty("hierarchyObjectMode"));
root.Add(hierarchyObjectModeField);
root.Bind(serializedObject);
root.TrackSerializedObjectValue(serializedObject, so =>
{
AlchemySettings.SaveSettings();
});
},
};
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7430b79e486304556b32ebe13b6674b2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -2,9 +2,9 @@ using System.Linq;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;
using UnityEngine.SceneManagement;
using Alchemy.Hierarchy;
using UnityEngine;
namespace Alchemy.Editor
{
@ -14,14 +14,16 @@ namespace Alchemy.Editor
public void OnProcessScene(Scene scene, BuildReport report)
{
var settings = AlchemySettings.GetOrCreateSettings();
var hierarchyObjects = scene.GetRootGameObjects()
.SelectMany(x => x.GetComponentsInChildren<HierarchyObject>())
.Where(x => x != null)
.ToArray();
foreach (var obj in hierarchyObjects)
{
switch (obj.HierarchyObjectMode)
switch (GetHierarchyObjectMode(obj))
{
case HierarchyObjectMode.None: break;
case HierarchyObjectMode.RemoveInPlayMode:
@ -37,7 +39,8 @@ namespace Alchemy.Editor
foreach (var obj in hierarchyObjects)
{
if (obj == null) continue;
switch (obj.HierarchyObjectMode)
switch (GetHierarchyObjectMode(obj))
{
case HierarchyObjectMode.None: break;
case HierarchyObjectMode.RemoveInPlayMode:
@ -51,6 +54,13 @@ namespace Alchemy.Editor
}
}
static HierarchyObjectMode GetHierarchyObjectMode(HierarchyObject obj)
{
return obj.HierarchyObjectMode != HierarchyObject.Mode.UseSettings
? (HierarchyObjectMode)obj.HierarchyObjectMode
: AlchemySettings.GetOrCreateSettings().HierarchyObjectMode;
}
static void PreRemove(HierarchyObject obj)
{
if (obj == null) return;
@ -62,7 +72,7 @@ namespace Alchemy.Editor
if (root == null) goto LOOP_END;
if (!root.TryGetComponent<HierarchyObject>(out var hierarchyObject)) goto LOOP_END;
switch (hierarchyObject.HierarchyObjectMode)
switch (GetHierarchyObjectMode(hierarchyObject))
{
case HierarchyObjectMode.None:
goto LOOP_END;

View File

@ -6,7 +6,14 @@ namespace Alchemy.Hierarchy
[AddComponentMenu("Alchemy/Hierarchy Object")]
public class HierarchyObject : MonoBehaviour
{
[SerializeField] HierarchyObjectMode hierarchyObjectMode = HierarchyObjectMode.RemoveInBuild;
public HierarchyObjectMode HierarchyObjectMode => hierarchyObjectMode;
public enum Mode
{
UseSettings = 0,
RemoveInPlayMode = 1,
RemoveInBuild = 2
}
[SerializeField] Mode hierarchyObjectMode = Mode.UseSettings;
public Mode HierarchyObjectMode => hierarchyObjectMode;
}
}

View File

@ -0,0 +1,3 @@
{
"hierarchyObjectMode": 2
}

View File

@ -6,7 +6,7 @@ QualitySettings:
serializedVersion: 5
m_CurrentQuality: 5
m_QualitySettings:
- serializedVersion: 2
- serializedVersion: 3
name: Very Low
pixelLightCount: 0
shadows: 0
@ -18,17 +18,21 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 0
blendWeights: 1
textureQuality: 1
skinWeights: 1
globalTextureMipmapLimit: 1
textureMipmapLimitSettings: []
anisotropicTextures: 0
antiAliasing: 0
softParticles: 0
softVegetation: 0
realtimeReflectionProbes: 0
billboardsFaceCameraPosition: 0
useLegacyDetailDistribution: 1
vSyncCount: 0
realtimeGICPUUsage: 25
lodBias: 0.3
maximumLODLevel: 0
enableLODCrossFade: 1
streamingMipmapsActive: 0
streamingMipmapsAddAllCameras: 1
streamingMipmapsMemoryBudget: 512
@ -40,8 +44,18 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
terrainQualityOverrides: 0
terrainPixelError: 1
terrainDetailDensityScale: 1
terrainBasemapDistance: 1000
terrainDetailDistance: 80
terrainTreeDistance: 5000
terrainBillboardStart: 50
terrainFadeLength: 5
terrainMaxTrees: 50
excludedTargetPlatforms: []
- serializedVersion: 2
- serializedVersion: 3
name: Low
pixelLightCount: 0
shadows: 0
@ -53,17 +67,21 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 0
blendWeights: 2
textureQuality: 0
skinWeights: 2
globalTextureMipmapLimit: 0
textureMipmapLimitSettings: []
anisotropicTextures: 0
antiAliasing: 0
softParticles: 0
softVegetation: 0
realtimeReflectionProbes: 0
billboardsFaceCameraPosition: 0
useLegacyDetailDistribution: 1
vSyncCount: 0
realtimeGICPUUsage: 25
lodBias: 0.4
maximumLODLevel: 0
enableLODCrossFade: 1
streamingMipmapsActive: 0
streamingMipmapsAddAllCameras: 1
streamingMipmapsMemoryBudget: 512
@ -75,8 +93,18 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
terrainQualityOverrides: 0
terrainPixelError: 1
terrainDetailDensityScale: 1
terrainBasemapDistance: 1000
terrainDetailDistance: 80
terrainTreeDistance: 5000
terrainBillboardStart: 50
terrainFadeLength: 5
terrainMaxTrees: 50
excludedTargetPlatforms: []
- serializedVersion: 2
- serializedVersion: 3
name: Medium
pixelLightCount: 1
shadows: 1
@ -88,17 +116,21 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 0
blendWeights: 2
textureQuality: 0
skinWeights: 2
globalTextureMipmapLimit: 0
textureMipmapLimitSettings: []
anisotropicTextures: 1
antiAliasing: 0
softParticles: 0
softVegetation: 0
realtimeReflectionProbes: 0
billboardsFaceCameraPosition: 0
useLegacyDetailDistribution: 1
vSyncCount: 1
realtimeGICPUUsage: 25
lodBias: 0.7
maximumLODLevel: 0
enableLODCrossFade: 1
streamingMipmapsActive: 0
streamingMipmapsAddAllCameras: 1
streamingMipmapsMemoryBudget: 512
@ -110,8 +142,18 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
terrainQualityOverrides: 0
terrainPixelError: 1
terrainDetailDensityScale: 1
terrainBasemapDistance: 1000
terrainDetailDistance: 80
terrainTreeDistance: 5000
terrainBillboardStart: 50
terrainFadeLength: 5
terrainMaxTrees: 50
excludedTargetPlatforms: []
- serializedVersion: 2
- serializedVersion: 3
name: High
pixelLightCount: 2
shadows: 2
@ -123,17 +165,21 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 1
blendWeights: 2
textureQuality: 0
skinWeights: 2
globalTextureMipmapLimit: 0
textureMipmapLimitSettings: []
anisotropicTextures: 1
antiAliasing: 0
softParticles: 0
softVegetation: 1
realtimeReflectionProbes: 1
billboardsFaceCameraPosition: 1
useLegacyDetailDistribution: 1
vSyncCount: 1
realtimeGICPUUsage: 50
lodBias: 1
maximumLODLevel: 0
enableLODCrossFade: 1
streamingMipmapsActive: 0
streamingMipmapsAddAllCameras: 1
streamingMipmapsMemoryBudget: 512
@ -145,8 +191,18 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
terrainQualityOverrides: 0
terrainPixelError: 1
terrainDetailDensityScale: 1
terrainBasemapDistance: 1000
terrainDetailDistance: 80
terrainTreeDistance: 5000
terrainBillboardStart: 50
terrainFadeLength: 5
terrainMaxTrees: 50
excludedTargetPlatforms: []
- serializedVersion: 2
- serializedVersion: 3
name: Very High
pixelLightCount: 3
shadows: 2
@ -158,17 +214,21 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 1
blendWeights: 4
textureQuality: 0
skinWeights: 4
globalTextureMipmapLimit: 0
textureMipmapLimitSettings: []
anisotropicTextures: 2
antiAliasing: 2
softParticles: 1
softVegetation: 1
realtimeReflectionProbes: 1
billboardsFaceCameraPosition: 1
useLegacyDetailDistribution: 1
vSyncCount: 1
realtimeGICPUUsage: 50
lodBias: 1.5
maximumLODLevel: 0
enableLODCrossFade: 1
streamingMipmapsActive: 0
streamingMipmapsAddAllCameras: 1
streamingMipmapsMemoryBudget: 512
@ -180,8 +240,18 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
terrainQualityOverrides: 0
terrainPixelError: 1
terrainDetailDensityScale: 1
terrainBasemapDistance: 1000
terrainDetailDistance: 80
terrainTreeDistance: 5000
terrainBillboardStart: 50
terrainFadeLength: 5
terrainMaxTrees: 50
excludedTargetPlatforms: []
- serializedVersion: 2
- serializedVersion: 3
name: Ultra
pixelLightCount: 4
shadows: 2
@ -193,17 +263,21 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 1
blendWeights: 4
textureQuality: 0
skinWeights: 4
globalTextureMipmapLimit: 0
textureMipmapLimitSettings: []
anisotropicTextures: 2
antiAliasing: 2
softParticles: 1
softVegetation: 1
realtimeReflectionProbes: 1
billboardsFaceCameraPosition: 1
useLegacyDetailDistribution: 1
vSyncCount: 1
realtimeGICPUUsage: 100
lodBias: 2
maximumLODLevel: 0
enableLODCrossFade: 1
streamingMipmapsActive: 0
streamingMipmapsAddAllCameras: 1
streamingMipmapsMemoryBudget: 512
@ -215,7 +289,18 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
terrainQualityOverrides: 0
terrainPixelError: 1
terrainDetailDensityScale: 1
terrainBasemapDistance: 1000
terrainDetailDistance: 80
terrainTreeDistance: 5000
terrainBillboardStart: 50
terrainFadeLength: 5
terrainMaxTrees: 50
excludedTargetPlatforms: []
m_TextureMipmapLimitGroupNames: []
m_PerPlatformDefaultQuality:
Android: 2
Lumin: 5
@ -223,6 +308,7 @@ QualitySettings:
Nintendo Switch: 5
PS4: 5
PSP2: 2
Server: 0
Stadia: 5
Standalone: 5
WebGL: 3