From b1019b84d0dd10a5a9fc4614b471ba845bbd1212 Mon Sep 17 00:00:00 2001
From: bnco <33021110+bnco-dev@users.noreply.github.com>
Date: Tue, 20 Aug 2024 11:29:37 +0100
Subject: [PATCH] Fix firework interaction and add lifetime
---
.../Demo (XRI)/Assets/Prefabs/Firework.prefab | 54 ++++++++++++++++---
.../Assets/Prefabs/Fireworks Box.prefab | 35 +++++++++---
.../Demo (XRI)/Assets/Scripts/Firework.cs | 20 +++++--
.../Demo (XRI)/Assets/Scripts/FireworksBox.cs | 29 ++++++++--
.../Assets/Ubiq/Samples/Demo (XRI)/Demo.unity | 10 ----
5 files changed, 114 insertions(+), 34 deletions(-)
diff --git a/Unity/Assets/Ubiq/Samples/Demo (XRI)/Assets/Prefabs/Firework.prefab b/Unity/Assets/Ubiq/Samples/Demo (XRI)/Assets/Prefabs/Firework.prefab
index 2cf26f9fa..ae7de40d1 100644
--- a/Unity/Assets/Ubiq/Samples/Demo (XRI)/Assets/Prefabs/Firework.prefab
+++ b/Unity/Assets/Ubiq/Samples/Demo (XRI)/Assets/Prefabs/Firework.prefab
@@ -25,13 +25,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 497636861439859922}
+ serializedVersion: 2
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: 1003247254327550688}
- m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &2572053252928660028
MonoBehaviour:
@@ -146,13 +146,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3583568802882782773}
+ serializedVersion: 2
m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068}
m_LocalPosition: {x: 0, y: -0.118, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 4514551385010556072}
- m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
--- !u!198 &7917524655125373086
ParticleSystem:
@@ -372,6 +372,7 @@ ParticleSystem:
atime6: 0
atime7: 0
m_Mode: 0
+ m_ColorSpace: -1
m_NumColorKeys: 2
m_NumAlphaKeys: 2
minGradient:
@@ -401,6 +402,7 @@ ParticleSystem:
atime6: 0
atime7: 0
m_Mode: 0
+ m_ColorSpace: -1
m_NumColorKeys: 2
m_NumAlphaKeys: 2
startSize:
@@ -722,6 +724,7 @@ ParticleSystem:
m_PostInfinity: 2
m_RotationOrder: 4
randomizeRotationDirection: 0
+ gravitySource: 0
maxNumParticles: 1000
customEmitterVelocity: {x: 0, y: 0, z: 0}
size3D: 0
@@ -1451,6 +1454,7 @@ ParticleSystem:
atime6: 0
atime7: 0
m_Mode: 0
+ m_ColorSpace: -1
m_NumColorKeys: 2
m_NumAlphaKeys: 2
minGradient:
@@ -1480,6 +1484,7 @@ ParticleSystem:
atime6: 0
atime7: 0
m_Mode: 0
+ m_ColorSpace: -1
m_NumColorKeys: 2
m_NumAlphaKeys: 2
UVModule:
@@ -3700,6 +3705,7 @@ ParticleSystem:
atime6: 0
atime7: 0
m_Mode: 0
+ m_ColorSpace: -1
m_NumColorKeys: 2
m_NumAlphaKeys: 2
minGradient:
@@ -3729,6 +3735,7 @@ ParticleSystem:
atime6: 0
atime7: 0
m_Mode: 0
+ m_ColorSpace: -1
m_NumColorKeys: 2
m_NumAlphaKeys: 2
range: {x: 0, y: 1}
@@ -4118,6 +4125,7 @@ ParticleSystem:
m_RotationOrder: 4
minVertexDistance: 0.2
textureMode: 0
+ textureScale: {x: 1, y: 1}
ribbonCount: 1
shadowBias: 0.5
worldSpace: 0
@@ -4160,6 +4168,7 @@ ParticleSystem:
atime6: 0
atime7: 0
m_Mode: 0
+ m_ColorSpace: -1
m_NumColorKeys: 2
m_NumAlphaKeys: 2
minGradient:
@@ -4189,6 +4198,7 @@ ParticleSystem:
atime6: 0
atime7: 0
m_Mode: 0
+ m_ColorSpace: -1
m_NumColorKeys: 2
m_NumAlphaKeys: 2
widthOverTrail:
@@ -4276,6 +4286,7 @@ ParticleSystem:
atime6: 0
atime7: 0
m_Mode: 0
+ m_ColorSpace: -1
m_NumColorKeys: 2
m_NumAlphaKeys: 2
minGradient:
@@ -4305,6 +4316,7 @@ ParticleSystem:
atime6: 0
atime7: 0
m_Mode: 0
+ m_ColorSpace: -1
m_NumColorKeys: 2
m_NumAlphaKeys: 2
CustomDataModule:
@@ -4343,6 +4355,7 @@ ParticleSystem:
atime6: 0
atime7: 0
m_Mode: 0
+ m_ColorSpace: -1
m_NumColorKeys: 2
m_NumAlphaKeys: 2
minGradient:
@@ -4372,6 +4385,7 @@ ParticleSystem:
atime6: 0
atime7: 0
m_Mode: 0
+ m_ColorSpace: -1
m_NumColorKeys: 2
m_NumAlphaKeys: 2
colorLabel0: Color
@@ -4625,6 +4639,7 @@ ParticleSystem:
atime6: 0
atime7: 0
m_Mode: 0
+ m_ColorSpace: -1
m_NumColorKeys: 2
m_NumAlphaKeys: 2
minGradient:
@@ -4654,6 +4669,7 @@ ParticleSystem:
atime6: 0
atime7: 0
m_Mode: 0
+ m_ColorSpace: -1
m_NumColorKeys: 2
m_NumAlphaKeys: 2
colorLabel1: Color
@@ -4929,13 +4945,15 @@ ParticleSystemRenderer:
m_RenderAlignment: 0
m_Pivot: {x: 0, y: 0, z: 0}
m_Flip: {x: 0, y: 0, z: 0}
- m_UseCustomVertexStreams: 1
m_EnableGPUInstancing: 1
m_ApplyActiveColorSpace: 1
m_AllowRoll: 1
m_FreeformStretching: 0
m_RotateWithStretchDirection: 1
+ m_UseCustomVertexStreams: 1
m_VertexStreams: 000304
+ m_UseCustomTrailVertexStreams: 0
+ m_TrailVertexStreams: 00010304
m_Mesh: {fileID: 0}
m_Mesh1: {fileID: 0}
m_Mesh2: {fileID: 0}
@@ -4971,6 +4989,7 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4511263541971767917}
+ serializedVersion: 2
m_LocalRotation: {x: -0, y: -0.7071068, z: -0, w: 0.7071068}
m_LocalPosition: {x: 4, y: 1.1630001, z: -2.9250002}
m_LocalScale: {x: 1, y: 1, z: 1}
@@ -4979,7 +4998,6 @@ Transform:
- {fileID: 1003247254327550688}
- {fileID: 4514551385010556072}
m_Father: {fileID: 0}
- m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!54 &358521151660322129
Rigidbody:
@@ -4988,10 +5006,21 @@ Rigidbody:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4511263541971767917}
- serializedVersion: 2
+ serializedVersion: 4
m_Mass: 0.2
m_Drag: 0
m_AngularDrag: 0.05
+ m_CenterOfMass: {x: 0, y: 0, z: 0}
+ m_InertiaTensor: {x: 1, y: 1, z: 1}
+ m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
+ m_IncludeLayers:
+ serializedVersion: 2
+ m_Bits: 0
+ m_ExcludeLayers:
+ serializedVersion: 2
+ m_Bits: 0
+ m_ImplicitCom: 1
+ m_ImplicitTensor: 1
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 1
@@ -5124,7 +5153,7 @@ MonoBehaviour:
m_SmoothScale: 0
m_SmoothScaleAmount: 8
m_TightenScale: 0.1
- m_ThrowOnDetach: 1
+ m_ThrowOnDetach: 0
m_ThrowSmoothingDuration: 0.25
m_ThrowSmoothingCurve:
serializedVersion: 2
@@ -5189,6 +5218,7 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7074151898749289021}
+ serializedVersion: 2
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}
@@ -5196,7 +5226,6 @@ Transform:
m_Children:
- {fileID: 8446491942243003209}
m_Father: {fileID: 3965644712137253237}
- m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &7670518505520222121
MeshFilter:
@@ -5256,8 +5285,17 @@ CapsuleCollider:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7074151898749289021}
m_Material: {fileID: 0}
+ m_IncludeLayers:
+ serializedVersion: 2
+ m_Bits: 0
+ m_ExcludeLayers:
+ serializedVersion: 2
+ m_Bits: 0
+ m_LayerOverridePriority: 0
m_IsTrigger: 0
+ m_ProvidesContacts: 0
m_Enabled: 1
+ serializedVersion: 2
m_Radius: 0.037345067
m_Height: 0.3781724
m_Direction: 1
@@ -5286,6 +5324,7 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8175397145799157221}
+ serializedVersion: 2
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}
@@ -5293,7 +5332,6 @@ Transform:
m_Children:
- {fileID: 6699209973184693969}
m_Father: {fileID: 3965644712137253237}
- m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &3658710582876860169
MonoBehaviour:
diff --git a/Unity/Assets/Ubiq/Samples/Demo (XRI)/Assets/Prefabs/Fireworks Box.prefab b/Unity/Assets/Ubiq/Samples/Demo (XRI)/Assets/Prefabs/Fireworks Box.prefab
index 7db189b15..510116a1a 100644
--- a/Unity/Assets/Ubiq/Samples/Demo (XRI)/Assets/Prefabs/Fireworks Box.prefab
+++ b/Unity/Assets/Ubiq/Samples/Demo (XRI)/Assets/Prefabs/Fireworks Box.prefab
@@ -24,6 +24,7 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 509411235045699198}
+ serializedVersion: 2
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}
@@ -31,7 +32,6 @@ Transform:
m_Children:
- {fileID: 3070695493358685514}
m_Father: {fileID: 8245267067570120123}
- m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &4945879630741660818
MonoBehaviour:
@@ -108,13 +108,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3240370694413710550}
+ serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.32551, y: 0.32551, z: 0.32551}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8245267067570120123}
- m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &3240370694413710570
MeshFilter:
@@ -144,7 +144,7 @@ MeshRenderer:
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- - {fileID: 670224309865224971, guid: be3083a5f26d4e859d594ecbe632f87e, type: 3}
+ - {fileID: 2100000, guid: 95740d400bace5446a4a35862ade2f81, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
@@ -174,9 +174,17 @@ BoxCollider:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3240370694413710550}
m_Material: {fileID: 0}
+ m_IncludeLayers:
+ serializedVersion: 2
+ m_Bits: 0
+ m_ExcludeLayers:
+ serializedVersion: 2
+ m_Bits: 0
+ m_LayerOverridePriority: 0
m_IsTrigger: 0
+ m_ProvidesContacts: 0
m_Enabled: 1
- serializedVersion: 2
+ serializedVersion: 3
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &8107293676157753161
@@ -204,13 +212,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8107293676157753161}
+ serializedVersion: 2
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: 8901737113673820539}
- m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &6184804017631619495
MonoBehaviour:
@@ -299,7 +307,7 @@ MonoBehaviour:
m_PersistentCalls:
m_Calls: []
m_MaterialPropertyBlockHelper: {fileID: 6184804017631619495}
- m_ColorPropertyName:
+ m_ColorPropertyName: _Color
--- !u!1 &8245267067570120064
GameObject:
m_ObjectHideFlags: 0
@@ -326,6 +334,7 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8245267067570120064}
+ serializedVersion: 2
m_LocalRotation: {x: -0, y: -0.7071068, z: -0, w: 0.7071068}
m_LocalPosition: {x: 1.463, y: 0.484, z: -1.358}
m_LocalScale: {x: 1, y: 1, z: 1}
@@ -334,7 +343,6 @@ Transform:
- {fileID: 8901737113673820539}
- {fileID: 3240370694413710573}
m_Father: {fileID: 0}
- m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!54 &1716084023271190560
Rigidbody:
@@ -343,10 +351,21 @@ Rigidbody:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8245267067570120064}
- serializedVersion: 2
+ serializedVersion: 4
m_Mass: 1
m_Drag: 0
m_AngularDrag: 0.05
+ m_CenterOfMass: {x: 0, y: 0, z: 0}
+ m_InertiaTensor: {x: 1, y: 1, z: 1}
+ m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
+ m_IncludeLayers:
+ serializedVersion: 2
+ m_Bits: 0
+ m_ExcludeLayers:
+ serializedVersion: 2
+ m_Bits: 0
+ m_ImplicitCom: 1
+ m_ImplicitTensor: 1
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 1
diff --git a/Unity/Assets/Ubiq/Samples/Demo (XRI)/Assets/Scripts/Firework.cs b/Unity/Assets/Ubiq/Samples/Demo (XRI)/Assets/Scripts/Firework.cs
index 76b83d118..04c91812d 100644
--- a/Unity/Assets/Ubiq/Samples/Demo (XRI)/Assets/Scripts/Firework.cs
+++ b/Unity/Assets/Ubiq/Samples/Demo (XRI)/Assets/Scripts/Firework.cs
@@ -23,6 +23,8 @@ public class Firework : MonoBehaviour, INetworkSpawnable
#if XRI_2_5_2_OR_NEWER
private NetworkContext context;
+ private Vector3 flightForce;
+ private float explodeTime;
private void Awake()
{
@@ -42,6 +44,12 @@ private void Start()
public void XRGrabInteractable_Activated(ActivateEventArgs eventArgs)
{
fired = true;
+
+ flightForce = new Vector3(
+ x:(Random.value - 0.5f)*0.2f,
+ y:0.3f,
+ z:(Random.value - 0.5f)*0.2f);
+ explodeTime = Time.time + 10.0f;
// Force the interactor(hand) to drop the firework
var interactor = (XRBaseInteractor)eventArgs.interactorObject;
@@ -60,12 +68,18 @@ private void Update()
if(owner && fired)
{
body.isKinematic = false;
- body.AddForce(transform.up * 0.75f, ForceMode.Force);
+ body.AddForce(flightForce, ForceMode.Force);
if (!particles.isPlaying)
{
particles.Play();
- body.AddForce(new Vector3(Random.value, Random.value, Random.value) * 1.1f, ForceMode.Force);
+ body.AddForce(Vector3.up * 2.0f, ForceMode.Impulse);
+ }
+
+ if (Time.time > explodeTime)
+ {
+ NetworkSpawnManager.Find(this).Despawn(gameObject);
+ return;
}
}
if(!owner && fired)
@@ -77,7 +91,7 @@ private void Update()
}
}
- public struct Message
+ private struct Message
{
public Pose pose;
public bool fired;
diff --git a/Unity/Assets/Ubiq/Samples/Demo (XRI)/Assets/Scripts/FireworksBox.cs b/Unity/Assets/Ubiq/Samples/Demo (XRI)/Assets/Scripts/FireworksBox.cs
index 0f83243c1..c29a2719c 100644
--- a/Unity/Assets/Ubiq/Samples/Demo (XRI)/Assets/Scripts/FireworksBox.cs
+++ b/Unity/Assets/Ubiq/Samples/Demo (XRI)/Assets/Scripts/FireworksBox.cs
@@ -10,10 +10,10 @@
namespace Ubiq.Samples
{
///
- /// The Fireworks Box is a basic interactive object. This object uses the NetworkSpawner
- /// to create shared objects (fireworks).
- /// The Box can be grasped and moved around, but note that the Box itself is *not* network
- /// enabled, and each player has their own copy.
+ /// The Fireworks Box is a basic interactive object. This object uses the
+ /// NetworkSpawner to create shared objects (fireworks). The Box can be
+ /// grasped and moved around, but note that the Box itself is *not* network
+ /// enabled. Each player has their own copy.
///
[RequireComponent(typeof(Rigidbody))]
public class FireworksBox : MonoBehaviour
@@ -23,12 +23,14 @@ public class FireworksBox : MonoBehaviour
#if XRI_2_5_2_OR_NEWER
private NetworkSpawnManager spawnManager;
private XRGrabInteractable interactable;
+ private XRInteractionManager interactionManager;
private void Start()
{
spawnManager = NetworkSpawnManager.Find(this);
interactable = GetComponent();
-
+ interactionManager = interactable.interactionManager;
+
interactable.activated.AddListener(XRGrabInteractable_Activated);
}
@@ -43,6 +45,23 @@ public void XRGrabInteractable_Activated(ActivateEventArgs eventArgs)
var firework = go.GetComponent();
firework.transform.position = transform.position;
firework.owner = true;
+
+ if (!interactionManager)
+ {
+ return;
+ }
+
+ // Force the interactor(hand) to drop the box and grab the firework
+ var selectInteractor = eventArgs.interactorObject as IXRSelectInteractor;
+ if (selectInteractor != null)
+ {
+ interactionManager.SelectExit(
+ selectInteractor,
+ this.interactable);
+ interactionManager.SelectEnter(
+ selectInteractor,
+ firework.GetComponent());
+ }
}
#endif
}
diff --git a/Unity/Assets/Ubiq/Samples/Demo (XRI)/Demo.unity b/Unity/Assets/Ubiq/Samples/Demo (XRI)/Demo.unity
index 9588c7c7b..6c6f52285 100644
--- a/Unity/Assets/Ubiq/Samples/Demo (XRI)/Demo.unity
+++ b/Unity/Assets/Ubiq/Samples/Demo (XRI)/Demo.unity
@@ -973,16 +973,6 @@ PrefabInstance:
propertyPath: m_RootOrder
value: 4
objectReference: {fileID: 0}
- - target: {fileID: 1296376847062281280, guid: 76e53f38a7ad1c44bb05311d46bf216d,
- type: 3}
- propertyPath: m_ColorPropertyName
- value: _Color
- objectReference: {fileID: 0}
- - target: {fileID: 3240370694413710571, guid: 76e53f38a7ad1c44bb05311d46bf216d,
- type: 3}
- propertyPath: m_Materials.Array.data[0]
- value:
- objectReference: {fileID: 2100000, guid: 95740d400bace5446a4a35862ade2f81, type: 2}
- target: {fileID: 4819973546623887357, guid: 76e53f38a7ad1c44bb05311d46bf216d,
type: 3}
propertyPath: m_RootOrder