Example #1
0
        private void SaveAsset(string path)
        {
            int assetIndex = path.LastIndexOf(@"Assets");

            if (assetIndex > 0)
            {
                path = path.Remove(0, assetIndex);
            }

            AssetDatabase.DeleteAsset(path);

            SpriteColorRampPreset asset = ScriptableObject.CreateInstance <SpriteColorRampPreset>();

            asset.version               = 1;
            asset.interpolateColors     = interpolateColors;
            asset.sortColorsByLuminance = sortColorsByLuminance;
            asset.presets               = presets.GetRange(0, presets.Count);

            AssetDatabase.CreateAsset(asset, path);

            AssetDatabase.SaveAssets();

            assetChanged = false;

            assetFile = path.Replace(@"Assets/", string.Empty);
            PlayerPrefs.SetString(assetPathKey, assetFile);
        }
Example #2
0
/* Planned for upcoming updates.
 *  private void AddPaletteFromImage()
 *  {
 *    string filePath = EditorUtility.OpenFilePanel(@"Select image", Application.dataPath + "/" + Path.GetDirectoryName(assetFile), "png");
 *    if (string.IsNullOrEmpty(filePath) == false)
 *    {
 *      Texture2D image = SpriteColorFXEditorHelper.LoadTexture(filePath);
 *      if (image != null)
 *      {
 *
 *      }
 *      else
 *        Debug.LogError(string.Format("Error loading '{0}'", filePath));
 *    }
 *  }
 */

        private void LoadAsset(string path)
        {
            int assetIndex = path.LastIndexOf(@"Assets");

            if (assetIndex > 0)
            {
                path = path.Remove(0, assetIndex);
            }

            SpriteColorRampPreset asset = AssetDatabase.LoadAssetAtPath(path, typeof(SpriteColorRampPreset)) as SpriteColorRampPreset;

            if (asset != null)
            {
                if (asset.version == 1)
                {
                    interpolateColors     = asset.interpolateColors;
                    sortColorsByLuminance = asset.sortColorsByLuminance;
                    presets      = asset.presets.GetRange(0, asset.presets.Count);
                    assetChanged = false;

                    assetFile = path.Replace(@"Assets/", string.Empty);
                    PlayerPrefs.SetString(assetPathKey, assetFile);
                }
                else
                {
                    Debug.LogWarning(string.Format("'{0}' unknown version.", path));
                }
            }
            else
            {
                Debug.LogWarning(string.Format("Error loading '{0}'.", path));
            }
        }