Skip to content

Commit

Permalink
Merge pull request #230 from Centurion-Creative-Connect/feature/incre…
Browse files Browse the repository at this point in the history
…ase-desktop-gun-handle-pickup-proximity-#224

Add QoL features for Desktop users
  • Loading branch information
DerpyNewbie authored Aug 22, 2024
2 parents c84ba29 + b4477ad commit fb0657a
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 24 deletions.
3 changes: 3 additions & 0 deletions Packages/org.centurioncc.system/Runtime/Gun/Gun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class Gun : GunBase
private const string RightHandTrigger = "Oculus_CrossPlatform_SecondaryIndexTrigger";
private const float FreeHandPickupProximity = .1F;
private const float SwapHandDisallowPickupProximity = 0.15F;
private const float DesktopPickupProximity = 2F;
private const float DisallowPickupFromBelowRange = -0.1F;

[UdonSynced] [FieldChangeCallback(nameof(RawState))]
Expand Down Expand Up @@ -908,6 +909,8 @@ protected void Internal_UpdateHandlePickupable()
else
{
var localInVR = Networking.LocalPlayer.IsUserInVR();
MainHandle.Proximity = localInVR ? FreeHandPickupProximity : DesktopPickupProximity;
MainHandle.AdjustScaleForDesktop(localInVR);
MainHandle.SetPickupable(true);
SubHandle.SetPickupable(IsDoubleHandedGun && localInVR);
CustomHandle.SetPickupable(Behaviour != null && Behaviour.RequireCustomHandle && IsPickedUp &&
Expand Down
154 changes: 131 additions & 23 deletions Packages/org.centurioncc.system/Runtime/Gun/GunHandle.asset
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ MonoBehaviour:
Data:
- Name:
Entry: 12
Data: 11
Data: 13
- Name:
Entry: 7
Data:
Expand Down Expand Up @@ -326,19 +326,19 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: _collider
Data: desktopScaleMultiplier
- Name: $v
Entry: 7
Data: 18|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _collider
Data: desktopScaleMultiplier
- Name: <UserType>k__BackingField
Entry: 7
Data: 19|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Collider, UnityEngine.PhysicsModule
Data: System.Single, mscorlib
- Name:
Entry: 8
Data:
Expand All @@ -356,7 +356,7 @@ MonoBehaviour:
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 20|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Expand All @@ -380,10 +380,64 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: _defaultMaterial
Data: _collider
- Name: $v
Entry: 7
Data: 21|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _collider
- Name: <UserType>k__BackingField
Entry: 7
Data: 22|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Collider, UnityEngine.PhysicsModule
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 22
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 23|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: _defaultMaterial
- Name: $v
Entry: 7
Data: 24|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _defaultMaterial
Expand All @@ -407,7 +461,61 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 22|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 25|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: _initialScale
- Name: $v
Entry: 7
Data: 26|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _initialScale
- Name: <UserType>k__BackingField
Entry: 7
Data: 27|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Vector3, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 27
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 28|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
Expand All @@ -431,13 +539,13 @@ MonoBehaviour:
Data: _isAttached
- Name: $v
Entry: 7
Data: 23|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 29|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _isAttached
- Name: <UserType>k__BackingField
Entry: 7
Data: 24|System.RuntimeType, mscorlib
Data: 30|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Boolean, mscorlib
Expand All @@ -446,7 +554,7 @@ MonoBehaviour:
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 24
Data: 30
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
Expand All @@ -461,7 +569,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 25|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 31|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
Expand All @@ -485,13 +593,13 @@ MonoBehaviour:
Data: _mesh
- Name: $v
Entry: 7
Data: 26|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 32|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _mesh
- Name: <UserType>k__BackingField
Entry: 7
Data: 27|System.RuntimeType, mscorlib
Data: 33|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.MeshRenderer, UnityEngine.CoreModule
Expand All @@ -500,7 +608,7 @@ MonoBehaviour:
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 27
Data: 33
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
Expand All @@ -515,7 +623,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 28|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 34|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
Expand All @@ -539,13 +647,13 @@ MonoBehaviour:
Data: _pickup
- Name: $v
Entry: 7
Data: 29|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 35|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _pickup
- Name: <UserType>k__BackingField
Entry: 7
Data: 30|System.RuntimeType, mscorlib
Data: 36|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: VRC.SDKBase.VRC_Pickup, VRCSDKBase
Expand All @@ -554,7 +662,7 @@ MonoBehaviour:
Data:
- Name: <SystemType>k__BackingField
Entry: 7
Data: 31|System.RuntimeType, mscorlib
Data: 37|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: VRC.SDK3.Components.VRCPickup, VRCSDK3
Expand All @@ -575,7 +683,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 32|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 38|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
Expand All @@ -599,16 +707,16 @@ MonoBehaviour:
Data: <IsHolstered>k__BackingField
- Name: $v
Entry: 7
Data: 33|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 39|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: <IsHolstered>k__BackingField
- Name: <UserType>k__BackingField
Entry: 9
Data: 24
Data: 30
- Name: <SystemType>k__BackingField
Entry: 9
Data: 24
Data: 30
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
Expand All @@ -623,7 +731,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 34|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 40|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
Expand Down
21 changes: 20 additions & 1 deletion Packages/org.centurioncc.system/Runtime/Gun/GunHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@

namespace CenturionCC.System.Gun
{
[DefaultExecutionOrder(-1)] [UdonBehaviourSyncMode(BehaviourSyncMode.NoVariableSync)]
[DefaultExecutionOrder(-1)]
[UdonBehaviourSyncMode(BehaviourSyncMode.NoVariableSync)]
public class GunHandle : UdonSharpBehaviour
{
public GunHandleCallbackBase callback;
public HandleType handleType;
public Transform target;
public Transform free;
public Material pickupableMaterial;
public float desktopScaleMultiplier = 10F;
private Collider _collider;
private Material _defaultMaterial;

private Vector3 _initialScale;
private bool _isAttached;
private MeshRenderer _mesh;
private VRC_Pickup _pickup;
Expand All @@ -28,19 +31,28 @@ public bool IsVisible
_mesh.enabled = value;
}
}

public bool IsAttached
{
get => _isAttached || IsHolstered;
private set => _isAttached = value;
}

public bool IsHolstered { get; private set; }
public bool IsPickupable => _pickup.pickupable;

public float Proximity
{
get => _pickup.proximity;
set => _pickup.proximity = value;
}

public string UseText
{
get => _pickup.UseText;
set => _pickup.UseText = value;
}

public bool IsPickedUp => _pickup.IsHeld;
public VRC_Pickup.PickupHand CurrentHand => _pickup.currentHand;
public VRCPlayerApi CurrentPlayer => _pickup.currentPlayer;
Expand All @@ -64,6 +76,8 @@ private void Start()
free = transform.root;
if (_collider)
_collider.enabled = _pickup.pickupable;

_initialScale = transform.localScale;
}

public void MoveToLocalPosition(Vector3 pos, Quaternion rot)
Expand All @@ -74,6 +88,11 @@ public void MoveToLocalPosition(Vector3 pos, Quaternion rot)
transform.SetPositionAndRotation(expectedPos, expectedRot);
}

public void AdjustScaleForDesktop(bool isVR)
{
transform.localScale = isVR ? _initialScale : _initialScale * desktopScaleMultiplier;
}

public void SetPickupable(bool isPickupable)
{
_pickup.pickupable = isPickupable;
Expand Down

0 comments on commit fb0657a

Please sign in to comment.