164 lines
No EOL
4.5 KiB
C#
164 lines
No EOL
4.5 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.XR;
|
|
|
|
[Serializable]
|
|
public class Rig
|
|
{
|
|
[HideInInspector]
|
|
public World world;
|
|
|
|
[Header("Design")]
|
|
public float scale;
|
|
public Vector3 headOffset, pivotPos;
|
|
|
|
public void Set(InspectorSetter setter)
|
|
{
|
|
setter.Set("Rig.scale", scale);
|
|
setter.Set("Rig.headOffset", headOffset);
|
|
setter.Set("Rig.pivotPos", pivotPos);
|
|
}
|
|
|
|
public void Fetch(InspectorSetter setter)
|
|
{
|
|
headOffset = setter.Fetch("Rig.scale", scale);
|
|
headOffset = setter.Fetch("Rig.headOffset", headOffset);
|
|
pivotPos = setter.Fetch("Rig.pivotPos", pivotPos);
|
|
}
|
|
|
|
[Header("References")]
|
|
public GameObject disconnected;
|
|
public Transform rig, head, con, lCon, hangingRod;
|
|
public Camera recordCam;
|
|
|
|
[Header("Variables")]
|
|
public OVRInput.Controller ovrCon;
|
|
|
|
[HideInInspector]
|
|
public Quaternion controllerRot = Quaternion.identity;
|
|
[HideInInspector]
|
|
public Quaternion inputRot = Quaternion.identity;
|
|
[HideInInspector]
|
|
public Vector3 controllerPos;
|
|
|
|
public Vector3 boxShake, boxOffset;
|
|
|
|
public bool alignRecordCam;
|
|
|
|
public void Start(World world)
|
|
{
|
|
this.world = world;
|
|
|
|
|
|
Game.OnBump += Bump; // replace these systems...
|
|
Game.OnCrash += Bump;
|
|
|
|
recordCam.gameObject.SetActive(Application.isEditor);
|
|
}
|
|
|
|
Quaternion flipRot = Quaternion.identity;
|
|
float flipEuler = 180;
|
|
public Lerper lerper;
|
|
public void Update()
|
|
{
|
|
// Apply to Transforms
|
|
Quaternion flip = Quaternion.identity;
|
|
head.localPosition = InputTracking.GetLocalPosition(XRNode.Head);
|
|
head.localRotation = InputTracking.GetLocalRotation(XRNode.Head);
|
|
con.localPosition = InputTracking.GetLocalPosition(XRNode.RightHand);
|
|
con.localRotation = InputTracking.GetLocalRotation(XRNode.RightHand);
|
|
lCon.localPosition = InputTracking.GetLocalPosition(XRNode.LeftHand);
|
|
lCon.localRotation = InputTracking.GetLocalRotation(XRNode.LeftHand);
|
|
|
|
// °inview
|
|
if (OVRInput.GetDown(OVRInput.Button.PrimaryHandTrigger, ovrCon))
|
|
{
|
|
flipEuler *= -1;
|
|
lerper.t *= -1;
|
|
}
|
|
rig.localScale = Vector3.one * scale;
|
|
Quaternion targetRot = Quaternion.Euler(0, flipEuler, 0);
|
|
if (OVRInput.Get(OVRInput.Button.PrimaryHandTrigger, ovrCon))
|
|
{
|
|
lerper.Update(1);
|
|
}
|
|
else
|
|
{
|
|
lerper.Update(0);
|
|
}
|
|
flipRot = Quaternion.SlerpUnclamped(Quaternion.identity, targetRot, lerper.t);
|
|
rig.rotation = flipRot;
|
|
rig.position = flipRot * -head.localPosition * scale;
|
|
rig.position += pivotPos + (head.rotation * headOffset);
|
|
|
|
// CONVERT TO LERPER
|
|
// Shake
|
|
boxShake = Vector3.Lerp(boxShake, (boxShake - boxOffset) * 0.5f, 13 * Time.deltaTime);
|
|
boxOffset += boxShake * 13 * Time.deltaTime;
|
|
rig.position += boxOffset;
|
|
|
|
// Hanging Rod
|
|
hangingRod.position = pivotPos;
|
|
hangingRod.rotation = head.rotation;
|
|
|
|
// Record Cam
|
|
Vector3 twoDir = new Vector3(head.position.x, 0, head.position.z).normalized;
|
|
Vector3 recPos = (Quaternion.LookRotation(twoDir) * new Vector3(0.5f, 0.25f, 0.5f).normalized * 40);
|
|
if (alignRecordCam)
|
|
{
|
|
recordCam.transform.position = recPos;
|
|
recordCam.transform.rotation = Quaternion.LookRotation(-recPos);
|
|
}
|
|
|
|
// °fullrot
|
|
// inputRot = controllerRot = OVRInput.GetLocalControllerRotation(remote);
|
|
|
|
|
|
// point & swipe swap/choose
|
|
// both hands? (nah makes point the odd one out)
|
|
// HOW TO FILTER OUT THE SPIN CHAIR VEL? (LCON? NAH... BUT MIGHT BE GOOD FOR TESTINGs)
|
|
// flip view? what about 90/45 degree snaps ( or drag view!? )
|
|
// all oculus bs pulled filtered through a single file
|
|
// menu system cull
|
|
|
|
// PRIORITY
|
|
// starting scene! the sooner the better ( break things! )
|
|
// refactor like vader life alyx!
|
|
|
|
|
|
// °dragdir
|
|
Vector3 conVel = flipRot * (con.localPosition - oldConPos) / Time.deltaTime;
|
|
OVRInput.SetControllerVibration(0, 0, OVRInput.Controller.RTouch);
|
|
if (OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger, ovrCon))
|
|
{
|
|
if (conVel.magnitude > 0.05f)
|
|
{
|
|
OVRInput.SetControllerVibration(1, 0.1f, OVRInput.Controller.RTouch);
|
|
}
|
|
|
|
rawDir = (rawDir + conVel * Time.deltaTime * 30).normalized;
|
|
}
|
|
inputRot = Quaternion.LookRotation(rawDir);
|
|
oldConPos = con.localPosition;
|
|
}
|
|
Vector3 oldConPos;
|
|
Vector3 rawDir = Vector3.forward;
|
|
|
|
public Vector3Int InputDirection(Main main)
|
|
{
|
|
Vector3Int newDir = Main.SnapDir((inputRot * Vector3.forward));
|
|
|
|
// no neck snaps
|
|
if (main.snake[0] + newDir != main.snake[1])
|
|
{
|
|
return newDir;
|
|
}
|
|
|
|
return main.dir;
|
|
}
|
|
|
|
void Bump(Vector3 dir)
|
|
{
|
|
boxShake -= dir;
|
|
}
|
|
} |