Initialer Upload neues Unity-Projekt
This commit is contained in:
@ -0,0 +1,18 @@
|
||||
//======= Copyright (c) Valve Corporation, All rights reserved. ===============
|
||||
//
|
||||
// Purpose: Adding this component to an object will allow the player to
|
||||
// initiate teleporting while that object is attached to their hand
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Valve.VR.InteractionSystem
|
||||
{
|
||||
//-------------------------------------------------------------------------
|
||||
public class AllowTeleportWhileAttachedToHand : MonoBehaviour
|
||||
{
|
||||
public bool teleportAllowed = true;
|
||||
public bool overrideHoverLock = true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8d4cc6cf300b3e4bb1411c4e041030c
|
||||
timeCreated: 1544851869
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,87 @@
|
||||
//======= Copyright (c) Valve Corporation, All rights reserved. ===============
|
||||
//
|
||||
// Purpose: Stores the play area size info from the players chaperone data
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using System.Collections;
|
||||
|
||||
namespace Valve.VR.InteractionSystem
|
||||
{
|
||||
//-------------------------------------------------------------------------
|
||||
public class ChaperoneInfo : MonoBehaviour
|
||||
{
|
||||
public bool initialized { get; private set; }
|
||||
public float playAreaSizeX { get; private set; }
|
||||
public float playAreaSizeZ { get; private set; }
|
||||
public bool roomscale { get; private set; }
|
||||
|
||||
public static SteamVR_Events.Event Initialized = new SteamVR_Events.Event();
|
||||
public static SteamVR_Events.Action InitializedAction( UnityAction action ) { return new SteamVR_Events.ActionNoArgs( Initialized, action ); }
|
||||
|
||||
//-------------------------------------------------
|
||||
private static ChaperoneInfo _instance;
|
||||
public static ChaperoneInfo instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( _instance == null )
|
||||
{
|
||||
_instance = new GameObject( "[ChaperoneInfo]" ).AddComponent<ChaperoneInfo>();
|
||||
_instance.initialized = false;
|
||||
_instance.playAreaSizeX = 1.0f;
|
||||
_instance.playAreaSizeZ = 1.0f;
|
||||
_instance.roomscale = false;
|
||||
|
||||
DontDestroyOnLoad( _instance.gameObject );
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
IEnumerator Start()
|
||||
{
|
||||
// Uncomment for roomscale testing
|
||||
//_instance.initialized = true;
|
||||
//_instance.playAreaSizeX = UnityEngine.Random.Range( 1.0f, 4.0f );
|
||||
//_instance.playAreaSizeZ = UnityEngine.Random.Range( 1.0f, _instance.playAreaSizeX );
|
||||
//_instance.roomscale = true;
|
||||
//ChaperoneInfo.Initialized.Send();
|
||||
//yield break;
|
||||
|
||||
// Get interface pointer
|
||||
var chaperone = OpenVR.Chaperone;
|
||||
if ( chaperone == null )
|
||||
{
|
||||
Debug.LogWarning("<b>[SteamVR Interaction]</b> Failed to get IVRChaperone interface.");
|
||||
initialized = true;
|
||||
yield break;
|
||||
}
|
||||
|
||||
// Get play area size
|
||||
while ( true )
|
||||
{
|
||||
float px = 0.0f, pz = 0.0f;
|
||||
if ( chaperone.GetPlayAreaSize( ref px, ref pz ) )
|
||||
{
|
||||
initialized = true;
|
||||
playAreaSizeX = px;
|
||||
playAreaSizeZ = pz;
|
||||
roomscale = Mathf.Max( px, pz ) > 1.01f;
|
||||
|
||||
Debug.LogFormat("<b>[SteamVR Interaction]</b> ChaperoneInfo initialized. {2} play area {0:0.00}m x {1:0.00}m", px, pz, roomscale ? "Roomscale" : "Standing" );
|
||||
|
||||
ChaperoneInfo.Initialized.Send();
|
||||
|
||||
yield break;
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ebcc975aa3c1d5240936c86b600ca2a5
|
||||
timeCreated: 1544851960
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,17 @@
|
||||
//======= Copyright (c) Valve Corporation, All rights reserved. ===============
|
||||
//
|
||||
// Purpose: Allows the teleport arc trace to pass through any colliders on this
|
||||
// object
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace Valve.VR.InteractionSystem
|
||||
{
|
||||
//-------------------------------------------------------------------------
|
||||
public class IgnoreTeleportTrace : MonoBehaviour
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dc3be917a80086a48b97933694257f09
|
||||
timeCreated: 1544851963
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1163
Assets/SteamVR/InteractionSystem/Teleport/Scripts/Teleport.cs
Normal file
1163
Assets/SteamVR/InteractionSystem/Teleport/Scripts/Teleport.cs
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f260935093f73f241bfaa1578e5e5506
|
||||
timeCreated: 1544852190
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -32000
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
311
Assets/SteamVR/InteractionSystem/Teleport/Scripts/TeleportArc.cs
Normal file
311
Assets/SteamVR/InteractionSystem/Teleport/Scripts/TeleportArc.cs
Normal file
@ -0,0 +1,311 @@
|
||||
//======= Copyright (c) Valve Corporation, All rights reserved. ===============
|
||||
//
|
||||
// Purpose: Displays the arc lines for teleporting and does the traces
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Valve.VR.InteractionSystem
|
||||
{
|
||||
//-------------------------------------------------------------------------
|
||||
public class TeleportArc : MonoBehaviour
|
||||
{
|
||||
public int segmentCount = 60;
|
||||
public float thickness = 0.01f;
|
||||
|
||||
[Tooltip("The amount of time in seconds to predict the motion of the projectile.")]
|
||||
public float arcDuration = 3.0f;
|
||||
|
||||
[Tooltip("The amount of time in seconds between each segment of the projectile.")]
|
||||
public float segmentBreak = 0.025f;
|
||||
|
||||
[Tooltip("The speed at which the line segments of the arc move.")]
|
||||
public float arcSpeed = 0.2f;
|
||||
|
||||
public Material material;
|
||||
|
||||
[HideInInspector]
|
||||
public int traceLayerMask = 0;
|
||||
|
||||
//Private data
|
||||
private LineRenderer[] lineRenderers;
|
||||
private float arcTimeOffset = 0.0f;
|
||||
private float prevThickness = 0.0f;
|
||||
private int prevSegmentCount = 0;
|
||||
private bool showArc = true;
|
||||
private Vector3 startPos;
|
||||
private Vector3 projectileVelocity;
|
||||
private bool useGravity = true;
|
||||
private Transform arcObjectsTransfrom;
|
||||
private bool arcInvalid = false;
|
||||
private float scale = 1;
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
void Start()
|
||||
{
|
||||
arcTimeOffset = Time.time;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
void Update()
|
||||
{
|
||||
//scale arc to match player scale
|
||||
scale = Player.instance.transform.lossyScale.x;
|
||||
if (thickness != prevThickness || segmentCount != prevSegmentCount)
|
||||
{
|
||||
CreateLineRendererObjects();
|
||||
prevThickness = thickness;
|
||||
prevSegmentCount = segmentCount;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
private void CreateLineRendererObjects()
|
||||
{
|
||||
//Destroy any existing line renderer objects
|
||||
if (arcObjectsTransfrom != null)
|
||||
{
|
||||
Destroy(arcObjectsTransfrom.gameObject);
|
||||
}
|
||||
|
||||
GameObject arcObjectsParent = new GameObject("ArcObjects");
|
||||
arcObjectsTransfrom = arcObjectsParent.transform;
|
||||
arcObjectsTransfrom.SetParent(this.transform);
|
||||
|
||||
//Create new line renderer objects
|
||||
lineRenderers = new LineRenderer[segmentCount];
|
||||
for (int i = 0; i < segmentCount; ++i)
|
||||
{
|
||||
GameObject newObject = new GameObject("LineRenderer_" + i);
|
||||
newObject.transform.SetParent(arcObjectsTransfrom);
|
||||
|
||||
lineRenderers[i] = newObject.AddComponent<LineRenderer>();
|
||||
|
||||
lineRenderers[i].receiveShadows = false;
|
||||
lineRenderers[i].reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
|
||||
lineRenderers[i].lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off;
|
||||
lineRenderers[i].shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
|
||||
lineRenderers[i].material = material;
|
||||
#if (UNITY_5_4)
|
||||
lineRenderers[i].SetWidth(thickness, thickness);
|
||||
#else
|
||||
lineRenderers[i].startWidth = thickness * scale;
|
||||
lineRenderers[i].endWidth = thickness * scale;
|
||||
#endif
|
||||
lineRenderers[i].enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public void SetArcData(Vector3 position, Vector3 velocity, bool gravity, bool pointerAtBadAngle)
|
||||
{
|
||||
startPos = position;
|
||||
projectileVelocity = velocity;
|
||||
useGravity = gravity;
|
||||
|
||||
if (arcInvalid && !pointerAtBadAngle)
|
||||
{
|
||||
arcTimeOffset = Time.time;
|
||||
}
|
||||
arcInvalid = pointerAtBadAngle;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public void Show()
|
||||
{
|
||||
showArc = true;
|
||||
if (lineRenderers == null)
|
||||
{
|
||||
CreateLineRendererObjects();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public void Hide()
|
||||
{
|
||||
//Hide the line segments if they were previously being shown
|
||||
if (showArc)
|
||||
{
|
||||
HideLineSegments(0, segmentCount);
|
||||
}
|
||||
showArc = false;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// Draws each segment of the arc individually
|
||||
//-------------------------------------------------
|
||||
public bool DrawArc(out RaycastHit hitInfo)
|
||||
{
|
||||
float timeStep = arcDuration / segmentCount;
|
||||
|
||||
float currentTimeOffset = (Time.time - arcTimeOffset) * arcSpeed;
|
||||
|
||||
//Reset the arc time offset when it has gone beyond a segment length
|
||||
if (currentTimeOffset > (timeStep + segmentBreak))
|
||||
{
|
||||
arcTimeOffset = Time.time;
|
||||
currentTimeOffset = 0.0f;
|
||||
}
|
||||
|
||||
float segmentStartTime = currentTimeOffset;
|
||||
|
||||
float arcHitTime = FindProjectileCollision(out hitInfo);
|
||||
|
||||
if (arcInvalid)
|
||||
{
|
||||
//Only draw first segment
|
||||
lineRenderers[0].enabled = true;
|
||||
lineRenderers[0].SetPosition(0, GetArcPositionAtTime(0.0f));
|
||||
lineRenderers[0].SetPosition(1, GetArcPositionAtTime(arcHitTime < timeStep ? arcHitTime : timeStep));
|
||||
|
||||
HideLineSegments(1, segmentCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Draw the first segment outside the loop if needed
|
||||
int loopStartSegment = 0;
|
||||
if (segmentStartTime > segmentBreak)
|
||||
{
|
||||
float firstSegmentEndTime = currentTimeOffset - segmentBreak;
|
||||
if (arcHitTime < firstSegmentEndTime)
|
||||
{
|
||||
firstSegmentEndTime = arcHitTime;
|
||||
}
|
||||
DrawArcSegment(0, 0.0f, firstSegmentEndTime);
|
||||
|
||||
loopStartSegment = 1;
|
||||
}
|
||||
|
||||
bool stopArc = false;
|
||||
int currentSegment = 0;
|
||||
if (segmentStartTime < arcHitTime)
|
||||
{
|
||||
for (currentSegment = loopStartSegment; currentSegment < segmentCount; ++currentSegment)
|
||||
{
|
||||
//Clamp the segment end time to the arc duration
|
||||
float segmentEndTime = segmentStartTime + timeStep;
|
||||
if (segmentEndTime >= arcDuration)
|
||||
{
|
||||
segmentEndTime = arcDuration;
|
||||
stopArc = true;
|
||||
}
|
||||
|
||||
if (segmentEndTime >= arcHitTime)
|
||||
{
|
||||
segmentEndTime = arcHitTime;
|
||||
stopArc = true;
|
||||
}
|
||||
|
||||
DrawArcSegment(currentSegment, segmentStartTime, segmentEndTime);
|
||||
|
||||
segmentStartTime += timeStep + segmentBreak;
|
||||
|
||||
//If the previous end time or the next start time is beyond the duration then stop the arc
|
||||
if (stopArc || segmentStartTime >= arcDuration || segmentStartTime >= arcHitTime)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
currentSegment--;
|
||||
}
|
||||
|
||||
//Hide the rest of the line segments
|
||||
HideLineSegments(currentSegment + 1, segmentCount);
|
||||
}
|
||||
|
||||
return arcHitTime != float.MaxValue;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
private void DrawArcSegment(int index, float startTime, float endTime)
|
||||
{
|
||||
lineRenderers[index].enabled = true;
|
||||
lineRenderers[index].SetPosition(0, GetArcPositionAtTime(startTime));
|
||||
lineRenderers[index].SetPosition(1, GetArcPositionAtTime(endTime));
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
for (int i = 0; i < segmentCount; ++i)
|
||||
{
|
||||
#if (UNITY_5_4)
|
||||
lineRenderers[i].SetColors(color, color);
|
||||
#else
|
||||
lineRenderers[i].startColor = color;
|
||||
lineRenderers[i].endColor = color;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
private float FindProjectileCollision(out RaycastHit hitInfo)
|
||||
{
|
||||
float timeStep = arcDuration / segmentCount;
|
||||
float segmentStartTime = 0.0f;
|
||||
|
||||
hitInfo = new RaycastHit();
|
||||
|
||||
Vector3 segmentStartPos = GetArcPositionAtTime(segmentStartTime);
|
||||
for (int i = 0; i < segmentCount; ++i)
|
||||
{
|
||||
float segmentEndTime = segmentStartTime + timeStep;
|
||||
Vector3 segmentEndPos = GetArcPositionAtTime(segmentEndTime);
|
||||
|
||||
if (Physics.Linecast(segmentStartPos, segmentEndPos, out hitInfo, traceLayerMask))
|
||||
{
|
||||
if (hitInfo.collider.GetComponent<IgnoreTeleportTrace>() == null)
|
||||
{
|
||||
Util.DrawCross(hitInfo.point, Color.red, 0.5f);
|
||||
float segmentDistance = Vector3.Distance(segmentStartPos, segmentEndPos);
|
||||
float hitTime = segmentStartTime + (timeStep * (hitInfo.distance / segmentDistance));
|
||||
return hitTime;
|
||||
}
|
||||
}
|
||||
|
||||
segmentStartTime = segmentEndTime;
|
||||
segmentStartPos = segmentEndPos;
|
||||
}
|
||||
|
||||
return float.MaxValue;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public Vector3 GetArcPositionAtTime(float time)
|
||||
{
|
||||
Vector3 gravity = useGravity ? Physics.gravity : Vector3.zero;
|
||||
|
||||
Vector3 arcPos = startPos + ((projectileVelocity * time) + (0.5f * time * time) * gravity) * scale;
|
||||
return arcPos;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
private void HideLineSegments(int startSegment, int endSegment)
|
||||
{
|
||||
if (lineRenderers != null)
|
||||
{
|
||||
for (int i = startSegment; i < endSegment; ++i)
|
||||
{
|
||||
lineRenderers[i].enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a043c731a29ecd745a9270fbf002ee68
|
||||
timeCreated: 1544852190
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,204 @@
|
||||
//======= Copyright (c) Valve Corporation, All rights reserved. ===============
|
||||
//
|
||||
// Purpose: An area that the player can teleport to
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace Valve.VR.InteractionSystem
|
||||
{
|
||||
//-------------------------------------------------------------------------
|
||||
public class TeleportArea : TeleportMarkerBase
|
||||
{
|
||||
//Public properties
|
||||
public Bounds meshBounds { get; private set; }
|
||||
|
||||
//Private data
|
||||
private MeshRenderer areaMesh;
|
||||
private int tintColorId = 0;
|
||||
private Color visibleTintColor = Color.clear;
|
||||
private Color highlightedTintColor = Color.clear;
|
||||
private Color lockedTintColor = Color.clear;
|
||||
private bool highlighted = false;
|
||||
|
||||
//-------------------------------------------------
|
||||
public void Awake()
|
||||
{
|
||||
areaMesh = GetComponent<MeshRenderer>();
|
||||
|
||||
#if UNITY_URP
|
||||
tintColorId = Shader.PropertyToID( "_BaseColor" );
|
||||
#else
|
||||
tintColorId = Shader.PropertyToID("_TintColor");
|
||||
#endif
|
||||
|
||||
CalculateBounds();
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public void Start()
|
||||
{
|
||||
visibleTintColor = Teleport.instance.areaVisibleMaterial.GetColor( tintColorId );
|
||||
highlightedTintColor = Teleport.instance.areaHighlightedMaterial.GetColor( tintColorId );
|
||||
lockedTintColor = Teleport.instance.areaLockedMaterial.GetColor( tintColorId );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public override bool ShouldActivate( Vector3 playerPosition )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public override bool ShouldMovePlayer()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public override void Highlight( bool highlight )
|
||||
{
|
||||
if ( !locked )
|
||||
{
|
||||
highlighted = highlight;
|
||||
|
||||
if ( highlight )
|
||||
{
|
||||
areaMesh.material = Teleport.instance.areaHighlightedMaterial;
|
||||
}
|
||||
else
|
||||
{
|
||||
areaMesh.material = Teleport.instance.areaVisibleMaterial;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public override void SetAlpha( float tintAlpha, float alphaPercent )
|
||||
{
|
||||
Color tintedColor = GetTintColor();
|
||||
tintedColor.a *= alphaPercent;
|
||||
areaMesh.material.SetColor( tintColorId, tintedColor );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public override void UpdateVisuals()
|
||||
{
|
||||
if ( locked )
|
||||
{
|
||||
areaMesh.material = Teleport.instance.areaLockedMaterial;
|
||||
}
|
||||
else
|
||||
{
|
||||
areaMesh.material = Teleport.instance.areaVisibleMaterial;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public void UpdateVisualsInEditor()
|
||||
{
|
||||
if (Teleport.instance == null)
|
||||
return;
|
||||
|
||||
areaMesh = GetComponent<MeshRenderer>();
|
||||
|
||||
if ( locked )
|
||||
{
|
||||
areaMesh.sharedMaterial = Teleport.instance.areaLockedMaterial;
|
||||
}
|
||||
else
|
||||
{
|
||||
areaMesh.sharedMaterial = Teleport.instance.areaVisibleMaterial;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
private bool CalculateBounds()
|
||||
{
|
||||
MeshFilter meshFilter = GetComponent<MeshFilter>();
|
||||
if ( meshFilter == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Mesh mesh = meshFilter.sharedMesh;
|
||||
if ( mesh == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
meshBounds = mesh.bounds;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
private Color GetTintColor()
|
||||
{
|
||||
if ( locked )
|
||||
{
|
||||
return lockedTintColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( highlighted )
|
||||
{
|
||||
return highlightedTintColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
return visibleTintColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
//-------------------------------------------------------------------------
|
||||
[CustomEditor( typeof( TeleportArea ) )]
|
||||
public class TeleportAreaEditor : Editor
|
||||
{
|
||||
//-------------------------------------------------
|
||||
void OnEnable()
|
||||
{
|
||||
if ( Selection.activeTransform != null )
|
||||
{
|
||||
TeleportArea teleportArea = Selection.activeTransform.GetComponent<TeleportArea>();
|
||||
if ( teleportArea != null )
|
||||
{
|
||||
teleportArea.UpdateVisualsInEditor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
|
||||
if ( Selection.activeTransform != null )
|
||||
{
|
||||
TeleportArea teleportArea = Selection.activeTransform.GetComponent<TeleportArea>();
|
||||
if ( GUI.changed && teleportArea != null )
|
||||
{
|
||||
teleportArea.UpdateVisualsInEditor();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84a4f15a3179f1d4993aded11f4d0232
|
||||
timeCreated: 1544852191
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,57 @@
|
||||
//======= Copyright (c) Valve Corporation, All rights reserved. ===============
|
||||
//
|
||||
// Purpose: Base class for all the objects that the player can teleport to
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Valve.VR.InteractionSystem
|
||||
{
|
||||
//-------------------------------------------------------------------------
|
||||
public abstract class TeleportMarkerBase : MonoBehaviour
|
||||
{
|
||||
public bool locked = false;
|
||||
public bool markerActive = true;
|
||||
|
||||
//-------------------------------------------------
|
||||
public virtual bool showReticle
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public void SetLocked( bool locked )
|
||||
{
|
||||
this.locked = locked;
|
||||
|
||||
UpdateVisuals();
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public virtual void TeleportPlayer( Vector3 pointedAtPosition )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public abstract void UpdateVisuals();
|
||||
|
||||
//-------------------------------------------------
|
||||
public abstract void Highlight( bool highlight );
|
||||
|
||||
//-------------------------------------------------
|
||||
public abstract void SetAlpha( float tintAlpha, float alphaPercent );
|
||||
|
||||
//-------------------------------------------------
|
||||
public abstract bool ShouldActivate( Vector3 playerPosition );
|
||||
|
||||
//-------------------------------------------------
|
||||
public abstract bool ShouldMovePlayer();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6bc348d47e14444f9ca466d8cf06d46
|
||||
timeCreated: 1544852191
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,369 @@
|
||||
//======= Copyright (c) Valve Corporation, All rights reserved. ===============
|
||||
//
|
||||
// Purpose: Single location that the player can teleport to
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#if UNITY_UGUI_UI || !UNITY_2019_2_OR_NEWER
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace Valve.VR.InteractionSystem
|
||||
{
|
||||
//-------------------------------------------------------------------------
|
||||
public class TeleportPoint : TeleportMarkerBase
|
||||
{
|
||||
public enum TeleportPointType
|
||||
{
|
||||
MoveToLocation,
|
||||
SwitchToNewScene
|
||||
};
|
||||
|
||||
//Public variables
|
||||
public TeleportPointType teleportType = TeleportPointType.MoveToLocation;
|
||||
public string title;
|
||||
public string switchToScene;
|
||||
public Color titleVisibleColor;
|
||||
public Color titleHighlightedColor;
|
||||
public Color titleLockedColor;
|
||||
public bool playerSpawnPoint = false;
|
||||
|
||||
//Private data
|
||||
private bool gotReleventComponents = false;
|
||||
private MeshRenderer markerMesh;
|
||||
private MeshRenderer switchSceneIcon;
|
||||
private MeshRenderer moveLocationIcon;
|
||||
private MeshRenderer lockedIcon;
|
||||
private MeshRenderer pointIcon;
|
||||
private Transform lookAtJointTransform;
|
||||
private new Animation animation;
|
||||
private Text titleText;
|
||||
private Player player;
|
||||
private Vector3 lookAtPosition = Vector3.zero;
|
||||
private int tintColorID = 0;
|
||||
private Color tintColor = Color.clear;
|
||||
private Color titleColor = Color.clear;
|
||||
private float fullTitleAlpha = 0.0f;
|
||||
|
||||
//Constants
|
||||
private const string switchSceneAnimation = "switch_scenes_idle";
|
||||
private const string moveLocationAnimation = "move_location_idle";
|
||||
private const string lockedAnimation = "locked_idle";
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public override bool showReticle
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
void Awake()
|
||||
{
|
||||
GetRelevantComponents();
|
||||
|
||||
animation = GetComponent<Animation>();
|
||||
|
||||
#if UNITY_URP
|
||||
tintColorID = Shader.PropertyToID( "_BaseColor" );
|
||||
#else
|
||||
tintColorID = Shader.PropertyToID("_TintColor");
|
||||
#endif
|
||||
|
||||
moveLocationIcon.gameObject.SetActive( false );
|
||||
switchSceneIcon.gameObject.SetActive( false );
|
||||
lockedIcon.gameObject.SetActive( false );
|
||||
|
||||
UpdateVisuals();
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
void Start()
|
||||
{
|
||||
player = Player.instance;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
void Update()
|
||||
{
|
||||
if ( Application.isPlaying )
|
||||
{
|
||||
lookAtPosition.x = player.hmdTransform.position.x;
|
||||
lookAtPosition.y = lookAtJointTransform.position.y;
|
||||
lookAtPosition.z = player.hmdTransform.position.z;
|
||||
|
||||
lookAtJointTransform.LookAt( lookAtPosition );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public override bool ShouldActivate( Vector3 playerPosition )
|
||||
{
|
||||
return ( Vector3.Distance( transform.position, playerPosition ) > 1.0f );
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public override bool ShouldMovePlayer()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public override void Highlight( bool highlight )
|
||||
{
|
||||
if ( !locked )
|
||||
{
|
||||
if ( highlight )
|
||||
{
|
||||
SetMeshMaterials( Teleport.instance.pointHighlightedMaterial, titleHighlightedColor );
|
||||
}
|
||||
else
|
||||
{
|
||||
SetMeshMaterials( Teleport.instance.pointVisibleMaterial, titleVisibleColor );
|
||||
}
|
||||
}
|
||||
|
||||
if ( highlight )
|
||||
{
|
||||
pointIcon.gameObject.SetActive( true );
|
||||
animation.Play();
|
||||
}
|
||||
else
|
||||
{
|
||||
pointIcon.gameObject.SetActive( false );
|
||||
animation.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public override void UpdateVisuals()
|
||||
{
|
||||
if ( !gotReleventComponents )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( locked )
|
||||
{
|
||||
SetMeshMaterials( Teleport.instance.pointLockedMaterial, titleLockedColor );
|
||||
|
||||
pointIcon = lockedIcon;
|
||||
|
||||
animation.clip = animation.GetClip( lockedAnimation );
|
||||
}
|
||||
else
|
||||
{
|
||||
SetMeshMaterials( Teleport.instance.pointVisibleMaterial, titleVisibleColor );
|
||||
|
||||
switch ( teleportType )
|
||||
{
|
||||
case TeleportPointType.MoveToLocation:
|
||||
{
|
||||
pointIcon = moveLocationIcon;
|
||||
|
||||
animation.clip = animation.GetClip( moveLocationAnimation );
|
||||
}
|
||||
break;
|
||||
case TeleportPointType.SwitchToNewScene:
|
||||
{
|
||||
pointIcon = switchSceneIcon;
|
||||
|
||||
animation.clip = animation.GetClip( switchSceneAnimation );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
titleText.text = title;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public override void SetAlpha( float tintAlpha, float alphaPercent )
|
||||
{
|
||||
tintColor = markerMesh.material.GetColor( tintColorID );
|
||||
tintColor.a = tintAlpha;
|
||||
|
||||
markerMesh.material.SetColor( tintColorID, tintColor );
|
||||
switchSceneIcon.material.SetColor( tintColorID, tintColor );
|
||||
moveLocationIcon.material.SetColor( tintColorID, tintColor );
|
||||
lockedIcon.material.SetColor( tintColorID, tintColor );
|
||||
|
||||
titleColor.a = fullTitleAlpha * alphaPercent;
|
||||
titleText.color = titleColor;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public void SetMeshMaterials( Material material, Color textColor )
|
||||
{
|
||||
markerMesh.material = material;
|
||||
switchSceneIcon.material = material;
|
||||
moveLocationIcon.material = material;
|
||||
lockedIcon.material = material;
|
||||
|
||||
titleColor = textColor;
|
||||
fullTitleAlpha = textColor.a;
|
||||
titleText.color = titleColor;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public void TeleportToScene()
|
||||
{
|
||||
if ( !string.IsNullOrEmpty( switchToScene ) )
|
||||
{
|
||||
Debug.Log("<b>[SteamVR Interaction]</b> TeleportPoint: Hook up your level loading logic to switch to new scene: " + switchToScene, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("<b>[SteamVR Interaction]</b> TeleportPoint: Invalid scene name to switch to: " + switchToScene, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public void GetRelevantComponents()
|
||||
{
|
||||
markerMesh = transform.Find( "teleport_marker_mesh" ).GetComponent<MeshRenderer>();
|
||||
switchSceneIcon = transform.Find( "teleport_marker_lookat_joint/teleport_marker_icons/switch_scenes_icon" ).GetComponent<MeshRenderer>();
|
||||
moveLocationIcon = transform.Find( "teleport_marker_lookat_joint/teleport_marker_icons/move_location_icon" ).GetComponent<MeshRenderer>();
|
||||
lockedIcon = transform.Find( "teleport_marker_lookat_joint/teleport_marker_icons/locked_icon" ).GetComponent<MeshRenderer>();
|
||||
lookAtJointTransform = transform.Find( "teleport_marker_lookat_joint" );
|
||||
|
||||
titleText = transform.Find( "teleport_marker_lookat_joint/teleport_marker_canvas/teleport_marker_canvas_text" ).GetComponent<Text>();
|
||||
|
||||
gotReleventComponents = true;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public void ReleaseRelevantComponents()
|
||||
{
|
||||
markerMesh = null;
|
||||
switchSceneIcon = null;
|
||||
moveLocationIcon = null;
|
||||
lockedIcon = null;
|
||||
lookAtJointTransform = null;
|
||||
titleText = null;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public void UpdateVisualsInEditor()
|
||||
{
|
||||
if ( Application.isPlaying )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GetRelevantComponents();
|
||||
|
||||
if ( locked )
|
||||
{
|
||||
lockedIcon.gameObject.SetActive( true );
|
||||
moveLocationIcon.gameObject.SetActive( false );
|
||||
switchSceneIcon.gameObject.SetActive( false );
|
||||
|
||||
markerMesh.sharedMaterial = Teleport.instance.pointLockedMaterial;
|
||||
lockedIcon.sharedMaterial = Teleport.instance.pointLockedMaterial;
|
||||
|
||||
titleText.color = titleLockedColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
lockedIcon.gameObject.SetActive( false );
|
||||
|
||||
markerMesh.sharedMaterial = Teleport.instance.pointVisibleMaterial;
|
||||
switchSceneIcon.sharedMaterial = Teleport.instance.pointVisibleMaterial;
|
||||
moveLocationIcon.sharedMaterial = Teleport.instance.pointVisibleMaterial;
|
||||
|
||||
titleText.color = titleVisibleColor;
|
||||
|
||||
switch ( teleportType )
|
||||
{
|
||||
case TeleportPointType.MoveToLocation:
|
||||
{
|
||||
moveLocationIcon.gameObject.SetActive( true );
|
||||
switchSceneIcon.gameObject.SetActive( false );
|
||||
}
|
||||
break;
|
||||
case TeleportPointType.SwitchToNewScene:
|
||||
{
|
||||
moveLocationIcon.gameObject.SetActive( false );
|
||||
switchSceneIcon.gameObject.SetActive( true );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
titleText.text = title;
|
||||
|
||||
ReleaseRelevantComponents();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
//-------------------------------------------------------------------------
|
||||
[CustomEditor( typeof( TeleportPoint ) )]
|
||||
public class TeleportPointEditor : Editor
|
||||
{
|
||||
//-------------------------------------------------
|
||||
void OnEnable()
|
||||
{
|
||||
if ( Selection.activeTransform )
|
||||
{
|
||||
TeleportPoint teleportPoint = Selection.activeTransform.GetComponent<TeleportPoint>();
|
||||
if (teleportPoint != null)
|
||||
teleportPoint.UpdateVisualsInEditor();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
|
||||
if ( Selection.activeTransform )
|
||||
{
|
||||
TeleportPoint teleportPoint = Selection.activeTransform.GetComponent<TeleportPoint>();
|
||||
if ( GUI.changed )
|
||||
{
|
||||
teleportPoint.UpdateVisualsInEditor();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
using UnityEngine;
|
||||
namespace Valve.VR.InteractionSystem { public class TeleportPoint : TeleportMarkerBase {
|
||||
public override void Highlight(bool highlight) { }
|
||||
public override void SetAlpha(float tintAlpha, float alphaPercent) { }
|
||||
public override bool ShouldActivate(Vector3 playerPosition) { return false; }
|
||||
public override bool ShouldMovePlayer() { return false; }
|
||||
public override void TeleportPlayer(Vector3 pointedAtPosition) { }
|
||||
public override void UpdateVisuals() { }
|
||||
public bool playerSpawnPoint = false;
|
||||
public enum TeleportPointType { MoveToLocation, SwitchToNewScene };
|
||||
public TeleportPointType teleportType = TeleportPointType.MoveToLocation;
|
||||
public void TeleportToScene() { }
|
||||
} }
|
||||
#endif
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0135c95e70592e4fac2f29e7b78abcf
|
||||
timeCreated: 1446611516
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: b93fe5c516cf6ed4b9153ec790f856e2, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,77 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace Valve.VR.InteractionSystem
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
public class TeleportURPHelper : MonoBehaviour
|
||||
{
|
||||
#if UNITY_URP && UNITY_EDITOR
|
||||
void Start()
|
||||
{
|
||||
if (UnityEditor.PrefabUtility.IsPartOfPrefabInstance(this) == false)
|
||||
return;
|
||||
|
||||
string teleportAssetPath = UnityEditor.PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(this);
|
||||
GameObject teleportPrefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(teleportAssetPath);
|
||||
|
||||
Teleport teleport = teleportPrefab.GetComponent<Teleport>();
|
||||
UnityEditor.SerializedObject serializedTeleport = new UnityEditor.SerializedObject(teleport);
|
||||
serializedTeleport.Update();
|
||||
bool changed = false;
|
||||
|
||||
changed |= FindURPVersion(serializedTeleport, "areaHighlightedMaterial");
|
||||
|
||||
changed |= FindURPVersion(serializedTeleport, "areaLockedMaterial");
|
||||
|
||||
changed |= FindURPVersion(serializedTeleport, "areaVisibleMaterial");
|
||||
|
||||
changed |= FindURPVersion(serializedTeleport, "pointHighlightedMaterial");
|
||||
|
||||
changed |= FindURPVersion(serializedTeleport, "pointLockedMaterial");
|
||||
|
||||
changed |= FindURPVersion(serializedTeleport, "pointVisibleMaterial");
|
||||
|
||||
if (changed)
|
||||
{
|
||||
serializedTeleport.ApplyModifiedProperties();
|
||||
UnityEditor.EditorUtility.SetDirty(teleport);
|
||||
}
|
||||
|
||||
TeleportArc arc = teleportPrefab.GetComponent<TeleportArc>();
|
||||
UnityEditor.SerializedObject serializedArc = new UnityEditor.SerializedObject(arc);
|
||||
serializedArc.Update();
|
||||
|
||||
changed = FindURPVersion(serializedArc, "material");
|
||||
|
||||
if (changed)
|
||||
{
|
||||
serializedArc.ApplyModifiedProperties();
|
||||
UnityEditor.EditorUtility.SetDirty(arc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private bool FindURPVersion(UnityEditor.SerializedObject teleportObject, string propertyName)
|
||||
{
|
||||
UnityEditor.SerializedProperty materialProp = teleportObject.FindProperty(propertyName);
|
||||
Material original = materialProp.objectReferenceValue as Material;
|
||||
if (original != null && !original.name.StartsWith("URP"))
|
||||
{
|
||||
string[] mats = UnityEditor.AssetDatabase.FindAssets(string.Format("URP{0} t:material", original.name));
|
||||
if (mats.Length > 0)
|
||||
{
|
||||
string path = UnityEditor.AssetDatabase.GUIDToAssetPath(mats[0]);
|
||||
materialProp.objectReferenceValue = UnityEditor.AssetDatabase.LoadAssetAtPath<Material>(path);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eedfa54ef02254a428194e8de8e14d75
|
||||
timeCreated: 1591419079
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user