From 4c71f9e9583d54dbf368fdb2719c506461f89696 Mon Sep 17 00:00:00 2001 From: dooly Date: Thu, 16 Jan 2025 05:34:28 +1000 Subject: [PATCH] cleaned up a bunch of pickup code --- .../com.basis.framework/Pickup/BasisPickup.cs | 2 +- .../Helpers/BasisObservableList.cs | 12 +- .../BasisNetworkClient.csproj.meta | 7 + .../BasisNetworkCore.csproj.meta | 7 + .../BasisNetworkServer.slnLaunch.user.meta | 7 + .../com.basis.tests/BasisExamples.asmdef | 3 +- .../Interactable/CachedList.cs | 91 ---- .../Interactable/CachedList.cs.meta | 2 - .../ExampleButtonInteractable.cs | 51 +- .../Examples/PickupInteractable.prefab | 34 +- .../Interactable/HoverInteractSphere.cs | 1 + .../Interactable/InteractableObject.cs | 9 +- .../Interactable/InteractableTestScene.unity | 450 +++--------------- .../Interactable/PickupInteractable.cs | 155 +++--- .../Interactable/PlayerInteract.cs | 163 ++++--- 15 files changed, 294 insertions(+), 700 deletions(-) create mode 100644 Basis/Packages/com.basis.server/BasisNetworkClient/BasisNetworkClient.csproj.meta create mode 100644 Basis/Packages/com.basis.server/BasisNetworkCore/BasisNetworkCore.csproj.meta create mode 100644 Basis/Packages/com.basis.server/BasisNetworkServer.slnLaunch.user.meta delete mode 100644 Basis/Packages/com.basis.tests/Interactable/CachedList.cs delete mode 100644 Basis/Packages/com.basis.tests/Interactable/CachedList.cs.meta diff --git a/Basis/Packages/com.basis.framework/Pickup/BasisPickup.cs b/Basis/Packages/com.basis.framework/Pickup/BasisPickup.cs index a2c139204..26fdb2e6e 100644 --- a/Basis/Packages/com.basis.framework/Pickup/BasisPickup.cs +++ b/Basis/Packages/com.basis.framework/Pickup/BasisPickup.cs @@ -61,4 +61,4 @@ public void LateUpdate() } } -} \ No newline at end of file +} diff --git a/Basis/Packages/com.basis.sdk/Helpers/BasisObservableList.cs b/Basis/Packages/com.basis.sdk/Helpers/BasisObservableList.cs index 7dc15b284..8de212460 100644 --- a/Basis/Packages/com.basis.sdk/Helpers/BasisObservableList.cs +++ b/Basis/Packages/com.basis.sdk/Helpers/BasisObservableList.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using UnityEngine; @@ -10,6 +10,7 @@ public class BasisObservableList : IList [SerializeField] public List _list = new List(); + public event Action OnListAdded; public event Action OnListChanged; public event Action OnListItemRemoved; public T this[int index] @@ -29,11 +30,11 @@ public T this[int index] public int Count => _list.Count; public bool IsReadOnly => false; - public void Add(T item) { - _list.Add(item); - OnListChanged?.Invoke(); + _list.Add(item); + OnListChanged?.Invoke(); + OnListAdded?.Invoke(item); } public void Clear() @@ -54,6 +55,7 @@ public void Insert(int index, T item) { _list.Insert(index, item); OnListChanged?.Invoke(); + OnListAdded?.Invoke(item); } public bool Remove(T item) @@ -86,4 +88,4 @@ public int RemoveAll(Predicate match) System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => _list.GetEnumerator(); } -} \ No newline at end of file +} diff --git a/Basis/Packages/com.basis.server/BasisNetworkClient/BasisNetworkClient.csproj.meta b/Basis/Packages/com.basis.server/BasisNetworkClient/BasisNetworkClient.csproj.meta new file mode 100644 index 000000000..a563b5b5d --- /dev/null +++ b/Basis/Packages/com.basis.server/BasisNetworkClient/BasisNetworkClient.csproj.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 3634058000f939b4094a179b7e56b412 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Basis/Packages/com.basis.server/BasisNetworkCore/BasisNetworkCore.csproj.meta b/Basis/Packages/com.basis.server/BasisNetworkCore/BasisNetworkCore.csproj.meta new file mode 100644 index 000000000..8b4d0e3ce --- /dev/null +++ b/Basis/Packages/com.basis.server/BasisNetworkCore/BasisNetworkCore.csproj.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 781f141bec8a3c048a88d9a3ad24e821 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Basis/Packages/com.basis.server/BasisNetworkServer.slnLaunch.user.meta b/Basis/Packages/com.basis.server/BasisNetworkServer.slnLaunch.user.meta new file mode 100644 index 000000000..e662abaa1 --- /dev/null +++ b/Basis/Packages/com.basis.server/BasisNetworkServer.slnLaunch.user.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: f73e7da5a9ef9e84789828c80217bbf2 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Basis/Packages/com.basis.tests/BasisExamples.asmdef b/Basis/Packages/com.basis.tests/BasisExamples.asmdef index 324f48219..b64350107 100644 --- a/Basis/Packages/com.basis.tests/BasisExamples.asmdef +++ b/Basis/Packages/com.basis.tests/BasisExamples.asmdef @@ -16,7 +16,8 @@ "GUID:da668404f8bf3b14ebd4691cc0a6d67c", "GUID:42c34c05b8d434943ad2cf21483d9cd0", "GUID:784bec3882b21ab4d8407cc870539fa9", - "GUID:45c7722710e2a37438daaacbf1cd4ad1" + "GUID:45c7722710e2a37438daaacbf1cd4ad1", + "GUID:d8b63aba1907145bea998dd612889d6b" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Basis/Packages/com.basis.tests/Interactable/CachedList.cs b/Basis/Packages/com.basis.tests/Interactable/CachedList.cs deleted file mode 100644 index 23c2e742d..000000000 --- a/Basis/Packages/com.basis.tests/Interactable/CachedList.cs +++ /dev/null @@ -1,91 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -public class CachedList : IEnumerable -{ - private readonly List _list; - private int _cachedCount; - private bool _isCountValid; - - public CachedList() - { - _list = new List(); - _isCountValid = false; - } - - public CachedList(IEnumerable collection) - { - _list = new List(collection); - _cachedCount = _list.Count; - _isCountValid = true; - } - - public int Count - { - get - { - if (!_isCountValid) - { - _cachedCount = _list.Count; - _isCountValid = true; - } - return _cachedCount; - } - } - - public void Add(T item) - { - _list.Add(item); - InvalidateCount(); - } - - public void AddRange(IEnumerable collection) - { - _list.AddRange(collection); - InvalidateCount(); - } - - public bool Remove(T item) - { - bool removed = _list.Remove(item); - if (removed) - { - InvalidateCount(); - } - return removed; - } - - public void RemoveAt(int index) - { - _list.RemoveAt(index); - InvalidateCount(); - } - - public void Clear() - { - _list.Clear(); - InvalidateCount(); - } - - public T this[int index] - { - get => _list[index]; - set => _list[index] = value; - } - - private void InvalidateCount() - { - _isCountValid = false; - } - - public IEnumerator GetEnumerator() - { - return _list.GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } -} diff --git a/Basis/Packages/com.basis.tests/Interactable/CachedList.cs.meta b/Basis/Packages/com.basis.tests/Interactable/CachedList.cs.meta deleted file mode 100644 index 1dbd5d0b3..000000000 --- a/Basis/Packages/com.basis.tests/Interactable/CachedList.cs.meta +++ /dev/null @@ -1,2 +0,0 @@ -fileFormatVersion: 2 -guid: 6e2c1163d84c2a746b66780455bbd908 \ No newline at end of file diff --git a/Basis/Packages/com.basis.tests/Interactable/Examples/ExampleButton/ExampleButtonInteractable.cs b/Basis/Packages/com.basis.tests/Interactable/Examples/ExampleButton/ExampleButtonInteractable.cs index 1fd3ada65..0be793aac 100644 --- a/Basis/Packages/com.basis.tests/Interactable/Examples/ExampleButton/ExampleButtonInteractable.cs +++ b/Basis/Packages/com.basis.tests/Interactable/Examples/ExampleButton/ExampleButtonInteractable.cs @@ -24,11 +24,7 @@ public class ExampleButtonInteractable : InteractableObject void Start() { - InputSources = new CachedList - { - new InputSource(null, false) - }; - + InputSource = new BasisInputWrapper(null, false); if (ColliderRef == null) { TryGetComponent(out ColliderRef); @@ -43,21 +39,21 @@ void Start() public override bool CanHover(BasisInput input) { - return InputSources[0].Source == null && IsWithinRange(input.transform.position) && isEnabled; + return InputSource.Source == null && IsWithinRange(input.transform.position) && isEnabled; } public override bool CanInteract(BasisInput input) { // must be the same input hovering if (!IsCurrentInput(input.UniqueDeviceIdentifier)) return false; // dont interact again till after interacting stopped - if (InputSources[0].IsInteracting) return false; + if (InputSource.IsInteracting) return false; return IsWithinRange(input.transform.position) && isEnabled; } public override void OnHoverStart(BasisInput input) { - InputSources[0] = new InputSource(input, false); + InputSource = new BasisInputWrapper(input, false); SetColor(HoverColor); } @@ -68,7 +64,7 @@ public override void OnHoverEnd(BasisInput input, bool willInteract) // leaving hover and wont interact this frame if (!willInteract) { - InputSources[0] = new InputSource(null, false); + InputSource = new BasisInputWrapper(null, false); SetColor(Color); } // Oninteract will update color @@ -77,42 +73,42 @@ public override void OnHoverEnd(BasisInput input, bool willInteract) public override void OnInteractStart(BasisInput input) { - if (IsCurrentInput(input.UniqueDeviceIdentifier) && !InputSources[0].IsInteracting) + if (IsCurrentInput(input.UniqueDeviceIdentifier) && !InputSource.IsInteracting) { // Set ownership to the local player // syncNetworking.IsOwner = true; SetColor(InteractColor); - InputSources[0] = new InputSource(input, true); + InputSource = new BasisInputWrapper(input, true); ButtonDown?.Invoke(); } } public override void OnInteractEnd(BasisInput input) { - if (IsCurrentInput(input.UniqueDeviceIdentifier) && InputSources[0].IsInteracting) + if (IsCurrentInput(input.UniqueDeviceIdentifier) && InputSource.IsInteracting) { SetColor(Color); - InputSources[0] = new InputSource(null, false); + InputSource = new BasisInputWrapper(null, false); ButtonUp?.Invoke(); } } public override bool IsInteractingWith(BasisInput input) { - return InputSources[0].Source != null && - InputSources[0].Source.UniqueDeviceIdentifier == input.UniqueDeviceIdentifier && - InputSources[0].IsInteracting; + return InputSource.Source != null && + InputSource.Source.UniqueDeviceIdentifier == input.UniqueDeviceIdentifier && + InputSource.IsInteracting; } public override bool IsHoveredBy(BasisInput input) { - return InputSources[0].Source != null && - InputSources[0].Source.UniqueDeviceIdentifier == input.UniqueDeviceIdentifier && - !InputSources[0].IsInteracting; + return InputSource.Source != null && + InputSource.Source.UniqueDeviceIdentifier == input.UniqueDeviceIdentifier && + !InputSource.IsInteracting; } private bool IsCurrentInput(string uid) { - return InputSources[0].Source != null && InputSources[0].Source.UniqueDeviceIdentifier == uid; + return InputSource.Source != null && InputSource.Source.UniqueDeviceIdentifier == uid; } // set material property to a color @@ -128,21 +124,22 @@ private void SetColor(Color color) // per-frame update, after IK transform public override void InputUpdate() { - if(!isEnabled) { + if (!isEnabled) + { // clean up currently hovering/interacting - if (InputSources[0].Source != null) + if (InputSource.Source != null) { - if (IsHoveredBy(InputSources[0].Source)) + if (IsHoveredBy(InputSource.Source)) { - OnHoverEnd(InputSources[0].Source, false); + OnHoverEnd(InputSource.Source, false); } - if (IsInteractingWith(InputSources[0].Source)) + if (IsInteractingWith(InputSource.Source)) { - OnInteractEnd(InputSources[0].Source); + OnInteractEnd(InputSource.Source); } } // setting same color every frame isnt optimal but fine for example SetColor(DisabledColor); } } -} \ No newline at end of file +} diff --git a/Basis/Packages/com.basis.tests/Interactable/Examples/PickupInteractable.prefab b/Basis/Packages/com.basis.tests/Interactable/Examples/PickupInteractable.prefab index 52ad4ef6a..69e403400 100644 --- a/Basis/Packages/com.basis.tests/Interactable/Examples/PickupInteractable.prefab +++ b/Basis/Packages/com.basis.tests/Interactable/Examples/PickupInteractable.prefab @@ -14,7 +14,6 @@ GameObject: - component: {fileID: 2600401473938556946} - component: {fileID: 1001019263030247314} - component: {fileID: 5036961803400065188} - - component: {fileID: 1266327906536326857} m_Layer: 8 m_Name: PickupInteractable m_TagString: Untagged @@ -134,7 +133,7 @@ Rigidbody: m_ImplicitCom: 1 m_ImplicitTensor: 1 m_UseGravity: 0 - m_IsKinematic: 0 + m_IsKinematic: 1 m_Interpolate: 0 m_Constraints: 0 m_CollisionDetection: 0 @@ -151,34 +150,11 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: InteractRange: 1 - CanEquip: 0 - equipPos: {x: 0, y: 0, z: 0} + CanEquip: 1 + equipPos: {x: 0, y: -0.1, z: 0.1} equipRot: {x: 0, y: 0, z: 0, w: 0} - KinematicWhileInteracting: 1 + RequiresUpdateLoop: 0 + KinematicWhileInteracting: 0 LocalOnly: 1 ColliderRef: {fileID: 0} RigidRef: {fileID: 0} - ConstraintRef: {fileID: 0} ---- !u!1773428102 &1266327906536326857 -ParentConstraint: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8381068889838832174} - m_Enabled: 1 - serializedVersion: 2 - m_Weight: 1 - m_TranslationAtRest: {x: -0.744, y: 1, z: 0} - m_RotationAtRest: {x: 0, y: 0, z: 0} - m_TranslationOffsets: [] - m_RotationOffsets: [] - m_AffectTranslationX: 1 - m_AffectTranslationY: 1 - m_AffectTranslationZ: 1 - m_AffectRotationX: 1 - m_AffectRotationY: 1 - m_AffectRotationZ: 1 - m_Active: 0 - m_IsLocked: 0 - m_Sources: [] diff --git a/Basis/Packages/com.basis.tests/Interactable/HoverInteractSphere.cs b/Basis/Packages/com.basis.tests/Interactable/HoverInteractSphere.cs index 19965aa22..117532297 100644 --- a/Basis/Packages/com.basis.tests/Interactable/HoverInteractSphere.cs +++ b/Basis/Packages/com.basis.tests/Interactable/HoverInteractSphere.cs @@ -1,6 +1,7 @@ using UnityEngine; [RequireComponent(typeof(SphereCollider))] +[System.Serializable] public class HoverInteractSphere : MonoBehaviour { diff --git a/Basis/Packages/com.basis.tests/Interactable/InteractableObject.cs b/Basis/Packages/com.basis.tests/Interactable/InteractableObject.cs index ae2a8fbf4..97332922a 100644 --- a/Basis/Packages/com.basis.tests/Interactable/InteractableObject.cs +++ b/Basis/Packages/com.basis.tests/Interactable/InteractableObject.cs @@ -3,15 +3,16 @@ // needs rigidbody for hover sphere `OnTriggerStay` +[System.Serializable] public abstract class InteractableObject: MonoBehaviour { - public CachedList InputSources; + public BasisInputWrapper InputSource; [Header("Interactable Settings")] public float InteractRange = 1.0f; public bool CanEquip = false; public Vector3 equipPos; public Quaternion equipRot; - + public bool RequiresUpdateLoop; /// /// Check if object is within range based on its transform and Interact Range @@ -58,9 +59,9 @@ public virtual Collider GetCollider() abstract public void InputUpdate(); - public struct InputSource + public struct BasisInputWrapper { - public InputSource(BasisInput source, bool isInteracting) + public BasisInputWrapper(BasisInput source, bool isInteracting) { Source = source; IsInteracting = isInteracting; diff --git a/Basis/Packages/com.basis.tests/Interactable/InteractableTestScene.unity b/Basis/Packages/com.basis.tests/Interactable/InteractableTestScene.unity index 0ff4a4a79..00a83a76c 100644 --- a/Basis/Packages/com.basis.tests/Interactable/InteractableTestScene.unity +++ b/Basis/Packages/com.basis.tests/Interactable/InteractableTestScene.unity @@ -119,34 +119,6 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} ---- !u!1 &11334214 stripped -GameObject: - m_CorrespondingSourceObject: {fileID: 8381068889838832174, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} - m_PrefabInstance: {fileID: 953741117} - m_PrefabAsset: {fileID: 0} ---- !u!1773428102 &11334222 -ParentConstraint: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 11334214} - m_Enabled: 1 - serializedVersion: 2 - m_Weight: 1 - m_TranslationAtRest: {x: -1.291, y: 1, z: 0} - m_RotationAtRest: {x: 45.029, y: 67.472, z: 49.67} - m_TranslationOffsets: [] - m_RotationOffsets: [] - m_AffectTranslationX: 1 - m_AffectTranslationY: 1 - m_AffectTranslationZ: 1 - m_AffectRotationX: 1 - m_AffectRotationY: 1 - m_AffectRotationZ: 1 - m_Active: 0 - m_IsLocked: 0 - m_Sources: [] --- !u!1 &21929887 GameObject: m_ObjectHideFlags: 0 @@ -161,7 +133,6 @@ GameObject: - component: {fileID: 21929891} - component: {fileID: 21929890} - component: {fileID: 21929889} - - component: {fileID: 21929895} m_Layer: 8 m_Name: Sphere m_TagString: Untagged @@ -185,11 +156,11 @@ MonoBehaviour: CanEquip: 0 equipPos: {x: 0, y: 0, z: 0} equipRot: {x: 0, y: 0, z: 0, w: 0} + RequiresUpdateLoop: 0 KinematicWhileInteracting: 0 LocalOnly: 1 ColliderRef: {fileID: 0} RigidRef: {fileID: 0} - ConstraintRef: {fileID: 0} --- !u!54 &21929890 Rigidbody: m_ObjectHideFlags: 0 @@ -306,29 +277,6 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1773428102 &21929895 -ParentConstraint: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 21929887} - m_Enabled: 1 - serializedVersion: 2 - m_Weight: 1 - m_TranslationAtRest: {x: -0.849, y: 0.953, z: -1.678} - m_RotationAtRest: {x: 0, y: 0, z: 0} - m_TranslationOffsets: [] - m_RotationOffsets: [] - m_AffectTranslationX: 1 - m_AffectTranslationY: 1 - m_AffectTranslationZ: 1 - m_AffectRotationX: 1 - m_AffectRotationY: 1 - m_AffectRotationZ: 1 - m_Active: 0 - m_IsLocked: 0 - m_Sources: [] --- !u!1 &241820446 GameObject: m_ObjectHideFlags: 0 @@ -521,10 +469,7 @@ PrefabInstance: m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] - m_AddedComponents: - - targetCorrespondingSourceObject: {fileID: 8381068889838832174, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} - insertIndex: -1 - addedObject: {fileID: 609646646} + m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} --- !u!1001 &391151166 PrefabInstance: @@ -610,7 +555,8 @@ PrefabInstance: propertyPath: m_IsActive value: 1 objectReference: {fileID: 0} - m_RemovedComponents: [] + m_RemovedComponents: + - {fileID: 1266327906536326857, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} m_RemovedGameObjects: [] m_AddedGameObjects: [] m_AddedComponents: [] @@ -629,7 +575,6 @@ GameObject: - component: {fileID: 462462410} - component: {fileID: 462462409} - component: {fileID: 462462408} - - component: {fileID: 462462414} m_Layer: 8 m_Name: Sphere (1) m_TagString: Untagged @@ -653,11 +598,11 @@ MonoBehaviour: CanEquip: 0 equipPos: {x: 0, y: 0, z: 0} equipRot: {x: 0, y: 0, z: 0, w: 0} + RequiresUpdateLoop: 0 KinematicWhileInteracting: 0 LocalOnly: 1 ColliderRef: {fileID: 0} RigidRef: {fileID: 0} - ConstraintRef: {fileID: 0} --- !u!54 &462462409 Rigidbody: m_ObjectHideFlags: 0 @@ -774,29 +719,6 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1773428102 &462462414 -ParentConstraint: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 462462406} - m_Enabled: 1 - serializedVersion: 2 - m_Weight: 1 - m_TranslationAtRest: {x: -1.191, y: 0.953, z: -1.678} - m_RotationAtRest: {x: 0, y: 0, z: 0} - m_TranslationOffsets: [] - m_RotationOffsets: [] - m_AffectTranslationX: 1 - m_AffectTranslationY: 1 - m_AffectTranslationZ: 1 - m_AffectRotationX: 1 - m_AffectRotationY: 1 - m_AffectRotationZ: 1 - m_Active: 0 - m_IsLocked: 0 - m_Sources: [] --- !u!1 &556741047 GameObject: m_ObjectHideFlags: 0 @@ -811,7 +733,6 @@ GameObject: - component: {fileID: 556741051} - component: {fileID: 556741050} - component: {fileID: 556741049} - - component: {fileID: 556741055} m_Layer: 8 m_Name: Sphere (2) m_TagString: Untagged @@ -835,11 +756,11 @@ MonoBehaviour: CanEquip: 0 equipPos: {x: 0, y: 0, z: 0} equipRot: {x: 0, y: 0, z: 0, w: 0} + RequiresUpdateLoop: 0 KinematicWhileInteracting: 0 LocalOnly: 1 ColliderRef: {fileID: 0} RigidRef: {fileID: 0} - ConstraintRef: {fileID: 0} --- !u!54 &556741050 Rigidbody: m_ObjectHideFlags: 0 @@ -956,57 +877,6 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1773428102 &556741055 -ParentConstraint: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 556741047} - m_Enabled: 1 - serializedVersion: 2 - m_Weight: 1 - m_TranslationAtRest: {x: -1.546, y: 0.953, z: -1.678} - m_RotationAtRest: {x: 0, y: 0, z: 0} - m_TranslationOffsets: [] - m_RotationOffsets: [] - m_AffectTranslationX: 1 - m_AffectTranslationY: 1 - m_AffectTranslationZ: 1 - m_AffectRotationX: 1 - m_AffectRotationY: 1 - m_AffectRotationZ: 1 - m_Active: 0 - m_IsLocked: 0 - m_Sources: [] ---- !u!1 &609646638 stripped -GameObject: - m_CorrespondingSourceObject: {fileID: 8381068889838832174, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} - m_PrefabInstance: {fileID: 264690768} - m_PrefabAsset: {fileID: 0} ---- !u!1773428102 &609646646 -ParentConstraint: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 609646638} - m_Enabled: 1 - serializedVersion: 2 - m_Weight: 1 - m_TranslationAtRest: {x: -0.92800003, y: 1, z: 0} - m_RotationAtRest: {x: 0, y: 0, z: 0} - m_TranslationOffsets: [] - m_RotationOffsets: [] - m_AffectTranslationX: 1 - m_AffectTranslationY: 1 - m_AffectTranslationZ: 1 - m_AffectRotationX: 1 - m_AffectRotationY: 1 - m_AffectRotationZ: 1 - m_Active: 0 - m_IsLocked: 0 - m_Sources: [] --- !u!1001 &782519661 PrefabInstance: m_ObjectHideFlags: 0 @@ -1082,10 +952,7 @@ PrefabInstance: m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] - m_AddedComponents: - - targetCorrespondingSourceObject: {fileID: 8381068889838832174, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} - insertIndex: -1 - addedObject: {fileID: 1212161320} + m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} --- !u!1001 &857767427 PrefabInstance: @@ -1163,9 +1030,6 @@ PrefabInstance: m_RemovedGameObjects: [] m_AddedGameObjects: [] m_AddedComponents: - - targetCorrespondingSourceObject: {fileID: 919132149155446097, guid: 7906979de341558478671be4f6bdf5e8, type: 3} - insertIndex: -1 - addedObject: {fileID: 1232611347} - targetCorrespondingSourceObject: {fileID: 919132149155446097, guid: 7906979de341558478671be4f6bdf5e8, type: 3} insertIndex: -1 addedObject: {fileID: 1232611346} @@ -1184,30 +1048,6 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 0} m_Modifications: - - target: {fileID: 1001019263030247314, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} - propertyPath: m_IsKinematic - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 5036961803400065188, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} - propertyPath: CanEquip - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 5036961803400065188, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} - propertyPath: equipPos.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 5036961803400065188, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} - propertyPath: equipPos.y - value: -0.1 - objectReference: {fileID: 0} - - target: {fileID: 5036961803400065188, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} - propertyPath: equipPos.z - value: 0.1 - objectReference: {fileID: 0} - - target: {fileID: 5036961803400065188, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} - propertyPath: KinematicWhileInteracting - value: 0 - objectReference: {fileID: 0} - target: {fileID: 6918077497000395064, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} propertyPath: m_LocalPosition.x value: -1.291 @@ -1252,50 +1092,11 @@ PrefabInstance: propertyPath: m_Name value: TestPickup (3) objectReference: {fileID: 0} - - target: {fileID: 8381068889838832174, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} - propertyPath: m_Layer - value: 8 - objectReference: {fileID: 0} - - target: {fileID: 8381068889838832174, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} - propertyPath: m_IsActive - value: 1 - objectReference: {fileID: 0} m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] - m_AddedComponents: - - targetCorrespondingSourceObject: {fileID: 8381068889838832174, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} - insertIndex: -1 - addedObject: {fileID: 11334222} + m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} ---- !u!1 &1212161312 stripped -GameObject: - m_CorrespondingSourceObject: {fileID: 8381068889838832174, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} - m_PrefabInstance: {fileID: 782519661} - m_PrefabAsset: {fileID: 0} ---- !u!1773428102 &1212161320 -ParentConstraint: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1212161312} - m_Enabled: 1 - serializedVersion: 2 - m_Weight: 1 - m_TranslationAtRest: {x: -1.1370001, y: 1, z: 0} - m_RotationAtRest: {x: 0, y: 0, z: 0} - m_TranslationOffsets: [] - m_RotationOffsets: [] - m_AffectTranslationX: 1 - m_AffectTranslationY: 1 - m_AffectTranslationZ: 1 - m_AffectRotationX: 1 - m_AffectRotationY: 1 - m_AffectRotationZ: 1 - m_Active: 0 - m_IsLocked: 0 - m_Sources: [] --- !u!1 &1232611343 stripped GameObject: m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: 7906979de341558478671be4f6bdf5e8, type: 3} @@ -1339,11 +1140,11 @@ MonoBehaviour: CanEquip: 0 equipPos: {x: 0, y: 0, z: 0} equipRot: {x: 0, y: 0, z: 0, w: 0} + RequiresUpdateLoop: 0 KinematicWhileInteracting: 1 LocalOnly: 1 ColliderRef: {fileID: 0} RigidRef: {fileID: 0} - ConstraintRef: {fileID: 0} --- !u!54 &1232611346 Rigidbody: m_ObjectHideFlags: 0 @@ -1371,29 +1172,59 @@ Rigidbody: m_Interpolate: 0 m_Constraints: 0 m_CollisionDetection: 0 ---- !u!1773428102 &1232611347 -ParentConstraint: +--- !u!1 &1262652854 +GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1232611343} - m_Enabled: 1 + serializedVersion: 6 + m_Component: + - component: {fileID: 1262652855} + - component: {fileID: 1262652856} + m_Layer: 0 + m_Name: Basis Scene + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1262652855 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1262652854} serializedVersion: 2 - m_Weight: 1 - m_TranslationAtRest: {x: -1.451, y: 0.991, z: 0.668} - m_RotationAtRest: {x: -89.98, y: 0, z: 0} - m_TranslationOffsets: [] - m_RotationOffsets: [] - m_AffectTranslationX: 1 - m_AffectTranslationY: 1 - m_AffectTranslationZ: 1 - m_AffectRotationX: 1 - m_AffectRotationY: 1 - m_AffectRotationZ: 1 - m_Active: 0 - m_IsLocked: 0 - m_Sources: [] + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1262652856 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1262652854} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a77971dc49cce9541828138eb5e2270e, type: 3} + m_Name: + m_EditorClassIdentifier: + BasisBundleDescription: + AssetBundleName: + AssetBundleDescription: + SpawnPoint: {fileID: 1262652855} + RespawnHeight: -100 + RespawnCheckTimer: 0.1 + Group: {fileID: 6216228358845890117, guid: 471a0209081144d4da2426822e8a0b47, type: 2} + MainCamera: {fileID: 1556212796} + IsReady: 0 --- !u!1 &1336315009 GameObject: m_ObjectHideFlags: 0 @@ -1408,7 +1239,6 @@ GameObject: - component: {fileID: 1336315013} - component: {fileID: 1336315012} - component: {fileID: 1336315017} - - component: {fileID: 1336315018} m_Layer: 8 m_Name: Capsule (3) m_TagString: Untagged @@ -1550,34 +1380,11 @@ MonoBehaviour: CanEquip: 0 equipPos: {x: 0, y: 0, z: 0} equipRot: {x: 0, y: 0, z: 0, w: 0} + RequiresUpdateLoop: 0 KinematicWhileInteracting: 0 LocalOnly: 1 ColliderRef: {fileID: 0} RigidRef: {fileID: 0} - ConstraintRef: {fileID: 0} ---- !u!1773428102 &1336315018 -ParentConstraint: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1336315009} - m_Enabled: 1 - serializedVersion: 2 - m_Weight: 1 - m_TranslationAtRest: {x: -2.2507, y: 1.0181, z: 0.001} - m_RotationAtRest: {x: 0, y: 0, z: 0} - m_TranslationOffsets: [] - m_RotationOffsets: [] - m_AffectTranslationX: 1 - m_AffectTranslationY: 1 - m_AffectTranslationZ: 1 - m_AffectRotationX: 1 - m_AffectRotationY: 1 - m_AffectRotationZ: 1 - m_Active: 0 - m_IsLocked: 0 - m_Sources: [] --- !u!1 &1405895927 GameObject: m_ObjectHideFlags: 0 @@ -1713,7 +1520,6 @@ GameObject: - component: {fileID: 1472934488} - component: {fileID: 1472934487} - component: {fileID: 1472934492} - - component: {fileID: 1472934493} m_Layer: 8 m_Name: Capsule (4) m_TagString: Untagged @@ -1855,34 +1661,11 @@ MonoBehaviour: CanEquip: 0 equipPos: {x: 0, y: 0, z: 0} equipRot: {x: 0, y: 0, z: 0, w: 0} + RequiresUpdateLoop: 0 KinematicWhileInteracting: 0 LocalOnly: 1 ColliderRef: {fileID: 0} RigidRef: {fileID: 0} - ConstraintRef: {fileID: 0} ---- !u!1773428102 &1472934493 -ParentConstraint: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1472934484} - m_Enabled: 1 - serializedVersion: 2 - m_Weight: 1 - m_TranslationAtRest: {x: -2.417, y: 1.0181, z: 0.001} - m_RotationAtRest: {x: 0, y: 0, z: 0} - m_TranslationOffsets: [] - m_RotationOffsets: [] - m_AffectTranslationX: 1 - m_AffectTranslationY: 1 - m_AffectTranslationZ: 1 - m_AffectRotationX: 1 - m_AffectRotationY: 1 - m_AffectRotationZ: 1 - m_Active: 0 - m_IsLocked: 0 - m_Sources: [] --- !u!1 &1556212794 GameObject: m_ObjectHideFlags: 0 @@ -2034,7 +1817,6 @@ GameObject: - component: {fileID: 1568311660} - component: {fileID: 1568311659} - component: {fileID: 1568311658} - - component: {fileID: 1568311657} m_Layer: 8 m_Name: Capsule (5) m_TagString: Untagged @@ -2042,29 +1824,6 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!1773428102 &1568311657 -ParentConstraint: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1568311656} - m_Enabled: 1 - serializedVersion: 2 - m_Weight: 1 - m_TranslationAtRest: {x: -1.897, y: 1.0181, z: 0.001} - m_RotationAtRest: {x: 0, y: 0, z: 0} - m_TranslationOffsets: [] - m_RotationOffsets: [] - m_AffectTranslationX: 1 - m_AffectTranslationY: 1 - m_AffectTranslationZ: 1 - m_AffectRotationX: 1 - m_AffectRotationY: 1 - m_AffectRotationZ: 1 - m_Active: 0 - m_IsLocked: 0 - m_Sources: [] --- !u!114 &1568311658 MonoBehaviour: m_ObjectHideFlags: 0 @@ -2081,11 +1840,11 @@ MonoBehaviour: CanEquip: 0 equipPos: {x: 0, y: 0, z: 0} equipRot: {x: 0, y: 0, z: 0, w: 0} + RequiresUpdateLoop: 0 KinematicWhileInteracting: 0 LocalOnly: 1 ColliderRef: {fileID: 0} RigidRef: {fileID: 0} - ConstraintRef: {fileID: 0} --- !u!54 &1568311659 Rigidbody: m_ObjectHideFlags: 0 @@ -2383,39 +2142,8 @@ PrefabInstance: m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] - m_AddedComponents: - - targetCorrespondingSourceObject: {fileID: 8381068889838832174, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} - insertIndex: -1 - addedObject: {fileID: 1896202243} + m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} ---- !u!1 &1896202235 stripped -GameObject: - m_CorrespondingSourceObject: {fileID: 8381068889838832174, guid: 2d8f3575614e0d7419c84f967185cdac, type: 3} - m_PrefabInstance: {fileID: 1770558167} - m_PrefabAsset: {fileID: 0} ---- !u!1773428102 &1896202243 -ParentConstraint: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1896202235} - m_Enabled: 1 - serializedVersion: 2 - m_Weight: 1 - m_TranslationAtRest: {x: -0.744, y: 1, z: 0} - m_RotationAtRest: {x: 0, y: 0, z: 0} - m_TranslationOffsets: [] - m_RotationOffsets: [] - m_AffectTranslationX: 1 - m_AffectTranslationY: 1 - m_AffectTranslationZ: 1 - m_AffectRotationX: 1 - m_AffectRotationY: 1 - m_AffectRotationZ: 1 - m_Active: 0 - m_IsLocked: 0 - m_Sources: [] --- !u!1 &1983638905 GameObject: m_ObjectHideFlags: 0 @@ -2430,7 +2158,6 @@ GameObject: - component: {fileID: 1983638909} - component: {fileID: 1983638908} - component: {fileID: 1983638913} - - component: {fileID: 1983638914} m_Layer: 8 m_Name: Capsule (2) m_TagString: Untagged @@ -2572,34 +2299,11 @@ MonoBehaviour: CanEquip: 0 equipPos: {x: 0, y: 0, z: 0} equipRot: {x: 0, y: 0, z: 0, w: 0} + RequiresUpdateLoop: 0 KinematicWhileInteracting: 0 LocalOnly: 1 ColliderRef: {fileID: 0} RigidRef: {fileID: 0} - ConstraintRef: {fileID: 0} ---- !u!1773428102 &1983638914 -ParentConstraint: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1983638905} - m_Enabled: 1 - serializedVersion: 2 - m_Weight: 1 - m_TranslationAtRest: {x: -2.075, y: 1.0181, z: 0.001} - m_RotationAtRest: {x: 0, y: 0, z: 0} - m_TranslationOffsets: [] - m_RotationOffsets: [] - m_AffectTranslationX: 1 - m_AffectTranslationY: 1 - m_AffectTranslationZ: 1 - m_AffectRotationX: 1 - m_AffectRotationY: 1 - m_AffectRotationZ: 1 - m_Active: 0 - m_IsLocked: 0 - m_Sources: [] --- !u!1 &2063075830 GameObject: m_ObjectHideFlags: 0 @@ -2614,7 +2318,6 @@ GameObject: - component: {fileID: 2063075834} - component: {fileID: 2063075833} - component: {fileID: 2063075838} - - component: {fileID: 2063075839} m_Layer: 8 m_Name: Capsule (1) m_TagString: Untagged @@ -2756,34 +2459,11 @@ MonoBehaviour: CanEquip: 0 equipPos: {x: 0, y: 0, z: 0} equipRot: {x: 0, y: 0, z: 0, w: 0} + RequiresUpdateLoop: 0 KinematicWhileInteracting: 0 LocalOnly: 1 ColliderRef: {fileID: 0} RigidRef: {fileID: 0} - ConstraintRef: {fileID: 0} ---- !u!1773428102 &2063075839 -ParentConstraint: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2063075830} - m_Enabled: 1 - serializedVersion: 2 - m_Weight: 1 - m_TranslationAtRest: {x: -1.897, y: 1.0181, z: 0.001} - m_RotationAtRest: {x: 0, y: 0, z: 0} - m_TranslationOffsets: [] - m_RotationOffsets: [] - m_AffectTranslationX: 1 - m_AffectTranslationY: 1 - m_AffectTranslationZ: 1 - m_AffectRotationX: 1 - m_AffectRotationY: 1 - m_AffectRotationZ: 1 - m_Active: 0 - m_IsLocked: 0 - m_Sources: [] --- !u!1001 &6034627799823193631 PrefabInstance: m_ObjectHideFlags: 0 @@ -2937,7 +2617,8 @@ PrefabInstance: propertyPath: m_IsActive value: 1 objectReference: {fileID: 0} - m_RemovedComponents: [] + m_RemovedComponents: + - {fileID: 2919849334597809319, guid: 1701187c6a784ab4f8030c14149b0bce, type: 3} m_RemovedGameObjects: [] m_AddedGameObjects: [] m_AddedComponents: [] @@ -2966,3 +2647,4 @@ SceneRoots: - {fileID: 6880374503260693233} - {fileID: 1734220527} - {fileID: 857767427} + - {fileID: 1262652855} diff --git a/Basis/Packages/com.basis.tests/Interactable/PickupInteractable.cs b/Basis/Packages/com.basis.tests/Interactable/PickupInteractable.cs index ffdecc79f..da47bc619 100644 --- a/Basis/Packages/com.basis.tests/Interactable/PickupInteractable.cs +++ b/Basis/Packages/com.basis.tests/Interactable/PickupInteractable.cs @@ -1,43 +1,38 @@ +using Basis.Scripts.BasisSdk.Players; using Basis.Scripts.Device_Management.Devices; +using Unity.Mathematics; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.Animations; -using UnityEngine.LowLevelPhysics; using UnityEngine.ResourceManagement.AsyncOperations; +using static UnityEngine.GraphicsBuffer; public class PickupInteractable : InteractableObject { // public BasisObjectSyncNetworking syncNetworking; - - - [Header("Reparent Settings")] public bool KinematicWhileInteracting = false; - + [SerializeField] private bool LocalOnly = true; [Header("References")] public Collider ColliderRef; public Rigidbody RigidRef; - public ParentConstraint ConstraintRef; // internal values private GameObject HighlightClone; private AsyncOperationHandle asyncOperationHighlightMat; private Material ColliderHighlightMat; private bool _previousKinematicValue = true; - + // constants const string k_LoadMaterialAddress = "Interactable/InteractHighlightMat.mat"; const string k_CloneName = "HighlightClone"; - - void Start() + public ParentConstraint ConstraintRef; + public void Start() { - InputSources = new CachedList - { - new InputSource(null, false) - }; + InputSource = new BasisInputWrapper(null, false); if (RigidRef == null) { @@ -51,14 +46,18 @@ void Start() { if (TryGetComponent(out ConstraintRef)) { - var nullSource = new ConstraintSource() { - sourceTransform = null, - weight = 1, - }; - ConstraintRef.AddSource(nullSource); } + else + { + ConstraintRef = this.gameObject.AddComponent(); + } + var nullSource = new ConstraintSource() + { + sourceTransform = null, + weight = 1, + }; + ConstraintRef.AddSource(nullSource); } - // TODO: netsync if (!LocalOnly) { @@ -79,7 +78,7 @@ void Start() { meshRenderer.material = ColliderHighlightMat; } - else + else { BasisDebug.LogWarning("Pickup Interactable could not find MeshRenderer component on mesh clone. Highlights will be broken"); } @@ -87,7 +86,7 @@ void Start() } - + public void HighlightObject(bool highlight) @@ -101,45 +100,41 @@ public void HighlightObject(bool highlight) public override bool CanHover(BasisInput input) { // must be dropped to hover - return InputSources[0].Source == null && IsWithinRange(input.transform.position); + return InputSource.Source == null && IsWithinRange(input.transform.position); } public override bool CanInteract(BasisInput input) { // currently hovering with this input - return InputSources[0].Source != null && - !InputSources[0].IsInteracting && - InputSources[0].Source.UniqueDeviceIdentifier == input.UniqueDeviceIdentifier && + return InputSource.Source != null && + !InputSource.IsInteracting && + InputSource.Source.UniqueDeviceIdentifier == input.UniqueDeviceIdentifier && IsWithinRange(input.transform.position); } public override void OnHoverStart(BasisInput input) { - InputSources[0] = new InputSource(input, false); + InputSource = new BasisInputWrapper(input, false); HighlightObject(true); } public override void OnHoverEnd(BasisInput input, bool willInteract) { - if (InputSources[0].Source.UniqueDeviceIdentifier == input.UniqueDeviceIdentifier) + if (InputSource.Source.UniqueDeviceIdentifier == input.UniqueDeviceIdentifier) { if (!willInteract) { - InputSources[0] = new InputSource(null, false); + InputSource = new BasisInputWrapper(null, false); } HighlightObject(false); } } - public override void OnInteractStart(BasisInput input) { // same input that was highlighting previously - if (InputSources[0].Source != null && - InputSources[0].Source.UniqueDeviceIdentifier == input.UniqueDeviceIdentifier && - !InputSources[0].IsInteracting - ) { - SetParentConstraint(input.transform); + if (InputSource.Source != null && InputSource.Source.UniqueDeviceIdentifier == input.UniqueDeviceIdentifier && !InputSource.IsInteracting) + { - if(RigidRef != null && KinematicWhileInteracting) + if (RigidRef != null && KinematicWhileInteracting) { _previousKinematicValue = RigidRef.isKinematic; RigidRef.isKinematic = true; @@ -147,7 +142,10 @@ public override void OnInteractStart(BasisInput input) // Set ownership to the local player // syncNetworking.IsOwner = true; - InputSources[0] = new InputSource(input, true); + InputSource = new BasisInputWrapper(input, true); + RequiresUpdateLoop = true; + // this.transform.parent = BasisLocalPlayer.Instance.transform; + SetParentConstraint(input.transform); } else { @@ -157,60 +155,55 @@ public override void OnInteractStart(BasisInput input) public override void OnInteractEnd(BasisInput input) { - if (InputSources[0].IsInteracting && InputSources[0].Source != null && InputSources[0].Source.UniqueDeviceIdentifier == input.UniqueDeviceIdentifier) + if (InputSource.IsInteracting && InputSource.Source != null && InputSource.Source.UniqueDeviceIdentifier == input.UniqueDeviceIdentifier) { - SetParentConstraint(null); - InputSources[0] = new InputSource(null, false); + InputSource = new BasisInputWrapper(null, false); - if(KinematicWhileInteracting && RigidRef != null) + if (KinematicWhileInteracting && RigidRef != null) { RigidRef.isKinematic = _previousKinematicValue; } - + RequiresUpdateLoop = false; // syncNetworking.IsOwner = false; + // this.transform.parent = null; + SetParentConstraint(null); } } - - public void SetParentConstraint(Transform source) { - if (ConstraintRef != null) + public void SetParentConstraint(Transform source) + { + // ignore source count, only modify the 0 index + var newSource = new ConstraintSource() { - // ignore source count, only modify the 0 index - var newSource = new ConstraintSource() - { - sourceTransform = source, - weight = 1, - }; - ConstraintRef.SetSource(0, newSource); - - if (CanEquip) - { - ConstraintRef.SetTranslationOffset(0, equipPos); - ConstraintRef.SetRotationOffset(0, equipRot.eulerAngles); - } - else if (source != null) - { - ConstraintRef.SetTranslationOffset(0, source.InverseTransformPoint(transform.position)); - ConstraintRef.SetRotationOffset(0, (Quaternion.Inverse(source.rotation) * transform.rotation).eulerAngles); - } - + sourceTransform = source, + weight = 1, + }; + ConstraintRef.SetSource(0, newSource); - // force constraint weight - ConstraintRef.weight = 1; - ConstraintRef.constraintActive = source != null; + if (CanEquip) + { + ConstraintRef.SetTranslationOffset(0, equipPos); + ConstraintRef.SetRotationOffset(0, equipRot.eulerAngles); } - else + else if (source != null) { - Debug.LogError("ReparentInteractable lost its parent constraint component!", gameObject); + ConstraintRef.SetTranslationOffset(0, source.InverseTransformPoint(transform.position)); + ConstraintRef.SetRotationOffset(0, (Quaternion.Inverse(source.rotation) * transform.rotation).eulerAngles); } - } + + // force constraint weight + ConstraintRef.weight = 1; + ConstraintRef.constraintActive = source != null; + } public override void InputUpdate() { - if (InputSources[0].IsInteracting && InputSources[0].Source != null) + if (InputSource.IsInteracting && InputSource.Source != null) { - // transform updated by transform heirarchy already + // Optionally, match the rotation. + // transform.rotation = target.rotation; + // this.transform.SetLocalPositionAndRotation(vector3 + PositionOffset, appliedRotation); // Update the networked data (Storeddata) to reflect the position, rotation, and scale if (!LocalOnly) @@ -225,16 +218,16 @@ public override void InputUpdate() public override bool IsInteractingWith(BasisInput input) { - return InputSources[0].IsInteracting && - InputSources[0].Source != null && - InputSources[0].Source.UniqueDeviceIdentifier == input.UniqueDeviceIdentifier; + return InputSource.IsInteracting && + InputSource.Source != null && + InputSource.Source.UniqueDeviceIdentifier == input.UniqueDeviceIdentifier; } public override bool IsHoveredBy(BasisInput input) { - return !InputSources[0].IsInteracting && - InputSources[0].Source != null && - InputSources[0].Source.UniqueDeviceIdentifier == input.UniqueDeviceIdentifier; + return !InputSource.IsInteracting && + InputSource.Source != null && + InputSource.Source.UniqueDeviceIdentifier == input.UniqueDeviceIdentifier; } // this is cached, use it @@ -255,7 +248,7 @@ public override Collider GetCollider() // // dont care otherwise, wait for hover/interact // } - void OnDestroy() + void OnDestroy() { Destroy(HighlightClone); if (asyncOperationHighlightMat.IsValid()) @@ -264,7 +257,7 @@ void OnDestroy() } } - #if UNITY_EDITOR +#if UNITY_EDITOR public void OnValidate() { string errPrefix = "ReparentInteractable needs component defined on self or given a reference for "; @@ -281,5 +274,5 @@ public void OnValidate() Debug.LogWarning(errPrefix + "ParentConstraint", gameObject); } } - #endif -} \ No newline at end of file +#endif +} diff --git a/Basis/Packages/com.basis.tests/Interactable/PlayerInteract.cs b/Basis/Packages/com.basis.tests/Interactable/PlayerInteract.cs index 5d31fccc5..8a3e72da8 100644 --- a/Basis/Packages/com.basis.tests/Interactable/PlayerInteract.cs +++ b/Basis/Packages/com.basis.tests/Interactable/PlayerInteract.cs @@ -17,15 +17,19 @@ public class PlayerInteract : MonoBehaviour [Tooltip("How far the player Hover.")] public float hoverRadius = 0.5f; [Tooltip("Both of the above are relative to object transforms, objects with larger colliders may have issues")] - + [System.Serializable] public struct InteractInput { public string deviceUid { get; set; } + [SerializeField] public BasisInput input { get; set; } - public GameObject interactOrigin { get; set; } + public Transform interactOrigin { get; set; } // TODO: use this ref + [SerializeField] public LineRenderer lineRenderer { get; set; } + [SerializeField] public HoverInteractSphere hoverInteract { get; set; } + [SerializeField] public InteractableObject lastTarget { get; set; } public bool IsInput(BasisInput input) @@ -33,10 +37,8 @@ public bool IsInput(BasisInput input) return deviceUid == input.UniqueDeviceIdentifier; } } - - public CachedList InteractInputs = new(); - - // private UniqueCounterList ActiveObjects = new(); + [SerializeField] + public InteractInput[] InteractInputs = new InteractInput[] { }; public Material LineMaterial; private AsyncOperationHandle asyncOperationLineMaterial; @@ -45,55 +47,48 @@ public bool IsInput(BasisInput input) // TODO: load with addressable. public static string LoadMaterialAddress = "Interactable/InteractLineMat.mat"; - - - void Start() + private void Start() { BasisLocalPlayer.Instance.LocalBoneDriver.OnSimulate += Simulate; - BasisDeviceManagement.Instance.AllInputDevices.OnListChanged += OnInputChanged; - BasisDeviceManagement.Instance.AllInputDevices.OnListItemRemoved += OnInputRemoved; + var Device = BasisDeviceManagement.Instance.AllInputDevices; + Device.OnListAdded += OnInputChanged; + Device.OnListItemRemoved += OnInputRemoved; AsyncOperationHandle op = Addressables.LoadAssetAsync(LoadMaterialAddress); LineMaterial = op.WaitForCompletion(); asyncOperationLineMaterial = op; } - void OnDestroy() + private void OnDestroy() { if (asyncOperationLineMaterial.IsValid()) { asyncOperationLineMaterial.Release(); } BasisLocalPlayer.Instance.LocalBoneDriver.OnSimulate -= Simulate; - BasisDeviceManagement.Instance.AllInputDevices.OnListChanged -= OnInputChanged; - BasisDeviceManagement.Instance.AllInputDevices.OnListItemRemoved -= OnInputRemoved; - - foreach (InteractInput input in InteractInputs) + var Device = BasisDeviceManagement.Instance.AllInputDevices; + Device.OnListAdded -= OnInputChanged; + Device.OnListItemRemoved -= OnInputRemoved; + int count = InteractInputs.Length; + for (int Index = 0; Index < count; Index++) { - Destroy(input.interactOrigin); + InteractInput input = InteractInputs[Index]; + if (input.interactOrigin != null) + { + Destroy(input.interactOrigin.gameObject); + } } } - private void OnInputChanged() + private void OnInputChanged(BasisInput Input) { - int count = BasisDeviceManagement.Instance.AllInputDevices.Count; - for (int Index = 0; Index < count; Index++) + // TODO: need a different config value for can interact/pickup/grab. Mainly input action/trigger values + if (Input.BasisDeviceMatchableNames != null && Input.BasisDeviceMatchableNames.HasRayCastSupport + ) { - BasisInput device = BasisDeviceManagement.Instance.AllInputDevices[Index]; - // skip invalid or already included - if (device == null || device != null && InteractInputs.Any(x => x.IsInput(device))) - { - continue; - } - - // TODO: need a different config value for can interact/pickup/grab. Mainly input action/trigger values - if (device.BasisDeviceMatchableNames != null && - device.BasisDeviceMatchableNames.HasRayCastSupport - ) { - AddInput(device); - } - // TODO: what if it has no matchable name? - // device removed handled elsewhere + AddInput(Input); } + // TODO: what if it has no matchable name? + // device removed handled elsewhere } private void OnInputRemoved(BasisInput input) @@ -105,8 +100,16 @@ private void OnInputRemoved(BasisInput input) [BurstCompile] private void Simulate() { - var count = InteractInputs.Count; - for (int Index = 0; Index < count; Index++) + if (InteractInputs == null) + { + return; + } + var InteractInputsCount = InteractInputs.Length; + if (InteractInputsCount == 0) + { + return; + } + for (int Index = 0; Index < InteractInputsCount; Index++) { InteractInput interactInput = InteractInputs[Index]; if (interactInput.input == null) @@ -117,7 +120,7 @@ private void Simulate() HoverInteractSphere hoverSphere = interactInput.hoverInteract; - Vector3 originPos = interactInput.interactOrigin.transform.position; + Vector3 originPos = interactInput.interactOrigin.position; Ray ray; if (hoverSphere.HoverTarget != null) { @@ -133,7 +136,7 @@ private void Simulate() else { Vector3 origin = originPos; - Vector3 direction = interactInput.interactOrigin.transform.forward; + Vector3 direction = interactInput.interactOrigin.forward; ray = new Ray(origin, direction); } } @@ -141,11 +144,11 @@ private void Simulate() RaycastHit rayHit; InteractableObject hitInteractable = null; // TODO: Interact layer - bool isValidRayHit = Physics.Raycast(ray, out rayHit, raycastDistance) && - rayHit.collider != null && + bool isValidRayHit = Physics.Raycast(ray, out rayHit, raycastDistance) && + rayHit.collider != null && rayHit.collider.TryGetComponent(out hitInteractable); - + if (isValidRayHit || hoverSphere.HoverTarget != null) { // prioritize hover @@ -186,35 +189,34 @@ private void Simulate() // write changes back InteractInputs[Index] = interactInput; } - - // update objects, seperate list to ensure each target only gets one update - List updateList = new(); - foreach (InteractInput input in InteractInputs) + // Iterate over all the inputs + for (int Index = 0; Index < InteractInputsCount; Index++) { - if (input.lastTarget != null && !updateList.Any(x => x.GetInstanceID() == input.lastTarget.GetInstanceID())) + InteractInput input = InteractInputs[Index]; + if (input.lastTarget != null) { - updateList.Add(input.lastTarget); + if (input.lastTarget.RequiresUpdateLoop) + { + input.lastTarget.InputUpdate(); + } } } - foreach (InteractableObject interactable in updateList) - { - interactable.InputUpdate(); - } // apply line renderer if (renderInteractLine) { - foreach (InteractInput input in InteractInputs) + for (int Index = 0; Index < InteractInputsCount; Index++) { + InteractInput input = InteractInputs[Index]; if (input.lastTarget != null && input.lastTarget.IsHoveredBy(input.input)) { - Vector3 origin = input.interactOrigin.transform.position; + Vector3 origin = input.interactOrigin.position; Vector3 start; // desktop offset for center eye (a little to the bottom right) if (IsDesktopCenterEye(input.input)) { - start = input.interactOrigin.transform.position + (input.interactOrigin.transform.forward * 0.1f) + Vector3.down * 0.1f + (input.interactOrigin.transform.right * 0.1f); + start = input.interactOrigin.position + (input.interactOrigin.forward * 0.1f) + Vector3.down * 0.1f + (input.interactOrigin.right * 0.1f); } else { @@ -240,8 +242,9 @@ private void Simulate() // turn all the lines off else { - foreach (InteractInput input in InteractInputs) + for (int Index = 0; Index < InteractInputsCount; Index++) { + InteractInput input = InteractInputs[Index]; input.lineRenderer.enabled = false; } } @@ -357,15 +360,15 @@ private bool IsInputGrabbing(BasisInput input) private void RemoveInput(string uid) { - var inputs = InteractInputs.Where(x => x.deviceUid == uid).ToArray(); - if (inputs.Length > 1) - { - BasisDebug.LogError("Interact Inputs has multiple inputs of the same UID. Please report this bug."); - } + // Find the inputs to remove based on the UID + InteractInput[] inputs = InteractInputs.Where(x => x.deviceUid == uid).ToArray(); + int length = inputs.Length; - if (inputs.Length > 0) + if (length > 0) // If matching inputs were found { InteractInput input = inputs[0]; + + // Handle hover and interaction states if (input.lastTarget != null) { if (input.lastTarget.IsHoveredBy(input.input)) @@ -378,10 +381,18 @@ private void RemoveInput(string uid) input.lastTarget.OnInteractEnd(input.input); } } - - Destroy(input.interactOrigin); - InteractInputs.Remove(input); + // Destroy the interact origin + Destroy(input.interactOrigin.gameObject); + + // Manually resize the array + InteractInputs = InteractInputs + .Where(x => x.deviceUid != input.deviceUid) // Exclude the removed input + .ToArray(); + } + else + { + BasisDebug.LogError("Interact Inputs has multiple inputs of the same UID. Please report this bug."); } } @@ -397,7 +408,7 @@ private void AddInput(BasisInput input) interactOrigin.layer = LayerMask.NameToLayer("Interactable"); // TODO: custom config to use center of palm instead of raycast offset (IK palm? but that breaks input on a bad avi upload, no?) interactOrigin.transform.SetLocalPositionAndRotation(input.BasisDeviceMatchableNames.PositionRayCastOffset, Quaternion.Euler(input.BasisDeviceMatchableNames.RotationRaycastOffset)); - + lineRenderer.enabled = false; lineRenderer.material = LineMaterial; lineRenderer.startWidth = interactLineWidth; @@ -415,36 +426,38 @@ private void AddInput(BasisInput input) sphereCollider.enabled = !IsDesktopCenterEye(input); - InteractInput interactInput = new() + InteractInput interactInput = new InteractInput() { deviceUid = input.UniqueDeviceIdentifier, input = input, - interactOrigin = interactOrigin, + interactOrigin = interactOrigin.transform, lineRenderer = lineRenderer, hoverInteract = interactSphere, }; - - InteractInputs.Add(interactInput); + List interactInputList = InteractInputs.ToList(); + interactInputList.Add(interactInput); + InteractInputs = interactInputList.ToArray(); } - private void OnDrawGizmos() { - foreach (var device in InteractInputs) + int count = InteractInputs.Length; + for (int Index = 0; Index < count; Index++) { + InteractInput device = InteractInputs[Index]; // pointer line - Gizmos.DrawLine(device.interactOrigin.transform.position, device.interactOrigin.transform.position + device.interactOrigin.transform.forward * raycastDistance); + Gizmos.DrawLine(device.interactOrigin.position, device.interactOrigin.position + device.interactOrigin.forward * raycastDistance); // hover target line if (device.hoverInteract != null && device.hoverInteract.HoverTarget != null) { - Gizmos.DrawLine(device.interactOrigin.transform.position, device.hoverInteract.TargetClosestPoint); + Gizmos.DrawLine(device.interactOrigin.position, device.hoverInteract.TargetClosestPoint); } // hover sphere if (!IsDesktopCenterEye(device.input)) { - Gizmos.DrawWireSphere(device.interactOrigin.transform.position, hoverRadius); + Gizmos.DrawWireSphere(device.interactOrigin.position, hoverRadius); } } }