Rough warehouse browsing by grabbing warehouse items with trigger

This commit is contained in:
2016-05-24 00:41:58 +02:00
parent 79a7a0b811
commit f44d87f51d
5 changed files with 70 additions and 8 deletions
+64 -2
View File
@@ -5,7 +5,25 @@ public class RightController : MonoBehaviour {
public GameObject banana;
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 () {
GetComponent<ViewFrustrumTrigger>().LeaveView += toggleBanana;
}
@@ -15,7 +33,51 @@ public class RightController : MonoBehaviour {
viveController.SetActive(!viveController.activeSelf);
}
// Update is called once per frame
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;
}
}
}