Skip to content

Commit

Permalink
✨ feat(interaction): Snappable now breakable
Browse files Browse the repository at this point in the history
  • Loading branch information
esnya committed May 28, 2022
1 parent 61184c2 commit 13610a3
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ MonoBehaviour:
Data:
- Name:
Entry: 12
Data: 4
Data: 5
- Name:
Entry: 7
Data:
Expand Down Expand Up @@ -238,7 +238,7 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: initialParent
Data: snapTarget
- Name: $v
Entry: 7
Data: 14|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Expand All @@ -263,6 +263,63 @@ MonoBehaviour:
- Name: symbolResolvedTypeName
Entry: 1
Data: UnityEngineTransform
- Name: symbolOriginalName
Entry: 1
Data: snapTarget
- Name: symbolUniqueName
Entry: 1
Data: snapTarget
- Name: symbolDefaultValue
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: fieldAttributes
Entry: 7
Data: 17|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name: userBehaviourSource
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: initialParent
- Name: $v
Entry: 7
Data: 18|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: fieldSymbol
Entry: 7
Data: 19|UdonSharp.Compiler.SymbolDefinition, UdonSharp.Editor
- Name: internalType
Entry: 9
Data: 16
- Name: declarationType
Entry: 3
Data: 2
- Name: syncMode
Entry: 3
Data: 0
- Name: symbolResolvedTypeName
Entry: 1
Data: UnityEngineTransform
- Name: symbolOriginalName
Entry: 1
Data: initialParent
Expand All @@ -277,7 +334,7 @@ MonoBehaviour:
Data:
- Name: fieldAttributes
Entry: 7
Data: 17|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 20|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
Expand Down
27 changes: 24 additions & 3 deletions Packages/com.nekometer.esnya.inari-udon/Interaction/Snappable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,48 @@ public class Snappable : UdonSharpBehaviour
};
public bool reparent;

private Transform snapTarget;
private Transform initialParent;
private void Start()
{
initialParent = transform.parent;
}

private void OnTriggerExit(Collider collider)
{
if (reparent && collider && collider.transform == snapTarget)
{
Break();
}

}

public override void OnPickup()
{
transform.SetParent(initialParent);
Break();
}

public override void OnDrop()
private void Snap(Transform target)
{
var snapTarget = FindSnapTarget();
snapTarget = target;
if (snapTarget)
{
transform.SetPositionAndRotation(snapTarget.position, snapTarget.rotation);
if (reparent) transform.SetParent(snapTarget);
}
}

private void Break()
{
snapTarget = null;
if (reparent) transform.SetParent(initialParent);
}

public override void OnDrop()
{
Snap(FindSnapTarget());
}

private Transform FindSnapTarget()
{
foreach (var collider in Physics.OverlapSphere(transform.position, 0.001f, layerMask, QueryTriggerInteraction.Collide))
Expand Down

Large diffs are not rendered by default.

0 comments on commit 13610a3

Please sign in to comment.