Ejemplo n.º 1
0
        private void UpdateComponents()
        {
            List<Tuple<List<PPtr<Object>>, List<KeyValuePair<string, AssetInfo>>>> containerGroups = new List<Tuple<List<PPtr<Object>>, List<KeyValuePair<string, AssetInfo>>>>(m_Container.Count);
            for (int i = 0; i < m_Container.Count; i++)
            {
                bool found = false;
                if (containerGroups.Count > 0)
                {
                    var group = containerGroups[containerGroups.Count - 1];
                    if (group.Item2[0].Value.preloadIndex == m_Container[i].Value.preloadIndex)
                    {
                        group.Item2.Add(m_Container[i]);
                        found = true;
                    }
                }
                if (!found && m_Container[i].Value.asset.asset.pathID != 0)
                {
                    List<PPtr<Object>> preloadPart = m_Container[i].Value.preloadIndex >= 0 ? m_PreloadTable.GetRange(m_Container[i].Value.preloadIndex, m_Container[i].Value.preloadSize) : new List<PPtr<Object>>();
                    List<KeyValuePair<string, AssetInfo>> containerEntries = new List<KeyValuePair<string, AssetInfo>>();
                    containerEntries.Add(m_Container[i]);
                    containerGroups.Add(new Tuple<List<PPtr<Object>>, List<KeyValuePair<string, AssetInfo>>>(preloadPart, containerEntries));
                }
            }

            HashSet<Component> dependantAssets = new HashSet<Component>();
            Stream stream = null;
            try
            {
                file.loadingReferencials = true;
                foreach (var group in containerGroups)
                {
                    foreach (PPtr<Object> assetPtr in group.Item1)
                    {
                        Component asset = assetPtr.asset is NotLoaded ? ((NotLoaded)assetPtr.asset).replacement : assetPtr.asset;
                        if (NeedsUpdate.Contains(asset))
                        {
                            asset = file.FindComponent(group.Item2[0].Value.asset.asset.pathID);
                            if (!dependantAssets.Contains(asset))
                            {
                                if (asset is NotLoaded)
                                {
                                    if (stream == null)
                                    {
                                        stream = File.OpenRead(file.Parser.FilePath);
                                    }
                                    asset = file.LoadComponent(stream, (NotLoaded)asset);
                                }
                                dependantAssets.Add(asset);
                            }
                            break;
                        }
                    }
                }
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                    stream.Dispose();
                }
                file.loadingReferencials = false;
            }
            NeedsUpdate.UnionWith(dependantAssets);
            foreach (var group in containerGroups)
            {
                foreach (var containerEntries in group.Item2)
                {
                    if (containerEntries.Value.asset.asset is NotLoaded)
                    {
                        Component asset = ((NotLoaded)containerEntries.Value.asset.asset).replacement;
                        if (asset != null)
                        {
                            containerEntries.Value.asset = new PPtr<Object>(asset);
                        }
                    }
                }
            }
            foreach (Component asset in NeedsUpdate)
            {
                UpdateComponent(asset, containerGroups);
            }
            NeedsUpdate.Clear();

            m_PreloadTable.Clear();
            m_Container.Clear();
            for (int i = 0; i < containerGroups.Count; i++)
            {
                int preloadIdx = m_PreloadTable.Count;
                m_PreloadTable.AddRange(containerGroups[i].Item1);

                var containerEntries = containerGroups[i].Item2;
                string groupName = containerGroups[i].Item2[0].Key;
                foreach (var entry in containerEntries)
                {
                    entry.Value.preloadIndex = preloadIdx;
                }
                if (i == 0 || m_Container[m_Container.Count - 1].Key.CompareTo(groupName) <= 0)
                {
                    m_Container.AddRange(containerEntries);
                }
                else
                {
                    for (int j = m_Container.Count - 1; j >= -1; j--)
                    {
                        if (j == -1 || m_Container[j].Key.CompareTo(groupName) <= 0)
                        {
                            m_Container.InsertRange(j + 1, containerEntries);
                            break;
                        }
                    }
                }
            }

            m_MainAsset = new AssetInfo(file);
            m_MainAsset.asset = new PPtr<Object>((Component)null);
        }
Ejemplo n.º 2
0
        private void UpdateComponent(Component asset, List<Tuple<List<PPtr<Object>>, List<KeyValuePair<string, AssetInfo>>>> containerGroups)
        {
            List<Component> assets = new List<Component>();
            List<Component> transforms = new List<Component>();
            List<Component> containerRelated = new List<Component>();
            GetDependantAssets(asset, assets, transforms, containerRelated);
            if (asset.classID1 == UnityClassID.GameObject)
            {
                GameObject gameObj = (GameObject)asset;
                Animator animator = gameObj.FindLinkedComponent(UnityClassID.Animator);
                if (animator == null)
                {
                    foreach (Component trans in transforms)
                    {
                        GetDependantAssets(trans, assets, null, null);
                    }
                    animator = new Animator(null, 0, UnityClassID.Animator, UnityClassID.Animator);
                    animator.m_Avatar = new PPtr<Avatar>((Component)null);
                    animator.m_Controller = new PPtr<RuntimeAnimatorController>((Component)null);
                    GetDependantAssets(animator, assets, transforms, containerRelated);
                    assets.Remove(animator);
                }
            }
            foreach (var group in containerGroups)
            {
                var preloadPart = group.Item1;
                var containerEntries = group.Item2;
                for (int i = 0; i < containerEntries.Count; i++)
                {
                    var assetPair = containerEntries[i];
                    if (assetPair.Value.asset.asset == asset)
                    {
                        preloadPart.Clear();
                        for (int j = 0; j < assets.Count; j++)
                        {
                            if (assets[j] is ExternalAsset)
                            {
                                ExternalAsset extAsset = (ExternalAsset)assets[j];
                                PPtr<Object> preloadEntry = new PPtr<Object>((Component)null);
                                preloadEntry.m_FileID = extAsset.FileID;
                                preloadEntry.m_PathID = extAsset.PathID;
                                preloadPart.Add(preloadEntry);
                            }
                            else
                            {
                                preloadPart.Add(new PPtr<Object>(assets[j]));
                            }
                        }

                        string groupName = containerEntries[0].Key;
                        string assetName = AssetCabinet.ToString(asset);
                        if (String.Compare(groupName, assetName, true) != 0)
                        {
                            groupName = assetName.ToLower();
                        }
                        if (containerEntries.Count > 1)
                        {
                            for (int j = 0; j < containerEntries.Count; j++)
                            {
                                switch (containerEntries[j].Value.asset.asset.classID1)
                                {
                                case UnityClassID.Mesh:
                                case UnityClassID.AnimationClip:
                                    containerEntries.RemoveAt(j);
                                    j--;
                                    break;
                                }
                            }
                            for (int j = containerRelated.Count - 1; j >= 0; j--)
                            {
                                AnimationClip clip = containerRelated[j] as AnimationClip;
                                if (clip != null)
                                {
                                    AssetInfo info = new AssetInfo(file);
                                    info.asset = new PPtr<Object>(clip);
                                    containerEntries.Insert(1, new KeyValuePair<string, AssetInfo>(groupName, info));
                                }
                            }
                            for (int j = containerRelated.Count - 1; j >= 0; j--)
                            {
                                MeshRenderer meshR = containerRelated[j] as MeshRenderer;
                                if (meshR != null)
                                {
                                    Mesh mesh = Operations.GetMesh(meshR);
                                    if (mesh != null)
                                    {
                                        AssetInfo info = new AssetInfo(file);
                                        info.asset = new PPtr<Object>(mesh);
                                        containerEntries.Insert(1, new KeyValuePair<string, AssetInfo>(groupName, info));
                                    }
                                }
                            }
                            for (int j = 0; j < containerEntries.Count; j++)
                            {
                                containerEntries[j].Value.preloadSize = assets.Count;
                            }
                        }
                        else
                        {
                            containerEntries[0].Value.preloadSize = assets.Count;
                        }
                        for (int j = 0; j < containerEntries.Count; j++)
                        {
                            if (containerEntries[j].Key != groupName)
                            {
                                containerEntries[j] = new KeyValuePair<string, AssetInfo>(groupName, containerEntries[j].Value);
                            }
                        }
                        return;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void LoadFrom(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);
            m_Name = reader.ReadNameA4();

            int numObjects = reader.ReadInt32();
            m_PreloadTable = new List<PPtr<Object>>(numObjects);
            for (int i = 0; i < numObjects; i++)
            {
                PPtr<Object> objPtr = new PPtr<Object>(stream);
                if (objPtr.m_FileID == 0)
                {
                    Component comp = file.FindComponent(objPtr.m_PathID, false);
                    if (comp == null)
                    {
                        comp = new NotLoaded(file, objPtr.m_PathID, 0, 0);
                    }
                    objPtr = new PPtr<Object>(comp);
                }
                m_PreloadTable.Add(objPtr);
            }

            int numContainerEntries = reader.ReadInt32();
            m_Container = new List<KeyValuePair<string, AssetInfo>>(numContainerEntries);
            for (int i = 0; i < numContainerEntries; i++)
            {
                m_Container.Add
                (
                    new KeyValuePair<string, AssetInfo>
                    (
                        reader.ReadNameA4(), new AssetInfo(file, stream)
                    )
                );
            }

            m_MainAsset = new AssetInfo(file, stream);

            int numScriptComps = reader.ReadInt32();
            m_ScriptCompatibility = new AssetBundleScriptInfo[numScriptComps];
            for (int i = 0; i < numScriptComps; i++)
            {
                m_ScriptCompatibility[i] = new AssetBundleScriptInfo(stream);
            }

            int numClassComps = reader.ReadInt32();
            m_ClassCompatibility = new KeyValuePair<int, uint>[numClassComps];
            for (int i = 0; i < numClassComps; i++)
            {
                m_ClassCompatibility[i] = new KeyValuePair<int, uint>
                (
                    reader.ReadInt32(), reader.ReadUInt32()
                );
            }

            m_RuntimeCompatibility = reader.ReadUInt32();
        }
Ejemplo n.º 4
0
        public void AppendComponent(string name, UnityClassID cls, Component asset)
        {
            string key = name.ToLower();
            for (int idx = 0; idx < m_Container.Count; idx++)
            {
                int cmp = m_Container[idx].Key.CompareTo(key);
                if (cmp == 0)
                {
                    while (m_Container[idx].Value.asset.asset.classID2 != cls)
                    {
                        if (++idx >= m_Container.Count)
                        {
                            return;
                        }
                        cmp = m_Container[idx].Key.CompareTo(key);
                        if (cmp != 0)
                        {
                            return;
                        }
                    }

                    AssetInfo info = new AssetInfo(file);
                    info.preloadIndex = m_Container[idx].Value.preloadIndex;
                    info.preloadSize = 0;
                    info.asset = new PPtr<Object>(asset);

                    while (++idx < m_Container.Count && m_Container[idx].Value.preloadIndex == info.preloadIndex)
                    {
                    }
                    m_Container.Insert(idx, new KeyValuePair<string, AssetInfo>(key, info));
                    return;
                }
                else if (cmp > 0)
                {
                    return;
                }
            }
        }
Ejemplo n.º 5
0
        public void AddComponents(string name, List<Component> assets)
        {
            string key = name.ToLower();
            int idx;
            for (idx = 0; idx < m_Container.Count; idx++)
            {
                if (m_Container[idx].Key.CompareTo(key) >= 0)
                {
                    break;
                }
            }
            --uniquePreloadIdx;
            for (int i = 0; i < assets.Count; i++)
            {
                Component asset = assets[i];
                AssetInfo info = new AssetInfo(file);
                info.preloadIndex = uniquePreloadIdx;
                info.preloadSize = 0;
                info.asset = new PPtr<Object>(asset);
                m_Container.Insert(idx++, new KeyValuePair<string, AssetInfo>(key, info));
            }

            RegisterForUpdate(assets[0]);
        }
Ejemplo n.º 6
0
        public void AddComponent(string name, Component asset)
        {
            AssetInfo info = new AssetInfo(file);
            info.preloadIndex = --uniquePreloadIdx;
            info.preloadSize = 0;
            info.asset = new PPtr<Object>(asset);
            string key = name.ToLower();
            int idx;
            for (idx = 0; idx < m_Container.Count; idx++)
            {
                if (m_Container[idx].Key.CompareTo(key) >= 0)
                {
                    break;
                }
            }
            m_Container.Insert(idx, new KeyValuePair<string, AssetInfo>(key, info));

            RegisterForUpdate(asset);
        }