コード例 #1
0
ファイル: pb_SceneNode.cs プロジェクト: kallqvist/giles
        /**
         * Deserialization constructor.
         */
        public pb_SceneNode(SerializationInfo info, StreamingContext context)
        {
            name      = (string)info.GetValue("name", typeof(string));
            transform = (pb_Transform)info.GetValue("transform", typeof(pb_Transform));
            children  = (List <pb_SceneNode>)info.GetValue("children", typeof(List <pb_SceneNode>));
            metadata  = (pb_MetaData)info.GetValue("metadata", typeof(pb_MetaData));

            if (metadata.AssetType == AssetType.Instance)
            {
                components = (List <pb_ISerializable>)info.GetValue("components", typeof(List <pb_ISerializable>));
            }
        }
コード例 #2
0
ファイル: pb_SceneNode.cs プロジェクト: kallqvist/giles
        /**
         * Recursively build a scene graph using `root` as the root node.
         */
        public pb_SceneNode(GameObject root)
        {
            name = root.name;

            components = new List <pb_ISerializable>();

            pb_MetaDataComponent metadata_component = root.GetComponent <pb_MetaDataComponent>();

            if (metadata_component == null)
            {
                metadata_component = root.AddComponent <pb_MetaDataComponent>();
            }

            metadata = metadata_component.metadata;

            if (metadata.AssetType == AssetType.Instance)
            {
                foreach (Component c in root.GetComponents <Component>())
                {
                    if (c == null ||
                        c is Transform ||
                        c.GetType().GetCustomAttributes(true).Any(x => x is pb_JsonIgnoreAttribute))
                    {
                        continue;
                    }

                    components.Add(pb_Serialization.CreateSerializableObject <Component>(c));
                }
            }

            // avoid calling constructor which automatically rebuilds the matrix
            transform = new pb_Transform();
            transform.SetTRS(root.transform);

            children = new List <pb_SceneNode>();

            foreach (Transform t in root.transform)
            {
                if (!t.gameObject.activeSelf)
                {
                    continue;
                }

                children.Add(new pb_SceneNode(t.gameObject));
            }
        }