unity core-prefab

Add prefab:

To add a component to the prefab, you need to mark the object as a part of the prefab by storing the object corresponding to the component on the disk. This part is in prefab.cpp

 

prefab delete

There are two ways for prefab to delete an object. The first is that if the object still exists in the prefab, it is placed in the removed object pool of PrefabModification::RemovedComponents, and the prefab is set to be dirty. Removed in a later state. The other is to remove it through DestroySingleObject of BaseObject in case of missing. He deletes the object in another thread after locking.

 

The deletion process of BaseObject.

 

storage:

SavePrefab_Internal of PrefabCreation.cpp is executed when the prefab is to be saved. First, he will find out whether there is a prefab under this name and path, and if it exists, it will be deleted first.

 

Then it is saved in several cases, one is in assets, one is in the instantiation tree, and the other is saved when the association is lost.

 

Then create id and meta

 

Then there are two cases when saving.

One is saved in the instantiated tree or lost the association, in which case the copy is directly copied for execution.

 

The other is saved in assets, which he needs to traverse all files in PersistentManager::GetInstanceIDsAtPath

 

Find all relevant prefabs and set them up

 

Then let the instantiated prefab execute awake and refresh the properties,

 

Then set properties on the cloned object.

 

Set properties in InheritGameObjectAndTransformProperties, including gameobject properties, component properties and transform properties

 

Then save the script data in InheritMonoBehaviours

 

Then write the cloned data to objectsToWrite,

 

Finally, write the object, which is actually a serialized file.

 

Instantiation of prefab:

Implemented in PrefabInstance.cpp. Instantiation is equivalent to placing it in the scene. This step requires copying the source prefab, which will also be executed when saving the prefab.

 

Copy the position, size, anchor point, etc. to the instantiation file. If the prefab source files are saved, these instantiated files need to be awake again, and then the data will be updated.

 

Instance rollback:

The instance also has a rollback function. It is implemented in the RevertPrefabInstance of the prefabInstance, that is, it is processed when it is revoked. First, the incoming object is transferred to the prefabinstance to determine whether it belongs to the prefabinstance, and GetObjectDataArrayFromPrefabRoot is used to collect which ones are existing and which are new ones. , RevertInstantiatedAssetReferencesToParentObject rolls back the used material.

Then first reverse addObjects via std::reverse, then delete the data one by one. Finally, roll back rootTransform, rootRectTransform and rootGO through RevertAllButDefaultPrefabOverrides.

 

If it is not linked, the object on the link can be directly linked. The method on his link is to find the source prefab, and then assign the prefab data.

 

Link prefab:

When starting the scene, when building the app, and saving the scene, the prefab will be linked. For example, when the scene is started, LoadSceneOperation::CompleteAwakeSequence() will be executed, and UnpackAllPrefabInstances will be executed under the editor.

 

Go to PrefabConnection.cpp and execute UnpackAllPrefabInstances to get all prefab instances and decompress each one.

 

If this prefab belongs to kPrefabUnpackMode_OuterRoot, that is, in the mode of parsing the outer layer, execute TransferModifiedPropertiesForUnpack, and execute TransferModifiedPropertiesFromNestedInstancesInAssetToNewInstancesForUnpack. This is mainly to correct the modified part of the prefab.

 

Then kPrefabUnpackMode_OuterRoot mode executes TransferRemovedComponentsForUnpack, executes to TransferRemovedComponentsFromNestedInstancesInAssetToNewInstancesForUnpack, and puts the objects to be removed into the removal queue.

Supongo que te gusta

Origin blog.csdn.net/llsansun/article/details/126652657
Recomendado
Clasificación