update MeatKit (9a1a68ab68cd0650227af944ffa30d1166b9e056)

This commit is contained in:
msk
2023-07-26 16:45:05 -07:00
parent 920875f56b
commit d2316bac96
266 changed files with 2855 additions and 9187 deletions
+192
View File
@@ -0,0 +1,192 @@
// Adapted from https://gist.github.com/kalineh/ad5135946f2009c36f755eea0a880998
using System;
using System.Collections.Generic;
using System.Linq;
#if H3VR_IMPORTED
using FistVR;
#endif
using UnityEditor;
using UnityEngine;
public class EnumPickerWindow : EditorWindow
{
private static GUIStyle _regularStyle;
private static GUIStyle _selectedStyle;
private string _enumName;
private string _filter;
private Action<string> _onSelectCallback;
private EditorWindow _parent;
private Vector2 _scroll;
private List<string> _valuesFiltered;
private List<string> _valuesRaw;
private void OnGUI()
{
GUILayout.Label(string.Format("Enum Type: {0}", _enumName));
GUI.SetNextControlName("filter");
var filterUpdate = GUILayout.TextField(_filter);
if (filterUpdate != _filter)
FilterValues(filterUpdate);
// always focused
GUI.FocusControl("filter");
_scroll = GUILayout.BeginScrollView(_scroll);
for (var i = 0; i < _valuesFiltered.Count; ++i)
{
var value = _valuesFiltered[i];
var style = i == 0 ? _selectedStyle : _regularStyle;
var rect = GUILayoutUtility.GetRect(new GUIContent(value), style);
var clicked = GUI.Button(rect, value);
if (clicked)
{
GUILayout.EndScrollView();
_onSelectCallback(value);
Close();
_parent.Repaint();
_parent.Focus();
return;
}
}
GUILayout.EndScrollView();
if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return)
{
if (_valuesFiltered.Count > 0)
_onSelectCallback(_valuesFiltered[0]);
Close();
_parent.Repaint();
_parent.Focus();
}
if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
{
Close();
_parent.Repaint();
_parent.Focus();
}
}
public void OnLostFocus()
{
Close();
}
public void ShowCustom(string enumName, List<string> values, Rect rect, Action<string> onSelect)
{
_regularStyle = new GUIStyle(EditorStyles.label);
_regularStyle.active = _regularStyle.normal;
_selectedStyle = new GUIStyle(EditorStyles.label);
_selectedStyle.normal = _selectedStyle.focused;
_selectedStyle.active = _selectedStyle.focused;
_enumName = enumName;
_valuesRaw = new List<string>(values);
_valuesFiltered = new List<string>(values);
_filter = "";
_onSelectCallback = onSelect;
_parent = focusedWindow;
var screenRect = rect;
var screenSize = new Vector2(400, 400);
screenRect.position = GUIUtility.GUIToScreenPoint(screenRect.position);
ShowAsDropDown(screenRect, screenSize);
Focus();
GUI.FocusControl("filter");
}
private void FilterValues(string filterUpdate)
{
_filter = filterUpdate;
var filterLower = _filter.ToLower();
_valuesFiltered.Clear();
foreach (var value in from value in _valuesRaw
let lower = value.ToLower()
where lower.Contains(filterLower)
select value)
_valuesFiltered.Add(value);
}
}
public class EnumPicker : PropertyDrawer
{
private EnumPickerWindow _window;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
Array valuesRaw = null;
Type enumType = fieldInfo.FieldType;
// Check if the property is an array or a list
if (enumType.IsArray) enumType = enumType.GetElementType();
else if (enumType.IsGenericType && enumType.GetGenericTypeDefinition() == typeof(List<>))
enumType = enumType.GetGenericArguments()[0];
if (enumType == null || !enumType.IsEnum)
{
Debug.LogError("Can't determine how to draw a field for " + fieldInfo.FieldType);
return;
}
valuesRaw = Enum.GetValues(enumType);
if (valuesRaw.Length <= 0)
return;
var valuesStr = new List<string>();
for (var i = 0; i < valuesRaw.Length; ++i)
{
object raw = valuesRaw.GetValue(i);
var str = raw.ToString();
valuesStr.Add(str);
}
string enumName = enumType.Name;
string currentName = Enum.GetName(enumType, property.intValue);
EditorGUI.PrefixLabel(position, label);
GUI.SetNextControlName(property.propertyPath);
var fieldRect = new Rect(position.x + EditorGUIUtility.labelWidth, position.y,
position.width - EditorGUIUtility.labelWidth, position.height);
if (GUI.Button(fieldRect, currentName, EditorStyles.popup))
{
_window = EditorWindow.GetWindow<EnumPickerWindow>();
Action<string> callback = str =>
{
var index = (int) Convert.ChangeType(Enum.Parse(enumType, str), enumType);
property.serializedObject.Update();
property.intValue = index;
property.serializedObject.ApplyModifiedProperties();
};
_window.ShowCustom(enumName, valuesStr, fieldRect, callback);
_window.Focus();
}
}
}
#if H3VR_IMPORTED
[CustomPropertyDrawer(typeof(FireArmMagazineType))]
[CustomPropertyDrawer(typeof(FireArmClipType))]
[CustomPropertyDrawer(typeof(FireArmRoundClass))]
[CustomPropertyDrawer(typeof(ItemSpawnerObjectDefinition.ItemSpawnerCategory))]
[CustomPropertyDrawer(typeof(ItemSpawnerID.EItemCategory))]
[CustomPropertyDrawer(typeof(ItemSpawnerID.ESubCategory))]
[CustomPropertyDrawer(typeof(FireArmRoundType))]
[CustomPropertyDrawer(typeof(SosigEnemyID))]
[CustomPropertyDrawer(typeof(FVRFireArmAttachementMountType))]
public class EnumDrawers : EnumPicker
{
}
#endif
+12
View File
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 27e4b73d795c232439cf3aee1d6ed3ba
timeCreated: 1628222780
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,110 @@
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
using System.Collections.Generic;
public class HiddenGameObjectTools : EditorWindow
{
#region Menu Command
[MenuItem("Tools/Hidden GameObject Tools")]
public static void ShowWindow()
{
var window = GetWindow<HiddenGameObjectTools>();
window.titleContent = new GUIContent("Hidden GOs");
window.GatherHiddenObjects();
}
#endregion
#region GUI
private static readonly GUILayoutOption ButtonWidth = GUILayout.Width(80);
private static readonly GUILayoutOption BigButtonHeight = GUILayout.Height(35);
private void OnGUI()
{
GUILayout.Space(10f);
GUILayout.BeginHorizontal();
{
if (GUILayout.Button("Refresh", BigButtonHeight))
{
GatherHiddenObjects();
}
if (GUILayout.Button("Test", BigButtonHeight, ButtonWidth))
{
var go = new GameObject("HiddenTestObject");
go.hideFlags = HideFlags.HideInHierarchy;
GatherHiddenObjects();
}
}
GUILayout.EndHorizontal();
GUILayout.Space(10f);
EditorGUILayout.LabelField("Hidden Objects (" + HiddenObjects.Count + ")", EditorStyles.boldLabel);
for (int i = 0; i < HiddenObjects.Count; i++)
{
var hiddenObject = HiddenObjects[i];
GUILayout.BeginHorizontal();
{
var gone = hiddenObject == null;
GUILayout.Label(gone ? "null" : hiddenObject.name);
GUILayout.FlexibleSpace();
if (gone)
{
GUILayout.Box("Select", ButtonWidth);
GUILayout.Box("Reveal", ButtonWidth);
GUILayout.Box("Delete", ButtonWidth);
}
else
{
if (GUILayout.Button("Select", ButtonWidth))
{
Selection.activeGameObject = hiddenObject;
}
if (GUILayout.Button(IsHidden(hiddenObject) ? "Reveal" : "Hide", ButtonWidth))
{
hiddenObject.hideFlags ^= HideFlags.HideInHierarchy;
EditorSceneManager.MarkSceneDirty(hiddenObject.scene);
}
if (GUILayout.Button("Delete", ButtonWidth))
{
var scene = hiddenObject.scene;
DestroyImmediate(hiddenObject);
EditorSceneManager.MarkSceneDirty(scene);
}
}
}
GUILayout.EndHorizontal();
}
}
#endregion
#region Hidden Objects
private List<GameObject> HiddenObjects = new List<GameObject>();
private void GatherHiddenObjects()
{
HiddenObjects.Clear();
var allObjects = FindObjectsOfType<GameObject>();
foreach (var go in allObjects)
{
if ((go.hideFlags & HideFlags.HideInHierarchy) != 0)
{
HiddenObjects.Add(go);
}
}
Repaint();
}
private static bool IsHidden(GameObject go)
{
return (go.hideFlags & HideFlags.HideInHierarchy) != 0;
}
#endregion
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 942768540f60f2a4084fdaee6fa509db
timeCreated: 1629347480
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,73 @@
using System.Collections.Generic;
using MeatKit;
using UnityEditor;
using UnityEngine;
public class PrefabLoader : EditorWindow
{
private AssetBundle _bundle;
private string[] _assets = new string[0];
private int _selectedAsset = 0;
private static readonly Dictionary<string, string> AssemblyNameReplaceMap = new Dictionary<string, string>
{
{MeatKit.MeatKit.AssemblyName + ".dll", MeatKit.MeatKit.AssemblyRename + ".dll"},
{MeatKit.MeatKit.AssemblyFirstpassName + ".dll", MeatKit.MeatKit.AssemblyFirstpassRename + ".dll"}
};
private static readonly Dictionary<string, AssetBundle> LoadedAssetBundles = new Dictionary<string, AssetBundle>();
[MenuItem("MeatKit/Prefab Loader")]
private static void Init()
{
GetWindow<PrefabLoader>().Show();
}
private void OnGUI()
{
if (GUILayout.Button("Select Asset Bundle"))
{
// If there's already a bundle loaded, unload it.
if (_bundle) _bundle = null;
// Ask for the new bundle, load it, and get its assets
string assetBundlePath = EditorUtility.OpenFilePanel("Select Asset Bundle", string.Empty, string.Empty);
// Make sure the user actually selected a file
if (!string.IsNullOrEmpty(assetBundlePath))
{
// Check if we already loaded it
if (!LoadedAssetBundles.TryGetValue(assetBundlePath, out _bundle))
{
_bundle = AssetBundle.LoadFromFile(assetBundlePath);
LoadedAssetBundles[assetBundlePath] = _bundle;
}
// Make sure a valid bundle was selected
if (_bundle != null)
{
_assets = _bundle.GetAllAssetNames();
_selectedAsset = 0;
}
}
}
// Only show spawn button if there's at least one asset
if (_bundle != null && _assets.Length > 0)
{
_selectedAsset = EditorGUILayout.Popup(_selectedAsset, _assets);
if (GUILayout.Button("Spawn"))
{
AssetBundleIO.EnableProcessing(AssemblyNameReplaceMap, true, false);
Instantiate(_bundle.LoadAsset(_assets[_selectedAsset]));
AssetBundleIO.DisableProcessing();
}
// Warn the user about the play mode thing
if (!EditorApplication.isPlaying)
{
EditorGUILayout.HelpBox("References on a prefab loaded object will break after a restart of the editor unless you enter play mode first.", MessageType.Warning);
}
}
}
}
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4d4b78186f45453aa4abc82dc1364363
timeCreated: 1637988640