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); }
private void InitIfNeeded() { if (ColorPicker.styles == null) { ColorPicker.styles = new ColorPicker.Styles(); } if (this.m_ColorLibraryEditorState == null) { this.m_ColorLibraryEditorState = new PresetLibraryEditorState(ColorPicker.presetsEditorPrefID); this.m_ColorLibraryEditorState.TransferEditorPrefsState(true); } if (this.m_ColorLibraryEditor == null) { ScriptableObjectSaveLoadHelper <ColorPresetLibrary> helper = new ScriptableObjectSaveLoadHelper <ColorPresetLibrary>("colors", SaveType.Text); this.m_ColorLibraryEditor = new PresetLibraryEditor <ColorPresetLibrary>(helper, this.m_ColorLibraryEditorState, new Action <int, object>(this.PresetClickedCallback)); this.m_ColorLibraryEditor.previewAspect = 1f; this.m_ColorLibraryEditor.minMaxPreviewHeight = new Vector2(14f, 14f); this.m_ColorLibraryEditor.settingsMenuRightMargin = 2f; this.m_ColorLibraryEditor.useOnePixelOverlappedGrid = true; this.m_ColorLibraryEditor.alwaysShowScrollAreaHorizontalLines = false; this.m_ColorLibraryEditor.marginsForGrid = new RectOffset(0, 0, 0, 0); this.m_ColorLibraryEditor.marginsForList = new RectOffset(0, 5, 2, 2); this.m_ColorLibraryEditor.InitializeGrid(193f - (float)(ColorPicker.styles.background.padding.left + ColorPicker.styles.background.padding.right)); } }
public GenericPresetLibraryInspector(UnityEngine.Object target, string header, Action <string> editButtonClicked) { m_Target = target; m_Header = header; m_EditButtonClickedCallback = editButtonClicked; string assetPath = AssetDatabase.GetAssetPath(m_Target.GetInstanceID()); string extension = Path.GetExtension(assetPath); if (!string.IsNullOrEmpty(extension)) { extension = extension.TrimStart('.'); } m_SaveLoadHelper = new ScriptableObjectSaveLoadHelper <T>(extension, SaveType.Text); m_Grid = new VerticalGrid(); // Default configuration maxShowNumPresets = 49; // We clear some preview caches when they reach 50 (See AnimationCurvePreviewCache and GradientPreviewCache) presetSize = new Vector2(14, 14); lineSpacing = 1f; useOnePixelOverlappedGrid = false; marginsForList = new RectOffset(10, 10, 5, 5); marginsForGrid = new RectOffset(10, 10, 5, 5); itemViewMode = PresetLibraryEditorState.ItemViewMode.List; }
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)); }
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); }
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); }
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 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); }
public GenericPresetLibraryInspector(UnityEngine.Object target, string header, Action <string> editButtonClicked) { this.m_Target = target; this.m_Header = header; this.m_EditButtonClickedCallback = editButtonClicked; string assetPath = AssetDatabase.GetAssetPath(this.m_Target.GetInstanceID()); string text = Path.GetExtension(assetPath); if (!string.IsNullOrEmpty(text)) { text = text.TrimStart(new char[] { '.' }); } this.m_SaveLoadHelper = new ScriptableObjectSaveLoadHelper <T>(text, SaveType.Text); this.m_Grid = new VerticalGrid(); this.maxShowNumPresets = 49; this.presetSize = new Vector2(14f, 14f); this.lineSpacing = 1f; this.useOnePixelOverlappedGrid = false; this.marginsForList = new RectOffset(10, 10, 5, 5); this.marginsForGrid = new RectOffset(10, 10, 5, 5); this.itemViewMode = PresetLibraryEditorState.ItemViewMode.List; }
public void SaveLibrary <T>(ScriptableObjectSaveLoadHelper <T> helper, T library, string presetLibraryPathWithoutExtension) where T : ScriptableObject { bool flag = File.Exists(presetLibraryPathWithoutExtension + "." + helper.fileExtensionWithoutDot); helper.Save(library, presetLibraryPathWithoutExtension); if (!flag) { AssetDatabase.Refresh(); } }
public void UnloadAllLibrariesFor <T>(ScriptableObjectSaveLoadHelper <T> helper) where T : ScriptableObject { for (int i = 0; i < this.m_LibraryCaches.Count; i++) { if (this.m_LibraryCaches[i].identifier == helper.fileExtensionWithoutDot) { this.m_LibraryCaches[i].UnloadScriptableObjects(); this.m_LibraryCaches.RemoveAt(i); break; } } }
public PresetLibraryEditor(ScriptableObjectSaveLoadHelper <T> helper, PresetLibraryEditorState state, System.Action <int, object> itemClickedCallback) { this.m_SaveLoadHelper = helper; this.m_State = state; this.m_ItemClickedCallback = itemClickedCallback; this.settingsMenuRightMargin = 10f; this.useOnePixelOverlappedGrid = false; this.alwaysShowScrollAreaHorizontalLines = true; this.marginsForList = new RectOffset(10, 10, 5, 5); this.marginsForGrid = new RectOffset(5, 5, 5, 5); this.m_PresetLibraryFileLocation = PresetLibraryLocations.GetFileLocationFromPath(this.currentLibraryWithoutExtension); }
public void InitIfNeeded() { if (this.m_CurveLibraryEditorState == null) { this.m_CurveLibraryEditorState = new PresetLibraryEditorState(this.GetEditorPrefBaseName()); this.m_CurveLibraryEditorState.TransferEditorPrefsState(true); } if (this.m_CurveLibraryEditor == null) { ScriptableObjectSaveLoadHelper <DoubleCurvePresetLibrary> helper = new ScriptableObjectSaveLoadHelper <DoubleCurvePresetLibrary>(PresetLibraryLocations.GetParticleCurveLibraryExtension(this.m_DoubleCurve.IsSingleCurve(), this.m_DoubleCurve.signedRange), SaveType.Text); this.m_CurveLibraryEditor = new PresetLibraryEditor <DoubleCurvePresetLibrary>(helper, this.m_CurveLibraryEditorState, new Action <int, object>(this.ItemClickedCallback)); this.m_CurveLibraryEditor.addDefaultPresets = (Action <PresetLibrary>)Delegate.Combine(this.m_CurveLibraryEditor.addDefaultPresets, new Action <PresetLibrary>(this.AddDefaultPresetsToLibrary)); this.m_CurveLibraryEditor.presetsWasReordered = new Action(this.PresetsWasReordered); this.m_CurveLibraryEditor.previewAspect = 4f; this.m_CurveLibraryEditor.minMaxPreviewHeight = new Vector2(24f, 24f); this.m_CurveLibraryEditor.showHeader = true; } }
public PresetLibraryEditor(ScriptableObjectSaveLoadHelper <T> helper, PresetLibraryEditorState state, Action <int, object> itemClickedCallback) { this.m_DragState = new DragState <T>(); this.m_Grid = new VerticalGrid(); this.m_MinMaxPreviewHeight = new Vector2(14f, 64f); this.m_PreviewAspect = 8f; this.m_ShowAddNewPresetItem = true; this.m_IsOpenForEdit = true; this.m_SaveLoadHelper = helper; this.m_State = state; this.m_ItemClickedCallback = itemClickedCallback; this.settingsMenuRightMargin = 10f; this.useOnePixelOverlappedGrid = false; this.alwaysShowScrollAreaHorizontalLines = true; this.marginsForList = new RectOffset(10, 10, 5, 5); this.marginsForGrid = new RectOffset(5, 5, 5, 5); this.m_PresetLibraryFileLocation = PresetLibraryLocations.GetFileLocationFromPath(this.currentLibraryWithoutExtension); }
public void InitIfNeeded() { if (this.m_CurveLibraryEditorState == null) { this.m_CurveLibraryEditorState = new PresetLibraryEditorState(GetBasePrefText(this.m_CurveLibraryType)); this.m_CurveLibraryEditorState.TransferEditorPrefsState(true); } if (this.m_CurveLibraryEditor == null) { ScriptableObjectSaveLoadHelper <CurvePresetLibrary> helper = new ScriptableObjectSaveLoadHelper <CurvePresetLibrary>(GetExtension(this.m_CurveLibraryType), SaveType.Text); this.m_CurveLibraryEditor = new PresetLibraryEditor <CurvePresetLibrary>(helper, this.m_CurveLibraryEditorState, new Action <int, object>(this.ItemClickedCallback)); this.m_CurveLibraryEditor.addDefaultPresets = (Action <PresetLibrary>)Delegate.Combine(this.m_CurveLibraryEditor.addDefaultPresets, new Action <PresetLibrary>(this.AddDefaultPresetsToLibrary)); this.m_CurveLibraryEditor.presetsWasReordered = (Action)Delegate.Combine(this.m_CurveLibraryEditor.presetsWasReordered, new Action(this.OnPresetsWasReordered)); this.m_CurveLibraryEditor.previewAspect = 4f; this.m_CurveLibraryEditor.minMaxPreviewHeight = new Vector2(24f, 24f); this.m_CurveLibraryEditor.showHeader = true; } }
public void InitIfNeeded() { if (m_CurveLibraryEditorState == null) { m_CurveLibraryEditorState = new PresetLibraryEditorState(GetBasePrefText(m_CurveLibraryType)); m_CurveLibraryEditorState.TransferEditorPrefsState(true); } if (m_CurveLibraryEditor == null) { var saveLoadHelper = new ScriptableObjectSaveLoadHelper <CurvePresetLibrary>(GetExtension(m_CurveLibraryType), SaveType.Text); m_CurveLibraryEditor = new PresetLibraryEditor <CurvePresetLibrary>(saveLoadHelper, m_CurveLibraryEditorState, ItemClickedCallback); m_CurveLibraryEditor.addDefaultPresets += AddDefaultPresetsToLibrary; m_CurveLibraryEditor.presetsWasReordered += OnPresetsWasReordered; m_CurveLibraryEditor.previewAspect = 4f; m_CurveLibraryEditor.minMaxPreviewHeight = new Vector2(24f, 24f); m_CurveLibraryEditor.showHeader = true; } }
private void InitIfNeeded() { if (this.m_GradientEditor == null) { this.m_GradientEditor = new GradientEditor(); this.m_GradientEditor.Init(this.m_Gradient, 0); } if (this.m_GradientLibraryEditorState == null) { this.m_GradientLibraryEditorState = new PresetLibraryEditorState(GradientPicker.presetsEditorPrefID); this.m_GradientLibraryEditorState.TransferEditorPrefsState(true); } if (this.m_GradientLibraryEditor == null) { ScriptableObjectSaveLoadHelper <GradientPresetLibrary> helper = new ScriptableObjectSaveLoadHelper <GradientPresetLibrary>("gradients", SaveType.Text); this.m_GradientLibraryEditor = new PresetLibraryEditor <GradientPresetLibrary>(helper, this.m_GradientLibraryEditorState, new Action <int, object>(this.PresetClickedCallback)); this.m_GradientLibraryEditor.showHeader = true; this.m_GradientLibraryEditor.minMaxPreviewHeight = new Vector2(14f, 14f); } }
public void InitIfNeeded() { if (m_CurveLibraryEditorState == null) { m_CurveLibraryEditorState = new PresetLibraryEditorState(GetEditorPrefBaseName()); m_CurveLibraryEditorState.TransferEditorPrefsState(true); } if (m_CurveLibraryEditor == null) { var extension = PresetLibraryLocations.GetParticleCurveLibraryExtension(m_DoubleCurve.IsSingleCurve(), m_DoubleCurve.signedRange); var saveLoadHelper = new ScriptableObjectSaveLoadHelper <DoubleCurvePresetLibrary>(extension, SaveType.Text); m_CurveLibraryEditor = new PresetLibraryEditor <DoubleCurvePresetLibrary>(saveLoadHelper, m_CurveLibraryEditorState, ItemClickedCallback); m_CurveLibraryEditor.addDefaultPresets += AddDefaultPresetsToLibrary; m_CurveLibraryEditor.presetsWasReordered = PresetsWasReordered; m_CurveLibraryEditor.previewAspect = 4f; m_CurveLibraryEditor.minMaxPreviewHeight = new Vector2(24f, 24f); m_CurveLibraryEditor.showHeader = true; } }
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); }
void InitIfNeeded() { // Init editor when needed if (m_GradientEditor == null) { m_GradientEditor = new GradientEditor(); m_GradientEditor.Init(m_Gradient, k_DefaultNumSteps, m_HDR); } if (m_GradientLibraryEditorState == null) { m_GradientLibraryEditorState = new PresetLibraryEditorState(presetsEditorPrefID); m_GradientLibraryEditorState.TransferEditorPrefsState(true); } if (m_GradientLibraryEditor == null) { var saveLoadHelper = new ScriptableObjectSaveLoadHelper <GradientPresetLibrary>("gradients", SaveType.Text); m_GradientLibraryEditor = new PresetLibraryEditor <GradientPresetLibrary>(saveLoadHelper, m_GradientLibraryEditorState, PresetClickedCallback); m_GradientLibraryEditor.showHeader = true; m_GradientLibraryEditor.minMaxPreviewHeight = new Vector2(14f, 14f); } }
public GenericPresetLibraryInspector(Object target, string header, Action <string> editButtonClicked) { this.m_LastRepaintedWidth = -1f; this.m_Target = target; this.m_Header = header; this.m_EditButtonClickedCallback = editButtonClicked; string extension = Path.GetExtension(AssetDatabase.GetAssetPath(this.m_Target.GetInstanceID())); if (!string.IsNullOrEmpty(extension)) { char[] trimChars = new char[] { '.' }; extension = extension.TrimStart(trimChars); } this.m_SaveLoadHelper = new ScriptableObjectSaveLoadHelper <T>(extension, SaveType.Text); this.m_Grid = new VerticalGrid(); this.maxShowNumPresets = 0x31; this.presetSize = new Vector2(14f, 14f); this.lineSpacing = 1f; this.useOnePixelOverlappedGrid = false; this.marginsForList = new RectOffset(10, 10, 5, 5); this.marginsForGrid = new RectOffset(10, 10, 5, 5); this.itemViewMode = PresetLibraryEditorState.ItemViewMode.List; }
public PresetLibraryGradientEditor(ScriptableObjectSaveLoadHelper <GradientPresetLibrary> helper, PresetLibraryEditorState state, System.Action <int, object> itemClickedCallback ) : base(helper, state, itemClickedCallback) { }
public void GetAvailableLibraries <T>(ScriptableObjectSaveLoadHelper <T> helper, out List <string> preferencesLibs, out List <string> projectLibs) where T : ScriptableObject { preferencesLibs = PresetLibraryLocations.GetAvailableFilesWithExtensionOnTheHDD(PresetFileLocation.PreferencesFolder, helper.fileExtensionWithoutDot); projectLibs = PresetLibraryLocations.GetAvailableFilesWithExtensionOnTheHDD(PresetFileLocation.ProjectFolder, helper.fileExtensionWithoutDot); }