示例#1
0
    private void CutObject()
    {
        //Release the target object first, then cut the slice
        targetObject.transform.parent = null;
        GameObject[] newChild = targetObject.SliceInstantiate(cutPlane.transform.position, cutPlane.transform.up);

        //Check if success
        if (newChild != null)
        {
            foreach (GameObject child in newChild)
            {
                //Free the new generated object
                //child.transform.position = this.transform.position;
                //child.transform.parent = null;

                //Change the layer and tag of the child
                child.layer = 9;
                child.tag   = "Structure";

                //Give them rigid body and colliderbox
                child.AddComponent <Rigidbody>();
                MeshCollider childCollider = child.AddComponent <MeshCollider>();
                childCollider.convex = true;        //Set to be convex

                //Add grabber to the child object
                OVRGrabbable childGrabble = child.AddComponent <OVRGrabbable>();
                childGrabble.enabled = false;
                childGrabble.NewGrabPoints(child.GetComponents <Collider>());
                childGrabble.enabled = true;

                //Add structure group to the object
                child.AddComponent <Structure>();
            }

            //Check if target is a structure object
            if (targetObject.tag == "Structure")
            {
                //Check if target object was in a tructure group
                if (targetObject.GetComponent <Structure>().trackingManager)
                {
                    //Set target manager to update
                    targetObject.GetComponent <Structure>().trackingManager.GetComponent <StructureGroup>().ifNeedUpdate = true;
                }
            }

            //Remove old object
            Destroy(targetObject);
        }
    }
示例#2
0
    void Update()
    {
        if (ifActive)
        {
            //Debug
            Debug.Log("Structure Group " + gameObject.name + " Child Count: " + transform.childCount);
            //Debug

            //Put all the child into the tracking list
            for (int i = 0; i < transform.childCount; i++)
            {
                Transform child = transform.GetChild(i);

                //Check if child still exist
                if (child == null)
                {
                    //Debug
                    Debug.Log("Structure Group: Delete null child");
                    //Debug

                    Destroy(transform.GetChild(i).gameObject);
                }

                //Set the iterator for each child
                if (child.name == "Nail")
                {
                    child.gameObject.GetComponent <Nail>().iterated = false;
                }
                else if (child.tag == "Structure")
                {
                    child.gameObject.GetComponent <Structure>().iterated = false;
                }

                //Check if there are new child which is not be tracked yet
                if (child != null)
                {
                    //Check if already in the child list
                    bool needAdd = true;
                    for (int j = 0; j < childList.Count; j++)
                    {
                        if (childList[j] != null)
                        {
                            if (ReferenceEquals(childList[j].gameObject, child.gameObject))
                            {
                                needAdd = false;
                            }
                        }
                        else
                        {
                            //Remove from the child list if the target is not exist anymore
                            childList.RemoveAt(j);
                        }
                    }

                    if (needAdd)
                    {
                        //ifNeedUpdate = true;
                        AddChild(child);
                    }
                }
            }

            //Set the grabble point to all the child collider
            grabPoints = gameObject.GetComponentsInChildren <Collider>();

            //Enable grab pointer for OVR Grababl
            grabScript.NewGrabPoints(grabPoints);

            //Update the structure if needed
            if (ifNeedUpdate)
            {
                UpdateStructure();
                ifNeedUpdate = false;
            }

            //Check if need to destroy empty SG
            if (transform.childCount == 0)
            {
                Destroy(gameObject);
            }
        }
    }