public void Deactivate() { //Debug.Log("Deactivating!"); attachingObject.busy = false; owningObject.busy = false; activated = false; attachStop = false; attachingObject.SetMoveMode(1); attachingObject.GetComponent <BoxCollider>().isTrigger = false; owningObject.IgnoreCollision(attachingObject.GetComponent <Collider>(), false); owningObject.ResetCenterOfMass(); }
void Highlight(InteractiveObjectController colorObj) { Color col = new Color(0.5f, 0.45f, 0); Renderer rend; rend = colorObj.GetComponent <Renderer>(); rend.material.EnableKeyword("_EMISSION"); rend.material.SetColor("_EmissionColor", col); colorObj.highlightedStatus = true; }
void Unhighlight(InteractiveObjectController colorObj) { if (colorObj) { Renderer rend; rend = colorObj.GetComponent <Renderer>(); rend.material.EnableKeyword("_EMISSION"); rend.material.SetColor("_EmissionColor", Color.black); colorObj.highlightedStatus = false; } }
public void Activate(AttachmentTriggerController trigger) { //Debug.Log("Activating!"); attachingTrigger = trigger; attachingObject = GetAttachingObject(attachingTrigger); attachingController = GetAttachingController(attachingTrigger); if (attachingController && attachingObject && attachingController) { attachingObject.GetComponent <BoxCollider>().isTrigger = true; owningObject.IgnoreCollision(attachingObject.GetComponent <Collider>(), true); attachingObject.SetMoveMode(0); SetInitialTrackingPositions(); attachingObject.transform.SetParent(objectGuide); attachingObject.busy = true; owningObject.busy = true; activated = true; } }
public void Plug(InteractiveObjectController pluggingObj) { //first, we need to get the plug's parent object GameObject plugParent = this.transform.parent.gameObject; //objects with rigid bodies containing child objects with rigidbodies is a big no-no, so we'll need to destroy the grabbed object's rigid body. Destroy(pluggingObj.GetComponent <Rigidbody>()); //and then we make the object and the plug children of the same object pluggingObj.transform.parent = plugParent.transform; //move grabbed object to guided position and rotation pluggingObj.transform.position = guide.position; pluggingObj.transform.rotation = guide.rotation; //end grabbed move, enable switch to guided move pluggingObj.guidedMove = true; //keep a copy of the plug for when we have to unplug pluggingObj.plugObj = this; //tell the object it has been plugged pluggingObj.pluggedStatus = true; //tell this it has a parent object that loves it pluggingObj.parentObj = parentObj; //tell the plug that everything is good to go pluggedStatus = true; }
public void Unplug(InteractiveObjectController unpluggingObj) { //we need to unparent the object unpluggingObj.transform.parent = null; //when unplugged, the object's rigidbody will need to be rebuilt unpluggingObj.gameObject.AddComponent <Rigidbody>(); unpluggingObj.GetComponent <Rigidbody>().mass = unpluggingObj.rbMass; unpluggingObj.GetComponent <Rigidbody>().drag = unpluggingObj.rbDrag; unpluggingObj.GetComponent <Rigidbody>().angularDrag = unpluggingObj.rbADrag; unpluggingObj.rigidBody = unpluggingObj.GetComponent <Rigidbody>(); //re-enable gravity and other physical forces unpluggingObj.GetComponent <Rigidbody>().isKinematic = false; unpluggingObj.GetComponent <Rigidbody>().useGravity = true; //re-enable grabbed move unpluggingObj.guidedMove = false; //reset the object unpluggingObj.pluggedStatus = false; unpluggingObj.plugObj = null; //tell the unplugging object that it no longer has a parent, and it has been given up for adoption unpluggingObj.parentObj = null; //reset the plug pluggedStatus = false; pluggedObj = null; }