Exemplo n.º 1
0
        public static LiveLinkChangeSet UpdateLiveLink(Scene scene, Hash128 sceneGUID, ref LiveLinkDiffGenerator liveLinkData, int sceneDirtyID, LiveLinkMode mode, BuildConfiguration config, out NativeArray <GUID> assetDependencies)
        {
            //Debug.Log("ApplyLiveLink: " + scene.SceneName);

            int framesToRetainBlobAssets = RetainBlobAssetsSetting.GetFramesToRetainBlobAssets(config);

            var liveLinkEnabled = mode != LiveLinkMode.Disabled;

            if (liveLinkData != null && liveLinkData._LiveLinkEnabled != liveLinkEnabled)
            {
                liveLinkData.Dispose();
                liveLinkData = null;
            }

            var unloadAllPreviousEntities = liveLinkData == null;

            if (liveLinkData == null)
            {
                liveLinkData = new LiveLinkDiffGenerator(sceneGUID, liveLinkEnabled);
            }

            if (!liveLinkEnabled)
            {
                assetDependencies = default;
                return(new LiveLinkChangeSet
                {
                    UnloadAllPreviousEntities = unloadAllPreviousEntities,
                    SceneName = scene.name,
                    SceneGUID = sceneGUID,
                    FramesToRetainBlobAssets = framesToRetainBlobAssets
                });
            }

            var flags = GameObjectConversionUtility.ConversionFlags.AddEntityGUID | GameObjectConversionUtility.ConversionFlags.AssignName | GameObjectConversionUtility.ConversionFlags.GameViewLiveLink;

            if (mode == LiveLinkMode.LiveConvertSceneView)
            {
                flags |= GameObjectConversionUtility.ConversionFlags.SceneViewLiveLink;
            }

            liveLinkData.Convert(scene, sceneGUID, flags, config, out assetDependencies);

            var convertedEntityManager = liveLinkData._ConvertedWorld.EntityManager;

            // We don't know the scene tag of the destination world, so we create a null Scene Tag.
            // In the patching code this will be translated into the final scene entity.
            convertedEntityManager.AddSharedComponentData(liveLinkData._MissingSceneQuery, new SceneTag {
                SceneEntity = Entity.Null
            });

#if UNITY_2020_1_OR_NEWER
            convertedEntityManager.AddSharedComponentData(liveLinkData._MissingRenderDataQuery, new EditorRenderData {
                SceneCullingMask = UnityEditor.SceneManagement.SceneCullingMasks.GameViewObjects, PickableObject = null
            });
#else
            convertedEntityManager.AddSharedComponentData(liveLinkData._MissingRenderDataQuery, new EditorRenderData {
                SceneCullingMask = EditorRenderData.LiveLinkEditGameViewMask, PickableObject = null
            });
#endif

            var options = EntityManagerDifferOptions.IncludeForwardChangeSet |
                          EntityManagerDifferOptions.FastForwardShadowWorld |
                          EntityManagerDifferOptions.ValidateUniqueEntityGuid |
                          EntityManagerDifferOptions.ClearMissingReferences;

            var changes = new LiveLinkChangeSet
            {
                Changes = liveLinkData._LiveLinkDiffer.GetChanges(options, Allocator.TempJob).ForwardChangeSet,
                UnloadAllPreviousEntities = unloadAllPreviousEntities,
                SceneName = scene.name,
                SceneGUID = sceneGUID,
                FramesToRetainBlobAssets = framesToRetainBlobAssets
            };


            liveLinkData.LiveLinkDirtyID = sceneDirtyID;
            // convertedEntityManager.Debug.CheckInternalConsistency();

            return(changes);
        }
        public static LiveLinkChangeSet UpdateLiveLink(Scene scene, Hash128 sceneGUID, ref LiveLinkDiffGenerator liveLinkData, int sceneDirtyID, LiveLinkMode mode, GUID configGUID, BuildConfiguration config)
        {
            //Debug.Log("ApplyLiveLink: " + scene.SceneName);

            int framesToRetainBlobAssets = RetainBlobAssetsSetting.GetFramesToRetainBlobAssets(config);

            var liveLinkEnabled = mode != LiveLinkMode.Disabled;

            if (liveLinkData != null && liveLinkData._LiveLinkEnabled != liveLinkEnabled)
            {
                liveLinkData.Dispose();
                liveLinkData = null;
            }

            var unloadAllPreviousEntities = liveLinkData == null;

            if (liveLinkData == null)
            {
                liveLinkData = new LiveLinkDiffGenerator(scene, sceneGUID, configGUID, config, liveLinkEnabled);
            }
            else if (liveLinkData._Scene != scene || !ReferenceEquals(liveLinkData._buildConfiguration, config) || liveLinkData._buildConfigurationGUID != configGUID)
            {
                liveLinkData._Scene = scene;
                liveLinkData._buildConfigurationGUID = configGUID;
                liveLinkData._buildConfiguration     = config;
                liveLinkData._RequestCleanConversion = true;
            }

            if (!liveLinkEnabled)
            {
                return(new LiveLinkChangeSet
                {
                    UnloadAllPreviousEntities = unloadAllPreviousEntities,
                    SceneName = scene.name,
                    SceneGUID = sceneGUID,
                    FramesToRetainBlobAssets = framesToRetainBlobAssets
                });
            }

            var flags = GameObjectConversionUtility.ConversionFlags.AddEntityGUID | GameObjectConversionUtility.ConversionFlags.AssignName | GameObjectConversionUtility.ConversionFlags.GameViewLiveLink;

            if (mode == LiveLinkMode.LiveConvertSceneView)
            {
                flags |= GameObjectConversionUtility.ConversionFlags.SceneViewLiveLink;
            }
            if (mode == LiveLinkMode.LiveConvertStandalonePlayer)
            {
                flags |= GameObjectConversionUtility.ConversionFlags.IsBuildingForPlayer;
            }

            liveLinkData.Convert(flags);
            const EntityManagerDifferOptions options =
                EntityManagerDifferOptions.IncludeForwardChangeSet |
                EntityManagerDifferOptions.FastForwardShadowWorld |
                EntityManagerDifferOptions.ValidateUniqueEntityGuid |
                EntityManagerDifferOptions.ClearMissingReferences;

            var changes = new LiveLinkChangeSet
            {
                Changes = liveLinkData._LiveLinkDiffer.GetChanges(options, Allocator.TempJob).ForwardChangeSet,
                UnloadAllPreviousEntities = unloadAllPreviousEntities,
                SceneName = scene.name,
                SceneGUID = sceneGUID,
                FramesToRetainBlobAssets = framesToRetainBlobAssets
            };

#if !UNITY_2020_2_OR_NEWER
            liveLinkData.LiveLinkDirtyID = sceneDirtyID;
#endif
            // convertedEntityManager.Debug.CheckInternalConsistency();

            return(changes);
        }