Rough warehouse browsing by grabbing warehouse items with trigger
This commit is contained in:
@@ -5,7 +5,25 @@ public class RightController : MonoBehaviour {
|
|||||||
public GameObject banana;
|
public GameObject banana;
|
||||||
public GameObject viveController;
|
public GameObject viveController;
|
||||||
|
|
||||||
// Use this for initialization
|
SteamVR_TrackedController trackedController;
|
||||||
|
WarehouseColumn warehouse;
|
||||||
|
|
||||||
|
WarehouseRow whRow = null;
|
||||||
|
Vector3? whScrollStartPos = null;
|
||||||
|
float whScrollDistance;
|
||||||
|
float whBaseOffset = 0.0f;
|
||||||
|
float whScrollOffset = 0.0f;
|
||||||
|
float whRowBaseOffset = 0.0f;
|
||||||
|
float whRowScrollOffset = 0.0f;
|
||||||
|
|
||||||
|
void Awake() {
|
||||||
|
trackedController = GetComponent<SteamVR_TrackedController>();
|
||||||
|
trackedController.TriggerClicked += triggerClicked;
|
||||||
|
trackedController.TriggerUnclicked += triggerUnclicked;
|
||||||
|
|
||||||
|
warehouse = GameObject.Find("Warehouse/Shelves/Column").GetComponent<WarehouseColumn>();
|
||||||
|
}
|
||||||
|
|
||||||
void Start () {
|
void Start () {
|
||||||
GetComponent<ViewFrustrumTrigger>().LeaveView += toggleBanana;
|
GetComponent<ViewFrustrumTrigger>().LeaveView += toggleBanana;
|
||||||
}
|
}
|
||||||
@@ -15,7 +33,51 @@ public class RightController : MonoBehaviour {
|
|||||||
viveController.SetActive(!viveController.activeSelf);
|
viveController.SetActive(!viveController.activeSelf);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
|
||||||
void Update () {
|
void Update () {
|
||||||
|
|
||||||
|
// Warehouse scroll
|
||||||
|
if (whScrollStartPos != null) {
|
||||||
|
Vector3 curPos = transform.position + (transform.forward * whScrollDistance);
|
||||||
|
|
||||||
|
whScrollOffset = (curPos - whScrollStartPos).Value.y;
|
||||||
|
whRowScrollOffset = (curPos - whScrollStartPos).Value.x;
|
||||||
|
|
||||||
|
warehouse.Offset = whBaseOffset + (-whScrollOffset);
|
||||||
|
whRow.Offset = whRowBaseOffset + whRowScrollOffset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RaycastHit raycast() {
|
||||||
|
var ray = new Ray(transform.position, transform.forward);
|
||||||
|
RaycastHit hit;
|
||||||
|
bool bHit = Physics.Raycast(ray, out hit);
|
||||||
|
return hit;
|
||||||
|
}
|
||||||
|
|
||||||
|
void triggerClicked(object sender, ClickedEventArgs e) {
|
||||||
|
var ray = new Ray(transform.position, transform.forward);
|
||||||
|
RaycastHit result;
|
||||||
|
bool hit = Physics.Raycast(ray, out result);
|
||||||
|
|
||||||
|
if (!hit) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var item = result.transform.GetComponent<WarehouseItem>();
|
||||||
|
if (!item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
whScrollStartPos = result.point;
|
||||||
|
whScrollDistance = result.distance;
|
||||||
|
whRow = item.GetComponentInParent<WarehouseRow>();
|
||||||
|
whBaseOffset = warehouse.Offset;
|
||||||
|
whRowBaseOffset = whRow.Offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
void triggerUnclicked(object sender, ClickedEventArgs e) {
|
||||||
|
if (whScrollStartPos != null) {
|
||||||
|
whScrollStartPos = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -8,7 +8,7 @@ public class WarehouseColumn : MonoBehaviour {
|
|||||||
private BezierCurve curve;
|
private BezierCurve curve;
|
||||||
private Transform rows;
|
private Transform rows;
|
||||||
|
|
||||||
private float offset = 0.0f;
|
public float Offset { get; set; }
|
||||||
|
|
||||||
void Awake() {
|
void Awake() {
|
||||||
curve = transform.Find("Curve").GetComponent<BezierCurve>();
|
curve = transform.Find("Curve").GetComponent<BezierCurve>();
|
||||||
@@ -21,12 +21,12 @@ public class WarehouseColumn : MonoBehaviour {
|
|||||||
|
|
||||||
void Update() {
|
void Update() {
|
||||||
if (Application.isPlaying) {
|
if (Application.isPlaying) {
|
||||||
offset += Time.deltaTime;
|
//offset += Time.deltaTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Transform row in rows) {
|
foreach (Transform row in rows) {
|
||||||
var i = row.GetSiblingIndex();
|
var i = row.GetSiblingIndex();
|
||||||
var distance = (float)i / (rows.childCount) * curve.length + offset;
|
var distance = (float)i / (rows.childCount) * curve.length + Offset;
|
||||||
distance = Mathf.Repeat(distance, curve.length);
|
distance = Mathf.Repeat(distance, curve.length);
|
||||||
var pos = curve.GetPointAtDistance(distance);
|
var pos = curve.GetPointAtDistance(distance);
|
||||||
row.position = pos;
|
row.position = pos;
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ using UnityEditor;
|
|||||||
public class WarehouseRow : MonoBehaviour {
|
public class WarehouseRow : MonoBehaviour {
|
||||||
public string Category;
|
public string Category;
|
||||||
|
|
||||||
|
public float Offset { get; set; }
|
||||||
|
|
||||||
BezierCurve curve;
|
BezierCurve curve;
|
||||||
Transform furniture;
|
Transform furniture;
|
||||||
|
|
||||||
float offset = 0;
|
|
||||||
|
|
||||||
void Awake() {
|
void Awake() {
|
||||||
curve = transform.Find("Curve").GetComponent<BezierCurve>();
|
curve = transform.Find("Curve").GetComponent<BezierCurve>();
|
||||||
furniture = transform.Find("Furniture");
|
furniture = transform.Find("Furniture");
|
||||||
@@ -43,7 +43,7 @@ public class WarehouseRow : MonoBehaviour {
|
|||||||
|
|
||||||
foreach (Transform t in furniture) {
|
foreach (Transform t in furniture) {
|
||||||
var i = t.GetSiblingIndex();
|
var i = t.GetSiblingIndex();
|
||||||
var distance = (float)i / (furniture.childCount) * curve.length + offset;
|
var distance = (float)i / (furniture.childCount) * curve.length + Offset;
|
||||||
distance = Mathf.Repeat(distance, curve.length);
|
distance = Mathf.Repeat(distance, curve.length);
|
||||||
var pos = curve.GetPointAtDistance(distance);
|
var pos = curve.GetPointAtDistance(distance);
|
||||||
t.position = pos;
|
t.position = pos;
|
||||||
|
|||||||
Reference in New Issue
Block a user