Miniature grabbing
This commit is contained in:
Binary file not shown.
@@ -2,16 +2,12 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|
||||||
public class FurnitureMiniature : MonoBehaviour {
|
public class FurnitureMiniature : MonoBehaviour {
|
||||||
public void Grab(Transform attachment) {
|
public void Grab() {
|
||||||
transform.parent = null;
|
transform.parent = null;
|
||||||
foreach (var collider in GetComponentsInChildren<Collider>()) {
|
foreach (var collider in GetComponentsInChildren<Collider>()) {
|
||||||
collider.enabled = false;
|
collider.enabled = false;
|
||||||
}
|
}
|
||||||
GetComponent<Rigidbody>().isKinematic = true;
|
GetComponent<Rigidbody>().isKinematic = true;
|
||||||
|
|
||||||
var mini = gameObject.AddComponent<WarehouseMiniatureAnim>();
|
|
||||||
mini.DestinationAttachment = attachment;
|
|
||||||
mini.Duration = 0.33f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Release() {
|
public void Release() {
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
public class RightController : MonoBehaviour {
|
public class RightController : MonoBehaviour {
|
||||||
public Transform MiniatureAttachmentPoint;
|
public Transform MiniatureAttachmentPoint;
|
||||||
|
|
||||||
SteamVR_LaserPointer laserPointer;
|
SteamVR_LaserPointer laserPointer;
|
||||||
SteamVR_ControllerEvents controllerEvents;
|
SteamVR_ControllerEvents controllerEvents;
|
||||||
|
BoxCollider boxCollider;
|
||||||
WarehouseColumn warehouse;
|
WarehouseColumn warehouse;
|
||||||
|
|
||||||
|
HashSet<GameObject> touchingItems = new HashSet<GameObject>();
|
||||||
GameObject heldItem;
|
GameObject heldItem;
|
||||||
|
|
||||||
WarehouseRow whRow = null;
|
WarehouseRow whRow = null;
|
||||||
@@ -48,11 +51,17 @@ public class RightController : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RaycastHit raycast() {
|
void OnTriggerEnter(Collider other) {
|
||||||
var ray = new Ray(transform.position, transform.forward);
|
var mini = other.GetComponentInParent<FurnitureMiniature>();
|
||||||
RaycastHit hit;
|
if (mini == null) {
|
||||||
bool bHit = Physics.Raycast(ray, out hit);
|
return;
|
||||||
return hit;
|
}
|
||||||
|
|
||||||
|
touchingItems.Add(other.gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnTriggerExit(Collider other) {
|
||||||
|
touchingItems.Remove(other.gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Furniture picking
|
// Furniture picking
|
||||||
@@ -82,7 +91,28 @@ public class RightController : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool grabByProximity() {
|
bool grabByProximity() {
|
||||||
return false;
|
GameObject closest = null;
|
||||||
|
foreach (var obj in touchingItems) {
|
||||||
|
if (closest == null) {
|
||||||
|
closest = obj;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((obj.transform.position - boxCollider.bounds.center).magnitude < (closest.transform.position - boxCollider.bounds.center).magnitude) {
|
||||||
|
closest = obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (closest == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var mini = closest.GetComponentInParent<FurnitureMiniature>();
|
||||||
|
mini.Grab();
|
||||||
|
mini.transform.parent = transform;
|
||||||
|
heldItem = mini.gameObject;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool grabByLaser() {
|
bool grabByLaser() {
|
||||||
@@ -98,18 +128,29 @@ public class RightController : MonoBehaviour {
|
|||||||
var warehouseItem = result.rigidbody.GetComponent<WarehouseItem>();
|
var warehouseItem = result.rigidbody.GetComponent<WarehouseItem>();
|
||||||
if (warehouseItem) {
|
if (warehouseItem) {
|
||||||
var mini = warehouseItem.Pick();
|
var mini = warehouseItem.Pick();
|
||||||
mini.Grab(MiniatureAttachmentPoint);
|
mini.Grab();
|
||||||
var anim = mini.GetComponent<WarehouseMiniatureAnim>();
|
|
||||||
|
var anim = mini.gameObject.AddComponent<WarehouseMiniatureAnim>();
|
||||||
anim.OriginItem = warehouseItem;
|
anim.OriginItem = warehouseItem;
|
||||||
|
anim.DestinationAttachment = MiniatureAttachmentPoint;
|
||||||
anim.GoalScale = new Vector3(0.05f, 0.05f, 0.05f);
|
anim.GoalScale = new Vector3(0.05f, 0.05f, 0.05f);
|
||||||
|
anim.Duration = 0.33f;
|
||||||
|
|
||||||
heldItem = mini.gameObject;
|
heldItem = mini.gameObject;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warehouse miniature grabbing remotely
|
// Warehouse miniature grabbing remotely
|
||||||
var furnitureMini = result.rigidbody.GetComponent<FurnitureMiniature>();
|
var furnitureMini = result.rigidbody.GetComponent<FurnitureMiniature>();
|
||||||
if (furnitureMini) {
|
if (furnitureMini) {
|
||||||
furnitureMini.Grab(MiniatureAttachmentPoint);
|
furnitureMini.Grab();
|
||||||
|
|
||||||
|
var anim = furnitureMini.gameObject.AddComponent<WarehouseMiniatureAnim>();
|
||||||
|
//anim.OriginItem = furnitureMini;
|
||||||
|
anim.DestinationAttachment = MiniatureAttachmentPoint;
|
||||||
|
anim.Duration = 0.33f;
|
||||||
|
|
||||||
heldItem = furnitureMini.gameObject;
|
heldItem = furnitureMini.gameObject;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user