Пример #1
0
        private void LoadIDMappingTo(AssetInfo asset,
                                     MappingInfo mapping,
                                     List <int> instanceIDs,
                                     List <int> persistentIDs,
                                     bool IIDtoPID, bool PIDtoObj)
        {
            if (IIDtoPID)
            {
                int instanceID = asset.Object.GetInstanceID();

                //Following if statement required because object can be added to multiple libraries and
                //have multiple persistetnt identifiers. Only first persistent identifier is added to dictionary.
                //Any persistent id can be converted to "first" persistent id using following approach:
                //(PersistenID -> Obj) -> (InstanceID -> First PersistentID)
                if (!mapping.InstanceIDtoPID.ContainsKey(instanceID))
                {
                    mapping.Add(instanceID, m_offset + asset.PersistentID);
                    instanceIDs.Add(instanceID);
                }
            }

            if (PIDtoObj)
            {
                int persistentID = m_offset + asset.PersistentID;
                mapping.Add(persistentID, asset.Object);
                persistentIDs.Add(persistentID);
            }

            if (asset.PrefabParts != null)
            {
                for (int i = 0; i < asset.PrefabParts.Count; ++i)
                {
                    PrefabPartInfo prefabPart = asset.PrefabParts[i];
                    if (prefabPart != null && prefabPart.Object != null)
                    {
                        if (IIDtoPID)
                        {
                            int instanceID = prefabPart.Object.GetInstanceID();
                            if (!mapping.InstanceIDtoPID.ContainsKey(instanceID))
                            {
                                mapping.Add(instanceID, m_offset + prefabPart.PersistentID);
                                instanceIDs.Add(instanceID);
                            }
                        }

                        if (PIDtoObj)
                        {
                            int persistentID = m_offset + prefabPart.PersistentID;
                            mapping.Add(persistentID, prefabPart.Object);
                            persistentIDs.Add(persistentID);
                        }
                    }
                }
            }
        }
Пример #2
0
        public void LoadIDMappingTo(MappingInfo mapping, bool IIDtoPID, bool PIDtoObj)
        {
            if (!IIDtoPID && !PIDtoObj)
            {
                return;
            }

            if (m_assetLibrary == null || m_assetLibrary.Folders == null || m_assetLibrary.Folders.Count == 0)
            {
                return;
            }

            List <int> instanceIDs   = new List <int>();
            List <int> persistentIDs = new List <int>();

            for (int i = 0; i < m_assetLibrary.Folders.Count; ++i)
            {
                AssetFolderInfo folder = m_assetLibrary.Folders[i];
                if (folder != null)
                {
                    if (folder.Assets != null && folder.Assets.Count > 0)
                    {
                        for (int j = 0; j < folder.Assets.Count; ++j)
                        {
                            AssetInfo asset = folder.Assets[j];
                            if (asset.Object != null)
                            {
                                LoadIDMappingTo(asset, mapping, instanceIDs, persistentIDs, IIDtoPID, PIDtoObj);
                            }
                        }
                    }
                }
            }

            mapping.Add(this, instanceIDs, persistentIDs);
        }