Beispiel #1
0
        public T GetLibrary <T>(ScriptableObjectSaveLoadHelper <T> helper, string presetLibraryPathWithoutExtension) where T : ScriptableObject
        {
            LibraryCache presetLibraryCache = this.GetPresetLibraryCache(helper.fileExtensionWithoutDot);

            for (int i = 0; i < presetLibraryCache.loadedLibraryIDs.Count; i++)
            {
                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;
                }
            }
            T item = helper.Load(presetLibraryPathWithoutExtension);

            if (item != null)
            {
                item.hideFlags = this.libraryHideFlag;
                presetLibraryCache.loadedLibraries.Add(item);
                presetLibraryCache.loadedLibraryIDs.Add(presetLibraryPathWithoutExtension);
                return(item);
            }
            return(null);
        }
Beispiel #2
0
        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)
                {
                    s_LastError = $"A library filename cannot contain the following character{(displayStringOfInvalidCharsOfFileName.Length <= 1) ? "" : "s"}:  {displayStringOfInvalidCharsOfFileName}";
                }
                else
                {
                    s_LastError = "Invalid filename";
                }
                return(null);
            }
            if (this.GetLibrary <T>(helper, presetLibraryPathWithoutExtension) != null)
            {
                s_LastError = "Library '" + libaryNameFromPath + "' already exists! Ensure a unique name.";
                return(null);
            }
            T item = helper.Create();

            item.hideFlags = this.libraryHideFlag;
            LibraryCache presetLibraryCache = this.GetPresetLibraryCache(helper.fileExtensionWithoutDot);

            presetLibraryCache.loadedLibraries.Add(item);
            presetLibraryCache.loadedLibraryIDs.Add(presetLibraryPathWithoutExtension);
            s_LastError = null;
            return(item);
        }
Beispiel #3
0
        public T CreateLibrary <T>(ScriptableObjectSaveLoadHelper <T> helper, string presetLibraryPathWithoutExtension) where T : ScriptableObject
        {
            string libraryName = GetLibaryNameFromPath(presetLibraryPathWithoutExtension);

            if (!InternalEditorUtility.IsValidFileName(libraryName))
            {
                string invalid = InternalEditorUtility.GetDisplayStringOfInvalidCharsOfFileName(libraryName);
                if (invalid.Length > 0)
                {
                    s_LastError = string.Format("A library filename cannot contain the following character{0}:  {1}", invalid.Length > 1 ? "s" : "", invalid);
                }
                else
                {
                    s_LastError = "Invalid filename";
                }
                return(null);
            }

            if (GetLibrary(helper, presetLibraryPathWithoutExtension) != null)
            {
                s_LastError = "Library '" + libraryName + "' already exists! Ensure a unique name.";
                return(null);
            }

            T library = helper.Create();

            library.hideFlags = libraryHideFlag;
            LibraryCache set = GetPresetLibraryCache(helper.fileExtensionWithoutDot);

            set.loadedLibraries.Add(library);
            set.loadedLibraryIDs.Add(presetLibraryPathWithoutExtension);
            s_LastError = null;
            return(library);
        }
Beispiel #4
0
        private LibraryCache GetPresetLibraryCache(string identifier)
        {
            foreach (LibraryCache cache in this.m_LibraryCaches)
            {
                if (cache.identifier == identifier)
                {
                    return(cache);
                }
            }
            LibraryCache item = new LibraryCache(identifier);

            this.m_LibraryCaches.Add(item);
            return(item);
        }
Beispiel #5
0
        private LibraryCache GetPresetLibraryCache(string identifier)
        {
            foreach (LibraryCache libraryCache in m_LibraryCaches)
            {
                if (libraryCache.identifier == identifier)
                {
                    return(libraryCache);
                }
            }

            // Add if not found
            LibraryCache set = new LibraryCache(identifier);

            m_LibraryCaches.Add(set);
            return(set);
        }
Beispiel #6
0
        public T GetLibrary <T>(ScriptableObjectSaveLoadHelper <T> helper, string presetLibraryPathWithoutExtension) where T : ScriptableObject
        {
            LibraryCache set = GetPresetLibraryCache(helper.fileExtensionWithoutDot);

            // Did we already load the lib
            for (int i = 0; i < set.loadedLibraryIDs.Count; ++i)
            {
                if (set.loadedLibraryIDs[i] == presetLibraryPathWithoutExtension)
                {
                    if (set.loadedLibraries[i] != null)
                    {
                        return(set.loadedLibraries[i] as T);
                    }
                    else
                    {
                        // The library has been destroyed. Remove it from the lists so it can be reloaded
                        set.loadedLibraries.RemoveAt(i);
                        set.loadedLibraryIDs.RemoveAt(i);
                        Debug.LogError("Invalid library detected: Reload " + set.loadedLibraryIDs[i] + " from HDD");
                        break;
                    }
                }
            }

            // Debug.Log ("Not loaded yet " + typeof(T));

            // Can we find on the hdd
            T library = helper.Load(presetLibraryPathWithoutExtension);

            if (library != null)
            {
                library.hideFlags = libraryHideFlag; // ensure correct hideflag with pre 4.3 versions
                set.loadedLibraries.Add(library);
                set.loadedLibraryIDs.Add(presetLibraryPathWithoutExtension);
                return(library);
            }

            // Debug.Log ("Not found on hdd");

            return(null);
        }