third person teleporting, grab interactables
This commit is contained in:
8
Assets/Project Files/Scripts/Helar.meta
Normal file
8
Assets/Project Files/Scripts/Helar.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f47f5c8565c6fef429ae4663cac97ca7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
39
Assets/Project Files/Scripts/Helar/Inventory.cs
Normal file
39
Assets/Project Files/Scripts/Helar/Inventory.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
|
||||
[Serializable]
|
||||
[RequireComponent(typeof(XRSocketInteractor))]
|
||||
public class Inventory : MonoBehaviour
|
||||
{
|
||||
public int slots = 1;
|
||||
private List<int> _inv;
|
||||
private XRSocketInteractor xrSocketInteractor;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
xrSocketInteractor = GetComponent<XRSocketInteractor>();
|
||||
_inv = new List<int>(slots);
|
||||
var oldestInteractableSelected = xrSocketInteractor.GetOldestInteractableSelected();
|
||||
|
||||
|
||||
xrSocketInteractor.selectEntered.AddListener(Call);
|
||||
|
||||
xrSocketInteractor.hoverEntered.AddListener(Call);
|
||||
}
|
||||
|
||||
private void Call(HoverEnterEventArgs arg0)
|
||||
{
|
||||
Debug.Log("hoverenter "+arg0.interactableObject + " " + xrSocketInteractor.hasHover + " " + xrSocketInteractor.hasSelection);
|
||||
|
||||
}
|
||||
|
||||
private void Call(SelectEnterEventArgs arg0)
|
||||
{
|
||||
Debug.Log("selectenter "+arg0.interactableObject);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
11
Assets/Project Files/Scripts/Helar/Inventory.cs.meta
Normal file
11
Assets/Project Files/Scripts/Helar/Inventory.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aca2b5bf18c279c4cb265c82010714b1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Assets/Project Files/Scripts/Helar/InventoryItem.cs
Normal file
18
Assets/Project Files/Scripts/Helar/InventoryItem.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class InventoryItem : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Project Files/Scripts/Helar/InventoryItem.cs.meta
Normal file
11
Assets/Project Files/Scripts/Helar/InventoryItem.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6bef3249ab68fd4184bea62f15c461f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Assets/Project Files/Scripts/Helar/ItemSpawner.cs
Normal file
14
Assets/Project Files/Scripts/Helar/ItemSpawner.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ItemSpawner : MonoBehaviour
|
||||
{
|
||||
|
||||
public GameObject objectToSpawn;
|
||||
public GameObject placeToSpawn;
|
||||
public void SpawnItem()
|
||||
{
|
||||
Instantiate(objectToSpawn, placeToSpawn.transform);
|
||||
}
|
||||
}
|
||||
11
Assets/Project Files/Scripts/Helar/ItemSpawner.cs.meta
Normal file
11
Assets/Project Files/Scripts/Helar/ItemSpawner.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f6cdca93f497ad41a707a61416fa3e3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.XR.CoreUtils;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
|
||||
[RequireComponent(
|
||||
typeof(ActionBasedContinuousMoveProvider),
|
||||
typeof(ActionBasedContinuousTurnProvider),
|
||||
typeof(ActionBasedSnapTurnProvider))]
|
||||
public class ThirdPersonTeleportController : MonoBehaviour
|
||||
{
|
||||
|
||||
public XROrigin xrOrigin;
|
||||
|
||||
private ActionBasedContinuousMoveProvider _continuousMoveProvider;
|
||||
private ActionBasedContinuousTurnProvider _continuousTurnProvider;
|
||||
private ActionBasedSnapTurnProvider _snapTurnProvider;
|
||||
|
||||
public GameObject cameraContainer;
|
||||
public bool switchToContinuous;
|
||||
|
||||
private bool _lastControllerMoveStatus;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_continuousMoveProvider = GetComponent<ActionBasedContinuousMoveProvider>();
|
||||
_continuousTurnProvider = GetComponent<ActionBasedContinuousTurnProvider>();
|
||||
_snapTurnProvider = GetComponent<ActionBasedSnapTurnProvider>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
if (StartedMoving())
|
||||
{
|
||||
Debug.Log("Started Moving");
|
||||
|
||||
cameraContainer.transform.parent = null;
|
||||
cameraContainer.transform.position = xrOrigin.transform.position;
|
||||
//Switch to continuous turn while remote controlling.
|
||||
if (switchToContinuous)
|
||||
{
|
||||
_continuousTurnProvider.enabled = true;
|
||||
_snapTurnProvider.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (StoppedMoving())
|
||||
{
|
||||
Debug.Log("Stopped Moving");
|
||||
|
||||
cameraContainer.transform.SetParent(xrOrigin.transform);
|
||||
var originTransform = xrOrigin.transform;
|
||||
cameraContainer.transform.position = originTransform.position;
|
||||
cameraContainer.transform.rotation = originTransform.rotation;
|
||||
|
||||
if (switchToContinuous)
|
||||
{
|
||||
_continuousTurnProvider.enabled = false;
|
||||
_snapTurnProvider.enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool StartedMoving()
|
||||
{
|
||||
var controllerStatus = GetControllerStatus();
|
||||
|
||||
if (controllerStatus && _lastControllerMoveStatus == false)
|
||||
{
|
||||
_lastControllerMoveStatus = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool StoppedMoving()
|
||||
{
|
||||
var controllerStatus = GetControllerStatus();
|
||||
if (_lastControllerMoveStatus && controllerStatus == false)
|
||||
{
|
||||
_lastControllerMoveStatus = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
_lastControllerMoveStatus = controllerStatus;
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool GetControllerStatus()
|
||||
{
|
||||
return _continuousMoveProvider.leftHandMoveAction.action.inProgress ||
|
||||
_continuousMoveProvider.rightHandMoveAction.action.inProgress;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7dc7145c2abdff444bdd4013a6f92c6c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user