update CCK to 3.10, fixing unity 2021 crash :)
This commit is contained in:
parent
48a978fa2a
commit
d11e0fb3a9
492 changed files with 2165204 additions and 437687 deletions
157
Assets/ABI.CCK/Scripts/Editor/CCK_FPRExclusion/CCK_FPRExclusionEditor.cs
Executable file
157
Assets/ABI.CCK/Scripts/Editor/CCK_FPRExclusion/CCK_FPRExclusionEditor.cs
Executable file
|
@ -0,0 +1,157 @@
|
|||
#if UNITY_EDITOR
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace ABI.CCK.Components
|
||||
{
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(FPRExclusion))]
|
||||
public partial class CCK_FPRExclusionEditor : Editor
|
||||
{
|
||||
#region EditorGUI Properties
|
||||
|
||||
// influenced transforms foldout
|
||||
private static bool _guiInfluencedTransformsFoldout;
|
||||
private Vector2 _influencedTransformsScrollPos;
|
||||
|
||||
// popup options
|
||||
private readonly string[] hideModePopupOptions = {"Cut", "Shrink"};
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Variables
|
||||
|
||||
private CVRAvatar _avatar;
|
||||
private FPRExclusion _fprExclusion;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Serialized Properties
|
||||
|
||||
private SerializedProperty m_isShownProp;
|
||||
private SerializedProperty m_shrinkToZeroProp;
|
||||
private SerializedProperty m_targetProp;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity Events
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (target == null) return;
|
||||
_fprExclusion = (FPRExclusion)target;
|
||||
|
||||
_avatar = _fprExclusion.GetComponentInParent<CVRAvatar>();
|
||||
if (_avatar == null) return;
|
||||
|
||||
m_isShownProp = serializedObject.FindProperty(nameof(FPRExclusion.isShown));
|
||||
m_shrinkToZeroProp = serializedObject.FindProperty(nameof(FPRExclusion.shrinkToZero));
|
||||
m_targetProp = serializedObject.FindProperty(nameof(FPRExclusion.target));
|
||||
|
||||
// collect influenced transforms
|
||||
CollectTransformInfluenceList(_avatar);
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (_fprExclusion == null)
|
||||
return;
|
||||
|
||||
Transform oldTarget = _fprExclusion.target;
|
||||
|
||||
EditorGUILayout.HelpBox(
|
||||
"Manual exclusion component for the TransformHider (FPR) system.\n" +
|
||||
"Allows you to manually hide and show chains of transforms that would otherwise be hidden in first person. (ex: hair, glasses, etc.)",
|
||||
MessageType.None);
|
||||
|
||||
if (_avatar == null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("This component is only functional when attached to an avatar.", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
serializedObject.Update();
|
||||
|
||||
Draw_ExclusionSettings();
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
if (oldTarget != _fprExclusion.target) // if target changed, update the children
|
||||
CollectTransformInfluenceList(_avatar);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Gizmo Drawing
|
||||
|
||||
[DrawGizmo(GizmoType.Selected)]
|
||||
private static void OnGizmosSelected(FPRExclusion exclusion, GizmoType _) => DrawGizmos(exclusion);
|
||||
|
||||
private static void DrawGizmos(FPRExclusion exclusion)
|
||||
{
|
||||
if (!_guiInfluencedTransformsFoldout)
|
||||
return;
|
||||
|
||||
Gizmos.color = exclusion.isShown ? Color.green : Color.red;
|
||||
|
||||
// draw lines to represent the influenced transform chain
|
||||
for (var i = 0; i < exclusion.influencedTransforms.Count; i++)
|
||||
{
|
||||
if (i + 1 >= exclusion.influencedTransforms.Count)
|
||||
continue; // skip first and last transform
|
||||
|
||||
Transform next = exclusion.influencedTransforms[i + 1];
|
||||
Transform parent = next.parent;
|
||||
if (parent == null || next == null) continue;
|
||||
Gizmos.DrawLine(parent.position, next.position);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private static readonly List<Transform> _seenTransforms = new();
|
||||
|
||||
private static void CollectTransformInfluenceList(Component avatarRoot)
|
||||
{
|
||||
_seenTransforms.Clear();
|
||||
|
||||
// head bone has a default exclusion, user can use their own tho
|
||||
Animator animator = avatarRoot.GetComponent<Animator>();
|
||||
if (animator != null && animator.avatar != null && animator.isHuman)
|
||||
{
|
||||
Transform headBone = animator.GetBoneTransform(HumanBodyBones.Head);
|
||||
if (headBone != null && headBone.GetComponent<FPRExclusion>() == null)
|
||||
_seenTransforms.Add(headBone); // if no custom exclusion, add manually to seen list
|
||||
}
|
||||
|
||||
var fprExclusions = avatarRoot.GetComponentsInChildren<FPRExclusion>(true).ToList();
|
||||
for (var i = fprExclusions.Count - 1; i >= 0; i--)
|
||||
{
|
||||
FPRExclusion exclusion = fprExclusions[i];
|
||||
exclusion.influencedTransforms.Clear(); // clear previous list
|
||||
ProcessExclusion(exclusion, exclusion.target ? exclusion.target : exclusion.transform);
|
||||
}
|
||||
|
||||
return;
|
||||
void ProcessExclusion(FPRExclusion exclusion, Transform transform)
|
||||
{
|
||||
if (_seenTransforms.Contains(transform)
|
||||
&& transform != exclusion.target)
|
||||
return; // found transform in existing exclusion
|
||||
|
||||
_seenTransforms.Add(transform);
|
||||
exclusion.influencedTransforms.Add(transform);
|
||||
foreach (Transform child in transform) // process children
|
||||
ProcessExclusion(exclusion, child);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 53888dfbf2034632a60fcc8ceffc6283
|
||||
timeCreated: 1708990953
|
|
@ -0,0 +1,79 @@
|
|||
using ABI.CCK.Scripts.Editor;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using static ABI.CCK.Scripts.Editor.SharedComponentGUI;
|
||||
|
||||
namespace ABI.CCK.Components
|
||||
{
|
||||
public partial class CCK_FPRExclusionEditor
|
||||
{
|
||||
private void Draw_ExclusionSettings()
|
||||
{
|
||||
using (new SharedComponentGUI.LabelScope("Exclusion Configuration"))
|
||||
{
|
||||
using (new EditorGUI.IndentLevelScope())
|
||||
{
|
||||
DrawExclusionSettings();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
DrawInfluencedTransforms();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Drawing Methods
|
||||
|
||||
private void DrawExclusionSettings()
|
||||
{
|
||||
EditorGUIUtility.labelWidth *= 0.75f;
|
||||
|
||||
EditorGUILayout.PropertyField(m_isShownProp);
|
||||
|
||||
const float indent = 15; // we are in an indent scope
|
||||
Rect rect = EditorGUILayout.GetControlRect();
|
||||
EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width - 65, rect.height), m_targetProp);
|
||||
rect.x += rect.width - 60 - indent;
|
||||
rect.width = 60 + indent;
|
||||
|
||||
int visibilityIndex = m_shrinkToZeroProp.intValue;
|
||||
|
||||
visibilityIndex = EditorGUI.Popup(rect, visibilityIndex, hideModePopupOptions);
|
||||
if (visibilityIndex != m_shrinkToZeroProp.intValue) m_shrinkToZeroProp.intValue = visibilityIndex;
|
||||
|
||||
EditorGUIUtility.labelWidth *= 1.25f;
|
||||
}
|
||||
|
||||
private void DrawInfluencedTransforms()
|
||||
{
|
||||
if (_fprExclusion.influencedTransforms.Count <= 0)
|
||||
return;
|
||||
|
||||
using (new EditorGUI.DisabledGroupScope(true))
|
||||
if (!InnerFoldout(ref _guiInfluencedTransformsFoldout, "Influenced Transforms (Read-Only)"))
|
||||
return;
|
||||
|
||||
// force repaint to update gizmos
|
||||
SceneView.RepaintAll();
|
||||
|
||||
EditorGUILayout.HelpBox(
|
||||
"This exclusion will affect the following transforms:",
|
||||
MessageType.Info);
|
||||
|
||||
_influencedTransformsScrollPos = EditorGUILayout.BeginScrollView(_influencedTransformsScrollPos, false, false,
|
||||
GUILayout.Height(90)); // cut off slightly so its apparent that it's a scroll view
|
||||
|
||||
EditorGUI.BeginDisabledGroup(true);
|
||||
foreach (Object o in targets) // account for multi-editing
|
||||
{
|
||||
FPRExclusion fprExclusion = (FPRExclusion)o;
|
||||
foreach (Transform transform in fprExclusion.influencedTransforms)
|
||||
EditorGUILayout.ObjectField(transform, typeof(Transform), true);
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
||||
EditorGUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 704bffdf0c254ac9985e3be3947e7f31
|
||||
timeCreated: 1708991595
|
Loading…
Add table
Add a link
Reference in a new issue