void OnTriggerEnter(Collider other) { if (isUsable && !isConnected) { // if both objects in this collision are connectors if (GetComponent <Connector>() && other.GetComponent <Connector>() && other.GetComponent <Connector>().isUsable) { // if female connectors are the glue of the hieracrhy // and they match if (connectable.GetComponent <Connectable>().hierarchalStructure == Connectable.HierarchalStructures.matriarchal && other.GetComponent <Connector>().connectable.GetComponent <Connectable>().hierarchalStructure == Connectable.HierarchalStructures.matriarchal) { // male connectors handle the connecting and detaching // if a male connector comes into contact with a female connector who share a coupleID // and niether are currently connected to another connector if (type == connectorType.male && other.GetComponent <Connector>().type == connectorType.female && coupleID == other.GetComponent <Connector>().coupleID&& !isConnected && !other.GetComponent <Connector>().isConnected) { // let both connectors know which game object they are touching // male touching = other.gameObject.GetComponent <Connector>(); //female other.GetComponent <Connector>().touching = this.gameObject.GetComponent <Connector>(); ConnectionCheck(); } } // if male connectors are the glue of the hieracrhy // and they match if (connectable.GetComponent <Connectable>().hierarchalStructure == Connectable.HierarchalStructures.patriarchal && other.GetComponent <Connector>().connectable.GetComponent <Connectable>().hierarchalStructure == Connectable.HierarchalStructures.patriarchal) { // female connectors handle the connecting and detaching // if a female connector comes into contact with a male connector who share a coupleID // and niether are currently connected to another connector if (type == connectorType.female && other.GetComponent <Connector>().type == connectorType.male && coupleID == other.GetComponent <Connector>().coupleID&& !isConnected && !other.GetComponent <Connector>().isConnected) { // let both connectors know which game object they are touching // female touching = other.gameObject.GetComponent <Connector>(); //male other.GetComponent <Connector>().touching = this.gameObject.GetComponent <Connector>(); ConnectionCheck(); } } } } }
/// <summary> /// While a connector is not attached but is touching another connector, /// this checks to see if either of the Connectables are currently grabbed. /// If neither are grabbed, the connection is made. /// </summary> public void ConnectionCheck() { // if the connectors that are touching are not attached if (attachedTo == null && touching != null) { // a check to make sure neither of the two connectables are currently grabbed bool noneGrabbed = true; bool thisIsGrabbed = false; bool touchingIsGrabbed = false; if (connectable.GetComponent <Grabbable>() && connectable.GetComponent <Grabbable>().isGrabbed) { noneGrabbed = false; thisIsGrabbed = true; } Connectable touchingConnectable = touching.connectable; if (touchingConnectable.GetComponent <Grabbable>() && touchingConnectable.GetComponent <Grabbable>().isGrabbed) { noneGrabbed = false; touchingIsGrabbed = true; } // search the hierarchies for parents that might be grabbed // search the hierarchy of this connectable List <GameObject> ancestors = PuppetJumpManager.Instance.GetAncestors(connectable.transform.gameObject); int numAncestors = ancestors.Count; for (int a = 0; a < numAncestors; a++) { if (ancestors[a].GetComponent <Grabbable>() && ancestors[a].GetComponent <Grabbable>().isGrabbed) { noneGrabbed = false; thisIsGrabbed = true; return; } } // search the hierarchy of touching connectable ancestors = PuppetJumpManager.Instance.GetAncestors(touchingConnectable.transform.gameObject); numAncestors = ancestors.Count; for (int a = 0; a < numAncestors; a++) { if (ancestors[a].GetComponent <Grabbable>() && ancestors[a].GetComponent <Grabbable>().isGrabbed) { noneGrabbed = false; touchingIsGrabbed = true; return; } } //Debug.Log(touchingIsGrabbed +"," + thisIsGrabbed); // if neither connectable is grabbed if (noneGrabbed) { // if the family structure is matriarchal // let the male establish the connection, just so they both aren't at the same time if (connectable.GetComponent <Connectable>().hierarchalStructure == Connectable.HierarchalStructures.matriarchal && type == connectorType.male) { // make a connection Connect(); } // if the family structure is patriarchal // let the female establish the connection, just so they both aren't at the same time if (connectable.GetComponent <Connectable>().hierarchalStructure == Connectable.HierarchalStructures.patriarchal && type == connectorType.female) { // make a connection Connect(); } } /* * else if(thisIsGrabbed && !touchingIsGrabbed) * { * touching.Connect(); * } * else if(!thisIsGrabbed && touchingIsGrabbed) * { * Connect(); * } */ } }