OldBlueWater/BlueWater/Assets/Distant Lands/Cozy Weather/Contents/Scripts/Utility/EditorUtilities.cs

85 lines
2.4 KiB
C#
Raw Normal View History

2023-09-13 05:07:40 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Linq;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace DistantLands.Cozy
{
public static class EditorUtilities
{
public static T[] GetAllInstances<T>() where T : ScriptableObject
{
#if UNITY_EDITOR
string[] guids = AssetDatabase.FindAssets("t:" + typeof(T).Name); //FindAssets uses tags check documentation for more info
T[] a = new T[guids.Length];
for (int i = 0; i < guids.Length; i++) //probably could get optimized
{
string path = AssetDatabase.GUIDToAssetPath(guids[i]);
a[i] = AssetDatabase.LoadAssetAtPath<T>(path);
}
return a;
#else
return null;
#endif
}
2024-01-03 06:34:33 +00:00
public static GUIStyle toolbarButtonIcon = new GUIStyle(GUI.skin.GetStyle("ToolbarButton"))
2023-09-13 05:07:40 +00:00
{
2024-01-03 06:34:33 +00:00
padding = new RectOffset(-5, -5, -5, -5),
fixedWidth = 20,
fixedHeight = 20
};
2023-09-13 05:07:40 +00:00
2024-01-03 06:34:33 +00:00
#if UNITY_EDITOR
public static GUIStyle FoldoutStyle => new GUIStyle(EditorStyles.toolbarButton)
{
fontStyle = FontStyle.Bold,
fontSize = 12,
padding = new RectOffset(15, 0, 0, 0),
alignment = TextAnchor.MiddleLeft,
margin = new RectOffset(30, 10, 5, 5),
fixedHeight = 30,
stretchWidth = true,
// normal = new GUIStyleState()
// {
// scaledBackgrounds = EditorStyles.toolbarButton.onNormal.scaledBackgrounds
// }
};
2023-09-13 05:07:40 +00:00
2024-01-03 06:34:33 +00:00
#endif
public static List<Type> ResetModuleList()
{
2023-09-13 05:07:40 +00:00
List<Type> listOfMods = (
from domainAssembly in AppDomain.CurrentDomain.GetAssemblies()
from type in domainAssembly.GetTypes()
where typeof(CozyModule).IsAssignableFrom(type)
select type).ToList();
return listOfMods;
}
public static List<Type> ResetBiomeModulesList()
{
List<Type> listOfMods = (
from domainAssembly in AppDomain.CurrentDomain.GetAssemblies()
from type in domainAssembly.GetTypes()
2024-01-03 06:34:33 +00:00
where typeof(CozyModule).IsAssignableFrom(type) && type.GetInterfaces().Any(i => i == typeof(ICozyBiomeModule))
2023-09-13 05:07:40 +00:00
select type).ToList();
return listOfMods;
}
}
}