Exemplo n.º 1
0
        /// <summary>
        /// Initializes the GameObject to which a new node will belong, and does not have to be called by the average Editor-User. Already called in CreateOctreeNode, immediately after InitializeNode.
        /// It may be overwritten with care (nodeHandle is particularly important).
        /// </summary>
        /// <param name="nodeHandle">The CubiquityDLL handle of the node we're creating. </param>
        protected virtual void InitializeNode(uint nodeHandle)
        {
            //DIS IS VEDDY, VEDDY IMPORTANT. Without this, we can do nothing. NOTHING! Call super to let this happpen!
            this.nodeHandle = nodeHandle;

            //All Octree nodes have positions. Let's get ours in 3 easy steps.
            int nx, ny, nz;

            CubiquityDLL.GetNodePosition(nodeHandle, out nx, out ny, out nz);
            lowerCorner = new Vector3(nx, ny, nz);
        }
Exemplo n.º 2
0
            public static GameObject CreateOctreeNode(uint nodeHandle, GameObject parentGameObject)
            {
                int xPos, yPos, zPos;

                //Debug.Log("Getting position for node handle = " + nodeHandle);
                CubiquityDLL.GetNodePosition(nodeHandle, out xPos, out yPos, out zPos);

                StringBuilder name = new StringBuilder("(" + xPos + ", " + yPos + ", " + zPos + ")");

                GameObject newGameObject = new GameObject(name.ToString());

                newGameObject.AddComponent <OctreeNode>();

                OctreeNode octreeNode = newGameObject.GetComponent <OctreeNode>();

                octreeNode.lowerCorner = new Vector3(xPos, yPos, zPos);
                octreeNode.nodeHandle  = nodeHandle;

                if (parentGameObject)
                {
                    newGameObject.layer = parentGameObject.layer;

                    newGameObject.transform.parent        = parentGameObject.transform;
                    newGameObject.transform.localPosition = new Vector3();
                    newGameObject.transform.localRotation = new Quaternion();
                    newGameObject.transform.localScale    = new Vector3(1.0f, 1.0f, 1.0f);

                    OctreeNode parentOctreeNode = parentGameObject.GetComponent <OctreeNode>();

                    if (parentOctreeNode != null)
                    {
                        Vector3 parentLowerCorner = parentOctreeNode.lowerCorner;
                        newGameObject.transform.localPosition = octreeNode.lowerCorner - parentLowerCorner;
                    }
                    else
                    {
                        newGameObject.transform.localPosition = octreeNode.lowerCorner;
                    }
                }
                else
                {
                    newGameObject.transform.localPosition = octreeNode.lowerCorner;
                }

                newGameObject.hideFlags = HideFlags.HideInHierarchy;

                return(newGameObject);
            }