-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
422 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,304 @@ | ||
%YAML 1.1 | ||
%TAG !u! tag:unity3d.com,2011: | ||
--- !u!114 &11400000 | ||
MonoBehaviour: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 0} | ||
m_Enabled: 1 | ||
m_EditorHideFlags: 0 | ||
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3} | ||
m_Name: Snappable | ||
m_EditorClassIdentifier: | ||
serializedUdonProgramAsset: {fileID: 11400000, guid: e358f3f6a930a504b8d55eacc7c78015, | ||
type: 2} | ||
udonAssembly: | ||
assemblyError: | ||
sourceCsScript: {fileID: 11500000, guid: bdb542f3ca0b57d40a073aebb870b4fe, type: 3} | ||
behaviourSyncMode: 1 | ||
behaviourIDHeapVarName: __refl_const_intnl_udonTypeID | ||
compileErrors: [] | ||
hasInteractEvent: 0 | ||
serializationData: | ||
SerializedFormat: 2 | ||
SerializedBytes: | ||
ReferencedUnityObjects: [] | ||
SerializedBytesString: | ||
Prefab: {fileID: 0} | ||
PrefabModificationsReferencedUnityObjects: [] | ||
PrefabModifications: [] | ||
SerializationNodes: | ||
- Name: fieldDefinitions | ||
Entry: 7 | ||
Data: 0|System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[UdonSharp.Compiler.FieldDefinition, | ||
UdonSharp.Editor]], mscorlib | ||
- Name: comparer | ||
Entry: 7 | ||
Data: 1|System.Collections.Generic.GenericEqualityComparer`1[[System.String, | ||
mscorlib]], mscorlib | ||
- Name: | ||
Entry: 8 | ||
Data: | ||
- Name: | ||
Entry: 12 | ||
Data: 4 | ||
- Name: | ||
Entry: 7 | ||
Data: | ||
- Name: $k | ||
Entry: 1 | ||
Data: layerMask | ||
- Name: $v | ||
Entry: 7 | ||
Data: 2|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor | ||
- Name: fieldSymbol | ||
Entry: 7 | ||
Data: 3|UdonSharp.Compiler.SymbolDefinition, UdonSharp.Editor | ||
- Name: internalType | ||
Entry: 7 | ||
Data: 4|System.RuntimeType, mscorlib | ||
- Name: | ||
Entry: 1 | ||
Data: UnityEngine.LayerMask, UnityEngine.CoreModule | ||
- Name: | ||
Entry: 8 | ||
Data: | ||
- Name: declarationType | ||
Entry: 3 | ||
Data: 1 | ||
- Name: syncMode | ||
Entry: 3 | ||
Data: 0 | ||
- Name: symbolResolvedTypeName | ||
Entry: 1 | ||
Data: UnityEngineLayerMask | ||
- Name: symbolOriginalName | ||
Entry: 1 | ||
Data: layerMask | ||
- Name: symbolUniqueName | ||
Entry: 1 | ||
Data: layerMask | ||
- Name: symbolDefaultValue | ||
Entry: 6 | ||
Data: | ||
- Name: | ||
Entry: 8 | ||
Data: | ||
- Name: fieldAttributes | ||
Entry: 7 | ||
Data: 5|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: snapTargetPrefixes | ||
- Name: $v | ||
Entry: 7 | ||
Data: 6|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor | ||
- Name: fieldSymbol | ||
Entry: 7 | ||
Data: 7|UdonSharp.Compiler.SymbolDefinition, UdonSharp.Editor | ||
- Name: internalType | ||
Entry: 7 | ||
Data: 8|System.RuntimeType, mscorlib | ||
- Name: | ||
Entry: 1 | ||
Data: System.String[], mscorlib | ||
- Name: | ||
Entry: 8 | ||
Data: | ||
- Name: declarationType | ||
Entry: 3 | ||
Data: 1 | ||
- Name: syncMode | ||
Entry: 3 | ||
Data: 0 | ||
- Name: symbolResolvedTypeName | ||
Entry: 1 | ||
Data: SystemStringArray | ||
- Name: symbolOriginalName | ||
Entry: 1 | ||
Data: snapTargetPrefixes | ||
- Name: symbolUniqueName | ||
Entry: 1 | ||
Data: snapTargetPrefixes | ||
- Name: symbolDefaultValue | ||
Entry: 6 | ||
Data: | ||
- Name: | ||
Entry: 8 | ||
Data: | ||
- Name: fieldAttributes | ||
Entry: 7 | ||
Data: 9|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: reparent | ||
- Name: $v | ||
Entry: 7 | ||
Data: 10|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor | ||
- Name: fieldSymbol | ||
Entry: 7 | ||
Data: 11|UdonSharp.Compiler.SymbolDefinition, UdonSharp.Editor | ||
- Name: internalType | ||
Entry: 7 | ||
Data: 12|System.RuntimeType, mscorlib | ||
- Name: | ||
Entry: 1 | ||
Data: System.Boolean, mscorlib | ||
- Name: | ||
Entry: 8 | ||
Data: | ||
- Name: declarationType | ||
Entry: 3 | ||
Data: 1 | ||
- Name: syncMode | ||
Entry: 3 | ||
Data: 0 | ||
- Name: symbolResolvedTypeName | ||
Entry: 1 | ||
Data: SystemBoolean | ||
- Name: symbolOriginalName | ||
Entry: 1 | ||
Data: reparent | ||
- Name: symbolUniqueName | ||
Entry: 1 | ||
Data: reparent | ||
- Name: symbolDefaultValue | ||
Entry: 6 | ||
Data: | ||
- Name: | ||
Entry: 8 | ||
Data: | ||
- Name: fieldAttributes | ||
Entry: 7 | ||
Data: 13|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: 14|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor | ||
- Name: fieldSymbol | ||
Entry: 7 | ||
Data: 15|UdonSharp.Compiler.SymbolDefinition, UdonSharp.Editor | ||
- Name: internalType | ||
Entry: 7 | ||
Data: 16|System.RuntimeType, mscorlib | ||
- Name: | ||
Entry: 1 | ||
Data: UnityEngine.Transform, UnityEngine.CoreModule | ||
- Name: | ||
Entry: 8 | ||
Data: | ||
- Name: declarationType | ||
Entry: 3 | ||
Data: 2 | ||
- Name: syncMode | ||
Entry: 3 | ||
Data: 0 | ||
- Name: symbolResolvedTypeName | ||
Entry: 1 | ||
Data: UnityEngineTransform | ||
- Name: symbolOriginalName | ||
Entry: 1 | ||
Data: initialParent | ||
- Name: symbolUniqueName | ||
Entry: 1 | ||
Data: initialParent | ||
- 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: 13 | ||
Data: | ||
- Name: | ||
Entry: 8 | ||
Data: |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
| ||
using InariUdon.Transforms; | ||
using UdonSharp; | ||
using UnityEngine; | ||
using VRC.SDK3.Components; | ||
using VRC.SDKBase; | ||
using VRC.Udon; | ||
|
||
namespace InariUdon.Interaction | ||
{ | ||
[UdonBehaviourSyncMode(BehaviourSyncMode.None)] | ||
[RequireComponent(typeof(VRCPickup))] | ||
public class Snappable : UdonSharpBehaviour | ||
{ | ||
public LayerMask layerMask = -1; | ||
public string[] snapTargetPrefixes = { | ||
"SNAP_TARGET_", | ||
}; | ||
public bool reparent; | ||
|
||
private Transform initialParent; | ||
private void Start() | ||
{ | ||
initialParent = transform.parent; | ||
} | ||
|
||
public override void OnPickup() | ||
{ | ||
transform.SetParent(initialParent); | ||
} | ||
|
||
public override void OnDrop() | ||
{ | ||
var snapTarget = FindSnapTarget(); | ||
if (snapTarget) | ||
{ | ||
transform.SetPositionAndRotation(snapTarget.position, snapTarget.rotation); | ||
if (reparent) transform.SetParent(snapTarget); | ||
} | ||
} | ||
|
||
private Transform FindSnapTarget() | ||
{ | ||
foreach (var collider in Physics.OverlapSphere(transform.position, 0.001f, layerMask, QueryTriggerInteraction.Collide)) | ||
{ | ||
if (!collider) continue; | ||
|
||
foreach (var prefix in snapTargetPrefixes) { | ||
if (collider.gameObject.name.StartsWith(prefix)) | ||
{ | ||
return collider.transform; | ||
} | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.