Inheritance: ISerializable
Example #1
0
        /**
         * Attempt to load a prefab from either Resources or AssetBundle using `metadata`.  Can return null
         * if object is not found.
         */
        public static GameObject LoadPrefabWithMetadata(pb_MetaData metadata)
        {
            if (metadata.assetType == AssetType.Instance)
            {
                Debug.LogWarning("Attempting to load instance asset through resource manager.");
                return(null);
            }

            switch (metadata.assetType)
            {
            case AssetType.Resource:
            {
                if (instance.lookup.ContainsKey(metadata.fileId))
                {
                    return(instance.lookup[metadata.fileId]);
                }
                else
                {
                    Debug.LogWarning("Resource manager could not find \"" + metadata.fileId + "\" in loaded resources.");
                    return(null);
                }
            }

            case AssetType.Bundle:
            {
                return(pb_AssetBundles.LoadAsset <GameObject>(metadata.assetBundlePath));
            }

            default:
            {
                Debug.LogError("File not found from metadata: " + metadata);
                return(null);
            }
            }
        }
Example #2
0
		/**
		 * 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>));
		}
Example #3
0
		/**
		 * 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) );
			}
		}