Skip to content

Commit

Permalink
cleaned up a bunch of pickup code
Browse files Browse the repository at this point in the history
  • Loading branch information
dooly123 committed Jan 15, 2025
1 parent 3900c9c commit 4c71f9e
Show file tree
Hide file tree
Showing 15 changed files with 294 additions and 700 deletions.
2 changes: 1 addition & 1 deletion Basis/Packages/com.basis.framework/Pickup/BasisPickup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ public void LateUpdate()

}
}
}
}
12 changes: 7 additions & 5 deletions Basis/Packages/com.basis.sdk/Helpers/BasisObservableList.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using UnityEngine;

Expand All @@ -10,6 +10,7 @@ public class BasisObservableList<T> : IList<T>
[SerializeField]
public List<T> _list = new List<T>();

public event Action<T> OnListAdded;
public event Action OnListChanged;
public event Action<T> OnListItemRemoved;
public T this[int index]
Expand All @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -86,4 +88,4 @@ public int RemoveAll(Predicate<T> match)

System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => _list.GetEnumerator();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Basis/Packages/com.basis.tests/BasisExamples.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"GUID:da668404f8bf3b14ebd4691cc0a6d67c",
"GUID:42c34c05b8d434943ad2cf21483d9cd0",
"GUID:784bec3882b21ab4d8407cc870539fa9",
"GUID:45c7722710e2a37438daaacbf1cd4ad1"
"GUID:45c7722710e2a37438daaacbf1cd4ad1",
"GUID:d8b63aba1907145bea998dd612889d6b"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
91 changes: 0 additions & 91 deletions Basis/Packages/com.basis.tests/Interactable/CachedList.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ public class ExampleButtonInteractable : InteractableObject

void Start()
{
InputSources = new CachedList<InputSource>
{
new InputSource(null, false)
};

InputSource = new BasisInputWrapper(null, false);
if (ColliderRef == null)
{
TryGetComponent(out ColliderRef);
Expand All @@ -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);
}

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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: []
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using UnityEngine;

[RequireComponent(typeof(SphereCollider))]
[System.Serializable]
public class HoverInteractSphere : MonoBehaviour
{

Expand Down
Loading

0 comments on commit 4c71f9e

Please sign in to comment.