Exemple #1
0
    public virtual bool Detach(HardpointController point, bool ignore)
    {
        AttachmentController attachment = point.Attached;

        if (Detach(point))
        {
            if (ignore)
            {
                IgnoreAttachments[attachment.GetInstanceID()] = attachment;
            }
            return(true);
        }
        return(false);
    }
Exemple #2
0
    public virtual void DiscoverConnected(bool clearCurrent = false)
    {
        if (clearCurrent)
        {
            ConnectedAttachments.Clear();
            AttachmentGroups.Clear();
            AttachmentTypes.Clear();
        }

        Joint[] connected = transform.GetComponentsInChildren <Joint>();
        for (int i = 0; i < connected.Length; i++)
        {
            Rigidbody other = connected[i].connectedBody;
            if (other != null)
            {
                //DiscoverConnected(other.transform);
                AttachmentController [] attachments = other.transform.GetComponentsInChildren <AttachmentController>();
                for (int j = 0; j < attachments.Length; j++)
                {
                    AttachmentController attachment = attachments[j];
                    string group    = attachment.AttachmentGroup;
                    string type     = attachment.AttachmentType;
                    bool   newGroup = !AttachmentGroups.ContainsKey(group);
                    bool   newType  = !AttachmentTypes.ContainsKey(type);
                    if (!OnDiscoverNewAttachment(attachment, newType, newGroup))
                    {
                        continue;
                    }
                    ConnectedAttachments[attachment.GetInstanceID()] = attachment;
                    if (newGroup)
                    {
                        AttachmentGroups[group] = new List <AttachmentController>();
                    }
                    if (newType)
                    {
                        AttachmentTypes[type] = new List <AttachmentController>();
                    }
                    AttachmentGroups[group].Add(attachment);
                    AttachmentTypes[type].Add(attachment);
                }
            }
        }

        CalculateCenterOfMass();
    }
Exemple #3
0
    public virtual bool Attach(HardpointController point, AttachmentController attachment, HardpointController attachmentPoint)
    {
        if (attachment == null)
        {
            Debug.Log("Cannot attach null attachment");
            return(false);
        }

        if (ConnectedAttachments.ContainsKey(attachment.GetInstanceID()))
        {
            return(false);
        }

        // Move into position then attach.
        if (attachment.rigidbody == null)
        {
            Debug.Log("Cannot attach if it does not have a rigidbody!");
            return(false);
        }
        FixedJoint joint = gameObject.AddComponent("FixedJoint") as FixedJoint;

        RotateConnect(point.transform, attachment.transform, attachmentPoint.transform);
        //attachment.transform.parent = transform;

        Vector3 translate = point.transform.position - attachmentPoint.transform.position;

        attachment.transform.Translate(translate, Space.World);

        point.Attached                = attachment;
        point.AttachedPoint           = attachmentPoint;
        attachmentPoint.Attached      = this;
        attachmentPoint.AttachedPoint = point;
        joint.connectedBody           = attachment.rigidbody;
        attachment.ParentAttachment   = this;

        return(true);
    }