Esempio n. 1
0
    void ConstrainObject(ConstrainedObject co)
    {
        //Desired location = parent + offset
        //If within Bounds, all is well
        //Otherwise, move object to closest point in constrained area
        Vector3 desiredLocation = Vector3.zero;

        if (hands == 1)
        {
            desiredLocation           = co.parent1.position + co.offset1;
            co.obj.transform.rotation = co.rot;
        }
        else if (hands == 2)
        {
            Vector3 desiredLoc1 = co.parent1.position + co.offset1;
            Vector3 desiredLoc2 = co.parent2.position + co.offset2;
            desiredLocation = desiredLoc1 + (desiredLoc2 - desiredLoc1) * .5f;
        }

        Vector3 boundPoint = constraintCollider.ClosestPoint(desiredLocation);

        if (boundPoint != desiredLocation)
        {
            //Outside of bounds
            co.obj.transform.position = boundPoint;
        }


        if (restrictY && hands == 1)
        {
            co.obj.transform.position = new Vector3(co.obj.transform.position.x, co.yPos, co.obj.transform.position.z);
        }
    }
Esempio n. 2
0
    // public void AddConstrainedObject() {
    // hands++;
    // if (constrainedObject != null) {
    // constrainedObject.parent2 = parent;
    // constrainedObject.offset2 = offset;
    // }
    // ConstrainedObject co = new ConstrainedObject();
    // co.parent1 =


    // }
    public void AddConstrainedObject(GameObject obj, Transform parent, Vector3 offset)
    {
        hands++;
        if (constrainedObject != null)
        {
            constrainedObject.parent2 = parent;
            constrainedObject.offset2 = offset;
            return;
        }
        ConstrainedObject co = new ConstrainedObject();

        co.obj            = obj;
        co.parent1        = parent;
        co.offset1        = offset;
        co.yPos           = obj.transform.position.y;
        co.rot            = obj.transform.rotation;
        co.areaRot        = constraintArea.transform.rotation;
        co.oldParent      = obj.transform.parent;
        constrainedObject = co;


        obj.transform.parent = parent;
        Rigidbody rb = obj.GetComponent <Rigidbody>();

        if (rb)
        {
            rb.isKinematic = true;
        }
    }
Esempio n. 3
0
 public void Write(EndianBinaryWriter writer)
 {
     UpVector.Write(writer);
     writer.Write(Distance);
     ConstrainedObject.Write(writer);
     ConstrainingObject.Write(writer);
 }
Esempio n. 4
0
 public void Read(EndianBinaryReader reader)
 {
     UpVector.Read(reader);
     Distance = reader.ReadSingle();
     ConstrainedObject.Read(reader);
     ConstrainingObject.Read(reader);
 }
Esempio n. 5
0
    //Perform fullness check when removing an object from UI
    public void RemoveObject(GameObject g)
    {
        if (currentObject != g)
        {
            return;
        }
        currentObject.transform.parent   = bedPool.transform;
        currentObject.transform.position = bedPool.transform.position;
        Rigidbody rb = currentObject.AddComponent <Rigidbody>();

        rb.mass           = 5;
        rb.drag           = 0.2f;
        currentObject     = null;
        constrainedObject = null;
        print("Removed: " + g.name);
    }
Esempio n. 6
0
    public void RemoveConstrainedObject(Transform parent)
    {
        hands--;
        if (hands > 0)
        {
            if (constrainedObject.parent1 == parent)
            {
                constrainedObject.parent1 = constrainedObject.parent2;
                constrainedObject.offset1 = constrainedObject.offset2;
            }
            constrainedObject.parent2 = null;
            constrainedObject.rot     = constrainedObject.obj.transform.rotation;
            constrainedObject.yPos    = constrainedObject.obj.transform.position.y;
            return;
        }
        constrainedObject.obj.transform.parent = constrainedObject.oldParent;
        Rigidbody rb = constrainedObject.obj.GetComponent <Rigidbody>();

        if (rb)
        {
            rb.isKinematic = true;
        }
        constrainedObject = null;
    }
Esempio n. 7
0
 public void Read(EndianBinaryReader reader)
 {
     UpVector.Read(reader);
     ConstrainedObject.Read(reader);
     ConstrainingObject.Read(reader);
 }