Delete legacy CultCache editor writers

This commit is contained in:
Meta Vens 2026-06-13 05:33:34 +01:00
commit aa5addf040
38 changed files with 53 additions and 2127 deletions

View file

@ -1,234 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Unity.Mathematics;
using UnityEditor;
using UnityEngine;
using static UnityEditor.EditorGUILayout;
using static Unity.Mathematics.math;
public class StatReferenceInspector : BaseInspector<StatReference>
{
public override StatReference Inspect(string label, StatReference value, object parent, DatabaseInspector inspectorWindow)
{
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
using (new VerticalScope())
{
var targetObjects = typeof(BehaviorData).GetAllChildClasses()
.Concat(typeof(EquippableItemData).GetAllChildClasses()).ToArray();
var objectNames = targetObjects.Select(b => b.Name).ToArray();
var selectedIndex = Array.IndexOf(objectNames, value.Target);
if (selectedIndex == -1)
{
selectedIndex = 0;
GUI.changed = true;
}
using (new HorizontalScope())
{
GUILayout.Label("Target", GUILayout.Width(width));
var newSelection = Popup(selectedIndex, objectNames);
if (newSelection != selectedIndex)
GUI.changed = true;
value.Target = objectNames[newSelection];
}
using (new HorizontalScope())
{
GUILayout.Label("Stat", GUILayout.Width(width));
var stats = targetObjects[selectedIndex].GetFields()
.Where(f => f.FieldType == typeof(PerformanceStat)).ToArray();
if(stats.Length==0)
GUILayout.Label("No Stats!");
else
{
var statNames = stats.Select(s => s.Name).ToArray();
var selectedStatIndex = Array.IndexOf(statNames, value.Stat);
if (selectedStatIndex == -1)
{
selectedStatIndex = 0;
GUI.changed = true;
}
var newSelection = Popup(selectedStatIndex, statNames);
if (newSelection != selectedStatIndex)
GUI.changed = true;
value.Stat = statNames[newSelection];
}
}
}
}
return value;
}
}
public class PerformanceStatInspector : BaseInspector<PerformanceStat>
{
public override PerformanceStat Inspect(string label, PerformanceStat value, object parent, DatabaseInspector inspectorWindow)
{
if(value == null)
value = new PerformanceStat();
using (new VerticalScope())
{
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
GUILayout.Label("Min", EditorStyles.miniLabel, GUILayout.Width(labelWidth));
value.Min = DelayedFloatField(value.Min);
GUILayout.Label("Max", EditorStyles.miniLabel, GUILayout.Width(labelWidth + 5));
value.Max = DelayedFloatField(value.Max);
}
// Only display heat, durability and quality effects if the stat actually varies
if (Math.Abs(value.Min - value.Max) > .0001f)
{
using (new HorizontalScope())
{
GUILayout.Label("", GUILayout.Width(width));
GUILayout.Label("H", EditorStyles.miniLabel, GUILayout.Width(labelWidth));
value.HeatExponentMultiplier = DelayedFloatField(value.HeatExponentMultiplier);
GUILayout.Label("D", EditorStyles.miniLabel, GUILayout.Width(labelWidth));
value.DurabilityExponentMultiplier = DelayedFloatField(value.DurabilityExponentMultiplier);
GUILayout.Label("Q", EditorStyles.miniLabel, GUILayout.Width(labelWidth));
value.QualityExponent = DelayedFloatField(value.QualityExponent);
}
}
Space();
}
return value;
}
}
public class ShapeInspector : BaseInspector<Shape>
{
private Material _schematicMat = new Material(Shader.Find("Legacy Shaders/Particles/Additive"));
public override Shape Inspect(string label, Shape value, object parent, DatabaseInspector inspectorWindow)
{
if(value == null)
{
value = new Shape(1, 1);
value[int2(0)] = true;
}
using (new VerticalScope())
{
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
GUILayout.Label("Size", GUILayout.ExpandWidth(false));
GUILayout.Label("X", GUILayout.Width(labelWidth));
value.Width = DelayedIntField(value.Width);
GUILayout.Label("Y", GUILayout.Width(labelWidth));
value.Height = DelayedIntField(value.Height);
}
using (new HorizontalScope())
{
GUILayout.Label("", GUILayout.Width(width));
using (new VerticalScope())
{
for (var y = value.Height - 1; y >= 0; y--)
{
using (new HorizontalScope())
{
for (var x = 0; x < value.Width; x++)
{
var oldColor = GUI.backgroundColor;
value[int2(x, y)] = Toggle(value[int2(x, y)], GUILayout.Width(toggleWidth));
GUI.backgroundColor = oldColor;
}
}
}
}
GUILayout.FlexibleSpace();
}
}
return value;
}
}
public class ShapeSchematicInspector : BaseInspector<Shape, InspectableSchematicShapeAttribute>
{
private Material _schematicMat = new Material(Shader.Find("Legacy Shaders/Particles/Additive"));
public override Shape Inspect(string label, Shape value, object parent, DatabaseInspector inspectorWindow, InspectableSchematicShapeAttribute attribute)
{
var item = parent as EquippableItemData;
if(value == null)
{
value = new Shape(1, 1);
value[int2(0)] = true;
}
using (new VerticalScope())
{
Texture2D schematic = null;
if(item != null && !string.IsNullOrEmpty(item.Schematic))
schematic = AssetDatabase.LoadAssetAtPath<Texture2D>(item.Schematic);
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
GUILayout.Label("Size", GUILayout.ExpandWidth(false));
if(schematic == null)
{
GUILayout.Label("X", GUILayout.Width(labelWidth));
value.Width = DelayedIntField(value.Width);
GUILayout.Label("Y", GUILayout.Width(labelWidth));
value.Height = DelayedIntField(value.Height);
}
else
{
GUILayout.Label("X", GUILayout.Width(labelWidth));
value.Width = DelayedIntField(value.Width);
value.Height = Mathf.RoundToInt(value.Width * ((float)schematic.height / schematic.width));
GUILayout.Label("Y", GUILayout.Width(labelWidth));
LabelField($"{value.Height}");
}
}
using (new HorizontalScope())
{
GUILayout.Label("", GUILayout.Width(width));
using (var a = new VerticalScope())
{
if(schematic != null)
{
EditorGUI.DrawPreviewTexture(a.rect, schematic, _schematicMat);
}
for (var y = value.Height - 1; y >= 0; y--)
{
using (new HorizontalScope())
{
for (var x = 0; x < value.Width; x++)
{
var oldColor = GUI.backgroundColor;
if(item is HullData hull)
{
var hardpoint = hull.Hardpoints
.FirstOrDefault(hp =>
hp.Shape.Coordinates
.Select(v => v + hp.Position)
.Any(v => v.x == x && v.y == y));
if (hardpoint != null)
GUI.backgroundColor = hardpoint.TintColor.ToColor();
}
value[int2(x, y)] = Toggle(value[int2(x, y)], GUILayout.Width(toggleWidth));
GUI.backgroundColor = oldColor;
}
}
}
}
GUILayout.FlexibleSpace();
}
}
return value;
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 57d0bc090768458b9428efd7a8a33741
timeCreated: 1617069994

View file

@ -1,58 +0,0 @@
using System.Linq;
using Unity.Mathematics;
using UnityEditor;
using UnityEngine;
using static UnityEditor.EditorGUILayout;
using static Unity.Mathematics.math;
public class AnimationCurveFloat4Inspector : BaseInspector<float4[]>
{
public override float4[] Inspect(string label, float4[] value, object parent, DatabaseInspector inspectorWindow)
{
var val = value != null && value.Length > 0
? value.ToCurve()
: new AnimationCurve();
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
val = CurveField(val, Color.yellow, new Rect(0, 0, 1, 1));
}
return val.keys.Select(k => float4(k.time, k.value, k.inTangent, k.outTangent)).ToArray();
}
}
public class BezierCurveInspector : BaseInspector<BezierCurve>
{
public override BezierCurve Inspect(string label, BezierCurve value, object parent, DatabaseInspector inspectorWindow)
{
var val = value != null && value.Keys != null && value.Keys.Length > 0
? value.ToCurve()
: new AnimationCurve();
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
val = CurveField(val, Color.yellow, new Rect(0, 0, 1, 1));
}
value.Keys = val.keys.Select(k => float4(k.time, k.value, k.inTangent, k.outTangent)).ToArray();
return value;
}
}
public class AnimationCurveInspect : BaseInspector<AnimationCurve>
{
public override AnimationCurve Inspect(string label, AnimationCurve value, object parent, DatabaseInspector inspectorWindow)
{
using (var h = new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
if (value == null)
value = new AnimationCurve();
value = CurveField(value, Color.yellow, new Rect(0, 0, 1, 1));
}
return value;
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: c89e0e7eb9f243cbbce28df59f6fb1c9
timeCreated: 1617066399

View file

@ -1,169 +0,0 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using static UnityEditor.EditorGUILayout;
public class DatabaseLinkInspector : BaseInspector<Guid, InspectableDatabaseLinkAttribute>
{
public override Guid Inspect(string label, Guid value, object parent, DatabaseInspector inspectorWindow, InspectableDatabaseLinkAttribute link)
{
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
var valueEntry = DatabaseInspector.CultCache.Get(value);
using (var h = new HorizontalScope(GUI.skin.box))
{
GUILayout.Label((valueEntry as INamedEntry)?.EntryName ?? valueEntry?.ID.ToString() ?? $"Drag and drop: {DatabaseListView.FormatTypeName(link.EntryType.Name)}");
if (h.rect.Contains(Event.current.mousePosition) && (Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform))
{
var guid = (Guid) DragAndDrop.GetGenericData("Item");
var dragEntry = DatabaseInspector.CultCache.Get(guid);
var dragValid = dragEntry != null && link.EntryType.IsInstanceOfType(dragEntry) && dragEntry != valueEntry;
if(Event.current.type == EventType.DragUpdated)
DragAndDrop.visualMode = dragValid ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected;
else if(Event.current.type == EventType.DragPerform)
{
if (dragValid)
{
DragAndDrop.AcceptDrag();
GUI.changed = true;
return guid;
}
}
}
if (GUILayout.Button("-", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3)*2), GUILayout.Height(EditorGUIUtility.singleLineHeight-3)))
{
return Guid.Empty;
}
}
}
return value;
}
}
public class DatabaseLinkObjectInspector<T> : BaseInspector<DatabaseLink<T>> where T : DatabaseEntry
{
public override DatabaseLink<T> Inspect(string label, DatabaseLink<T> value, object parent, DatabaseInspector inspectorWindow)
{
if (value == null)
value = new DatabaseLink<T>();
if(!string.IsNullOrEmpty(label))
{
GUILayout.BeginHorizontal();
GUILayout.Label(label, GUILayout.Width(width));
}
var valueEntry = value.Value;
using (var h = string.IsNullOrEmpty(label) ? new HorizontalScope() : new HorizontalScope(GUI.skin.box))
{
GUILayout.Label((valueEntry as INamedEntry)?.EntryName ?? valueEntry?.ID.ToString() ?? $"Drag and drop: {DatabaseListView.FormatTypeName(typeof(T).Name)}");
if (h.rect.Contains(Event.current.mousePosition) && (Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform))
{
var guid = (Guid) DragAndDrop.GetGenericData("Item");
var dragEntry = DatabaseInspector.CultCache.Get(guid);
var dragValid = dragEntry is T && dragEntry != valueEntry;
if(Event.current.type == EventType.DragUpdated)
DragAndDrop.visualMode = dragValid ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected;
else if(Event.current.type == EventType.DragPerform)
{
if (dragValid)
{
DragAndDrop.AcceptDrag();
value.LinkID = guid;
return value;
}
}
}
if(value.LinkID != Guid.Empty)
{
if (GUILayout.Button("-",
GUILayout.Width((EditorGUIUtility.singleLineHeight - 3) * 2),
GUILayout.Height(EditorGUIUtility.singleLineHeight - 3)))
{
value.LinkID = Guid.Empty;
}
}
}
if(!string.IsNullOrEmpty(label))
{
GUILayout.EndHorizontal();
}
return value;
}
}
public class DatabaseLinkListInspector : BaseInspector<List<Guid>, InspectableDatabaseLinkAttribute>
{
private bool _listItemStyle;
public GUIStyle ListItemStyle =>
(_listItemStyle = !_listItemStyle) ? DatabaseListView.ListStyleEven : DatabaseListView.ListStyleOdd;
public override List<Guid> Inspect(string label,
List<Guid> value,
object parent,
DatabaseInspector inspectorWindow,
InspectableDatabaseLinkAttribute link)
{
using (var v = new VerticalScope(GUI.skin.box))
{
GUILayout.Label(label, EditorStyles.boldLabel);
if (value.Count == 0)
{
using (new HorizontalScope(ListItemStyle))
{
GUILayout.Label($"Drag from list to add {link.EntryType.Name}");
}
}
foreach (var guid in value.ToArray())
{
using (new HorizontalScope(ListItemStyle))
{
var entry = DatabaseInspector.CultCache.Get(guid);
if (entry == null)
{
value.Remove(guid);
GUI.changed = true;
}
else
{
GUILayout.Label((entry as INamedEntry)?.EntryName ?? entry.ID.ToString());
// var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight));
// GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0);
if (GUILayout.Button("-", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3)*2), GUILayout.Height(EditorGUIUtility.singleLineHeight-3)))
{
value.Remove(guid);
}
}
}
}
if (v.rect.Contains(Event.current.mousePosition))
{
var guid = DragAndDrop.GetGenericData("Item");
var dragObj = DragAndDrop.GetGenericData("Item") is Guid ? DatabaseInspector.CultCache.Get((Guid) guid) : null;
var dragValid = dragObj != null && link.EntryType.IsInstanceOfType(dragObj) && !value.Contains(dragObj.ID);
if(Event.current.type == EventType.DragUpdated)
DragAndDrop.visualMode = dragValid ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected;
else if(Event.current.type == EventType.DragPerform)
{
if (dragValid)
{
DragAndDrop.AcceptDrag();
value.Add((Guid) guid);
GUI.changed = true;
}
}
}
}
return value;
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 5e08712ea4854536b130f82ad61db7a8
timeCreated: 1617069551

View file

@ -1,211 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using static UnityEditor.EditorGUILayout;
public class FloatDictionaryInspector : BaseInspector<Dictionary<Guid, float>, InspectableDatabaseLinkAttribute>
{
public override Dictionary<Guid, float> Inspect(string label,
Dictionary<Guid, float> value,
object parent,
DatabaseInspector inspectorWindow,
InspectableDatabaseLinkAttribute attribute)
{
Space();
LabelField(label, EditorStyles.boldLabel);
using (var v = new VerticalScope(GUI.skin.box))
{
if (value.Count == 0)
{
using (new HorizontalScope(DatabaseInspector.ListItemStyle))
{
GUILayout.Label("Drag from list to add item");
}
}
foreach (var ingredient in value.ToArray())
{
using (new HorizontalScope(DatabaseInspector.ListItemStyle))
{
var entry = DatabaseInspector.CultCache.Get(ingredient.Key);
if (entry == null)
{
value.Remove(ingredient.Key);
GUI.changed = true;
return value;
}
if(entry is INamedEntry named)
GUILayout.Label(named.EntryName);
else GUILayout.Label(entry.ID.ToString());
value[ingredient.Key] = DelayedFloatField(value[ingredient.Key], GUILayout.Width(50));
// var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight));
// GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0);
if (GUILayout.Button("-", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3)*2), GUILayout.Height(EditorGUIUtility.singleLineHeight-3)))
value.Remove(ingredient.Key);
}
}
if (v.rect.Contains(Event.current.mousePosition))
{
var dragData = DragAndDrop.GetGenericData("Item");
var isId = dragData is Guid;
var dragEntry = isId ? DatabaseInspector.CultCache.Get((Guid)dragData) : null;
var correctType = attribute.EntryType.IsInstanceOfType(dragEntry);
if(Event.current.type == EventType.DragUpdated)
DragAndDrop.visualMode = correctType ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected;
else if(Event.current.type == EventType.DragPerform)
{
if (isId && correctType)
{
DragAndDrop.AcceptDrag();
value[(Guid)dragData] = 1;
GUI.changed = true;
}
}
}
}
return value;
}
}
public class RangedFloatDictionaryInspector : BaseInspector<Dictionary<Guid, float>, InspectableDatabaseLinkAttribute, RangedFloatAttribute>
{
public override Dictionary<Guid, float> Inspect(string label,
Dictionary<Guid, float> value,
object parent,
DatabaseInspector inspectorWindow,
InspectableDatabaseLinkAttribute link,
RangedFloatAttribute range)
{
Space();
LabelField(label, EditorStyles.boldLabel);
using (var v = new VerticalScope(GUI.skin.box))
{
if (value.Count == 0)
{
using (new HorizontalScope(DatabaseInspector.ListItemStyle))
{
GUILayout.Label("Drag from list to add item");
}
}
foreach (var ingredient in value.ToArray())
{
using (new HorizontalScope(DatabaseInspector.ListItemStyle))
{
var entry = DatabaseInspector.CultCache.Get(ingredient.Key);
if (entry == null)
{
value.Remove(ingredient.Key);
GUI.changed = true;
return value;
}
if(entry is INamedEntry named)
GUILayout.Label(named.EntryName);
else GUILayout.Label(entry.ID.ToString());
value[ingredient.Key] = Slider(value[ingredient.Key], range.Min, range.Max);
// var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight));
// GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0);
if (GUILayout.Button("-", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3)*2), GUILayout.Height(EditorGUIUtility.singleLineHeight-3)))
value.Remove(ingredient.Key);
}
}
if (v.rect.Contains(Event.current.mousePosition))
{
var dragData = DragAndDrop.GetGenericData("Item");
var isId = dragData is Guid;
var dragEntry = isId ? DatabaseInspector.CultCache.Get((Guid)dragData) : null;
var correctType = link.EntryType.IsInstanceOfType(dragEntry);
if(Event.current.type == EventType.DragUpdated)
DragAndDrop.visualMode = correctType ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected;
else if(Event.current.type == EventType.DragPerform)
{
if (isId && correctType)
{
DragAndDrop.AcceptDrag();
value[(Guid)dragData] = range.Max;
GUI.changed = true;
}
}
}
}
return value;
}
}
public class IntDictionaryInspector : BaseInspector<Dictionary<Guid, int>, InspectableDatabaseLinkAttribute>
{
public override Dictionary<Guid, int> Inspect(string label,
Dictionary<Guid, int> value,
object parent,
DatabaseInspector inspectorWindow,
InspectableDatabaseLinkAttribute attribute)
{
Space();
LabelField(label, EditorStyles.boldLabel);
using (var v = new VerticalScope(GUI.skin.box))
{
if (value.Count == 0)
{
using (var h = new HorizontalScope(DatabaseInspector.ListItemStyle))
{
GUILayout.Label("Drag from list to add item");
}
}
foreach (var ingredient in value.ToArray())
{
using (var h = new HorizontalScope(DatabaseInspector.ListItemStyle))
{
var entry = DatabaseInspector.CultCache.Get(ingredient.Key);
if (entry == null)
{
value.Remove(ingredient.Key);
GUI.changed = true;
return value;
}
if(entry is INamedEntry named)
GUILayout.Label(named.EntryName);
else GUILayout.Label(entry.ID.ToString());
value[ingredient.Key] = DelayedIntField(value[ingredient.Key], GUILayout.Width(50));
// var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight));
// GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0);
if (GUILayout.Button("-", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3)*2), GUILayout.Height(EditorGUIUtility.singleLineHeight-3)) || value[ingredient.Key]==0)
value.Remove(ingredient.Key);
}
}
if (v.rect.Contains(Event.current.mousePosition))
{
var dragData = DragAndDrop.GetGenericData("Item");
var isId = dragData is Guid;
var dragEntry = isId ? DatabaseInspector.CultCache.Get((Guid)dragData) : null;
var correctType = attribute.EntryType.IsInstanceOfType(dragEntry);
if(Event.current.type == EventType.DragUpdated)
DragAndDrop.visualMode = correctType ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected;
else if(Event.current.type == EventType.DragPerform)
{
if (isId && correctType)
{
DragAndDrop.AcceptDrag();
value[(Guid)dragData] = 1;
GUI.changed = true;
}
}
}
}
return value;
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: a42620fd406045889578e2ad8d5fd8de
timeCreated: 1617067689

View file

@ -1,59 +0,0 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using static Unity.Mathematics.math;
using static UnityEditor.EditorGUILayout;
public class EnumInspector<T> : BaseInspector<List<T>, InspectableEnumValuesAttribute>
{
public override List<T> Inspect(string label, List<T> list, object parent, DatabaseInspector inspectorWindow, InspectableEnumValuesAttribute attribute)
{
var names = Enum.GetNames(attribute.EnumType);
list ??= new List<T>();
while(list.Count < names.Length) list.Add(Activator.CreateInstance<T>());
while(list.Count > names.Length) list.RemoveAt(list.Count-1);
for (var i = 0; i < names.Length; i++)
inspectorWindow.InspectMember(names[i], list[i], parent, typeof(T));
return list;
}
}
public class EnumDictionaryInspector<E, T> : BaseInspector<EnumDictionary<E, T>> where E : Enum
{
private static HashSet<object> _foldouts = new HashSet<object>();
public override EnumDictionary<E, T> Inspect(string label, EnumDictionary<E, T> dict, object parent, DatabaseInspector inspectorWindow)
{
var names = Enum.GetNames(typeof(E));
if (dict == null || dict.Values.Length != names.Length)
{
var newValue = new T[names.Length];
if(dict != null && dict.Values.Length > 0)
Array.Copy(dict.Values, newValue, min(dict.Values.Length, newValue.Length));
dict.Values = newValue;
}
using (new VerticalScope(GUI.skin.box))
{
if (Foldout(_foldouts.Contains(dict), label, true, EditorStyles.boldLabel))
_foldouts.Add(dict);
else _foldouts.Remove(dict);
if(_foldouts.Contains(dict))
{
for (var i = 0; i < names.Length; i++)
{
using (new VerticalScope(DatabaseInspector.ListItemStyle))
{
dict.Values[i] = (T) inspectorWindow.InspectMember(names[i], dict.Values[i], parent, typeof(T));
}
}
}
}
return dict;
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: da1b15e5564747958639c8f959226c74
timeCreated: 1617335525

View file

@ -1,54 +0,0 @@
using UnityEditor;
using UnityEngine;
using static UnityEditor.EditorGUILayout;
public class FloatInspector : BaseInspector<float>
{
public override float Inspect(string label, float value, object parent, DatabaseInspector inspectorWindow)
{
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
return DelayedFloatField(value);
}
}
}
public class RangedFloatInspector : BaseInspector<float, InspectableRangedFloatAttribute>
{
public override float Inspect(string label,
float value,
object parent,
DatabaseInspector inspectorWindow,
InspectableRangedFloatAttribute attribute)
{
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
return Slider(value, attribute.Min, attribute.Max);
}
}
}
public class TemperatureFloatInspector : BaseInspector<float, InspectableTemperatureAttribute>
{
public override float Inspect(string label,
float value,
object parent,
DatabaseInspector inspectorWindow,
InspectableTemperatureAttribute attribute)
{
using (var h = new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
GUILayout.Label("°K", EditorStyles.miniLabel, GUILayout.Width(labelWidth));
value = DelayedFloatField(value);
GUILayout.Label("°C", EditorStyles.miniLabel, GUILayout.Width(labelWidth));
value = DelayedFloatField(value - 273.15f) + 273.15f;
GUILayout.Label("°F", EditorStyles.miniLabel, GUILayout.Width(labelWidth));
value = (DelayedFloatField((value - 273.15f) * 1.8f + 32) - 32) / 1.8f + 273.15f;
return value;
}
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 47b8e5bc90714055881eb31baf2ab879
timeCreated: 1617065074

View file

@ -1,40 +0,0 @@
using static Unity.Mathematics.math;
using UnityEditor;
using UnityEngine;
using static UnityEditor.EditorGUILayout;
public class IntInspector : BaseInspector<int>
{
public override int Inspect(string label, int value, object parent, DatabaseInspector inspectorWindow)
{
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
return DelayedIntField(value);
}
}
}
public class UintInspector : BaseInspector<uint>
{
public override uint Inspect(string label, uint value, object parent, DatabaseInspector inspectorWindow)
{
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
return (uint) max(DelayedIntField((int)value), 0);
}
}
}
public class RangedIntInspector : BaseInspector<int, InspectableRangedIntAttribute>
{
public override int Inspect(string label, int value, object parent, DatabaseInspector inspectorWindow, InspectableRangedIntAttribute attribute)
{
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
return IntSlider(value, attribute.Min, attribute.Max);
}
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: ac7d3b8651964ce1a732a002447d6f69
timeCreated: 1617065365

View file

@ -1,132 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using static UnityEditor.EditorGUILayout;
public class ListInspector<T> : BaseInspector<List<T>>
{
private static HashSet<object> _foldouts = new HashSet<object>();
public override List<T> Inspect(string label, List<T> list, object parent, DatabaseInspector inspectorWindow)
{
var listType = typeof(T);
var inspectable = listType.GetCustomAttribute<InspectableAttribute>();
// if (listType.GetCustomAttribute<InspectableAttribute>() != null)
// {
//Space();
using (new VerticalScope(GUI.skin.box))
{
if (list == null)
{
list = new List<T>();
}
else
{
var sorted = true;
var order = int.MinValue;
foreach(var element in list)
{
if (element == null)
{
list.Remove(element);
return list;
}
var elementType = element.GetType();
var elementOrder = elementType.GetCustomAttribute<OrderAttribute>()?.Order ?? 0;
if (elementOrder < order)
sorted = false;
order = elementOrder;
}
if (!sorted)
{
list.Sort((x, y) => (x.GetType().GetCustomAttribute<OrderAttribute>()?.Order ?? 0).CompareTo(y.GetType().GetCustomAttribute<OrderAttribute>()?.Order ?? 0));
}
}
if (Foldout(_foldouts.Contains(list), label, true, EditorStyles.boldLabel))
_foldouts.Add(list);
else _foldouts.Remove(list);
if (_foldouts.Contains(list))
{
foreach (var o in list)
{
if (o == null)
{
list.Remove(o);
break;
}
bool _tinted = false;
var originalColor = GUI.backgroundColor;
if (o is ITintInspector tint)
{
_tinted = true;
GUI.backgroundColor = tint.TintColor.ToColor();
}
using (new VerticalScope(DatabaseInspector.ListItemStyle))
{
using (new HorizontalScope())
{
if (inspectable != null)
{
if (Foldout(_foldouts.Contains(o), o.ToString(), true, EditorStyles.boldLabel))
_foldouts.Add(o);
else
_foldouts.Remove(o);
}
else inspectorWindow.InspectMember("", o, parent, listType, true);
if (GUILayout.Button("-", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3)*2), GUILayout.Height(EditorGUIUtility.singleLineHeight-3)))
{
list.Remove(o);
break;
}
}
if(inspectable != null && _foldouts.Contains(o))
inspectorWindow.InspectMember("", o, parent, o.GetType(), true);
}
if(_tinted)
GUI.backgroundColor = originalColor;
}
using (new HorizontalScope(DatabaseInspector.ListItemStyle))
{
GUILayout.Label($"Add new {listType.GetFullName()}", GUILayout.ExpandWidth(true));
// var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight));
// GUI.DrawTexture(rect, Icons.Instance.plus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0);
if (GUILayout.Button("+", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3)*2), GUILayout.Height(EditorGUIUtility.singleLineHeight-3)))
{
if (listType.IsAbstract || listType.IsInterface)
{
var menu = new GenericMenu();
foreach (var childType in listType.GetAllChildClasses().Where(t=>!t.IsAbstract && !t.IsInterface))
{
menu.AddItem(new GUIContent(childType.Name), false, () =>
{
var o = (T) Activator.CreateInstance(childType);
_foldouts.Add(o);
list.Add(o);
});
}
menu.ShowAsContext();
}
else
{
var o = Activator.CreateInstance<T>();
_foldouts.Add(o);
list.Add(o);
}
}
}
}
}
// }
// else Debug.Log($"Field \"{label}\" is a list of non-Inspectable type {listType.Name}. No inspector was generated.");
return list;
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 551335721057411d942b3317ae028546
timeCreated: 1617145746

View file

@ -1,144 +0,0 @@
using Unity.Mathematics;
using UnityEditor;
using UnityEngine;
using static UnityEditor.EditorGUILayout;
public class Float2Inspector : BaseInspector<float2>
{
public override float2 Inspect(string label, float2 value, object parent, DatabaseInspector inspectorWindow)
{
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
GUILayout.Label("X", GUILayout.Width(labelWidth));
value.x = DelayedFloatField(value.x);
GUILayout.Label("Y", GUILayout.Width(labelWidth));
value.y = DelayedFloatField(value.y);
return value;
}
}
}
public class Float3Inspector : BaseInspector<float3>
{
public override float3 Inspect(string label, float3 value, object parent, DatabaseInspector inspectorWindow)
{
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
GUILayout.Label("X", GUILayout.Width(labelWidth));
value.x = DelayedFloatField(value.x);
GUILayout.Label("Y", GUILayout.Width(labelWidth));
value.y = DelayedFloatField(value.y);
GUILayout.Label("Z", GUILayout.Width(labelWidth));
value.z = DelayedFloatField(value.z);
return value;
}
}
}
public class Float3ColorInspector : BaseInspector<float3, InspectableColorAttribute>
{
public override float3 Inspect(string label, float3 value, object parent, DatabaseInspector inspectorWindow, InspectableColorAttribute attribute)
{
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
return ColorField(value.ToColor()).ToFloat3();
}
}
}
public class Float4Inspector : BaseInspector<float4>
{
public override float4 Inspect(string label, float4 value, object parent, DatabaseInspector inspectorWindow)
{
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
GUILayout.Label("X", GUILayout.Width(labelWidth));
value.x = DelayedFloatField(value.x);
GUILayout.Label("Y", GUILayout.Width(labelWidth));
value.y = DelayedFloatField(value.y);
GUILayout.Label("Z", GUILayout.Width(labelWidth));
value.z = DelayedFloatField(value.z);
GUILayout.Label("W", GUILayout.Width(labelWidth));
value.w = DelayedFloatField(value.w);
return value;
}
}
}
public class Float4ColorInspector : BaseInspector<float4, InspectableColorAttribute>
{
public override float4 Inspect(string label, float4 value, object parent, DatabaseInspector inspectorWindow, InspectableColorAttribute attribute)
{
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
return ColorField(value.ToColor()).ToFloat4();
}
}
}
public class Int2Inspector : BaseInspector<int2>
{
public override int2 Inspect(string label, int2 value, object parent, DatabaseInspector inspectorWindow)
{
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
GUILayout.Label("X", GUILayout.Width(labelWidth));
value.x = DelayedIntField(value.x);
GUILayout.Label("Y", GUILayout.Width(labelWidth));
value.y = DelayedIntField(value.y);
if (GUILayout.Button("\u2190", GUILayout.Width(arrowWidth)))
value.x--;
if (GUILayout.Button("\u2192", GUILayout.Width(arrowWidth)))
value.x++;
if (GUILayout.Button("\u2191", GUILayout.Width(arrowWidth)))
value.y++;
if (GUILayout.Button("\u2193", GUILayout.Width(arrowWidth)))
value.y--;
return value;
}
}
}
public class Int3Inspector : BaseInspector<int3>
{
public override int3 Inspect(string label, int3 value, object parent, DatabaseInspector inspectorWindow)
{
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
GUILayout.Label("X", GUILayout.Width(labelWidth));
value.x = DelayedIntField(value.x);
GUILayout.Label("Y", GUILayout.Width(labelWidth));
value.y = DelayedIntField(value.y);
GUILayout.Label("Z", GUILayout.Width(labelWidth));
value.z = DelayedIntField(value.z);
return value;
}
}
}
public class Int4Inspector : BaseInspector<int4>
{
public override int4 Inspect(string label, int4 value, object parent, DatabaseInspector inspectorWindow)
{
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
GUILayout.Label("X", GUILayout.Width(labelWidth));
value.x = DelayedIntField(value.x);
GUILayout.Label("Y", GUILayout.Width(labelWidth));
value.y = DelayedIntField(value.y);
GUILayout.Label("Z", GUILayout.Width(labelWidth));
value.z = DelayedIntField(value.z);
GUILayout.Label("W", GUILayout.Width(labelWidth));
value.w = DelayedIntField(value.w);
return value;
}
}
}

View file

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: ae5bba94d1f1a7144944aebf833497b3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,40 +0,0 @@
using UnityEditor;
using UnityEngine;
using static UnityEditor.EditorGUILayout;
public class BoolInspector : BaseInspector<bool>
{
public override bool Inspect(string label, bool value, object parent, DatabaseInspector inspectorWindow)
{
using (var h = new EditorGUILayout.HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
return Toggle(value);
}
}
}
public class StringInspector : BaseInspector<string>
{
public override string Inspect(string label, string value, object parent, DatabaseInspector inspectorWindow)
{
using (var h = new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
return DelayedTextField(value);
}
}
}
public class StringAreaInspector : BaseInspector<string, InspectableTextAttribute>
{
public override string Inspect(string label, string value, object parent, DatabaseInspector inspectorWindow, InspectableTextAttribute attribute)
{
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
EditorStyles.textArea.wordWrap = true;
return DelayedTextField(value, EditorStyles.textArea, GUILayout.Height(100));
}
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 91dcbfa1679e4be1944d6856ca63bf13
timeCreated: 1617065181

View file

@ -1,23 +0,0 @@
using System;
using System.Linq;
using UnityEditor;
using UnityEngine;
using static UnityEditor.EditorGUILayout;
public class TypeInspector : BaseInspector<Type, InspectableTypeAttribute>
{
public override Type Inspect(string label, Type value, object parent, DatabaseInspector inspectorWindow, InspectableTypeAttribute attribute)
{
var types = attribute.Type.GetAllChildClasses();
var enumOptions = new[] {"None"}.Concat(types.Select(t => t.Name)).ToArray();
var index = Array.IndexOf(types, value) + 1;
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
index = Popup(index, enumOptions);
}
return index == 0 ? null : types[index - 1];
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 4762384a61dc4d08a1ba4e7564a20081
timeCreated: 1617066802

View file

@ -1,47 +0,0 @@
using UnityEditor;
using UnityEngine;
using static UnityEditor.EditorGUILayout;
public class TextureInspector : BaseInspector<string, InspectableTextureAttribute>
{
public override string Inspect(string label,
string value,
object parent,
DatabaseInspector inspectorWindow,
InspectableTextureAttribute attribute)
{
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
return AssetDatabase.GetAssetPath(ObjectField(AssetDatabase.LoadAssetAtPath<Texture2D>(value), typeof(Texture2D), false));
}
}
}
public class GameObjectInspector : BaseInspector<string, InspectablePrefabAttribute>
{
public override string Inspect(string label, string value, object parent, DatabaseInspector inspectorWindow, InspectablePrefabAttribute attribute)
{
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
return AssetDatabase.GetAssetPath(ObjectField(AssetDatabase.LoadAssetAtPath<GameObject>(value), typeof(GameObject), false));
}
}
}
public class TextAssetInspector : BaseInspector<string, InspectableTextAssetAttribute>
{
public override string Inspect(string label,
string value,
object parent,
DatabaseInspector inspectorWindow,
InspectableTextAssetAttribute attribute)
{
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
return AssetDatabase.GetAssetPath(ObjectField(AssetDatabase.LoadAssetAtPath<TextAsset>(value), typeof(TextAsset), false));
}
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 8519fa7d4f06468bb9be151f053d1fcb
timeCreated: 1617067005