public void CabinetStateChangedHandler(CabinetState newState) { if (newState == CabinetState.Snapped) { Debug.Log("Snapped"); } if (newState == CabinetState.Placed) { Debug.Log("Placed"); } }
public void CabinetStateChangedHandler(CabinetState newState) { if (newState == CabinetState.Snapped) { Debug.Log(string.Format("Placement Manager - Cabinet Snapped: {0}", objPlacement.gameObject.transform.position.ToString())); //objPlacement.GetComponent<CabinetManager>().cabinetState = CabinetState.Placed; } if (newState == CabinetState.Placed) { //Debug.Log("Placement Manager - Cabinet Placed"); objPlacement.transform.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; objPlacement = null; } }
void Update() { if (activeController) { if (activeController.GetComponent <VRTK_ControllerEvents>().triggerClicked&& pointer && objPlacement) { currentPosition = objPlacement.transform.position; Vector3 newPos = new Vector3(); if (state == CabinetState.Snapped && (manager.collisionLeft || manager.collisionRight)) { newPos.x = manager.snapPos.x; } else { newPos.x = pointer.pointerRenderer.GetDestinationHit().point.x; } if (state == CabinetState.Snapped && manager.collisionRear) { newPos.z = manager.snapPos.z; } else { newPos.z = pointer.pointerRenderer.GetDestinationHit().point.z; } newPos.y = objPlacement.transform.position.y; objPlacement.transform.position = newPos; } if (!activeController.GetComponent <VRTK_ControllerEvents>().triggerClicked&& objPlacement) { objPlacement.transform.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; objPlacement.GetComponent <CabinetManager>().cabinetState = CabinetState.Placed; objPlacement = null; } if (objPlacement) { state = manager.cabinetState; if (objPlacement.gameObject.GetComponent <CabinetManager>().cabinetState == CabinetState.Placed) { objPlacement.transform.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; objPlacement = null; } } } }
public void CabinetStateChangedHandler(CabinetState newState) { state = newState; if (newState == CabinetState.Snapped) { Debug.Log(string.Format("Placement Manager - Cabinet Snapped: {0}", objPlacement.gameObject.transform.position.ToString())); } if (newState == CabinetState.Placed) { Debug.Log(string.Format("XZ angle is {0}", objPlacement.transform.eulerAngles.y)); Debug.Log(string.Format("X,Z point of object origin is {0},{1}", objPlacement.transform.position.x, objPlacement.transform.position.z)); float dZ = Mathf.Sin(objPlacement.transform.eulerAngles.y * Mathf.Deg2Rad) * 0.3f; float dX = Mathf.Cos(objPlacement.transform.eulerAngles.y * Mathf.Deg2Rad) * 0.3f; float newX = objPlacement.transform.position.x + dX; float newZ = objPlacement.transform.position.z - dZ; Debug.Log(string.Format("X,Z point of object opposite end is {0},{1}", newX, newZ)); Instantiate(marker, new Vector3(newX, 0, newZ), Quaternion.identity); objPlacement = null; } }
// Start is called before the first frame update void Start() { OnCabinetStateChanged.AddListener(CabinetStateChangedHandler); cabinetState = CabinetState.Instantiated; }
private void OnCollisionEnter(Collision collision) { float dx = collision.transform.position.x - gameObject.transform.position.x; float dz = collision.transform.position.z - gameObject.transform.position.z; if (!collisionLeft && !collisionRight) //collision.gameObject.GetComponent<CabinetManager>() && { Debug.Log(string.Format("Collision object: {0}", collision.gameObject.name)); Debug.Log(string.Format("Collision object position: {0}", collision.transform.position)); Debug.Log(string.Format("Collision object collider scale: {0}", collision.gameObject.GetComponent <Collider>().bounds.size)); Debug.Log(string.Format("Object position: {0}", gameObject.transform.position)); Debug.Log(string.Format("Object collider scale: {0}", gameObject.GetComponent <Collider>().bounds.size)); Debug.Log(string.Format("Collision dX: {0}", dx)); Debug.Log(string.Format("Object size differential X: {0}", (collision.gameObject.GetComponent <Collider>().bounds.size.x / 2 + gameObject.GetComponent <Collider>().bounds.size.x / 2))); Debug.Log(string.Format("Collision dZ: {0}", dz)); Debug.Log(string.Format("Object size differential Z: {0}", (collision.gameObject.GetComponent <Collider>().bounds.size.z / 2 + gameObject.GetComponent <Collider>().bounds.size.z / 2))); cabinetState = CabinetState.Snapped; //if(collision.transform.position.x > gameObject.transform.position.x) //Determine if cabinet snapped on left or right side //{ // gameObject.transform.position = collision.transform.position - new Vector3(gameObject.GetComponent<BoxCollider>().size.x, 0, 0); //} //else //{ // gameObject.transform.position = collision.transform.position + new Vector3(collision.gameObject.GetComponent<BoxCollider>().size.x, 0, 0); //} if (Mathf.Abs(dx) >= (collision.gameObject.GetComponent <Collider>().bounds.size.x / 2 + gameObject.GetComponent <Collider>().bounds.size.x / 2) - 0.05f) { if (dx > 0) { Debug.Log("Right"); collisionRight = true; snapPos.x = collision.transform.position.x - (collision.gameObject.GetComponent <Collider>().bounds.size.x / 2 + gameObject.GetComponent <Collider>().bounds.size.x / 2); snapPos.y = gameObject.transform.position.y; snapPos.z = gameObject.transform.position.z; gameObject.transform.position = snapPos; } else { Debug.Log("Left"); collisionLeft = true; snapPos.x = collision.transform.position.x + collision.gameObject.GetComponent <Collider>().bounds.size.x / 2 + gameObject.GetComponent <Collider>().bounds.size.x / 2; snapPos.y = gameObject.transform.position.y; snapPos.z = gameObject.transform.position.z; gameObject.transform.position = snapPos; } } } if (!collisionRear) { cabinetState = CabinetState.Snapped; if (Mathf.Abs(dz) >= (collision.gameObject.GetComponent <Collider>().bounds.size.z / 2 + gameObject.GetComponent <Collider>().bounds.size.z / 2) - 0.05f) { Debug.Log("Rear"); collisionRear = true; snapPos.x = gameObject.transform.position.x; snapPos.y = gameObject.transform.position.y; snapPos.z = collision.transform.position.z - (collision.gameObject.GetComponent <Collider>().bounds.size.z / 2 + gameObject.GetComponent <Collider>().bounds.size.z / 2); gameObject.transform.position = snapPos; } } }