1
0
forked from cgvr/DeltaVR

deltavr multiplayer 2.0

This commit is contained in:
Toomas Tamm
2023-05-08 15:56:10 +03:00
parent 978809a002
commit 07b9b9e2f4
10937 changed files with 2968397 additions and 1521012 deletions

View File

@@ -0,0 +1,48 @@
using System;
using UnityEngine.Events;
namespace UnityEngine.XR.Content.Interaction
{
/// <summary>
/// Detects a collision with a tagged collider, replacing this object with a 'broken' version
/// </summary>
public class Breakable : MonoBehaviour
{
[Serializable] public class BreakEvent : UnityEvent<GameObject, GameObject> { }
[SerializeField]
[Tooltip("The 'broken' version of this object.")]
GameObject m_BrokenVersion;
[SerializeField]
[Tooltip("The tag a collider must have to cause this object to break.")]
string m_ColliderTag = "Destroyer";
[SerializeField]
[Tooltip("Events to fire when a matching object collides and break this object. " +
"The first parameter is the colliding object, the second parameter is the 'broken' version.")]
BreakEvent m_OnBreak = new BreakEvent();
bool m_Destroyed = false;
/// <summary>
/// Events to fire when a matching object collides and break this object.
/// The first parameter is the colliding object, the second parameter is the 'broken' version.
/// </summary>
public BreakEvent onBreak => m_OnBreak;
void OnCollisionEnter(Collision collision)
{
if (m_Destroyed)
return;
if (collision.gameObject.tag.Equals(m_ColliderTag, System.StringComparison.InvariantCultureIgnoreCase))
{
m_Destroyed = true;
var brokenVersion = Instantiate(m_BrokenVersion, transform.position, transform.rotation);
m_OnBreak.Invoke(collision.gameObject, brokenVersion);
Destroy(gameObject);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ecc3a8c5ad509204cb2ac78f2182017c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,57 @@
using System;
using UnityEngine.Events;
namespace UnityEngine.XR.Content.Interaction
{
/// <summary>
/// Calls functionality when a physics collision occurs
/// </summary>
public class OnCollision : MonoBehaviour
{
[Serializable] public class CollisionEvent : UnityEvent<Collision> { }
[SerializeField]
[Tooltip("If set, this collision will only fire if the other gameobject has this tag.")]
string m_RequiredTag = string.Empty;
[SerializeField]
[Tooltip("Events to fire when a matcing object collides with this one.")]
CollisionEvent m_OnEnter = new CollisionEvent();
[SerializeField]
[Tooltip("Events to fire when a matching object stops colliding with this one.")]
CollisionEvent m_OnExit = new CollisionEvent();
/// <summary>
/// If set, this collision will only fire if the other gameobject has this tag.
/// </summary>
public string requiredTag => m_RequiredTag;
/// <summary>
/// Events to fire when a matching object collides with this one.
/// </summary>
public CollisionEvent onEnter => m_OnEnter;
/// <summary>
/// Events to fire when a matching object stops colliding with this one.
/// </summary>
public CollisionEvent onExit => m_OnExit;
void OnCollisionEnter(Collision collision)
{
if (CanInvoke(collision.gameObject))
m_OnEnter?.Invoke(collision);
}
void OnCollisionExit(Collision collision)
{
if (CanInvoke(collision.gameObject))
m_OnExit?.Invoke(collision);
}
bool CanInvoke(GameObject otherGameObject)
{
return string.IsNullOrEmpty(m_RequiredTag) || otherGameObject.CompareTag(m_RequiredTag);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9f1b1ca3d366080408e9007a6b566953
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,66 @@
using System;
using UnityEngine.Events;
namespace UnityEngine.XR.Content.Interaction
{
/// <summary>
/// Calls functionality when a physics trigger occurs
/// </summary>
public class OnTrigger : MonoBehaviour
{
[Serializable] public class TriggerEvent : UnityEvent<GameObject> { }
[SerializeField]
[Tooltip("If set, this trigger will only fire if the other gameobject has this tag.")]
string m_RequiredTag = string.Empty;
[SerializeField]
[Tooltip("Events to fire when a matcing object collides with this trigger.")]
TriggerEvent m_OnEnter = new TriggerEvent();
[SerializeField]
[Tooltip("Events to fire when a matching object stops colliding with this trigger.")]
TriggerEvent m_OnExit = new TriggerEvent();
/// <summary>
/// If set, this trigger will only fire if the other gameobject has this tag.
/// </summary>
public string requiredTag => m_RequiredTag;
/// <summary>
/// Events to fire when a matching object collides with this trigger.
/// </summary>
public TriggerEvent onEnter => m_OnEnter;
/// <summary>
/// Events to fire when a matching object stops colliding with this trigger.
/// </summary>
public TriggerEvent onExit => m_OnExit;
void OnTriggerEnter(Collider other)
{
if (CanTrigger(other.gameObject))
m_OnEnter?.Invoke(other.gameObject);
}
void OnTriggerExit(Collider other)
{
if (CanTrigger(other.gameObject))
m_OnExit?.Invoke(other.gameObject);
}
void OnParticleCollision(GameObject other)
{
if (CanTrigger(other.gameObject))
m_OnEnter?.Invoke(other);
}
bool CanTrigger(GameObject otherGameObject)
{
if (m_RequiredTag != string.Empty)
return otherGameObject.CompareTag(m_RequiredTag);
else
return true;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 59fe722e016ecae438f59fbf21af3ecf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,36 @@
using UnityEngine.Events;
using UnityEngine.XR.Content.Animation;
namespace UnityEngine.XR.Content.Interaction
{
public class TargetRing : MonoBehaviour, IAnimationEventActionBegin, IAnimationEventActionFinished
{
const string k_ActiveLabel = "active";
[SerializeField]
UnityEvent m_OnHit;
[SerializeField]
UnityEvent m_OnActive;
[SerializeField]
UnityEvent m_OnInactive;
public void OnHit()
{
m_OnHit.Invoke();
}
void IAnimationEventActionBegin.ActionBegin(string label)
{
if (label == k_ActiveLabel)
m_OnActive.Invoke();
}
void IAnimationEventActionFinished.ActionFinished(string label)
{
if (label == k_ActiveLabel)
m_OnInactive.Invoke();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a75979ceb20a38641959e8f116d9b60e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,118 @@
using System;
using System.Collections.Generic;
using UnityEngine.Events;
namespace UnityEngine.XR.Content.Interaction
{
/// <summary>
/// Rewinds positional changes made this object and its children to restore it back to a 'complete' object
/// </summary>
public class Unbreakable : MonoBehaviour
{
[Serializable] public class RestoreEvent : UnityEvent<GameObject> { }
[SerializeField]
[Tooltip("How long to wait before rewinding the object's motion.")]
float m_RestTime = 1.0f;
[SerializeField]
[Tooltip("How long to spend restoring the object.")]
float m_RestoreTime = 2.0f;
[SerializeField]
[Tooltip("A 'non broken' object to replace this object with when motion rewinding is complete.")]
GameObject m_RestoredVersion;
[SerializeField]
[Tooltip("Events to fire when the 'non broken' object is restored.")]
RestoreEvent m_OnRestore = new RestoreEvent();
bool m_Resting = true;
float m_Timer = 0.0f;
bool m_Restored = false;
struct ChildPoses
{
internal Pose m_StartPose;
internal Pose m_EndPose;
}
Dictionary<Transform, ChildPoses> m_ChildPoses = new Dictionary<Transform, ChildPoses>();
List<Transform> m_ChildTransforms = new List<Transform>();
/// <summary>
/// Events to fire when the 'non broken' object is restored.
/// </summary>
public RestoreEvent onRestore => m_OnRestore;
void Start()
{
// Go through all children
GetComponentsInChildren(m_ChildTransforms);
// Cache their start positions
foreach (var child in m_ChildTransforms)
{
m_ChildPoses.Add(child, new ChildPoses { m_StartPose = new Pose(child.position, child.rotation) });
}
}
void Update()
{
if (m_Restored)
return;
// Phase 1 - wait to rewind
// Phase 2 - rewind all positions, using a an inverse quadratic curve
// Phase 3 - replace object, destroy this one
m_Timer += Time.deltaTime;
if (m_Resting)
{
if (m_Timer > m_RestTime)
{
m_Timer = 0.0f;
m_Resting = false;
foreach (var child in m_ChildTransforms)
{
if (child == null)
continue;
var poses = m_ChildPoses[child];
poses.m_EndPose = new Pose(child.position, child.rotation);
m_ChildPoses[child] = poses;
}
}
}
else
{
var timePercent = m_Timer / m_RestoreTime;
if (timePercent > 1.0f)
{
m_Restored = true;
var restoredVersion = Instantiate(m_RestoredVersion, transform.position, transform.rotation);
m_OnRestore.Invoke(restoredVersion);
Destroy(gameObject);
}
else
{
timePercent = 1.0f - ((1.0f - timePercent) * (1.0f - timePercent));
foreach (var child in m_ChildTransforms)
{
if (child == null)
continue;
var poses = m_ChildPoses[child];
var lerpedPosition = Vector3.Lerp(poses.m_EndPose.position, poses.m_StartPose.position, timePercent);
var lerpedRotation = Quaternion.Slerp(poses.m_EndPose.rotation, poses.m_StartPose.rotation, timePercent);
child.position = lerpedPosition;
child.rotation = lerpedRotation;
}
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 765744fd7cc8e0c468cbb2e596fcf6ff
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: