private void SetParents()
    {
        //parentObjects.Clear();

        foreach (AttachmentTriggerController trigger in triggers)
        {
            AttachmentPointController attachmentPoint = trigger.GetOverlappingAttachmentPoint();

            if (attachmentPoint)
            {
                InteractiveObjectController newParent = attachmentPoint.GetOwningObject();

                if (newParent && (newParent.grabbed || newParent.attached) && !parentObjects.Contains(newParent))
                {
                    newParent.AddObjects(this);
                    newParent.AddMass(mass);
                    parentObjects.Add(newParent);

                    //Debug.Log("Object: " + this.name + " adding object: " + attachmentPoint.GetOwningObject().name + " as a parent object.");
                    //Debug.Log("Parent objects count: " + parentObjects.Count);
                }
            }
        }

        if (attachedObjects.Count > 0)
        {
            foreach (InteractiveObjectController attached in attachedObjects)
            {
                attached.SetParents();
            }
        }

        //SayParents();
    }
Esempio n. 2
0
    private void OnTriggerExit(Collider other)
    {
        AttachmentPointController attachmentPoint = other.GetComponent <AttachmentPointController>();

        if (attachmentPoint && attachmentPoint == overlappingAttachmentPoint)
        {
            overlappingAttachmentPoint = null;
        }
    }
Esempio n. 3
0
    private void OnTriggerEnter(Collider other)
    {
        AttachmentPointController attachmentPoint = other.GetComponent <AttachmentPointController>();

        if (attachmentPoint)
        {
            overlappingAttachmentPoint = attachmentPoint;
        }
    }
Esempio n. 4
0
    private void OnCollisionEnter(Collision collision)
    {
        InteractiveObjectController otherObject = collision.gameObject.GetComponent <InteractiveObjectController>();

        if (otherObject && otherObject.attached)
        {
            AttachmentPointController otherAttachment = otherObject.parentAttachmentPoint;
            otherObject.Detach();
            otherAttachment.Deactivate();
        }
    }
Esempio n. 5
0
    private void OnTriggerEnter(Collider other)
    {
        InteractiveObjectController otherObject = other.GetComponent <InteractiveObjectController>();

        if (otherObject && otherObject.attached && otherObject.breakMomentum <= GetMomentum())
        {
            AttachmentPointController otherAttachment = otherObject.parentAttachmentPoint;
            otherObject.Detach();
            otherAttachment.Deactivate();
        }
    }
 public void AttachTo(InteractiveObjectController otherObject, AttachmentPointController attachmentPoint)
 {
     parentObject          = otherObject;
     parentAttachmentPoint = attachmentPoint;
     //parentObject.AddObjects(this);
     Reroot(FindRoot(parentObject));
     parentObject.AddObjects(this);
     Destroy(this.GetComponent <Rigidbody>());
     this.GetComponent <Collider>().isTrigger = false;
     //parentObject.AddMass(mass);
     attached = true;
     //Debug.Log(this.name + " attached to " + parentObject.name + ", with root object " + rootObject.name);
     SetParents();
 }
    public void Detach()
    {
        SetAttached();
        //Reroot(FindRoot(parentObject));

        this.transform.SetParent(parentAttachmentPoint.GetGuide()); // reparent to attachment point guide
        this.gameObject.AddComponent <Rigidbody>();
        rigidBody      = GetComponent <Rigidbody>();                // reset the local variable for the object's rigid body
        rigidBody.mass = mass;                                      // set the rigid body's mass to the stored value
        //parentObject.RemoveObjects(this); // remove this object from the parent object's attached objects group
        //parentObject.SubtractMass(mass);
        ClearParents();
        rootObject   = null;                                    // we're detaching here, there is no more root object (this object is root)
        parentObject = null;                                    // we're detaching here, there is no more parent object (this object is its own parent)
        Reroot(this);                                           // reroot all of this object's attached objects to this object
        attached = false;                                       // this object is no longer attached

        AttachmentPointController temp = parentAttachmentPoint; // temp reference for the attachment point that will be deleted once out of scope

        parentAttachmentPoint = null;                           // get rid of the attachment point global
        temp.Activate(temp.GetAttachingTrigger());              // reactivate the attachment point
    }
Esempio n. 8
0
 public void Deactivate()
 {
     activated             = false;
     pairedAttachmentPoint = null;
 }
Esempio n. 9
0
    // helpers

    public void Activate(AttachmentPointController activatingPoint)
    {
        pairedAttachmentPoint = activatingPoint;
        activated             = true;
    }
Esempio n. 10
0
 // Use this for initialization
 void Start()
 {
     activated             = false;
     owningObject          = GetComponentInParent <InteractiveObjectController>();
     pairedAttachmentPoint = null;
 }
Esempio n. 11
0
 public void AttachToPoint(AttachmentPointController attachmentPoint)
 {
     attachmentPoint.attachedPart = parentPart;
     AttachToPart(attachmentPoint.parentPart);
 }