/* #region CONTEXT MENU METHODS * [ContextMenu( "Build SwatchPalette None" )] * public void BuildColorSwatch_None() { BuildSwatchPalette( SwatchSortMode.None ); } * * [ContextMenu( "Build SwatchPalette Ascending" )] * public void BuildColorSwatch_Ascending() { BuildSwatchPalette( SwatchSortMode.Ascending ); } * * [ContextMenu( "Build SwatchPalette Descending" )] * public void BuildColorSwatch_Descending() { BuildSwatchPalette( SwatchSortMode.Descending ); } * * [ContextMenu( "Build SwatchPalette RGB MaxDifference" )] * public void BuildColorSwatch_MaxDifferenceRGB() { BuildSwatchPalette( SwatchSortMode.MaxDifferenceRGB ); } * * [ContextMenu( "Build SwatchPalette HSV MaxDifference" )] * public void BuildColorSwatch_MaxDifferenceHSV() { BuildSwatchPalette( SwatchSortMode.MaxDifferenceHSV ); } #endregion */ #if UNITY_EDITOR public void BuildSwatchPalette(SwatchSortMode swatchSortMode) { ColorSwatchPalette colorSwatchPalette = CreateColorSwatchAsset(); if (null == colorSwatchPalette) { Debug.LogError("Unable to create ColorSwatchPalette asset"); return; } // Get Colors from texture Color[] srcSwatches = GetColorsFromTextureSwatch(); // Apply sort mode switch (swatchSortMode) { case SwatchSortMode.Ascending: SortByLinq(srcSwatches, swatchSortMode); break; case SwatchSortMode.Descending: SortByLinq(srcSwatches, swatchSortMode); break; case SwatchSortMode.MaxDifferenceRGB: SortByMaxDiffRGB(srcSwatches); break; case SwatchSortMode.MaxDifferenceHSV: SortByMaxDiffHSV(srcSwatches); break; } // Put colors into asset colorSwatchPalette.m_SwatchColors = srcSwatches; // Save Asset SaveUpdatedAssets(colorSwatchPalette); }
ColorSwatchPalette CreateColorSwatchAsset() { string lastpath = EditorPrefs.GetString("NoiseCrimeStudiosLastPath", ""); if (string.IsNullOrEmpty(lastpath)) { lastpath = Application.dataPath + "/assets"; } string filePath = EditorUtility.SaveFilePanelInProject("Save ColorSwatchPalette", "ColorSwatchPalette", "asset", "", lastpath); if (string.IsNullOrEmpty(filePath)) { return(null); } EditorPrefs.SetString("NoiseCrimeStudiosLastPath", System.IO.Path.GetDirectoryName(filePath)); ColorSwatchPalette colorSwatchPalette = (ColorSwatchPalette)ScriptableObject.CreateInstance(typeof(ColorSwatchPalette)); AssetDatabase.CreateAsset(colorSwatchPalette, filePath); AssetDatabase.SaveAssets(); return(colorSwatchPalette); }
void SaveUpdatedAssets(ColorSwatchPalette colorSwatchPalette) { EditorUtility.SetDirty(colorSwatchPalette); AssetDatabase.SaveAssets(); }