ParticleEffectForUGUI/Runtime/Internal/Utilities/Misc.cs

77 lines
1.9 KiB
C#
Raw Normal View History

2024-12-22 12:09:07 +08:00
using System;
2024-09-29 23:17:16 +08:00
using System.Diagnostics;
using UnityEditor;
using UnityEngine;
2024-12-22 12:09:07 +08:00
using Object = UnityEngine.Object;
#if UNITY_EDITOR && UNITY_2021_2_OR_NEWER
using UnityEditor.SceneManagement;
#elif UNITY_EDITOR
using UnityEditor.Experimental.SceneManagement;
#endif
2024-09-29 23:17:16 +08:00
namespace Coffee.UIParticleInternal
{
internal static class Misc
{
2024-11-21 00:36:51 +08:00
public static T[] FindObjectsOfType<T>() where T : Object
{
#if UNITY_2023_1_OR_NEWER
return Object.FindObjectsByType<T>(FindObjectsInactive.Include, FindObjectsSortMode.None);
#else
return Object.FindObjectsOfType<T>();
#endif
}
2024-09-29 23:17:16 +08:00
public static void Destroy(Object obj)
{
if (!obj) return;
#if UNITY_EDITOR
if (!Application.isPlaying)
{
Object.DestroyImmediate(obj);
}
else
#endif
{
Object.Destroy(obj);
}
}
public static void DestroyImmediate(Object obj)
{
if (!obj) return;
#if UNITY_EDITOR
if (Application.isEditor)
{
Object.DestroyImmediate(obj);
}
else
#endif
{
Object.Destroy(obj);
}
}
[Conditional("UNITY_EDITOR")]
public static void SetDirty(Object obj)
{
#if UNITY_EDITOR
if (!obj) return;
EditorUtility.SetDirty(obj);
#endif
}
2024-12-22 12:09:07 +08:00
#if UNITY_EDITOR
public static T[] GetAllComponentsInPrefabStage<T>() where T : Component
{
var prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
if (prefabStage == null) return Array.Empty<T>();
return prefabStage.prefabContentsRoot.GetComponentsInChildren<T>(true);
}
2025-01-03 21:58:18 +08:00
public static bool isBatchOrBuilding => Application.isBatchMode || BuildPipeline.isBuildingPlayer;
2024-12-22 12:09:07 +08:00
#endif
2024-09-29 23:17:16 +08:00
}
}