-
-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Coffee.UIExtensions | ||
{ | ||
/// <summary> | ||
/// Blur effect mode. | ||
/// </summary> | ||
public enum BlurMode | ||
{ | ||
None = 0, | ||
FastBlur = 1, | ||
MediumBlur = 2, | ||
DetailBlur = 3, | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Coffee.UIExtensions | ||
{ | ||
/// <summary> | ||
/// Color effect mode. | ||
/// </summary> | ||
public enum ColorMode | ||
{ | ||
Multiply = 0, | ||
Fill = 1, | ||
Add = 2, | ||
Subtract = 3, | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#if UNITY_EDITOR | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Coffee.UIExtensions | ||
{ | ||
public class MaterialResolver | ||
{ | ||
static readonly StringBuilder s_StringBuilder = new StringBuilder (); | ||
|
||
public static Material GetOrGenerateMaterialVariant (Shader shader, params object[] append) | ||
{ | ||
if (!shader) { | ||
return null; | ||
} | ||
|
||
string[] keywords = append.Where (x => 0 < (int)x) | ||
.Select (x => x.ToString ().ToUpper ()) | ||
.ToArray (); | ||
Material mat = GetMaterial (shader, append); | ||
if (mat) { | ||
if(!mat.shaderKeywords.OrderBy(x=>x).SequenceEqual(keywords.OrderBy(x=>x))) | ||
{ | ||
mat.shaderKeywords = keywords; | ||
EditorUtility.SetDirty (mat); | ||
if (!Application.isPlaying) | ||
{ | ||
EditorApplication.delayCall += AssetDatabase.SaveAssets; | ||
} | ||
} | ||
return mat; | ||
} | ||
|
||
var variantName = GetVariantName (shader, append); | ||
Debug.Log ("Generate material : " + variantName); | ||
mat = new Material (shader); | ||
mat.shaderKeywords = keywords; | ||
|
||
mat.name = variantName; | ||
mat.hideFlags |= HideFlags.NotEditable; | ||
|
||
#if UIEFFECT_SEPARATE | ||
string dir = Path.GetDirectoryName(GetDefaultMaterialPath (shader)); | ||
string materialPath = Path.Combine(Path.Combine(dir, "Separated"), mat.name + ".mat"); | ||
|
||
Directory.CreateDirectory (Path.GetDirectoryName (materialPath)); | ||
AssetDatabase.CreateAsset (mat, materialPath); | ||
AssetDatabase.SaveAssets (); | ||
#else | ||
if (append.Cast<int> ().All (x => x == 0)) { | ||
string materialPath = GetDefaultMaterialPath (shader); | ||
Directory.CreateDirectory (Path.GetDirectoryName (materialPath)); | ||
AssetDatabase.CreateAsset (mat, materialPath); | ||
AssetDatabase.SaveAssets (); | ||
} else { | ||
GetOrGenerateMaterialVariant (shader); | ||
string materialPath = GetDefaultMaterialPath (shader); | ||
mat.hideFlags |= HideFlags.HideInHierarchy; | ||
AssetDatabase.AddObjectToAsset (mat, materialPath); | ||
} | ||
#endif | ||
return mat; | ||
} | ||
|
||
public static Material GetMaterial (Shader shader, params object[] append) | ||
{ | ||
string variantName = GetVariantName (shader, append); | ||
return AssetDatabase.FindAssets ("t:Material " + Path.GetFileName (shader.name)) | ||
.Select (x => AssetDatabase.GUIDToAssetPath (x)) | ||
.SelectMany (x => AssetDatabase.LoadAllAssetsAtPath (x)) | ||
.OfType<Material> () | ||
.FirstOrDefault (x => x.name == variantName); | ||
} | ||
|
||
public static string GetDefaultMaterialPath (Shader shader) | ||
{ | ||
var name = Path.GetFileName (shader.name); | ||
return AssetDatabase.FindAssets ("t:Material " + name) | ||
.Select (x => AssetDatabase.GUIDToAssetPath (x)) | ||
.FirstOrDefault (x => Path.GetFileNameWithoutExtension (x) == name) | ||
?? ("Assets/" + name + ".mat"); | ||
} | ||
|
||
public static string GetVariantName (Shader shader, params object[] append) | ||
{ | ||
s_StringBuilder.Length = 0; | ||
|
||
#if UIEFFECT_SEPARATE | ||
s_StringBuilder.Append("[Separated] "); | ||
#endif | ||
s_StringBuilder.Append (Path.GetFileName (shader.name)); | ||
foreach (object mode in append.Where(x=>0<(int)x)) { | ||
s_StringBuilder.Append ("-"); | ||
s_StringBuilder.Append (mode.ToString ()); | ||
} | ||
return s_StringBuilder.ToString (); | ||
} | ||
} | ||
} | ||
#endif |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Coffee.UIExtensions | ||
{ | ||
/// <summary> | ||
/// Shadow effect style. | ||
/// </summary> | ||
public enum ShadowStyle | ||
{ | ||
None = 0, | ||
Shadow, | ||
Outline, | ||
Outline8, | ||
Shadow3, | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Coffee.UIExtensions | ||
{ | ||
/// <summary> | ||
/// Effect mode. | ||
/// </summary> | ||
public enum ToneMode | ||
{ | ||
None = 0, | ||
Grayscale = 1, | ||
Sepia = 2, | ||
Nega = 3, | ||
Pixel = 4, | ||
Mono = 5, | ||
Cutoff = 6, | ||
Hue = 7, | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.