private void Awake()
 {
     CreateNodesFromHierachy();
     GUID = new Guid(GUIDHelper.ExtractGUIDFromName(this.name));
 }
Example #2
0
        // FIXME: this should be the contructor
        public static Node FindChildNodes(GameObject unityObj)
        {
            var node = new Node()
            {
                Children = new Node[unityObj.transform.childCount],
                UnityObj = unityObj,
                GUID     = new Guid(GUIDHelper.ExtractGUIDFromName(unityObj.name)),
                Name     = GUIDHelper.RemoveGUIDFromName(unityObj.name)
            };

            // unityObj.name = node.Name; // write name without GUID back to Object
            node.IsAnnotatable = node.CheckIfObjectIsAnnotatable();

            var renderer = unityObj.GetComponent <MeshRenderer>();

            if (renderer != null && unityObj.GetComponent <IgnoreNode>() == null)
            {
                node.HasBounds = true;

                node.BoundsWithContext.Bounds = renderer.bounds;

                var meshfilter = unityObj.GetComponent <MeshFilter>();

                if (node.BoundsWithContext.HasLocalBounds = meshfilter != null)
                {
                    node.BoundsWithContext.LocalBounds    = meshfilter.mesh.bounds;
                    node.BoundsWithContext.LocalTransform = unityObj.transform;
                }

                var meshCollider = unityObj.GetComponent <MeshCollider>();
                if (meshCollider == null && meshfilter != null)
                {
                    meshCollider = unityObj.AddComponent <MeshCollider>();
                }

                if (node.BoundsWithContext.HasMeshCollider = meshCollider != null)
                {
                    node.BoundsWithContext.MeshCollider = meshCollider;
                }

                node.HasGeometry = true;
            }

            for (int index = 0; index < unityObj.transform.childCount; index++)
            {
                var childObj  = unityObj.transform.GetChild(index).gameObject;
                var childNode = FindChildNodes(childObj);
                childNode.Parent = node;

                node.Children[index] = childNode;

                if (childNode.HasBounds)
                {
                    if (node.HasBounds)
                    {
                        node.BoundsWithContext.Bounds.Encapsulate(childNode.BoundsWithContext.Bounds);
                        node.HasBounds = true;
                    }
                    else
                    {
                        node.BoundsWithContext.Bounds = childNode.BoundsWithContext.Bounds;
                        node.HasBounds = childNode.HasBounds;
                    }
                }
            }
            return(node);
        }