update
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e5f9d4ace3c305419ac88a619fa7aab
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5cd6fed3b96daa344899e175f5b7ad6f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(fileName = "GradientTexture", menuName = "Gradient Texture", order = 310)]
|
||||
public class GradientTexture : ScriptableObject
|
||||
{
|
||||
[Delayed]
|
||||
public int width = 64;
|
||||
|
||||
public List<Gradient> gradients = new List<Gradient>();
|
||||
private Texture2D _texture;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if(_texture == null && gradients.Count > 0)
|
||||
Generate();
|
||||
}
|
||||
|
||||
[ContextMenu("Generate")]
|
||||
private void Generate()
|
||||
{
|
||||
// create texture that is width x gradients.Count
|
||||
// for each gradient, draw a line from left to right with the gradient
|
||||
// save to disk
|
||||
|
||||
if(_texture != null)
|
||||
DestroyImmediate(_texture);
|
||||
_texture = new Texture2D(width, gradients.Count)
|
||||
{
|
||||
name = name
|
||||
};
|
||||
|
||||
for (int i = 0; i < gradients.Count; i++)
|
||||
{
|
||||
var gradient = gradients[i];
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
var color = gradient.Evaluate((float)x / width);
|
||||
_texture.SetPixel(x, i, color);
|
||||
}
|
||||
}
|
||||
_texture.Apply();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// delayed call to save the icon
|
||||
UnityEditor.EditorApplication.delayCall += SaveIcon;
|
||||
#endif
|
||||
}
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
if(gradients.Count > 0)
|
||||
Generate();
|
||||
}
|
||||
|
||||
[ContextMenu("Save")]
|
||||
private void SaveToDisk()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// save to disk the texture using the AssetDatabase API
|
||||
var path = UnityEditor.AssetDatabase.GetAssetPath(this);
|
||||
path = path.Replace(".asset", ".png");
|
||||
var bytes = _texture.EncodeToPNG();
|
||||
System.IO.File.WriteAllBytes(path, bytes);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
private void SaveIcon()
|
||||
{
|
||||
// use _texture as the icon for this object
|
||||
var path = UnityEditor.AssetDatabase.GetAssetPath(this);
|
||||
|
||||
// add as sub asset or replace existing
|
||||
var icon = UnityEditor.AssetDatabase.LoadAssetAtPath<Texture2D>(path);
|
||||
|
||||
if (icon == null)
|
||||
{
|
||||
if(_texture != null)
|
||||
{
|
||||
UnityEditor.AssetDatabase.AddObjectToAsset(_texture, this);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(_texture != null)
|
||||
{
|
||||
UnityEditor.EditorUtility.CopySerialized(_texture, icon);
|
||||
}
|
||||
}
|
||||
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f05a51f4cf024800962869cda1090f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29b68e1eacecd4849b13b6a06c1bb2c2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b98a9ecd5b917a246a06c2a79eb1d9e5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7c4a6308fa963d41ac657519444f353
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3a4b2cf5769c60479760f27e2daf0e6
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3}
|
||||
Reference in New Issue
Block a user