Ejemplo n.º 1
0
        internal static List <ObjectIdentifier> GetSortedSceneObjectIdentifiers(List <ObjectIdentifier> objects)
        {
            var types         = new List <Type>(BuildCacheUtility.GetMainTypeForObjects(objects));
            var sortedObjects = new List <SortObject>();

            for (int i = 0; i < objects.Count; i++)
            {
                sortedObjects.Add(new SortObject {
                    sortIndex = GetSortIndex(types[i]), objectId = objects[i]
                });
            }
            return(sortedObjects.OrderBy(x => x.sortIndex).Select(x => x.objectId).ToList());
        }
        public void BuildCacheUtility_GetMainTypeForObjects_ReturnsUniqueAndSortedTypeArray()
        {
            var includes = ContentBuildInterface.GetPlayerObjectIdentifiersInAsset(k_TempGuid, EditorUserBuildSettings.activeBuildTarget);

            // Test prefab is created using 2 primitive cubes, one parented to the other, so the includes will in turn contain the sequence:
            Type[] expectedTypes = new[] { typeof(GameObject), typeof(Transform), typeof(MeshFilter), typeof(MeshRenderer), typeof(BoxCollider),
                                           typeof(GameObject), typeof(Transform), typeof(MeshFilter), typeof(MeshRenderer), typeof(BoxCollider) };
            // One catch, the ordering of the expected types is based on the order of includes which is in turn ordered by the local identifier in file.
            // Since we are generating the prefab as part of the test, and lfids generation is random, we don't know what order they will be returned in.
            // So sort both expected types lists and compare exact.
            Array.Sort(expectedTypes, (x, y) => x.AssemblyQualifiedName.CompareTo(y.AssemblyQualifiedName));

            var actualTypes = BuildCacheUtility.GetMainTypeForObjects(includes);

            Array.Sort(actualTypes, (x, y) => x.AssemblyQualifiedName.CompareTo(y.AssemblyQualifiedName));

            Assert.AreEqual(expectedTypes.Length, includes.Length);
            Assert.AreEqual(expectedTypes.Length, actualTypes.Length);
            CollectionAssert.AreEqual(expectedTypes, actualTypes);
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public ReturnCode Run()
        {
            HashSet <ObjectIdentifier> buildInObjects = new HashSet <ObjectIdentifier>();

            foreach (AssetLoadInfo dependencyInfo in m_DependencyData.AssetInfo.Values)
            {
                buildInObjects.UnionWith(dependencyInfo.referencedObjects.Where(x => x.guid == k_BuiltInGuid));
            }

            foreach (SceneDependencyInfo dependencyInfo in m_DependencyData.SceneInfo.Values)
            {
                buildInObjects.UnionWith(dependencyInfo.referencedObjects.Where(x => x.guid == k_BuiltInGuid));
            }

            ObjectIdentifier[] usedSet   = buildInObjects.ToArray();
            Type[]             usedTypes = BuildCacheUtility.GetMainTypeForObjects(usedSet);

            if (m_Layout == null)
            {
                m_Layout = new BundleExplictObjectLayout();
            }

            Type shader = typeof(Shader);

            for (int i = 0; i < usedTypes.Length; i++)
            {
                if (usedTypes[i] != shader)
                {
                    continue;
                }

                m_Layout.ExplicitObjectLocation.Add(usedSet[i], ShaderBundleName);
            }

            if (m_Layout.ExplicitObjectLocation.Count == 0)
            {
                m_Layout = null;
            }

            return(ReturnCode.Success);
        }