update CCK to 3.10, fixing unity 2021 crash :)

This commit is contained in:
Crispy 2024-08-03 22:24:42 +02:00
parent 48a978fa2a
commit d11e0fb3a9
492 changed files with 2165204 additions and 437687 deletions

View file

@ -1,250 +1,48 @@
using System.Collections.Generic;
using ABI.CCK.Components;
using ABI.CCK.Components;
using ABI.CCK.Scripts.Editor;
using ABI.CCK.Scripts.Editor.Tools;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using AnimatorControllerParameterType = UnityEngine.AnimatorControllerParameterType;
namespace ABI.CCK.Scripts.Editor
{
[CustomEditor(typeof(ABI.CCK.Components.CVRSpawnable), true)]
//[CustomEditor(typeof(CVRSpawnable), true)]
public class CCK_CVRSpawnableEditor : UnityEditor.Editor
{
private CVRSpawnable _spawnable;
private ReorderableList reorderableList;
private ReorderableList subSyncList;
private CVRSpawnableValue entity;
private CVRSpawnableSubSync subSyncEntity;
private float SubSyncCosts = 0f;
private bool outOfBoundsError = false;
private void InitializeList()
{
if (!_spawnable.useAdditionalValues) return;
reorderableList = new ReorderableList(_spawnable.syncValues, typeof(CVRAdvancedSettingsEntry), true, true, true, true);
reorderableList.drawHeaderCallback = OnDrawHeader;
reorderableList.drawElementCallback = OnDrawElement;
reorderableList.elementHeightCallback = OnHeightElement;
reorderableList.onAddCallback = OnAdd;
reorderableList.onChangedCallback = OnChanged;
}
private ReorderableList _syncedValueList;
private CVRSpawnableValue _syncedValueEntry;
private void InitializeSubSyncList()
private ReorderableList _subSyncList;
private CVRSpawnableSubSync _subSyncEntry;
private float _subSyncCosts;
private bool _outOfBoundsError;
#region Unity Events
public void OnEnable()
{
if (!_spawnable.useAdditionalValues) return;
// Occurs on recompile
if (target == null)
return;
subSyncList = new ReorderableList(_spawnable.subSyncs, typeof(CVRSpawnableSubSync), false, true, true, true);
subSyncList.drawHeaderCallback = OnDrawHeaderSubSync;
subSyncList.drawElementCallback = OnDrawElementSubSync;
subSyncList.elementHeightCallback = OnHeightElementSubSync;
subSyncList.onAddCallback = OnAddSubSync;
subSyncList.onChangedCallback = OnChangedSubSync;
}
private void OnDrawHeaderSubSync(Rect rect)
{
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
GUI.Label(_rect, "Sub Sync Transforms");
}
private void OnDrawElementSubSync(Rect rect, int index, bool isactive, bool isfocused)
{
if (index > _spawnable.subSyncs.Count) return;
subSyncEntity = _spawnable.subSyncs[index];
rect.y += 2;
Rect _rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
EditorGUI.LabelField(_rect, "Transform");
_rect.x += 120;
_rect.width = rect.width - 120;
subSyncEntity.transform = (Transform) EditorGUI.ObjectField(_rect, subSyncEntity.transform, typeof(Transform));
_spawnable = (CVRSpawnable)target;
_spawnable.Reset();
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
_rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
if (_syncedValueList == null)
InitializeList();
EditorGUI.LabelField(_rect, "Synced Properties");
_rect.x += 120;
_rect.width = rect.width - 120;
subSyncEntity.syncedValues = (CVRSpawnableSubSync.SyncFlags) EditorGUI.EnumFlagsField(_rect, subSyncEntity.syncedValues);
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
_rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
EditorGUI.LabelField(_rect, "Sync Precision");
_rect.x += 120;
_rect.width = rect.width - 120;
subSyncEntity.precision = (CVRSpawnableSubSync.SyncPrecision) EditorGUI.EnumPopup(_rect, subSyncEntity.precision);
if (subSyncEntity.precision == CVRSpawnableSubSync.SyncPrecision.Full) return;
if (subSyncEntity.transform != null &&
(Mathf.Abs(subSyncEntity.transform.localPosition.x) > subSyncEntity.syncBoundary ||
Mathf.Abs(subSyncEntity.transform.localPosition.y) > subSyncEntity.syncBoundary ||
Mathf.Abs(subSyncEntity.transform.localPosition.z) > subSyncEntity.syncBoundary))
{
outOfBoundsError = true;
}
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
_rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
EditorGUI.LabelField(_rect, "Sync Boundary");
_rect.x += 120;
_rect.width = rect.width - 120;
subSyncEntity.syncBoundary = EditorGUI.FloatField(_rect, subSyncEntity.syncBoundary);
}
private float OnHeightElementSubSync(int index)
{
if (_spawnable.subSyncs[index].precision == CVRSpawnableSubSync.SyncPrecision.Full) return EditorGUIUtility.singleLineHeight * 3.75f;
return EditorGUIUtility.singleLineHeight * 5f;
}
private void OnAddSubSync(ReorderableList list)
{
if (_spawnable.subSyncs.Count < 40)
{
_spawnable.subSyncs.Add(new CVRSpawnableSubSync());
Repaint();
}
}
private void OnChangedSubSync(ReorderableList list)
{
//EditorUtility.SetDirty(target);
}
private void OnChanged(ReorderableList list)
{
//EditorUtility.SetDirty(target);
}
private void OnAdd(ReorderableList list)
{
if (_spawnable.syncValues.Count < 40)
{
_spawnable.syncValues.Add(new CVRSpawnableValue());
Repaint();
}
}
private float OnHeightElement(int index)
{
return EditorGUIUtility.singleLineHeight * 7.5f;
}
private void OnDrawElement(Rect rect, int index, bool isactive, bool isfocused)
{
if (index > _spawnable.syncValues.Count) return;
entity = _spawnable.syncValues[index];
rect.y += 2;
Rect _rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
EditorGUI.LabelField(_rect, "Name");
_rect.x += 120;
_rect.width = rect.width - 120;
entity.name = EditorGUI.TextField(_rect, entity.name);
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
_rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
EditorGUI.LabelField(_rect, "Start Value");
_rect.x += 120;
_rect.width = rect.width - 120;
entity.startValue = EditorGUI.FloatField(_rect, entity.startValue);
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
_rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
EditorGUI.LabelField(_rect, "Update Type");
_rect.x += 120;
_rect.width = rect.width - 120;
entity.updatedBy = (CVRSpawnableValue.UpdatedBy) EditorGUI.EnumPopup(_rect, entity.updatedBy);
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
_rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
EditorGUI.LabelField(_rect, "Update Method");
_rect.x += 120;
_rect.width = rect.width - 120;
entity.updateMethod = (CVRSpawnableValue.UpdateMethod) EditorGUI.EnumPopup(_rect, entity.updateMethod);
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
_rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
EditorGUI.LabelField(_rect, "Connected Animator");
_rect.x += 120;
_rect.width = rect.width - 120;
entity.animator = (Animator) EditorGUI.ObjectField(_rect, entity.animator, typeof(Animator));
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
_rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
EditorGUI.LabelField(_rect, "Animator Parameter");
_rect.x += 120;
_rect.width = rect.width - 120;
var parameters = new List<string>();
parameters.Add("-none-");
var parameterIndex = 0;
if (entity.animator != null)
{
if (entity.animator.runtimeAnimatorController != null)
{
foreach (var parameter in ((UnityEditor.Animations.AnimatorController) entity.animator.runtimeAnimatorController).parameters)
{
if (parameter.type == AnimatorControllerParameterType.Float)
{
parameters.Add(parameter.name);
}
}
parameterIndex = parameters.FindIndex(match => match == entity.animatorParameterName);
}
}
if (parameterIndex < 0) parameterIndex = 0;
parameterIndex = EditorGUI.Popup(_rect, parameterIndex, parameters.ToArray());
entity.animatorParameterName = parameters[parameterIndex];
}
private void OnDrawHeader(Rect rect)
{
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
GUI.Label(_rect, "Values");
}
public void UpdateSubSyncCosts()
{
SubSyncCosts = 0f;
foreach (var subSync in _spawnable.subSyncs)
{
if (subSync.syncedValues.HasFlag(CVRSpawnableSubSync.SyncFlags.TransformX))
SubSyncCosts += (int) subSync.precision / 4f;
if (subSync.syncedValues.HasFlag(CVRSpawnableSubSync.SyncFlags.TransformY))
SubSyncCosts += (int) subSync.precision / 4f;
if (subSync.syncedValues.HasFlag(CVRSpawnableSubSync.SyncFlags.TransformZ))
SubSyncCosts += (int) subSync.precision / 4f;
if (subSync.syncedValues.HasFlag(CVRSpawnableSubSync.SyncFlags.RotationX))
SubSyncCosts += (int) subSync.precision / 4f;
if (subSync.syncedValues.HasFlag(CVRSpawnableSubSync.SyncFlags.RotationY))
SubSyncCosts += (int) subSync.precision / 4f;
if (subSync.syncedValues.HasFlag(CVRSpawnableSubSync.SyncFlags.RotationZ))
SubSyncCosts += (int) subSync.precision / 4f;
}
if (_subSyncList == null)
InitializeSubSyncList();
}
public override void OnInspectorGUI()
{
if (_spawnable == null) _spawnable = (CVRSpawnable) target;
if (_spawnable == null)
return;
EditorGUI.BeginChangeCheck();
@ -266,28 +64,25 @@ namespace ABI.CCK.Scripts.Editor
GUILayout.BeginHorizontal();
GUILayout.BeginVertical("GroupBox");
var SyncCost = _spawnable.syncValues.Count + SubSyncCosts;
var SyncCost = _spawnable.syncValues.Count + _subSyncCosts;
Rect _rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight);
EditorGUI.ProgressBar(_rect, SyncCost / 40f, Mathf.CeilToInt(SyncCost) + " of 40 Synced Parameter Slots used");
EditorGUI.ProgressBar(_rect, SyncCost / 40f, Mathf.CeilToInt(SyncCost) + " of 40 Synced Values used");
EditorGUILayout.Space();
if (SubSyncCosts > 0f)
if (_subSyncCosts > 0f)
{
EditorGUILayout.HelpBox(SubSyncCosts.ToString("F2")+" Values are used for Sub Sync Transforms", MessageType.Info);
EditorGUILayout.HelpBox(_subSyncCosts.ToString("F2")+" Values are used for Sub Sync Transforms", MessageType.Info);
EditorGUILayout.Space();
}
if (reorderableList == null) InitializeList();
reorderableList.displayAdd = SyncCost <= 39f;
reorderableList.DoLayoutList();
_syncedValueList.displayAdd = SyncCost <= 39f;
_syncedValueList.DoLayoutList();
EditorGUILayout.Space();
outOfBoundsError = false;
if (subSyncList == null) InitializeSubSyncList();
subSyncList.displayAdd = SyncCost <= 39f;
subSyncList.DoLayoutList();
_subSyncList.displayAdd = SyncCost <= 39f;
_subSyncList.DoLayoutList();
GUILayout.EndVertical();
GUILayout.EndHorizontal();
@ -295,15 +90,185 @@ namespace ABI.CCK.Scripts.Editor
GUILayout.EndVertical();
if (outOfBoundsError)
if (_outOfBoundsError)
{
EditorGUILayout.HelpBox("A Sub Sync Transform is out of bounds by default. This object will snap to its bounds, when it is being synced.", MessageType.Error);
_outOfBoundsError = false;
}
if (EditorGUI.EndChangeCheck())
{
EditorUtility.SetDirty(_spawnable);
}
#endregion
#region ReorderableList SyncedValue
private void InitializeList()
{
_syncedValueList = new ReorderableList(_spawnable.syncValues, typeof(CVRAdvancedSettingsEntry), true, true, true, true)
{
drawHeaderCallback = OnDrawHeaderSyncedValue,
drawElementCallback = OnDrawElementSyncedValue,
elementHeightCallback = OnHeightElementSyncedValue,
onAddCallback = OnAddSyncedValue,
onChangedCallback = OnChangedSyncedValue
};
}
private void OnChangedSyncedValue(ReorderableList list)
{
//EditorUtility.SetDirty(target);
}
private void OnAddSyncedValue(ReorderableList list)
{
if (_spawnable.syncValues.Count >= 40) return;
_spawnable.syncValues.Add(new CVRSpawnableValue());
Repaint();
}
private float OnHeightElementSyncedValue(int index)
{
return EditorGUIUtility.singleLineHeight * 7.5f;
}
private void OnDrawElementSyncedValue(Rect rect, int index, bool isactive, bool isfocused)
{
if (index > _spawnable.syncValues.Count) return;
_syncedValueEntry = _spawnable.syncValues[index];
rect = new Rect(rect.x, rect.y + 2, rect.width, EditorGUIUtility.singleLineHeight);
float spacing = EditorGUIUtility.singleLineHeight * 1.25f;
float originalLabelWidth = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 120;
_syncedValueEntry.name = EditorGUI.TextField(rect, "Name", _syncedValueEntry.name);
rect.y += spacing;
_syncedValueEntry.startValue = EditorGUI.FloatField(rect, "Start Value", _syncedValueEntry.startValue);
rect.y += spacing;
_syncedValueEntry.updatedBy = (CVRSpawnableValue.UpdatedBy) EditorGUI.EnumPopup(rect, "Update Type", _syncedValueEntry.updatedBy);
rect.y += spacing;
_syncedValueEntry.updateMethod = (CVRSpawnableValue.UpdateMethod) EditorGUI.EnumPopup(rect, "Update Method", _syncedValueEntry.updateMethod);
rect.y += spacing;
_syncedValueEntry.animator = (Animator)EditorGUI.ObjectField(rect, "Connected Animator", _syncedValueEntry.animator, typeof(Animator), true);
rect.y += spacing;
_syncedValueEntry.animatorParameterName = EditorGUIExtensions.AdvancedDropdownInput(rect, _syncedValueEntry.animatorParameterName,
CVRCommon.GetParametersFromAnimatorAsString(_syncedValueEntry.animator), "Animator Parameter","No Parameters");
EditorGUIUtility.labelWidth = originalLabelWidth;
}
private void OnDrawHeaderSyncedValue(Rect rect)
{
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
GUI.Label(_rect, "Values");
EditorGUIExtensions.UtilityMenu(_rect, _syncedValueList);
}
#endregion
#region ReorderableList SubSync
private void InitializeSubSyncList()
{
_subSyncList = new ReorderableList(_spawnable.subSyncs, typeof(CVRSpawnableSubSync), false, true, true, true)
{
drawHeaderCallback = OnDrawHeaderSubSync,
drawElementCallback = OnDrawElementSubSync,
elementHeightCallback = OnHeightElementSubSync,
onAddCallback = OnAddSubSync,
onChangedCallback = OnChangedSubSync
};
}
private void OnDrawHeaderSubSync(Rect rect)
{
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
GUI.Label(_rect, "Sub Sync Transforms");
EditorGUIExtensions.UtilityMenu(_rect, _subSyncList);
}
private void OnDrawElementSubSync(Rect rect, int index, bool isactive, bool isfocused)
{
if (index > _spawnable.subSyncs.Count) return;
_subSyncEntry = _spawnable.subSyncs[index];
rect = new Rect(rect.x, rect.y + 2, rect.width, EditorGUIUtility.singleLineHeight);
float spacing = EditorGUIUtility.singleLineHeight * 1.25f;
float originalLabelWidth = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 120;
_subSyncEntry.transform = (Transform)EditorGUI.ObjectField(rect, "Transform", _subSyncEntry.transform, typeof(Transform), true);
rect.y += spacing;
_subSyncEntry.syncedValues = (CVRSpawnableSubSync.SyncFlags) EditorGUI.EnumFlagsField(rect, "Synced Properties", _subSyncEntry.syncedValues);
rect.y += spacing;
_subSyncEntry.precision = (CVRSpawnableSubSync.SyncPrecision) EditorGUI.EnumPopup(rect, "Sync Precision", _subSyncEntry.precision);
rect.y += spacing;
if (_subSyncEntry.precision != CVRSpawnableSubSync.SyncPrecision.Full)
{
_subSyncEntry.syncBoundary = EditorGUI.FloatField(rect, "Sync Boundary", _subSyncEntry.syncBoundary);
rect.y += spacing;
if (_subSyncEntry.transform != null)
{
Vector3 localPosition = _subSyncEntry.transform.localPosition;
_outOfBoundsError = Mathf.Abs(localPosition.x) > _subSyncEntry.syncBoundary ||
Mathf.Abs(localPosition.y) > _subSyncEntry.syncBoundary ||
Mathf.Abs(localPosition.z) > _subSyncEntry.syncBoundary;
}
}
EditorGUIUtility.labelWidth = originalLabelWidth;
}
private float OnHeightElementSubSync(int index)
{
if (_spawnable.subSyncs[index].precision == CVRSpawnableSubSync.SyncPrecision.Full)
return EditorGUIUtility.singleLineHeight * 3.75f;
return EditorGUIUtility.singleLineHeight * 5f;
}
private void OnAddSubSync(ReorderableList list)
{
if (_spawnable.subSyncs.Count >= 40) return;
_spawnable.subSyncs.Add(new CVRSpawnableSubSync());
Repaint();
}
private void OnChangedSubSync(ReorderableList list)
{
//EditorUtility.SetDirty(target);
}
#endregion
#region Private Methods
private void UpdateSubSyncCosts()
{
_subSyncCosts = 0f;
foreach (CVRSpawnableSubSync subSync in _spawnable.subSyncs)
{
if (subSync.syncedValues.HasFlag(CVRSpawnableSubSync.SyncFlags.TransformX))
_subSyncCosts += (int) subSync.precision / 4f;
if (subSync.syncedValues.HasFlag(CVRSpawnableSubSync.SyncFlags.TransformY))
_subSyncCosts += (int) subSync.precision / 4f;
if (subSync.syncedValues.HasFlag(CVRSpawnableSubSync.SyncFlags.TransformZ))
_subSyncCosts += (int) subSync.precision / 4f;
if (subSync.syncedValues.HasFlag(CVRSpawnableSubSync.SyncFlags.RotationX))
_subSyncCosts += (int) subSync.precision / 4f;
if (subSync.syncedValues.HasFlag(CVRSpawnableSubSync.SyncFlags.RotationY))
_subSyncCosts += (int) subSync.precision / 4f;
if (subSync.syncedValues.HasFlag(CVRSpawnableSubSync.SyncFlags.RotationZ))
_subSyncCosts += (int) subSync.precision / 4f;
}
}
#endregion
}
}