static unsafe NativeList <RuntimeGlobalObjectId> ReferencedUnityObjectsToRuntimeGlobalObjectIds(ReferencedUnityObjects referencedUnityObjects, Allocator allocator = Allocator.Temp)
        {
            var globalObjectIds     = new GlobalObjectId[referencedUnityObjects.Array.Length];
            var runtimeGlobalObjIDs = new NativeList <RuntimeGlobalObjectId>(globalObjectIds.Length, allocator);

            GlobalObjectId.GetGlobalObjectIdsSlow(referencedUnityObjects.Array, globalObjectIds);

            for (int i = 0; i != globalObjectIds.Length; i++)
            {
                var globalObjectId = globalObjectIds[i];

                //@TODO: HACK (Object is a scene object)
                if (globalObjectId.identifierType == 2)
                {
                    Debug.LogWarning($"{referencedUnityObjects.Array[i]} is part of a scene, LiveLink can't transfer scene objects. (Note: LiveConvertSceneView currently triggers this)");
                    continue;
                }

                if (globalObjectId.assetGUID == new GUID())
                {
                    //@TODO: How do we handle this
                    Debug.LogWarning($"{referencedUnityObjects.Array[i]} has no valid GUID. LiveLink currently does not support built-in assets.");
                    continue;
                }

                var runtimeGlobalObjectId =
                    System.Runtime.CompilerServices.Unsafe.AsRef <RuntimeGlobalObjectId>(&globalObjectId);
                runtimeGlobalObjIDs.Add(runtimeGlobalObjectId);
            }

            return(runtimeGlobalObjIDs);
        }
        internal GlobalObjectId[] GetGlobalObjectIds(IList <Object> objects)
        {
            var gids = new GlobalObjectId[objects.Count];

            GlobalObjectId.GetGlobalObjectIdsSlow(objects.ToArray(), gids);
            return(gids);
        }
        public static void GetSceneObjectIdentifiersSlow(int[] instanceIds, SceneObjectIdentifier[] outputIdentifiers)
        {
            var globalIds = new GlobalObjectId[outputIdentifiers.Length];

            GlobalObjectId.GetGlobalObjectIdsSlow(instanceIds, globalIds);

            for (int i = 0; i < instanceIds.Length; i++)
            {
                outputIdentifiers[i] = FromGlobalObjectId(globalIds[i]);
            }
        }
Exemplo n.º 4
0
        private void IndexObjects(GameObject[] objects, string type, string containerName, string containerPath, bool checkIfDocumentExists)
        {
            var options   = settings.options;
            var globalIds = new GlobalObjectId[objects.Length];

            GlobalObjectId.GetGlobalObjectIdsSlow(objects, globalIds);

            for (int i = 0; i < objects.Length; ++i)
            {
                var obj = objects[i];
                if (!obj || (obj.hideFlags & (HideFlags.DontSave | HideFlags.HideInHierarchy)) != 0)
                {
                    continue;
                }

                var gid = globalIds[i];
                if (gid.identifierType == 0 || gid.assetGUID.Empty())
                {
                    continue;
                }

                if (PrefabUtility.IsPrefabAssetMissing(obj))
                {
                    continue;
                }

                if (obj.tag?.Equals("noindex~", StringComparison.Ordinal) ?? false)
                {
                    continue;
                }

                var id            = gid.ToString();
                var transformPath = SearchUtils.GetTransformPath(obj.transform);
                var documentIndex = AddDocument(id, options.types ? transformPath : null, containerPath, checkIfDocumentExists, SearchDocumentFlags.Nested | SearchDocumentFlags.Object);

                if (options.types)
                {
                    IndexNumber(documentIndex, "depth", GetObjectDepth(obj));
                    IndexProperty(documentIndex, "from", type, saveKeyword: true, exact: true);
                }

                if (options.dependencies)
                {
                    IndexProperty(documentIndex, type, containerName, saveKeyword: false);
                    IndexProperty(documentIndex, type, containerPath, exact: true, saveKeyword: false);
                }

                IndexWord(documentIndex, Path.GetFileName(transformPath));
                IndexProperty(documentIndex, "is", "nested", saveKeyword: true, exact: true);
                IndexGameObject(documentIndex, obj, options);
                IndexCustomGameObjectProperties(id, documentIndex, obj);
            }
        }
Exemplo n.º 5
0
        unsafe static public void BuildManifest(Object[] objects, AssetObjectManifest manifest)
        {
            manifest.Objects         = objects;
            manifest.GlobalObjectIds = new RuntimeGlobalObjectId[objects.Length];
            var globalobjectIds = new GlobalObjectId[objects.Length];

            GlobalObjectId.GetGlobalObjectIdsSlow(objects, globalobjectIds);

            fixed(GlobalObjectId *src = globalobjectIds)
            fixed(RuntimeGlobalObjectId * dst = manifest.GlobalObjectIds)
            {
                UnsafeUtility.MemCpy(dst, src, UnsafeUtility.SizeOf <RuntimeGlobalObjectId>() * objects.Length);
            }
        }
Exemplo n.º 6
0
        private void IndexObjects(GameObject[] objects, string type, string containerName, bool checkIfDocumentExists)
        {
            var options   = settings.options;
            var globalIds = new GlobalObjectId[objects.Length];

            GlobalObjectId.GetGlobalObjectIdsSlow(objects, globalIds);

            for (int i = 0; i < objects.Length; ++i)
            {
                var obj = objects[i];
                if (!obj)
                {
                    continue;
                }

                if (PrefabUtility.IsPrefabAssetMissing(obj))
                {
                    continue;
                }

                if (obj.tag?.Equals("noindex~", StringComparison.Ordinal) ?? false)
                {
                    continue;
                }

                var gid           = globalIds[i];
                var id            = gid.ToString();
                var path          = SearchUtils.GetTransformPath(obj.transform);
                var documentIndex = AddDocument(id, path, checkIfDocumentExists);

                if (!String.IsNullOrEmpty(name))
                {
                    IndexProperty(documentIndex, "a", name, saveKeyword: true);
                }

                var depth = GetObjectDepth(obj);
                IndexNumber(documentIndex, "depth", depth);

                IndexWordComponents(documentIndex, path);
                IndexProperty(documentIndex, "from", type, saveKeyword: true, exact: true);
                IndexProperty(documentIndex, type, containerName, saveKeyword: true);
                IndexGameObject(documentIndex, obj, options);
                IndexCustomGameObjectProperties(id, documentIndex, obj);
            }
        }
Exemplo n.º 7
0
 static void RegisterDependencies(AssetImportContext importContext, ref ConversionDependencies dependencies)
 {
     using (var assets = dependencies.AssetDependencyTracker.GetAllDependencies(Allocator.Temp))
     {
         var goids = new GlobalObjectId[assets.Length];
         GlobalObjectId.GetGlobalObjectIdsSlow(assets.ToArray(), goids);
         for (int i = 0; i < assets.Length; i++)
         {
             var guid = goids[i].assetGUID;
             if (GUIDHelper.IsBuiltin(in guid))
             {
                 // AssetImportContext does not support dependencies on inbuilt assets
                 continue;
             }
             if (guid.Empty())
             {
                 continue;
             }
             importContext.DependsOnArtifact(guid);
         }
     }
 }
Exemplo n.º 8
0
        static unsafe NativeList <Hash128> ReferencedUnityObjectsToGUIDs(ReferencedUnityObjects referencedUnityObjects, AssetImportContext ctx)
        {
            var globalObjectIds = new GlobalObjectId[referencedUnityObjects.Array.Length];
            var guids           = new NativeList <Hash128>(globalObjectIds.Length, Allocator.Temp);

            GlobalObjectId.GetGlobalObjectIdsSlow(referencedUnityObjects.Array, globalObjectIds);

            for (int i = 0; i != globalObjectIds.Length; i++)
            {
                var assetGUID = globalObjectIds[i].assetGUID;
                // Skip most built-ins, except for BuiltInExtra which we need to depend on
                if (GUIDHelper.IsBuiltin(assetGUID))
                {
                    if (GUIDHelper.IsBuiltinExtraResources(assetGUID))
                    {
                        var objectIdentifiers = ContentBuildInterface.GetPlayerObjectIdentifiersInAsset(assetGUID, ctx.selectedBuildTarget);

                        foreach (var objectIdentifier in objectIdentifiers)
                        {
                            var packedGUID = assetGUID;
                            GUIDHelper.PackBuiltinExtraWithFileIdent(ref packedGUID, objectIdentifier.localIdentifierInFile);

                            guids.Add(packedGUID);
                        }
                    }
                    else if (GUIDHelper.IsBuiltinResources(assetGUID))
                    {
                        guids.Add(assetGUID);
                    }
                }
                else if (!assetGUID.Empty())
                {
                    guids.Add(assetGUID);
                }
            }

            return(guids);
        }
Exemplo n.º 9
0
        public static void Serialize(EntityChangeSet entityChangeSet, UnsafeAppendBuffer *buffer, out NativeArray <RuntimeGlobalObjectId> outAssets)
        {
            // @FIXME Workaround to solve an issue with hybrid components, LiveLink player builds do NOT support hybrid components.
            //
            // An implementation detail of hybrid components is the `CompanionLink` component.
            // This component is used to link an entity to a GameObject which hosts all of the hybrid components.
            // This companion GameObject lives in the scene and is NOT being serialized across to the player yet.
            //
            // In order to avoid crashing the companion link system in the player build we strip this component during serialization.
            //
            var companionLinkPackedTypeIndex             = GetCompanionLinkPackedTypeIndex(entityChangeSet.TypeHashes);
            var addComponentsWithoutCompanionLinks       = GetPackedComponentsWithoutCompanionLinks(entityChangeSet.AddComponents, companionLinkPackedTypeIndex, Allocator.Temp);
            var removeComponentWithoutCompanionLinks     = GetPackedComponentsWithoutCompanionLinks(entityChangeSet.RemoveComponents, companionLinkPackedTypeIndex, Allocator.Temp);
            var setManagedComponentWithoutCompanionLinks = GetPackedManagedComponentChangesWithoutCompanionLinks(entityChangeSet.SetManagedComponents, companionLinkPackedTypeIndex);

            // Write EntityChangeSet
            buffer->Add(entityChangeSet.TypeHashes);
            buffer->Add(entityChangeSet.CreatedEntityCount);
            buffer->Add(entityChangeSet.DestroyedEntityCount);
            buffer->Add(entityChangeSet.Entities);
            buffer->Add(entityChangeSet.Names);
            buffer->Add(addComponentsWithoutCompanionLinks.AsArray());
            buffer->Add(removeComponentWithoutCompanionLinks.AsArray());
            buffer->Add(entityChangeSet.SetComponents);
            buffer->Add(entityChangeSet.ComponentData);
            buffer->Add(entityChangeSet.EntityReferenceChanges);
            buffer->Add(entityChangeSet.BlobAssetReferenceChanges);
            buffer->Add(entityChangeSet.LinkedEntityGroupAdditions);
            buffer->Add(entityChangeSet.LinkedEntityGroupRemovals);
            buffer->Add(entityChangeSet.CreatedBlobAssets);
            buffer->Add(entityChangeSet.DestroyedBlobAssets);
            buffer->Add(entityChangeSet.BlobAssetData);

            var writer = new ManagedObjectBinaryWriter(buffer);

            WriteSharedComponentDataChanges(buffer, writer, entityChangeSet.SetSharedComponents);
            WriteManagedComponentDataChanges(buffer, writer, setManagedComponentWithoutCompanionLinks);

            var objectTable     = writer.GetUnityObjects();
            var globalObjectIds = new GlobalObjectId[objectTable.Length];

            GlobalObjectId.GetGlobalObjectIdsSlow(objectTable, globalObjectIds);

            outAssets = new NativeArray <RuntimeGlobalObjectId>(globalObjectIds.Length, Allocator.Persistent);
            for (int i = 0; i != globalObjectIds.Length; i++)
            {
                var globalObjectId = globalObjectIds[i];

                //@TODO: HACK (Object is a scene object)
                if (globalObjectId.identifierType == 2)
                {
                    Debug.LogWarning($"{objectTable[i]} is part of a scene, LiveLink can't transfer scene objects. (Note: LiveConvertSceneView currently triggers this)");
                    globalObjectId = new GlobalObjectId();
                }

                if (globalObjectId.assetGUID == new GUID())
                {
                    //@TODO: How do we handle this
                    Debug.LogWarning($"{objectTable[i]} has no valid GUID. LiveLink currently does not support built-in assets.");
                    globalObjectId = new GlobalObjectId();
                }

                outAssets[i] = UnsafeUtility.AsRef <RuntimeGlobalObjectId>(&globalObjectId);
            }

            addComponentsWithoutCompanionLinks.Dispose();
            removeComponentWithoutCompanionLinks.Dispose();
        }