public T CreateLibrary <T>(ScriptableObjectSaveLoadHelper <T> helper, string presetLibraryPathWithoutExtension) where T : ScriptableObject
        {
            string libaryNameFromPath = this.GetLibaryNameFromPath(presetLibraryPathWithoutExtension);

            if (!InternalEditorUtility.IsValidFileName(libaryNameFromPath))
            {
                string displayStringOfInvalidCharsOfFileName = InternalEditorUtility.GetDisplayStringOfInvalidCharsOfFileName(libaryNameFromPath);
                if (displayStringOfInvalidCharsOfFileName.Length > 0)
                {
                    PresetLibraryManager.s_LastError = string.Format("A library filename cannot contain the following character{0}:  {1}", (displayStringOfInvalidCharsOfFileName.Length <= 1) ? string.Empty : "s", displayStringOfInvalidCharsOfFileName);
                }
                else
                {
                    PresetLibraryManager.s_LastError = "Invalid filename";
                }
                return((T)((object)null));
            }
            if (this.GetLibrary <T>(helper, presetLibraryPathWithoutExtension) != null)
            {
                PresetLibraryManager.s_LastError = "Library '" + libaryNameFromPath + "' already exists! Ensure a unique name.";
                return((T)((object)null));
            }
            T t = helper.Create();

            t.hideFlags = this.libraryHideFlag;
            PresetLibraryManager.LibraryCache presetLibraryCache = this.GetPresetLibraryCache(helper.fileExtensionWithoutDot);
            presetLibraryCache.loadedLibraries.Add(t);
            presetLibraryCache.loadedLibraryIDs.Add(presetLibraryPathWithoutExtension);
            PresetLibraryManager.s_LastError = null;
            return(t);
        }
Exemple #2
0
        public T GetLibrary <T>(ScriptableObjectSaveLoadHelper <T> helper, string presetLibraryPathWithoutExtension) where T : ScriptableObject
        {
            PresetLibraryManager.LibraryCache presetLibraryCache = this.GetPresetLibraryCache(helper.fileExtensionWithoutDot);
            for (int index = 0; index < presetLibraryCache.loadedLibraryIDs.Count; ++index)
            {
                if (presetLibraryCache.loadedLibraryIDs[index] == presetLibraryPathWithoutExtension)
                {
                    if ((Object)presetLibraryCache.loadedLibraries[index] != (Object)null)
                    {
                        return(presetLibraryCache.loadedLibraries[index] as T);
                    }
                    presetLibraryCache.loadedLibraries.RemoveAt(index);
                    presetLibraryCache.loadedLibraryIDs.RemoveAt(index);
                    Debug.LogError((object)("Invalid library detected: Reload " + presetLibraryCache.loadedLibraryIDs[index] + " from HDD"));
                    break;
                }
            }
            T obj = helper.Load(presetLibraryPathWithoutExtension);

            if (!((Object)obj != (Object)null))
            {
                return((T)null);
            }
            obj.hideFlags = this.libraryHideFlag;
            presetLibraryCache.loadedLibraries.Add((ScriptableObject)obj);
            presetLibraryCache.loadedLibraryIDs.Add(presetLibraryPathWithoutExtension);
            return(obj);
        }
        public T GetLibrary <T>(ScriptableObjectSaveLoadHelper <T> helper, string presetLibraryPathWithoutExtension) where T : ScriptableObject
        {
            PresetLibraryManager.LibraryCache presetLibraryCache = this.GetPresetLibraryCache(helper.fileExtensionWithoutDot);
            int i = 0;

            while (i < presetLibraryCache.loadedLibraryIDs.Count)
            {
                if (presetLibraryCache.loadedLibraryIDs[i] == presetLibraryPathWithoutExtension)
                {
                    if (presetLibraryCache.loadedLibraries[i] != null)
                    {
                        return(presetLibraryCache.loadedLibraries[i] as T);
                    }
                    presetLibraryCache.loadedLibraries.RemoveAt(i);
                    presetLibraryCache.loadedLibraryIDs.RemoveAt(i);
                    Debug.LogError("Invalid library detected: Reload " + presetLibraryCache.loadedLibraryIDs[i] + " from HDD");
                    break;
                }
                else
                {
                    i++;
                }
            }
            T t = helper.Load(presetLibraryPathWithoutExtension);

            if (t != null)
            {
                t.hideFlags = this.libraryHideFlag;
                presetLibraryCache.loadedLibraries.Add(t);
                presetLibraryCache.loadedLibraryIDs.Add(presetLibraryPathWithoutExtension);
                return(t);
            }
            return((T)((object)null));
        }
 private PresetLibraryManager.LibraryCache GetPresetLibraryCache(string identifier)
 {
     foreach (PresetLibraryManager.LibraryCache current in this.m_LibraryCaches)
     {
         if (current.identifier == identifier)
         {
             return(current);
         }
     }
     PresetLibraryManager.LibraryCache libraryCache = new PresetLibraryManager.LibraryCache(identifier);
     this.m_LibraryCaches.Add(libraryCache);
     return(libraryCache);
 }
Exemple #5
0
 private PresetLibraryManager.LibraryCache GetPresetLibraryCache(string identifier)
 {
     using (List <PresetLibraryManager.LibraryCache> .Enumerator enumerator = this.m_LibraryCaches.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             PresetLibraryManager.LibraryCache current = enumerator.Current;
             if (current.identifier == identifier)
             {
                 return(current);
             }
         }
     }
     PresetLibraryManager.LibraryCache libraryCache = new PresetLibraryManager.LibraryCache(identifier);
     this.m_LibraryCaches.Add(libraryCache);
     return(libraryCache);
 }