init assets and filemgt

This commit is contained in:
2022-03-07 18:33:30 +02:00
parent 62585ef143
commit 813cd0c451
1274 changed files with 346654 additions and 249 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 41046c77e43588040865b14561b12e82
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,136 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
using UnityEngine.XR.Interaction.Toolkit;
using PDollarGestureRecognizer;
using System.IO;
using UnityEngine.Events;
public class GestureRecognizer : MonoBehaviour
{
public XRNode rightHandSource;
public InputHelpers.Button rightInputButton;
public InputHelpers.Button rightControlButton;
public float inputThreshold = 0.1f;
public Transform movementSource;
public float newPositionThresholdDistance = 0.05f;
public GameObject debugCubePrefab;
public bool creationMode = true;
public string newGestureName;
public float recognitionThreshold = 0.8f;
[System.Serializable]
public class UnityStringEvent : UnityEvent<string> { }
public UnityStringEvent OnRecognized;
private List<Gesture> trainingSet = new List<Gesture>();
private bool isMoving = false;
private List<Vector3> positionsList = new List<Vector3>();
// Start is called before the first frame update
void Start()
{
// Path = ..\AppData\LocalLow\DefaultCompany\Heroes of Hiis SCM
Debug.Log(Application.persistentDataPath);
string[] gestureFiles = Directory.GetFiles(Application.persistentDataPath, "*.xml");
foreach (var item in gestureFiles)
{
trainingSet.Add(GestureIO.ReadGestureFromFile(item));
}
foreach (var item in trainingSet)
{
Debug.Log(item.Name);
}
}
// Update is called once per frame
void Update()
{
InputHelpers.IsPressed(InputDevices.GetDeviceAtXRNode(rightHandSource), rightInputButton, out bool isPressed, inputThreshold);
InputHelpers.IsPressed(InputDevices.GetDeviceAtXRNode(rightHandSource), rightControlButton, out bool isControlPressed, inputThreshold);
bool startGesture = isPressed && isControlPressed;
// Start the movement
if (!isMoving && startGesture)
{
StartMovement();
}
// Ending the movement
else if (isMoving && !startGesture)
{
EndMovement();
}
// Updating the movement
else if (isMoving && startGesture)
{
UpdateMovement();
}
}
void StartMovement()
{
Debug.Log("Movement started");
isMoving = true;
positionsList.Clear();
positionsList.Add(movementSource.position);
if (debugCubePrefab)
{
Destroy(Instantiate(debugCubePrefab, movementSource.position, Quaternion.identity), 3);
}
}
void EndMovement()
{
Debug.Log("Movement ended");
isMoving = false;
// Create gesture from position list
Point[] pointArray = new Point[positionsList.Count];
for (int i = 0; i < positionsList.Count; i++)
{
Vector2 screenPoint = Camera.main.WorldToScreenPoint(positionsList[i]);
pointArray[i] = new Point(screenPoint.x, screenPoint.y, 0);
}
Gesture newGesture = new Gesture(pointArray);
// Add gesture to training set. (only for demo)
if (creationMode)
{
newGesture.Name = newGestureName;
trainingSet.Add(newGesture);
string fileName = Application.persistentDataPath + "/" + newGestureName + ".xml";
GestureIO.WriteGesture(pointArray, newGestureName, fileName);
}
// Recognize
else
{
Result result = PointCloudRecognizer.Classify(newGesture, trainingSet.ToArray());
if (result.Score > recognitionThreshold)
{
OnRecognized.Invoke(result.GestureClass);
}
}
}
void UpdateMovement()
{
Vector3 lastPosition = positionsList[positionsList.Count - 1];
if (Vector3.Distance(movementSource.position, lastPosition) > newPositionThresholdDistance)
{
positionsList.Add(movementSource.position);
if (debugCubePrefab)
{
Destroy(Instantiate(debugCubePrefab, movementSource.position, Quaternion.identity), 3);
}
}
}
}

View File

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

View File

@@ -0,0 +1,251 @@
using System;
using System.Collections;
using UnityEngine;
public class PlayerMotion : MonoBehaviour
{
[SerializeField] private GameObject OVRPlayerControllerGameObject = null;
[SerializeField] private Transform LeftHandAnchorTransform = null;
[SerializeField] private Transform RightHandAnchorTransform = null;
private OVRPlayerController OVRPlayerControllerComponent;
// identical to fields of OVRPlayerController class
private CharacterController Controller;
private Vector3 MoveThrottle = Vector3.zero;
private float MoveScale = 1.0f;
private float MoveScaleMultiplier = 1.0f;
private float SimulationRate = 60f;
private float FallSpeed = 0.0f;
private float Acceleration;
private float Damping;
private float GravityModifier;
private float JumpForce;
// original fields for this script
private Vector3 touchVelocityL;
private Vector3 touchVelocityR;
private Vector3 touchAccelerationL;
private Vector3 touchAccelerationR;
private bool motionInertia = false;
private float motionInertiaDuration = 1.0f;
const float WALK_THRESHOLD = 0.8f;
const float RUN_THRESHOLD = 1.3f;
const float JUMP_THRESHOLD = 1.5f;
private void Awake()
{
Controller
= OVRPlayerControllerGameObject.GetComponent<CharacterController>();
OVRPlayerControllerComponent
= Controller.GetComponent<OVRPlayerController>();
}
private void Start()
{
// store public fields of OVRPlayerController-class to local private fileds
Acceleration = OVRPlayerControllerComponent.Acceleration;
Damping = OVRPlayerControllerComponent.Damping;
GravityModifier = OVRPlayerControllerComponent.GravityModifier;
JumpForce = OVRPlayerControllerComponent.JumpForce;
// pre-setting for overriding character-control
OVRPlayerControllerComponent.PreCharacterMove
+= () => CharacterMoveByHandShake();
OVRPlayerControllerComponent.EnableLinearMovement = false;
// necessary for initial grounded-evaluation
Controller.Move(Vector3.zero * Time.deltaTime);
}
private void Update()
{
//Debug.Log("L-touch velocity: " + touchVelocityL);
//Debug.Log("R-touch velocity: " + touchVelocityR);
}
private void CharacterMoveByHandShake()
{
HandShakeControler();
UpdateController();
// display for development purpose
//Debug.Log("L-touch velocity: " + touchVelocityL);
//Debug.Log("R-touch velocity: " + touchVelocityR);
}
private void HandShakeControler()
{
touchVelocityL
= OVRInput.GetLocalControllerVelocity(OVRInput.Controller.LTouch);
touchVelocityR
= OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTouch);
touchAccelerationL
= OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.LTouch);
touchAccelerationR
= OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.RTouch);
if (!IsGrounded()) MoveScale = 0.0f;
else MoveScale = 1.0f;
MoveScale *= SimulationRate * Time.deltaTime;
float moveInfluence
= Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;
Transform activeHand;
Vector3 handShakeVel;
Vector3 handShakeAcc;
if (Math.Abs(touchVelocityL.y) > Math.Abs(touchVelocityR.y))
{
activeHand = LeftHandAnchorTransform;
handShakeVel = touchVelocityL;
handShakeAcc = touchAccelerationL;
}
else
{
activeHand = RightHandAnchorTransform;
handShakeVel = touchVelocityR;
handShakeAcc = touchAccelerationR;
}
Quaternion ort = activeHand.rotation;
Vector3 ortEuler = ort.eulerAngles;
ortEuler.z = ortEuler.x = 0f;
ort = Quaternion.Euler(ortEuler);
MoveThrottle += CalculateMoveEffect(moveInfluence, ort, handShakeVel, handShakeAcc);
}
private Vector3 CalculateMoveEffect(float moveInfluence,
Quaternion ort, Vector3 handShakeVel, Vector3 handShakeAcc)
{
Vector3 tmpMoveThrottle = Vector3.zero;
bool isWalk = DetectHandShakeWalk(Math.Abs(handShakeVel.y)) || motionInertia;
if (isWalk)
{
if (!motionInertia)
SetMotionInertia();
tmpMoveThrottle += ort
* (OVRPlayerControllerGameObject.transform.lossyScale.z
* moveInfluence * Vector3.forward) * 0.2f;
bool isRun = DetectHandShakeRun(Math.Abs(handShakeVel.y));
if (isRun)
tmpMoveThrottle *= 2.0f;
}
bool isJump = DetectHandShakeJump();
if (isJump)
tmpMoveThrottle += new Vector3(0.0f, JumpForce, 0.0f);
return tmpMoveThrottle;
}
IEnumerator SetMotionInertia()
{
motionInertia = true;
yield return new WaitForSecondsRealtime(motionInertiaDuration);
motionInertia = false;
}
private bool DetectHandShakeWalk(float speed)
{
if (!IsGrounded()) return false;
if (speed > WALK_THRESHOLD) return true;
return false;
}
private bool DetectHandShakeRun(float speed)
{
if (!IsGrounded()) return false;
if (speed > RUN_THRESHOLD) return true;
return false;
}
private bool DetectHandShakeJump()
{
if (!IsGrounded())
return false;
if (touchVelocityL.y > JUMP_THRESHOLD && touchVelocityR.y > JUMP_THRESHOLD)
return true;
return false;
}
private bool IsGrounded()
{
if (Controller.isGrounded) return true;
var pos = OVRPlayerControllerGameObject.transform.position;
var ray = new Ray(pos + Vector3.up * 0.1f, Vector3.down);
var tolerance = 0.3f;
return Physics.Raycast(ray, tolerance);
}
private void UpdateController()
{
Vector3 moveDirection = Vector3.zero;
float motorDamp = 1.0f + (Damping * SimulationRate * Time.deltaTime);
MoveThrottle.x /= motorDamp;
MoveThrottle.y = (MoveThrottle.y > 0.0f) ?
(MoveThrottle.y / motorDamp) : MoveThrottle.y;
MoveThrottle.z /= motorDamp;
moveDirection += MoveThrottle * SimulationRate * Time.deltaTime;
// calculate gravity influence
if (Controller.isGrounded && FallSpeed <= 0)
FallSpeed = Physics.gravity.y * (GravityModifier * 0.002f);
else
FallSpeed += Physics.gravity.y
* (GravityModifier * 0.002f) * SimulationRate * Time.deltaTime;
moveDirection.y += FallSpeed * SimulationRate * Time.deltaTime;
if (Controller.isGrounded && MoveThrottle.y
<= OVRPlayerControllerGameObject.transform.lossyScale.y * 0.001f)
{
// offset correction for uneven ground
float bumpUpOffset
= Mathf.Max(
Controller.stepOffset,
new Vector3(moveDirection.x, 0, moveDirection.z).magnitude);
moveDirection -= bumpUpOffset * Vector3.up;
}
Vector3 predictedXZ
= Vector3.Scale(
Controller.transform.localPosition + moveDirection,
new Vector3(1, 0, 1));
// update character position
Controller.Move(moveDirection);
Vector3 actualXZ
= Vector3.Scale(
Controller.transform.localPosition,
new Vector3(1, 0, 1));
if (predictedXZ != actualXZ)
MoveThrottle += (actualXZ - predictedXZ)
/ (SimulationRate * Time.deltaTime);
}
}

View File

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

View File

@@ -0,0 +1,23 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnerGestureInteraction : MonoBehaviour
{
public List<GameObject> objects;
public Transform rightHandTransform;
public void SpawnObject(string objectName)
{
Debug.Log(objectName);
foreach (var item in objects)
{
if (item.name == objectName)
{
Instantiate(item, rightHandTransform.position, Quaternion.identity);
}
}
}
}

View File

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

View File

@@ -0,0 +1,71 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.XR.Interaction.Toolkit;
public class TeleportationManager : MonoBehaviour
{
[SerializeField] private InputActionAsset actionAsset;
[SerializeField] private XRRayInteractor rayInteractor;
[SerializeField] private TeleportationProvider provider;
private InputAction _xButton;
private bool _isActive;
void Start()
{
rayInteractor.enabled = false;
var activate = actionAsset.FindActionMap("XRI LeftHand").FindAction("Teleport Mode Activate");
activate.Enable();
activate.performed += OnTeleportActivate;
var cancel = actionAsset.FindActionMap("XRI LeftHand").FindAction("Teleport Mode Cancel");
cancel.Enable();
cancel.performed += OnTeleportCancel;
_xButton = actionAsset.FindActionMap("XRI LeftHand").FindAction("Teleport Move Enable");
_xButton.Enable();
}
void Update()
{
if (!_isActive)
{
return;
}
if (_xButton.IsPressed())
{
return;
}
if (rayInteractor.TryGetCurrent3DRaycastHit(out RaycastHit hitt))
{
rayInteractor.enabled = false;
_isActive = false;
return;
}
TeleportRequest request = new TeleportRequest()
{
destinationPosition = hitt.point
};
provider.QueueTeleportRequest(request);
rayInteractor.enabled = false;
_isActive = false;
}
private void OnTeleportActivate(InputAction.CallbackContext context)
{
rayInteractor.enabled = true;
_isActive = true;
}
private void OnTeleportCancel(InputAction.CallbackContext context)
{
rayInteractor.enabled = false;
_isActive = false;
}
}

View File

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