squash commits

This commit is contained in:
2025-01-07 18:54:46 +02:00
parent 855639487b
commit 62c0a21987
3632 changed files with 708443 additions and 999 deletions
+135
View File
@@ -0,0 +1,135 @@
#if UMA_ADDRESSABLES
#if !UMA_NOASMDEF
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.AddressableAssets.Settings;
using UnityEditor.AddressableAssets.Settings.GroupSchemas;
using UnityEngine;
namespace UMA
{
public class AddressableInfo
{
public string AddressableAddress;
public string AddressableGroup;
public string AddressableLabels;
public AddressableInfo(string addressableAddress, string addressableGroup, string addressableLabels)
{
AddressableAddress = addressableAddress;
AddressableGroup = addressableGroup;
AddressableLabels = addressableLabels;
}
};
public class AddressableUtility
{
private static readonly AddressableUtility addressableUtility = new AddressableUtility();
private static AddressableAssetSettings _AddressableSettings;
public static AddressableAssetSettings AddressableSettings
{
get
{
if (_AddressableSettings == null)
{
string[] Settings = AssetDatabase.FindAssets("AddressableAssetSettings");
string path = AssetDatabase.GUIDToAssetPath(Settings[0]);
_AddressableSettings = AssetDatabase.LoadAssetAtPath<AddressableAssetSettings>(path);
}
return _AddressableSettings;
}
}
public static bool DoesAddressExist(string label)
{
List<AddressableAssetEntry> allEntries = new List<AddressableAssetEntry>();
AddressableUtility.AddressableSettings.GetAllAssets(allEntries, false);
foreach (AddressableAssetEntry entry in allEntries)
{
if (entry.labels.Contains(label))
{
return true;
}
}
return false;
}
public static AddressableAssetEntry GetAddressableAssetEntry(string assetPath, out AddressableAssetGroup assetgroup)
{
assetgroup = null;
if (AddressableSettings == null)
{
return null;
}
foreach (var group in AddressableSettings.groups)
{
foreach (AddressableAssetEntry e in group.entries)
{
if (e.AssetPath == assetPath)
{
assetgroup = group;
return e;
}
}
}
// Not found
return null;
}
public static AddressableAssetEntry GetAddressableAssetEntry(string AssetPath)
{
if (AddressableSettings == null)
{
return null;
}
foreach (var group in AddressableSettings.groups)
{
if (group == null)
{
continue;
}
foreach (AddressableAssetEntry e in group.entries)
{
if (e.AssetPath == AssetPath)
{
return e;
}
}
}
// Not found
return null;
}
public static string GetAddressableLabels(AddressableAssetEntry ae)
{
string retval = "";
foreach (string s in ae.labels)
{
retval += s + ";";
}
return retval;
}
public static AddressableInfo GetAddressableInfo(string assetPath)
{
AddressableAssetEntry ae = GetAddressableAssetEntry(assetPath);
if (ae != null)
{
return new AddressableInfo(ae.address, ae.parentGroup.Name, GetAddressableLabels(ae));
}
return null;
}
}
}
#endif
#endif
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 1f3f426aab7612947b6480a71bc6215d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 35611
packageName: UMA 2
packageVersion: 2.13
assetPath: Assets/UMA/Editor/AddressableUtility.cs
uploadId: 679826
@@ -0,0 +1,19 @@
{
"name": "Addressable_Editor",
"rootNamespace": "",
"references": [
"Unity.Addressables.Editor",
"Unity.ResourceManager"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
@@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: bf214390b0b80ac41b53432ba8eaaeb5
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 35611
packageName: UMA 2
packageVersion: 2.13
assetPath: Assets/UMA/Editor/Addressable_Editor.asmdef
uploadId: 679826
+92
View File
@@ -0,0 +1,92 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
public class ConvertToSubstance : EditorWindow
{
private MonoScript targetMonoScript;
private Vector2 scrollPos;
Texture2D texture;
[MenuItem("UMA/Tools/Convert ZB Alpha to Substance Alpha")]
public static void ShowWindow()
{
GetWindow<ConvertToSubstance>(true, "Convert Grayscale to Subtance Alpha", true);
}
void OnGUI()
{
texture = (Texture2D)EditorGUILayout.ObjectField("Texture (2D)", texture, typeof(Texture2D), false);
if (GUILayout.Button("Convert"))
{
if (texture == null)
{
EditorUtility.DisplayDialog("Error", "Please select a texture", "OK");
return;
}
string path = EditorUtility.SaveFilePanel("Save Texture", "","file.png", "png");
if (!string.IsNullOrEmpty(path))
{
var newTex = ConvertTexture(texture);
if (newTex == null)
{
EditorUtility.DisplayDialog("Error", "Texture is not readable", "OK");
return;
}
byte[] bytes = newTex.EncodeToPNG();
System.IO.File.WriteAllBytes(path, bytes);
GameObject.DestroyImmediate(newTex);
}
}
}
private static Texture2D ConvertTexture(Texture TextureToConvert)
{
if (TextureToConvert != null)
{
Texture2D tex = (Texture2D)TextureToConvert;
Color32[] pixels = tex.GetPixels32();
byte alphabase = pixels[0].r;
for (int i = 0; i < pixels.Length; i++)
{
Color32 pixel = pixels[i];
float alpha = 1.0f;
float dist = Mathf.Abs(pixel.r - alphabase);
if (pixel.r > alphabase)
{
float upperRange = 255 - alphabase;
if (upperRange == 0)
{
alpha = 1;
}
else
{
alpha = dist / upperRange;
}
}
else
{
float lowerRange = alphabase;
if (lowerRange == 0)
{
alpha = 0;
}
else
{
alpha = dist / lowerRange;
}
}
pixels[i].a = (byte)(alpha * 255);
}
Texture2D newTex = new Texture2D(tex.width, tex.height, TextureFormat.RGBA32,false);
newTex.SetPixels32(pixels);
newTex.Apply();
}
return null;
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 159116ba93abb34479758f50b5b5ebb3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 35611
packageName: UMA 2
packageVersion: 2.13
assetPath: Assets/UMA/Editor/ConvertToSubstance.cs
uploadId: 679826
+32
View File
@@ -0,0 +1,32 @@
using UnityEditor;
using UnityEngine;
public class FindComponentUsagesWindow : EditorWindow {
private MonoScript targetMonoScript;
private Vector2 scrollPos;
[MenuItem("UMA/Tools/Find Component Usages")]
public static void ShowWindow() {
GetWindow<FindComponentUsagesWindow>(true, "Find Component Usages", true);
}
void OnGUI() {
targetMonoScript = (MonoScript)EditorGUILayout.ObjectField(targetMonoScript, typeof(MonoScript), false);
if(targetMonoScript != null) {
scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
System.Type targetType = targetMonoScript.GetClass();
if(targetType != null && targetType.IsSubclassOf(typeof(MonoBehaviour))) {
Object[] allMonoscriptsAsObjects = Resources.FindObjectsOfTypeAll(targetType);
foreach(Object monoscriptAsObject in allMonoscriptsAsObjects) {
GameObject prefab = ((MonoBehaviour)monoscriptAsObject).gameObject;
if(GUILayout.Button(prefab.name)) {
Selection.activeObject = prefab;
}
}
} else {
EditorGUILayout.LabelField($"{targetMonoScript.name} is not a subclass of MonoBehavior");
}
EditorGUILayout.EndScrollView();
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 8c9d52b7aabbd1c42b7a042f06506fea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 35611
packageName: UMA 2
packageVersion: 2.13
assetPath: Assets/UMA/Editor/FindComponentUsages.cs
uploadId: 679826
+64
View File
@@ -0,0 +1,64 @@
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
using System.Reflection;
/// <summary>
/// This attribute can only be applied to fields because its
/// associated PropertyDrawer only operates on fields (either
/// public or tagged with the [SerializeField] attribute) in
/// the target MonoBehaviour.
/// </summary>
[System.AttributeUsage(System.AttributeTargets.Field)]
public class InspectorButtonAttribute : PropertyAttribute
{
public static float kDefaultButtonWidth = 180;
public readonly string MethodName;
private float _buttonWidth = kDefaultButtonWidth;
public float ButtonWidth
{
get { return _buttonWidth; }
set { _buttonWidth = value; }
}
public InspectorButtonAttribute(string MethodName)
{
this.MethodName = MethodName;
}
}
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(InspectorButtonAttribute))]
public class InspectorButtonPropertyDrawer : PropertyDrawer
{
private MethodInfo _eventMethodInfo = null;
public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
{
InspectorButtonAttribute inspectorButtonAttribute = (InspectorButtonAttribute)attribute;
Rect buttonRect = new Rect(position.x + (position.width - inspectorButtonAttribute.ButtonWidth) * 0.5f, position.y, inspectorButtonAttribute.ButtonWidth, position.height);
if (GUI.Button(buttonRect, label.text))
{
System.Type eventOwnerType = prop.serializedObject.targetObject.GetType();
string eventName = inspectorButtonAttribute.MethodName;
if (_eventMethodInfo == null)
{
_eventMethodInfo = eventOwnerType.GetMethod(eventName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
}
if (_eventMethodInfo != null)
{
_eventMethodInfo.Invoke(prop.serializedObject.targetObject, null);
}
else
{
Debug.LogWarning(string.Format("InspectorButton: Unable to find method {0} in {1}", eventName, eventOwnerType));
}
}
}
}
#endif
+18
View File
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 30b14b0de8c8b134f96201d99c8782b7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 35611
packageName: UMA 2
packageVersion: 2.13
assetPath: Assets/UMA/Editor/InspectorButton.cs
uploadId: 679826