You've already forked ParticleEffectForUGUI
mirror of
https://github.com/mob-sakai/ParticleEffectForUGUI.git
synced 2026-06-26 00:13:54 +00:00
chore: update internal
This commit is contained in:
@@ -14,6 +14,15 @@ namespace Coffee.UIParticleInternal
|
||||
public abstract class PreloadedProjectSettings : ScriptableObject
|
||||
#if UNITY_EDITOR
|
||||
{
|
||||
[Tooltip("When enabled, this settings asset will be added to PlayerSettings.preloadedAssets in build.\n\n" +
|
||||
"When disable, you should load this settings via Resources, AssetBundles or Addressables to use.")]
|
||||
[SerializeField]
|
||||
[Header("Advanced")]
|
||||
[HideInInspector]
|
||||
private bool m_PreLoadSettingsInBuild = true;
|
||||
|
||||
protected static bool s_BuildingPlayer;
|
||||
|
||||
private class Postprocessor : AssetPostprocessor
|
||||
{
|
||||
private static void OnPostprocessAllAssets(string[] _, string[] __, string[] ___, string[] ____)
|
||||
@@ -22,12 +31,35 @@ namespace Coffee.UIParticleInternal
|
||||
}
|
||||
}
|
||||
|
||||
private class PreprocessBuildWithReport : IPreprocessBuildWithReport
|
||||
private class ExcludeFromBuild : IPreprocessBuildWithReport, IPostprocessBuildWithReport
|
||||
{
|
||||
int IOrderedCallback.callbackOrder => 0;
|
||||
|
||||
void IPreprocessBuildWithReport.OnPreprocessBuild(BuildReport report)
|
||||
{
|
||||
AssetDatabase.Refresh();
|
||||
Initialize();
|
||||
s_BuildingPlayer = true;
|
||||
|
||||
foreach (var t in TypeCache.GetTypesDerivedFrom(typeof(PreloadedProjectSettings<>)))
|
||||
{
|
||||
var settings = GetDefaultSettings(t);
|
||||
if (!settings || settings.m_PreLoadSettingsInBuild) continue;
|
||||
|
||||
PlayerSettings.SetPreloadedAssets(
|
||||
PlayerSettings.GetPreloadedAssets()
|
||||
.Where(x => x && x.GetType() != t)
|
||||
.ToArray());
|
||||
|
||||
Debug.Log($"[PreloadedProjectSettings] Build started: removed '{settings.name}' " +
|
||||
$"({t.Name}) from PreloadedAssets. " +
|
||||
$"It will be restored after build completes.");
|
||||
}
|
||||
}
|
||||
|
||||
void IPostprocessBuildWithReport.OnPostprocessBuild(BuildReport report)
|
||||
{
|
||||
s_BuildingPlayer = false;
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
@@ -39,13 +71,16 @@ namespace Coffee.UIParticleInternal
|
||||
var defaultSettings = GetDefaultSettings(t);
|
||||
if (defaultSettings == null)
|
||||
{
|
||||
// When create a new instance, automatically set it as default settings.
|
||||
defaultSettings = CreateInstance(t) as PreloadedProjectSettings;
|
||||
SetDefaultSettings(defaultSettings);
|
||||
if (!s_BuildingPlayer)
|
||||
{
|
||||
// When create a new instance, automatically set it as default settings.
|
||||
defaultSettings = CreateInstance(t) as PreloadedProjectSettings;
|
||||
SetDefaultSettings(defaultSettings);
|
||||
}
|
||||
}
|
||||
else if (GetPreloadedSettings(t).Length != 1)
|
||||
{
|
||||
SetDefaultSettings(defaultSettings);
|
||||
if (!s_BuildingPlayer) SetDefaultSettings(defaultSettings);
|
||||
}
|
||||
|
||||
if (defaultSettings != null)
|
||||
@@ -73,7 +108,7 @@ namespace Coffee.UIParticleInternal
|
||||
protected static PreloadedProjectSettings GetDefaultSettings(Type type)
|
||||
{
|
||||
return GetPreloadedSettings(type).FirstOrDefault() as PreloadedProjectSettings
|
||||
?? AssetDatabase.FindAssets($"t:{nameof(PreloadedProjectSettings)}")
|
||||
?? AssetDatabase.FindAssets($"t:{type.Name}")
|
||||
.Select(AssetDatabase.GUIDToAssetPath)
|
||||
.Select(AssetDatabase.LoadAssetAtPath<PreloadedProjectSettings>)
|
||||
.FirstOrDefault(x => x != null && x.GetType() == type);
|
||||
@@ -120,6 +155,35 @@ namespace Coffee.UIParticleInternal
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
internal abstract class PreloadedProjectSettingsEditor : Editor
|
||||
{
|
||||
private SerializedProperty _preLoadSettingsInBuild;
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
_preLoadSettingsInBuild = serializedObject.FindProperty("m_PreLoadSettingsInBuild");
|
||||
}
|
||||
|
||||
protected void DrawPreLoadSettingsInBuild(string packageName)
|
||||
{
|
||||
EditorGUILayout.PropertyField(_preLoadSettingsInBuild);
|
||||
if (!_preLoadSettingsInBuild.boolValue)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.HelpBox(
|
||||
$"{target.GetType().Name} asset will not be built in.\n" +
|
||||
$"please load manually from Resources, AssetBundle, or Addressables before using {packageName}.",
|
||||
MessageType.Warning);
|
||||
if (GUILayout.Button("Ping"))
|
||||
{
|
||||
EditorGUIUtility.PingObject(target);
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
{
|
||||
}
|
||||
@@ -151,7 +215,7 @@ namespace Coffee.UIParticleInternal
|
||||
return s_Instance;
|
||||
}
|
||||
|
||||
SetDefaultSettings(s_Instance);
|
||||
if (!s_BuildingPlayer) SetDefaultSettings(s_Instance);
|
||||
return s_Instance;
|
||||
}
|
||||
}
|
||||
@@ -193,9 +257,12 @@ namespace Coffee.UIParticleInternal
|
||||
}
|
||||
|
||||
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
|
||||
#else
|
||||
if (s_Instance && s_Instance != this)
|
||||
{
|
||||
Destroy(s_Instance);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (s_Instance != null) return;
|
||||
s_Instance = this as T;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user