Пример #1
0
        void CleanAssetsMemory()
        {
            if (LastLoadedType == 0)
            {
                //Textures
                UsedTerrainTexturesMemory.Clear();

                for (int i = 0; i < ScmapEditor.Current.Textures.Length; i++)
                {
                    if (ScmapEditor.Current.Textures[i].Albedo != null)
                    {
                        UsedTerrainTexturesMemory.Add(ScmapEditor.Current.Textures[i].Albedo);
                    }
                    if (ScmapEditor.Current.Textures[i].Normal != null)
                    {
                        UsedTerrainTexturesMemory.Add(ScmapEditor.Current.Textures[i].Normal);
                    }
                }


                int count = LoadedTextures.Count;
                for (int i = 0; i < count; i++)
                {
                    if (LoadedTextures[i] != null && !UsedTerrainTexturesMemory.Contains(LoadedTextures[i]))
                    {
                        Destroy(LoadedTextures[i]);
                    }
                }
                UsedTerrainTexturesMemory.Clear();
            }
            else if (LastLoadedType == 1 || LastLoadedType == 2)
            {
                // Decals
                UsedTerrainTexturesMemory.Clear();

                HashSet <Decal.DecalSharedSettings> .Enumerator ListEnum = Decal.AllDecalsShared.GetEnumerator();
                while (ListEnum.MoveNext())
                {
                    Decal.DecalSharedSettings Current = ListEnum.Current;
                    if (Current != null)
                    {
                        if (Current.Texture1)
                        {
                            UsedTerrainTexturesMemory.Add(Current.Texture1);
                        }
                        if (Current.Texture2)
                        {
                            UsedTerrainTexturesMemory.Add(Current.Texture2);
                        }
                    }
                }

                int count = LoadedTextures.Count;
                for (int i = 0; i < count; i++)
                {
                    if (LoadedTextures[i] != null && !UsedTerrainTexturesMemory.Contains(LoadedTextures[i]))
                    {
                        Destroy(LoadedTextures[i]);
                    }
                }
                UsedTerrainTexturesMemory.Clear();
            }
            else if (LastLoadedType == 3)
            {
                int count = LoadedProps.Count;
                for (int i = 0; i < count; i++)
                {
                    for (int l = 0; l < LoadedProps[i].BP.LODs.Length; l++)
                    {
                        if (!GetGamedataFile.IsStoredInMemory(LoadedProps[i].BP.LODs[l].Albedo) && LoadedProps[i].BP.LODs[l].Albedo != Texture2D.whiteTexture)
                        {
                            Destroy(LoadedProps[i].BP.LODs[l].Albedo);
                        }
                        if (!GetGamedataFile.IsStoredInMemory(LoadedProps[i].BP.LODs[l].Normal) && LoadedProps[i].BP.LODs[l].Normal != GetGamedataFile.emptyNormalTexture)
                        {
                            Destroy(LoadedProps[i].BP.LODs[l].Normal);
                        }
                    }
                }
            }

            LoadedTextures.Clear();
            LoadedPaths.Clear();
            LoadedProps.Clear();
        }