Stable version
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "CFXREditor",
|
||||
"references": [],
|
||||
"optionalUnityReferences": [],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": []
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb5cb7c323a395242a81960087292f3c
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,66 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEditor.Rendering;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine;
|
||||
|
||||
namespace CartoonFX
|
||||
{
|
||||
class CFXR_BuildShaderPreprocessor : IPreprocessShaders, IPreprocessBuildWithReport, IPostprocessBuildWithReport
|
||||
{
|
||||
static int shaderVariantsRemoved;
|
||||
static bool isUsingURP;
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------------------
|
||||
// IPreprocessBuildWithReport, IPostprocessBuildWithReport
|
||||
|
||||
public void OnPreprocessBuild(BuildReport report)
|
||||
{
|
||||
// Figure out if we're using built-in or URP
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
var renderPipeline = GraphicsSettings.currentRenderPipeline;
|
||||
#else
|
||||
var renderPipeline = GraphicsSettings.renderPipelineAsset;
|
||||
#endif
|
||||
isUsingURP = renderPipeline != null && renderPipeline.GetType().Name.Contains("Universal");
|
||||
shaderVariantsRemoved = 0;
|
||||
}
|
||||
|
||||
public void OnPostprocessBuild(BuildReport report)
|
||||
{
|
||||
if (shaderVariantsRemoved > 0)
|
||||
{
|
||||
string currentPipeline = isUsingURP ? "Universal" : "Built-in";
|
||||
Debug.Log(string.Format("<color=#ec7d38>[Cartoon FX Remaster]</color> {0} Render Pipeline detected, {1} Shader variants have been stripped from the build.", currentPipeline, shaderVariantsRemoved));
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------------------
|
||||
// IPreprocessShaders
|
||||
|
||||
public int callbackOrder
|
||||
{
|
||||
get { return 1000; }
|
||||
}
|
||||
|
||||
public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList<ShaderCompilerData> shaderCompilerData)
|
||||
{
|
||||
if (snippet.passType == PassType.ShadowCaster)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (shader.name.Contains("Cartoon FX/Remaster"))
|
||||
{
|
||||
// Strip Cartoon FX Remaster Shader variants based on current render pipeline
|
||||
if ((isUsingURP && snippet.passType != PassType.ScriptableRenderPipeline) ||
|
||||
(!isUsingURP && snippet.passType == PassType.ScriptableRenderPipeline))
|
||||
{
|
||||
shaderVariantsRemoved += shaderCompilerData.Count;
|
||||
shaderCompilerData.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00a9608d23679304bbbcf63f569012f8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,275 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------
|
||||
// Cartoon FX
|
||||
// (c) 2012-2020 Jean Moreno
|
||||
//--------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
// Parse conditional expressions from CFXR_MaterialInspector to show/hide some parts of the UI easily
|
||||
|
||||
namespace CartoonFX
|
||||
{
|
||||
public static class ExpressionParser
|
||||
{
|
||||
public delegate bool EvaluateFunction(string content);
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------------
|
||||
// Main Function to use
|
||||
|
||||
static public bool EvaluateExpression(string expression, EvaluateFunction evalFunction)
|
||||
{
|
||||
//Remove white spaces and double && ||
|
||||
string cleanExpr = "";
|
||||
for(int i = 0; i < expression.Length; i++)
|
||||
{
|
||||
switch(expression[i])
|
||||
{
|
||||
case ' ': break;
|
||||
case '&': cleanExpr += expression[i]; i++; break;
|
||||
case '|': cleanExpr += expression[i]; i++; break;
|
||||
default: cleanExpr += expression[i]; break;
|
||||
}
|
||||
}
|
||||
|
||||
List<Token> tokens = new List<Token>();
|
||||
StringReader reader = new StringReader(cleanExpr);
|
||||
Token t = null;
|
||||
do
|
||||
{
|
||||
t = new Token(reader);
|
||||
tokens.Add(t);
|
||||
} while(t.type != Token.TokenType.EXPR_END);
|
||||
|
||||
List<Token> polishNotation = Token.TransformToPolishNotation(tokens);
|
||||
|
||||
var enumerator = polishNotation.GetEnumerator();
|
||||
enumerator.MoveNext();
|
||||
Expression root = MakeExpression(ref enumerator, evalFunction);
|
||||
|
||||
return root.Evaluate();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------------
|
||||
// Expression Token
|
||||
|
||||
public class Token
|
||||
{
|
||||
static Dictionary<char, KeyValuePair<TokenType, string>> typesDict = new Dictionary<char, KeyValuePair<TokenType, string>>()
|
||||
{
|
||||
{'(', new KeyValuePair<TokenType, string>(TokenType.OPEN_PAREN, "(")},
|
||||
{')', new KeyValuePair<TokenType, string>(TokenType.CLOSE_PAREN, ")")},
|
||||
{'!', new KeyValuePair<TokenType, string>(TokenType.UNARY_OP, "NOT")},
|
||||
{'&', new KeyValuePair<TokenType, string>(TokenType.BINARY_OP, "AND")},
|
||||
{'|', new KeyValuePair<TokenType, string>(TokenType.BINARY_OP, "OR")}
|
||||
};
|
||||
|
||||
public enum TokenType
|
||||
{
|
||||
OPEN_PAREN,
|
||||
CLOSE_PAREN,
|
||||
UNARY_OP,
|
||||
BINARY_OP,
|
||||
LITERAL,
|
||||
EXPR_END
|
||||
}
|
||||
|
||||
public TokenType type;
|
||||
public string value;
|
||||
|
||||
public Token(StringReader s)
|
||||
{
|
||||
int c = s.Read();
|
||||
if(c == -1)
|
||||
{
|
||||
type = TokenType.EXPR_END;
|
||||
value = "";
|
||||
return;
|
||||
}
|
||||
|
||||
char ch = (char)c;
|
||||
|
||||
//Special case: solve bug where !COND_FALSE_1 && COND_FALSE_2 would return True
|
||||
bool embeddedNot = (ch == '!' && s.Peek() != '(');
|
||||
|
||||
if(typesDict.ContainsKey(ch) && !embeddedNot)
|
||||
{
|
||||
type = typesDict[ch].Key;
|
||||
value = typesDict[ch].Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
string str = "";
|
||||
str += ch;
|
||||
while(s.Peek() != -1 && !typesDict.ContainsKey((char)s.Peek()))
|
||||
{
|
||||
str += (char)s.Read();
|
||||
}
|
||||
type = TokenType.LITERAL;
|
||||
value = str;
|
||||
}
|
||||
}
|
||||
|
||||
static public List<Token> TransformToPolishNotation(List<Token> infixTokenList)
|
||||
{
|
||||
Queue<Token> outputQueue = new Queue<Token>();
|
||||
Stack<Token> stack = new Stack<Token>();
|
||||
|
||||
int index = 0;
|
||||
while(infixTokenList.Count > index)
|
||||
{
|
||||
Token t = infixTokenList[index];
|
||||
|
||||
switch(t.type)
|
||||
{
|
||||
case Token.TokenType.LITERAL:
|
||||
outputQueue.Enqueue(t);
|
||||
break;
|
||||
case Token.TokenType.BINARY_OP:
|
||||
case Token.TokenType.UNARY_OP:
|
||||
case Token.TokenType.OPEN_PAREN:
|
||||
stack.Push(t);
|
||||
break;
|
||||
case Token.TokenType.CLOSE_PAREN:
|
||||
while(stack.Peek().type != Token.TokenType.OPEN_PAREN)
|
||||
{
|
||||
outputQueue.Enqueue(stack.Pop());
|
||||
}
|
||||
stack.Pop();
|
||||
if(stack.Count > 0 && stack.Peek().type == Token.TokenType.UNARY_OP)
|
||||
{
|
||||
outputQueue.Enqueue(stack.Pop());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
while(stack.Count > 0)
|
||||
{
|
||||
outputQueue.Enqueue(stack.Pop());
|
||||
}
|
||||
|
||||
var list = new List<Token>(outputQueue);
|
||||
list.Reverse();
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------------
|
||||
// Boolean Expression Classes
|
||||
|
||||
public abstract class Expression
|
||||
{
|
||||
public abstract bool Evaluate();
|
||||
}
|
||||
|
||||
public class ExpressionLeaf : Expression
|
||||
{
|
||||
private string content;
|
||||
private EvaluateFunction evalFunction;
|
||||
|
||||
public ExpressionLeaf(EvaluateFunction _evalFunction, string _content)
|
||||
{
|
||||
this.evalFunction = _evalFunction;
|
||||
this.content = _content;
|
||||
}
|
||||
|
||||
override public bool Evaluate()
|
||||
{
|
||||
//embedded not, see special case in Token declaration
|
||||
if(content.StartsWith("!"))
|
||||
{
|
||||
return !this.evalFunction(content.Substring(1));
|
||||
}
|
||||
|
||||
return this.evalFunction(content);
|
||||
}
|
||||
}
|
||||
|
||||
public class ExpressionAnd : Expression
|
||||
{
|
||||
private Expression left;
|
||||
private Expression right;
|
||||
|
||||
public ExpressionAnd(Expression _left, Expression _right)
|
||||
{
|
||||
this.left = _left;
|
||||
this.right = _right;
|
||||
}
|
||||
|
||||
override public bool Evaluate()
|
||||
{
|
||||
return left.Evaluate() && right.Evaluate();
|
||||
}
|
||||
}
|
||||
|
||||
public class ExpressionOr : Expression
|
||||
{
|
||||
private Expression left;
|
||||
private Expression right;
|
||||
|
||||
public ExpressionOr(Expression _left, Expression _right)
|
||||
{
|
||||
this.left = _left;
|
||||
this.right = _right;
|
||||
}
|
||||
|
||||
override public bool Evaluate()
|
||||
{
|
||||
return left.Evaluate() || right.Evaluate();
|
||||
}
|
||||
}
|
||||
|
||||
public class ExpressionNot : Expression
|
||||
{
|
||||
private Expression expr;
|
||||
|
||||
public ExpressionNot(Expression _expr)
|
||||
{
|
||||
this.expr = _expr;
|
||||
}
|
||||
|
||||
override public bool Evaluate()
|
||||
{
|
||||
return !expr.Evaluate();
|
||||
}
|
||||
}
|
||||
|
||||
static public Expression MakeExpression(ref List<Token>.Enumerator polishNotationTokensEnumerator, EvaluateFunction _evalFunction)
|
||||
{
|
||||
if(polishNotationTokensEnumerator.Current.type == Token.TokenType.LITERAL)
|
||||
{
|
||||
Expression lit = new ExpressionLeaf(_evalFunction, polishNotationTokensEnumerator.Current.value);
|
||||
polishNotationTokensEnumerator.MoveNext();
|
||||
return lit;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(polishNotationTokensEnumerator.Current.value == "NOT")
|
||||
{
|
||||
polishNotationTokensEnumerator.MoveNext();
|
||||
Expression operand = MakeExpression(ref polishNotationTokensEnumerator, _evalFunction);
|
||||
return new ExpressionNot(operand);
|
||||
}
|
||||
else if(polishNotationTokensEnumerator.Current.value == "AND")
|
||||
{
|
||||
polishNotationTokensEnumerator.MoveNext();
|
||||
Expression left = MakeExpression(ref polishNotationTokensEnumerator, _evalFunction);
|
||||
Expression right = MakeExpression(ref polishNotationTokensEnumerator, _evalFunction);
|
||||
return new ExpressionAnd(left, right);
|
||||
}
|
||||
else if(polishNotationTokensEnumerator.Current.value == "OR")
|
||||
{
|
||||
polishNotationTokensEnumerator.MoveNext();
|
||||
Expression left = MakeExpression(ref polishNotationTokensEnumerator, _evalFunction);
|
||||
Expression right = MakeExpression(ref polishNotationTokensEnumerator, _evalFunction);
|
||||
return new ExpressionOr(left, right);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce7d96d3a4d4f3b4681ab437a9710d60
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,592 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------
|
||||
// Cartoon FX
|
||||
// (c) 2012-2020 Jean Moreno
|
||||
//--------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
// Custom material inspector for Stylized FX shaders
|
||||
// - organize UI using comments in the shader code
|
||||
// - more flexibility than the material property drawers
|
||||
// version 2 (dec 2017)
|
||||
|
||||
namespace CartoonFX
|
||||
{
|
||||
public class MaterialInspector : ShaderGUI
|
||||
{
|
||||
//Set by PropertyDrawers to defined if the next properties should be visible
|
||||
static private Stack<bool> ShowStack = new Stack<bool>();
|
||||
|
||||
static public bool ShowNextProperty { get; private set; }
|
||||
static public void PushShowProperty(bool value)
|
||||
{
|
||||
ShowStack.Push(ShowNextProperty);
|
||||
ShowNextProperty &= value;
|
||||
}
|
||||
static public void PopShowProperty()
|
||||
{
|
||||
ShowNextProperty = ShowStack.Pop();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
const string kGuiCommandPrefix = "//#";
|
||||
const string kGC_IfKeyword = "IF_KEYWORD";
|
||||
const string kGC_IfProperty = "IF_PROPERTY";
|
||||
const string kGC_EndIf = "END_IF";
|
||||
const string kGC_HelpBox = "HELP_BOX";
|
||||
const string kGC_Label = "LABEL";
|
||||
|
||||
Dictionary<int, List<GUICommand>> guiCommands = new Dictionary<int, List<GUICommand>>();
|
||||
|
||||
bool initialized = false;
|
||||
AssetImporter shaderImporter;
|
||||
ulong lastTimestamp;
|
||||
void Initialize(MaterialEditor editor, bool force)
|
||||
{
|
||||
if((!initialized || force) && editor != null)
|
||||
{
|
||||
initialized = true;
|
||||
|
||||
guiCommands.Clear();
|
||||
|
||||
//Find the shader and parse the source to find special comments that will organize the GUI
|
||||
//It's hackish, but at least it allows any character to be used (unlike material property drawers/decorators) and can be used along with property drawers
|
||||
|
||||
var materials = new List<Material>();
|
||||
foreach(var o in editor.targets)
|
||||
{
|
||||
var m = o as Material;
|
||||
if(m != null)
|
||||
materials.Add(m);
|
||||
}
|
||||
if(materials.Count > 0 && materials[0].shader != null)
|
||||
{
|
||||
var path = AssetDatabase.GetAssetPath(materials[0].shader);
|
||||
//get asset importer
|
||||
shaderImporter = AssetImporter.GetAtPath(path);
|
||||
if(shaderImporter != null)
|
||||
{
|
||||
lastTimestamp = shaderImporter.assetTimeStamp;
|
||||
}
|
||||
//remove 'Assets' and replace with OS path
|
||||
path = Application.dataPath + path.Substring(6);
|
||||
//convert to cross-platform path
|
||||
path = path.Replace('/', Path.DirectorySeparatorChar);
|
||||
//open file for reading
|
||||
var lines = File.ReadAllLines(path);
|
||||
|
||||
bool insideProperties = false;
|
||||
//regex pattern to find properties, as they need to be counted so that
|
||||
//special commands can be inserted at the right position when enumerating them
|
||||
var regex = new Regex(@"[a-zA-Z0-9_]+\s*\([^\)]*\)");
|
||||
int propertyCount = 0;
|
||||
bool insideCommentBlock = false;
|
||||
foreach(var l in lines)
|
||||
{
|
||||
var line = l.TrimStart();
|
||||
|
||||
if(insideProperties)
|
||||
{
|
||||
bool isComment = line.StartsWith("//");
|
||||
|
||||
if(line.Contains("/*"))
|
||||
insideCommentBlock = true;
|
||||
if(line.Contains("*/"))
|
||||
insideCommentBlock = false;
|
||||
|
||||
//finished properties block?
|
||||
if(line.StartsWith("}"))
|
||||
break;
|
||||
|
||||
//comment
|
||||
if(line.StartsWith(kGuiCommandPrefix))
|
||||
{
|
||||
string command = line.Substring(kGuiCommandPrefix.Length).TrimStart();
|
||||
//space
|
||||
if(string.IsNullOrEmpty(command))
|
||||
AddGUICommand(propertyCount, new GC_Space());
|
||||
//separator
|
||||
else if(command.StartsWith("---"))
|
||||
AddGUICommand(propertyCount, new GC_Separator());
|
||||
//separator
|
||||
else if(command.StartsWith("==="))
|
||||
AddGUICommand(propertyCount, new GC_SeparatorDouble());
|
||||
//if keyword
|
||||
else if(command.StartsWith(kGC_IfKeyword))
|
||||
{
|
||||
var expr = command.Substring(command.LastIndexOf(kGC_IfKeyword) + kGC_IfKeyword.Length + 1);
|
||||
AddGUICommand(propertyCount, new GC_IfKeyword() { expression = expr, materials = materials.ToArray() });
|
||||
}
|
||||
//if property
|
||||
else if(command.StartsWith(kGC_IfProperty))
|
||||
{
|
||||
var expr = command.Substring(command.LastIndexOf(kGC_IfProperty) + kGC_IfProperty.Length + 1);
|
||||
AddGUICommand(propertyCount, new GC_IfProperty() { expression = expr, materials = materials.ToArray() });
|
||||
}
|
||||
//end if
|
||||
else if(command.StartsWith(kGC_EndIf))
|
||||
{
|
||||
AddGUICommand(propertyCount, new GC_EndIf());
|
||||
}
|
||||
//help box
|
||||
else if(command.StartsWith(kGC_HelpBox))
|
||||
{
|
||||
var messageType = MessageType.Error;
|
||||
var message = "Invalid format for HELP_BOX:\n" + command;
|
||||
var cmd = command.Substring(command.LastIndexOf(kGC_HelpBox) + kGC_HelpBox.Length + 1).Split(new string[] { "::" }, System.StringSplitOptions.RemoveEmptyEntries);
|
||||
if(cmd.Length == 1)
|
||||
{
|
||||
message = cmd[0];
|
||||
messageType = MessageType.None;
|
||||
}
|
||||
else if(cmd.Length == 2)
|
||||
{
|
||||
try
|
||||
{
|
||||
var msgType = (MessageType)System.Enum.Parse(typeof(MessageType), cmd[0], true);
|
||||
message = cmd[1].Replace(" ", "\n");
|
||||
messageType = msgType;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
AddGUICommand(propertyCount, new GC_HelpBox()
|
||||
{
|
||||
message = message,
|
||||
messageType = messageType
|
||||
});
|
||||
}
|
||||
//label
|
||||
else if(command.StartsWith(kGC_Label))
|
||||
{
|
||||
var label = command.Substring(command.LastIndexOf(kGC_Label) + kGC_Label.Length + 1);
|
||||
AddGUICommand(propertyCount, new GC_Label() { label = label });
|
||||
}
|
||||
//header: plain text after command
|
||||
else
|
||||
{
|
||||
AddGUICommand(propertyCount, new GC_Header() { label = command });
|
||||
}
|
||||
}
|
||||
else
|
||||
//property
|
||||
{
|
||||
if(regex.IsMatch(line) && !insideCommentBlock && !isComment)
|
||||
propertyCount++;
|
||||
}
|
||||
}
|
||||
|
||||
//start properties block?
|
||||
if(line.StartsWith("Properties"))
|
||||
{
|
||||
insideProperties = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AddGUICommand(int propertyIndex, GUICommand command)
|
||||
{
|
||||
if(!guiCommands.ContainsKey(propertyIndex))
|
||||
guiCommands.Add(propertyIndex, new List<GUICommand>());
|
||||
|
||||
guiCommands[propertyIndex].Add(command);
|
||||
}
|
||||
|
||||
public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader)
|
||||
{
|
||||
initialized = false;
|
||||
base.AssignNewShaderToMaterial(material, oldShader, newShader);
|
||||
}
|
||||
|
||||
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
|
||||
{
|
||||
//init:
|
||||
//- read metadata in properties comment to generate ui layout
|
||||
//- force update if timestamp doesn't match last (= file externally updated)
|
||||
bool force = (shaderImporter != null && shaderImporter.assetTimeStamp != lastTimestamp);
|
||||
Initialize(materialEditor, force);
|
||||
|
||||
var shader = (materialEditor.target as Material).shader;
|
||||
materialEditor.SetDefaultGUIWidths();
|
||||
|
||||
//show all properties by default
|
||||
ShowNextProperty = true;
|
||||
ShowStack.Clear();
|
||||
|
||||
for(int i = 0; i < properties.Length; i++)
|
||||
{
|
||||
if(guiCommands.ContainsKey(i))
|
||||
{
|
||||
for(int j = 0; j < guiCommands[i].Count; j++)
|
||||
{
|
||||
guiCommands[i][j].OnGUI();
|
||||
}
|
||||
}
|
||||
|
||||
//Use custom properties to enable/disable groups based on keywords
|
||||
if(ShowNextProperty)
|
||||
{
|
||||
if((properties[i].flags & (MaterialProperty.PropFlags.HideInInspector | MaterialProperty.PropFlags.PerRendererData)) == MaterialProperty.PropFlags.None)
|
||||
{
|
||||
DisplayProperty(properties[i], materialEditor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//make sure to show gui commands that are after properties
|
||||
int index = properties.Length;
|
||||
if(guiCommands.ContainsKey(index))
|
||||
{
|
||||
for(int j = 0; j < guiCommands[index].Count; j++)
|
||||
{
|
||||
guiCommands[index][j].OnGUI();
|
||||
}
|
||||
}
|
||||
|
||||
//Special fields
|
||||
Styles.MaterialDrawSeparatorDouble();
|
||||
materialEditor.RenderQueueField();
|
||||
materialEditor.EnableInstancingField();
|
||||
}
|
||||
|
||||
virtual protected void DisplayProperty(MaterialProperty property, MaterialEditor materialEditor)
|
||||
{
|
||||
float propertyHeight = materialEditor.GetPropertyHeight(property, property.displayName);
|
||||
Rect controlRect = EditorGUILayout.GetControlRect(true, propertyHeight, EditorStyles.layerMaskField, new GUILayoutOption[0]);
|
||||
materialEditor.ShaderProperty(controlRect, property, property.displayName);
|
||||
}
|
||||
}
|
||||
|
||||
// Same as Toggle drawer, but doesn't set any keyword
|
||||
// This will avoid adding unnecessary shader keyword to the project
|
||||
internal class MaterialToggleNoKeywordDrawer : MaterialPropertyDrawer
|
||||
{
|
||||
private static bool IsPropertyTypeSuitable(MaterialProperty prop)
|
||||
{
|
||||
return prop.type == MaterialProperty.PropType.Float || prop.type == MaterialProperty.PropType.Range;
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor)
|
||||
{
|
||||
float height;
|
||||
if (!MaterialToggleNoKeywordDrawer.IsPropertyTypeSuitable(prop))
|
||||
{
|
||||
height = 40f;
|
||||
}
|
||||
else
|
||||
{
|
||||
height = base.GetPropertyHeight(prop, label, editor);
|
||||
}
|
||||
return height;
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor)
|
||||
{
|
||||
if (!MaterialToggleNoKeywordDrawer.IsPropertyTypeSuitable(prop))
|
||||
{
|
||||
EditorGUI.HelpBox(position, "Toggle used on a non-float property: " + prop.name, MessageType.Warning);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
bool flag = Mathf.Abs(prop.floatValue) > 0.001f;
|
||||
EditorGUI.showMixedValue = prop.hasMixedValue;
|
||||
flag = EditorGUI.Toggle(position, label, flag);
|
||||
EditorGUI.showMixedValue = false;
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
prop.floatValue = ((!flag) ? 0f : 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Same as KeywordEnum drawer, but uses the keyword supplied as is rather than adding a prefix to them
|
||||
internal class MaterialKeywordEnumNoPrefixDrawer : MaterialPropertyDrawer
|
||||
{
|
||||
private readonly GUIContent[] labels;
|
||||
private readonly string[] keywords;
|
||||
|
||||
public MaterialKeywordEnumNoPrefixDrawer(string lbl1, string kw1) : this(new[] { lbl1 }, new[] { kw1 }) { }
|
||||
public MaterialKeywordEnumNoPrefixDrawer(string lbl1, string kw1, string lbl2, string kw2) : this(new[] { lbl1, lbl2 }, new[] { kw1, kw2 }) { }
|
||||
public MaterialKeywordEnumNoPrefixDrawer(string lbl1, string kw1, string lbl2, string kw2, string lbl3, string kw3) : this(new[] { lbl1, lbl2, lbl3 }, new[] { kw1, kw2, kw3 }) { }
|
||||
public MaterialKeywordEnumNoPrefixDrawer(string lbl1, string kw1, string lbl2, string kw2, string lbl3, string kw3, string lbl4, string kw4) : this(new[] { lbl1, lbl2, lbl3, lbl4 }, new[] { kw1, kw2, kw3, kw4 }) { }
|
||||
public MaterialKeywordEnumNoPrefixDrawer(string lbl1, string kw1, string lbl2, string kw2, string lbl3, string kw3, string lbl4, string kw4, string lbl5, string kw5) : this(new[] { lbl1, lbl2, lbl3, lbl4, lbl5 }, new[] { kw1, kw2, kw3, kw4, kw5 }) { }
|
||||
public MaterialKeywordEnumNoPrefixDrawer(string lbl1, string kw1, string lbl2, string kw2, string lbl3, string kw3, string lbl4, string kw4, string lbl5, string kw5, string lbl6, string kw6) : this(new[] { lbl1, lbl2, lbl3, lbl4, lbl5, lbl6 }, new[] { kw1, kw2, kw3, kw4, kw5, kw6 }) { }
|
||||
|
||||
public MaterialKeywordEnumNoPrefixDrawer(string[] labels, string[] keywords)
|
||||
{
|
||||
this.labels= new GUIContent[keywords.Length];
|
||||
this.keywords = new string[keywords.Length];
|
||||
for (int i = 0; i < keywords.Length; ++i)
|
||||
{
|
||||
this.labels[i] = new GUIContent(labels[i]);
|
||||
this.keywords[i] = keywords[i];
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsPropertyTypeSuitable(MaterialProperty prop)
|
||||
{
|
||||
return prop.type == MaterialProperty.PropType.Float || prop.type == MaterialProperty.PropType.Range;
|
||||
}
|
||||
|
||||
void SetKeyword(MaterialProperty prop, int index)
|
||||
{
|
||||
for (int i = 0; i < keywords.Length; ++i)
|
||||
{
|
||||
string keyword = GetKeywordName(prop.name, keywords[i]);
|
||||
foreach (Material material in prop.targets)
|
||||
{
|
||||
if (index == i)
|
||||
material.EnableKeyword(keyword);
|
||||
else
|
||||
material.DisableKeyword(keyword);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor)
|
||||
{
|
||||
if (!IsPropertyTypeSuitable(prop))
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight * 2.5f;
|
||||
}
|
||||
return base.GetPropertyHeight(prop, label, editor);
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor)
|
||||
{
|
||||
if (!IsPropertyTypeSuitable(prop))
|
||||
{
|
||||
EditorGUI.HelpBox(position, "Toggle used on a non-float property: " + prop.name, MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
EditorGUI.showMixedValue = prop.hasMixedValue;
|
||||
var value = (int)prop.floatValue;
|
||||
value = EditorGUI.Popup(position, label, value, labels);
|
||||
EditorGUI.showMixedValue = false;
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
prop.floatValue = value;
|
||||
SetKeyword(prop, value);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Apply(MaterialProperty prop)
|
||||
{
|
||||
base.Apply(prop);
|
||||
if (!IsPropertyTypeSuitable(prop))
|
||||
return;
|
||||
|
||||
if (prop.hasMixedValue)
|
||||
return;
|
||||
|
||||
SetKeyword(prop, (int)prop.floatValue);
|
||||
}
|
||||
|
||||
// Final keyword name: property name + "_" + display name. Uppercased,
|
||||
// and spaces replaced with underscores.
|
||||
private static string GetKeywordName(string propName, string name)
|
||||
{
|
||||
// Just return the supplied name
|
||||
return name;
|
||||
|
||||
// Original code:
|
||||
/*
|
||||
string n = propName + "_" + name;
|
||||
return n.Replace(' ', '_').ToUpperInvariant();
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//================================================================================================================================================================================================
|
||||
// GUI Commands System
|
||||
//
|
||||
// Workaround to Material Property Drawers limitations:
|
||||
// - uses shader comments to organize the GUI, and show/hide properties based on conditions
|
||||
// - can use any character (unlike property drawers)
|
||||
// - parsed once at material editor initialization
|
||||
|
||||
internal class GUICommand
|
||||
{
|
||||
public virtual bool Visible() { return true; }
|
||||
public virtual void OnGUI() { }
|
||||
}
|
||||
|
||||
internal class GC_Separator : GUICommand { public override void OnGUI() { if(MaterialInspector.ShowNextProperty) Styles.MaterialDrawSeparator(); } }
|
||||
internal class GC_SeparatorDouble : GUICommand { public override void OnGUI() { if(MaterialInspector.ShowNextProperty) Styles.MaterialDrawSeparatorDouble(); } }
|
||||
internal class GC_Space : GUICommand { public override void OnGUI() { if(MaterialInspector.ShowNextProperty) GUILayout.Space(8); } }
|
||||
internal class GC_HelpBox : GUICommand
|
||||
{
|
||||
public string message { get; set; }
|
||||
public MessageType messageType { get; set; }
|
||||
|
||||
public override void OnGUI()
|
||||
{
|
||||
if(MaterialInspector.ShowNextProperty)
|
||||
Styles.HelpBoxRichText(message, messageType);
|
||||
}
|
||||
}
|
||||
internal class GC_Header : GUICommand
|
||||
{
|
||||
public string label { get; set; }
|
||||
GUIContent guiContent;
|
||||
|
||||
public override void OnGUI()
|
||||
{
|
||||
if(guiContent == null)
|
||||
guiContent = new GUIContent(label);
|
||||
|
||||
if(MaterialInspector.ShowNextProperty)
|
||||
Styles.MaterialDrawHeader(guiContent);
|
||||
}
|
||||
}
|
||||
internal class GC_Label : GUICommand
|
||||
{
|
||||
public string label { get; set; }
|
||||
GUIContent guiContent;
|
||||
|
||||
public override void OnGUI()
|
||||
{
|
||||
if(guiContent == null)
|
||||
guiContent = new GUIContent(label);
|
||||
|
||||
if(MaterialInspector.ShowNextProperty)
|
||||
GUILayout.Label(guiContent);
|
||||
}
|
||||
}
|
||||
internal class GC_IfKeyword : GUICommand
|
||||
{
|
||||
public string expression { get; set; }
|
||||
public Material[] materials { get; set; }
|
||||
public override void OnGUI()
|
||||
{
|
||||
bool show = ExpressionParser.EvaluateExpression(expression, (string s) =>
|
||||
{
|
||||
foreach(var m in materials)
|
||||
{
|
||||
if(m.IsKeywordEnabled(s))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
MaterialInspector.PushShowProperty(show);
|
||||
}
|
||||
}
|
||||
internal class GC_EndIf : GUICommand { public override void OnGUI() { MaterialInspector.PopShowProperty(); } }
|
||||
|
||||
internal class GC_IfProperty : GUICommand
|
||||
{
|
||||
string _expression;
|
||||
public string expression
|
||||
{
|
||||
get { return _expression; }
|
||||
set { _expression = value.Replace("!=", "<>"); }
|
||||
}
|
||||
public Material[] materials { get; set; }
|
||||
|
||||
public override void OnGUI()
|
||||
{
|
||||
bool show = ExpressionParser.EvaluateExpression(expression, EvaluatePropertyExpression);
|
||||
MaterialInspector.PushShowProperty(show);
|
||||
}
|
||||
|
||||
bool EvaluatePropertyExpression(string expr)
|
||||
{
|
||||
//expression is expected to be in the form of: property operator value
|
||||
var reader = new StringReader(expr);
|
||||
string property = "";
|
||||
string op = "";
|
||||
float value = 0f;
|
||||
|
||||
int overflow = 0;
|
||||
while(true)
|
||||
{
|
||||
char c = (char)reader.Read();
|
||||
|
||||
//operator
|
||||
if(c == '=' || c == '>' || c == '<' || c == '!')
|
||||
{
|
||||
op += c;
|
||||
//second operator character, if any
|
||||
char c2 = (char)reader.Peek();
|
||||
if(c2 == '=' || c2 == '>')
|
||||
{
|
||||
reader.Read();
|
||||
op += c2;
|
||||
}
|
||||
|
||||
//end of string is the value
|
||||
var end = reader.ReadToEnd();
|
||||
if(!float.TryParse(end, out value))
|
||||
{
|
||||
Debug.LogError("Couldn't parse float from property expression:\n" + end);
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
//property name
|
||||
property += c;
|
||||
|
||||
overflow++;
|
||||
if(overflow >= 9999)
|
||||
{
|
||||
Debug.LogError("Expression parsing overflow!\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//evaluate property
|
||||
bool conditionMet = false;
|
||||
foreach(var m in materials)
|
||||
{
|
||||
float propValue = 0f;
|
||||
if(property.Contains(".x") || property.Contains(".y") || property.Contains(".z") || property.Contains(".w"))
|
||||
{
|
||||
string[] split = property.Split('.');
|
||||
string component = split[1];
|
||||
switch(component)
|
||||
{
|
||||
case "x": propValue = m.GetVector(split[0]).x; break;
|
||||
case "y": propValue = m.GetVector(split[0]).y; break;
|
||||
case "z": propValue = m.GetVector(split[0]).z; break;
|
||||
case "w": propValue = m.GetVector(split[0]).w; break;
|
||||
default: Debug.LogError("Invalid component for vector property: '" + property + "'"); break;
|
||||
}
|
||||
}
|
||||
else
|
||||
propValue = m.GetFloat(property);
|
||||
|
||||
switch(op)
|
||||
{
|
||||
case ">=": conditionMet = propValue >= value; break;
|
||||
case "<=": conditionMet = propValue <= value; break;
|
||||
case ">": conditionMet = propValue > value; break;
|
||||
case "<": conditionMet = propValue < value; break;
|
||||
case "<>": conditionMet = propValue != value; break; //not equal, "!=" is replaced by "<>" to prevent bug with leading ! ("not" operator)
|
||||
case "==": conditionMet = propValue == value; break;
|
||||
default:
|
||||
Debug.LogError("Invalid property expression:\n" + expr);
|
||||
break;
|
||||
}
|
||||
if(conditionMet)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4fb4c15e772a1cc4baecc7a958bf9cc7
|
||||
timeCreated: 1486392341
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,362 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------
|
||||
// Cartoon FX
|
||||
// (c) 2012-2020 Jean Moreno
|
||||
//--------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
// GUI Styles and UI methods
|
||||
|
||||
namespace CartoonFX
|
||||
{
|
||||
public static class Styles
|
||||
{
|
||||
//================================================================================================================================
|
||||
// GUI Styles
|
||||
//================================================================================================================================
|
||||
|
||||
//================================================================================================================================
|
||||
// (x) close button
|
||||
static GUIStyle _closeCrossButton;
|
||||
public static GUIStyle CloseCrossButton
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_closeCrossButton == null)
|
||||
{
|
||||
//Try to load GUISkin according to its GUID
|
||||
//Assumes that its .meta file should always stick with it!
|
||||
string guiSkinPath = AssetDatabase.GUIDToAssetPath("02d396fa782e5d7438e231ea9f8be23c");
|
||||
var gs = AssetDatabase.LoadAssetAtPath<GUISkin>(guiSkinPath);
|
||||
if(gs != null)
|
||||
{
|
||||
_closeCrossButton = System.Array.Find<GUIStyle>(gs.customStyles, x => x.name == "CloseCrossButton");
|
||||
}
|
||||
|
||||
//Else fall back to minibutton
|
||||
if(_closeCrossButton == null)
|
||||
_closeCrossButton = EditorStyles.miniButton;
|
||||
}
|
||||
return _closeCrossButton;
|
||||
}
|
||||
}
|
||||
|
||||
//================================================================================================================================
|
||||
// Shuriken Toggle with label alignment fix
|
||||
static GUIStyle _shurikenToggle;
|
||||
public static GUIStyle ShurikenToggle
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_shurikenToggle == null)
|
||||
{
|
||||
_shurikenToggle = new GUIStyle("ShurikenToggle");
|
||||
_shurikenToggle.fontSize = 9;
|
||||
_shurikenToggle.contentOffset = new Vector2(16, -1);
|
||||
if(EditorGUIUtility.isProSkin)
|
||||
{
|
||||
var textColor = new Color(.8f, .8f, .8f);
|
||||
_shurikenToggle.normal.textColor = textColor;
|
||||
_shurikenToggle.active.textColor = textColor;
|
||||
_shurikenToggle.focused.textColor = textColor;
|
||||
_shurikenToggle.hover.textColor = textColor;
|
||||
_shurikenToggle.onNormal.textColor = textColor;
|
||||
_shurikenToggle.onActive.textColor = textColor;
|
||||
_shurikenToggle.onFocused.textColor = textColor;
|
||||
_shurikenToggle.onHover.textColor = textColor;
|
||||
}
|
||||
}
|
||||
return _shurikenToggle;
|
||||
}
|
||||
}
|
||||
|
||||
//================================================================================================================================
|
||||
// Bold mini-label (the one from EditorStyles isn't actually "mini")
|
||||
static GUIStyle _miniBoldLabel;
|
||||
public static GUIStyle MiniBoldLabel
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_miniBoldLabel == null)
|
||||
{
|
||||
_miniBoldLabel = new GUIStyle(EditorStyles.boldLabel);
|
||||
_miniBoldLabel.fontSize = 10;
|
||||
_miniBoldLabel.margin = new RectOffset(0, 0, 0, 0);
|
||||
}
|
||||
return _miniBoldLabel;
|
||||
}
|
||||
}
|
||||
|
||||
//================================================================================================================================
|
||||
// Bold mini-foldout
|
||||
static GUIStyle _miniBoldFoldout;
|
||||
public static GUIStyle MiniBoldFoldout
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_miniBoldFoldout == null)
|
||||
{
|
||||
_miniBoldFoldout = new GUIStyle(EditorStyles.foldout);
|
||||
_miniBoldFoldout.fontSize = 10;
|
||||
_miniBoldFoldout.fontStyle = FontStyle.Bold;
|
||||
_miniBoldFoldout.margin = new RectOffset(0, 0, 0, 0);
|
||||
}
|
||||
return _miniBoldFoldout;
|
||||
}
|
||||
}
|
||||
|
||||
//================================================================================================================================
|
||||
// Gray right-aligned label for Orderable List (Material Animator)
|
||||
static GUIStyle _PropertyTypeLabel;
|
||||
public static GUIStyle PropertyTypeLabel
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_PropertyTypeLabel == null)
|
||||
{
|
||||
_PropertyTypeLabel = new GUIStyle(EditorStyles.label);
|
||||
_PropertyTypeLabel.alignment = TextAnchor.MiddleRight;
|
||||
_PropertyTypeLabel.normal.textColor = Color.gray;
|
||||
_PropertyTypeLabel.fontSize = 9;
|
||||
}
|
||||
return _PropertyTypeLabel;
|
||||
}
|
||||
}
|
||||
|
||||
// Dark Gray right-aligned label for Orderable List (Material Animator)
|
||||
static GUIStyle _PropertyTypeLabelFocused;
|
||||
public static GUIStyle PropertyTypeLabelFocused
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_PropertyTypeLabelFocused == null)
|
||||
{
|
||||
_PropertyTypeLabelFocused = new GUIStyle(EditorStyles.label);
|
||||
_PropertyTypeLabelFocused.alignment = TextAnchor.MiddleRight;
|
||||
_PropertyTypeLabelFocused.normal.textColor = new Color(.2f, .2f, .2f);
|
||||
_PropertyTypeLabelFocused.fontSize = 9;
|
||||
}
|
||||
return _PropertyTypeLabelFocused;
|
||||
}
|
||||
}
|
||||
|
||||
//================================================================================================================================
|
||||
// Rounded Box
|
||||
static GUIStyle _roundedBox;
|
||||
public static GUIStyle RoundedBox
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_roundedBox == null)
|
||||
{
|
||||
_roundedBox = new GUIStyle(EditorStyles.helpBox);
|
||||
}
|
||||
return _roundedBox;
|
||||
}
|
||||
}
|
||||
|
||||
//================================================================================================================================
|
||||
// Center White Label ("Editing Spline" label in Scene View)
|
||||
static GUIStyle _CenteredWhiteLabel;
|
||||
public static GUIStyle CenteredWhiteLabel
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_CenteredWhiteLabel == null)
|
||||
{
|
||||
_CenteredWhiteLabel = new GUIStyle(EditorStyles.centeredGreyMiniLabel);
|
||||
_CenteredWhiteLabel.fontSize = 20;
|
||||
_CenteredWhiteLabel.normal.textColor = Color.white;
|
||||
}
|
||||
return _CenteredWhiteLabel;
|
||||
}
|
||||
}
|
||||
|
||||
//================================================================================================================================
|
||||
// Used to draw lines for separators
|
||||
static public GUIStyle _LineStyle;
|
||||
static public GUIStyle LineStyle
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_LineStyle == null)
|
||||
{
|
||||
_LineStyle = new GUIStyle();
|
||||
_LineStyle.normal.background = EditorGUIUtility.whiteTexture;
|
||||
_LineStyle.stretchWidth = true;
|
||||
}
|
||||
|
||||
return _LineStyle;
|
||||
}
|
||||
}
|
||||
|
||||
//================================================================================================================================
|
||||
// HelpBox with rich text formatting support
|
||||
static GUIStyle _HelpBoxRichTextStyle;
|
||||
static public GUIStyle HelpBoxRichTextStyle
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_HelpBoxRichTextStyle == null)
|
||||
{
|
||||
_HelpBoxRichTextStyle = new GUIStyle("HelpBox");
|
||||
_HelpBoxRichTextStyle.richText = true;
|
||||
}
|
||||
return _HelpBoxRichTextStyle;
|
||||
}
|
||||
}
|
||||
|
||||
//================================================================================================================================
|
||||
// Material Blue Header
|
||||
static public GUIStyle _MaterialHeaderStyle;
|
||||
static public GUIStyle MaterialHeaderStyle
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_MaterialHeaderStyle == null)
|
||||
{
|
||||
_MaterialHeaderStyle = new GUIStyle(EditorStyles.label);
|
||||
_MaterialHeaderStyle.fontStyle = FontStyle.Bold;
|
||||
_MaterialHeaderStyle.fontSize = 11;
|
||||
_MaterialHeaderStyle.padding.top = 0;
|
||||
_MaterialHeaderStyle.padding.bottom = 0;
|
||||
_MaterialHeaderStyle.normal.textColor = EditorGUIUtility.isProSkin ? new Color32(75, 128, 255, 255) : new Color32(0, 50, 230, 255);
|
||||
_MaterialHeaderStyle.stretchWidth = true;
|
||||
}
|
||||
|
||||
return _MaterialHeaderStyle;
|
||||
}
|
||||
}
|
||||
|
||||
//================================================================================================================================
|
||||
// Material Header emboss effect
|
||||
static public GUIStyle _MaterialHeaderStyleHighlight;
|
||||
static public GUIStyle MaterialHeaderStyleHighlight
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_MaterialHeaderStyleHighlight == null)
|
||||
{
|
||||
_MaterialHeaderStyleHighlight = new GUIStyle(MaterialHeaderStyle);
|
||||
_MaterialHeaderStyleHighlight.contentOffset = new Vector2(1, 1);
|
||||
_MaterialHeaderStyleHighlight.normal.textColor = EditorGUIUtility.isProSkin ? new Color32(255, 255, 255, 16) : new Color32(255, 255, 255, 32);
|
||||
}
|
||||
|
||||
return _MaterialHeaderStyleHighlight;
|
||||
}
|
||||
}
|
||||
|
||||
//================================================================================================================================
|
||||
// Filled rectangle
|
||||
|
||||
static private GUIStyle _WhiteRectangleStyle;
|
||||
|
||||
static public void DrawRectangle(Rect position, Color color)
|
||||
{
|
||||
var col = GUI.color;
|
||||
GUI.color *= color;
|
||||
DrawRectangle(position);
|
||||
GUI.color = col;
|
||||
}
|
||||
static public void DrawRectangle(Rect position)
|
||||
{
|
||||
if(_WhiteRectangleStyle == null)
|
||||
{
|
||||
_WhiteRectangleStyle = new GUIStyle();
|
||||
_WhiteRectangleStyle.normal.background = EditorGUIUtility.whiteTexture;
|
||||
}
|
||||
|
||||
if(Event.current != null && Event.current.type == EventType.Repaint)
|
||||
{
|
||||
_WhiteRectangleStyle.Draw(position, false, false, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
//================================================================================================================================
|
||||
// Methods
|
||||
//================================================================================================================================
|
||||
|
||||
static public void DrawLine(float height = 2f)
|
||||
{
|
||||
DrawLine(Color.black, height);
|
||||
}
|
||||
static public void DrawLine(Color color, float height = 1f)
|
||||
{
|
||||
Rect position = GUILayoutUtility.GetRect(0f, float.MaxValue, height, height, LineStyle);
|
||||
DrawLine(position, color);
|
||||
}
|
||||
static public void DrawLine(Rect position, Color color)
|
||||
{
|
||||
if(Event.current.type == EventType.Repaint)
|
||||
{
|
||||
Color orgColor = GUI.color;
|
||||
GUI.color = orgColor * color;
|
||||
LineStyle.Draw(position, false, false, false, false);
|
||||
GUI.color = orgColor;
|
||||
}
|
||||
}
|
||||
|
||||
static public void MaterialDrawHeader(GUIContent guiContent)
|
||||
{
|
||||
var rect = GUILayoutUtility.GetRect(guiContent, MaterialHeaderStyle);
|
||||
GUI.Label(rect, guiContent, MaterialHeaderStyleHighlight);
|
||||
GUI.Label(rect, guiContent, MaterialHeaderStyle);
|
||||
}
|
||||
|
||||
static public void MaterialDrawSeparator()
|
||||
{
|
||||
GUILayout.Space(4);
|
||||
if(EditorGUIUtility.isProSkin)
|
||||
DrawLine(new Color(.3f, .3f, .3f, 1f), 1);
|
||||
else
|
||||
DrawLine(new Color(.6f, .6f, .6f, 1f), 1);
|
||||
GUILayout.Space(4);
|
||||
}
|
||||
|
||||
static public void MaterialDrawSeparatorDouble()
|
||||
{
|
||||
GUILayout.Space(6);
|
||||
if(EditorGUIUtility.isProSkin)
|
||||
{
|
||||
DrawLine(new Color(.1f, .1f, .1f, 1f), 1);
|
||||
DrawLine(new Color(.4f, .4f, .4f, 1f), 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawLine(new Color(.3f, .3f, .3f, 1f), 1);
|
||||
DrawLine(new Color(.9f, .9f, .9f, 1f), 1);
|
||||
}
|
||||
GUILayout.Space(6);
|
||||
}
|
||||
|
||||
//built-in console icons, also used in help box
|
||||
static Texture2D warnIcon;
|
||||
static Texture2D infoIcon;
|
||||
static Texture2D errorIcon;
|
||||
|
||||
static public void HelpBoxRichText(Rect position, string message, MessageType msgType)
|
||||
{
|
||||
Texture2D icon = null;
|
||||
switch(msgType)
|
||||
{
|
||||
case MessageType.Warning: icon = warnIcon ?? (warnIcon = EditorGUIUtility.Load("console.warnicon") as Texture2D); break;
|
||||
case MessageType.Info: icon = infoIcon ?? (infoIcon = EditorGUIUtility.Load("console.infoicon") as Texture2D); break;
|
||||
case MessageType.Error: icon = errorIcon ?? (errorIcon = EditorGUIUtility.Load("console.erroricon") as Texture2D); break;
|
||||
}
|
||||
EditorGUI.LabelField(position, GUIContent.none, new GUIContent(message, icon), HelpBoxRichTextStyle);
|
||||
}
|
||||
|
||||
static public void HelpBoxRichText(string message, MessageType msgType)
|
||||
{
|
||||
Texture2D icon = null;
|
||||
switch(msgType)
|
||||
{
|
||||
case MessageType.Warning: icon = warnIcon ?? (warnIcon = EditorGUIUtility.Load("console.warnicon") as Texture2D); break;
|
||||
case MessageType.Info: icon = infoIcon ?? (infoIcon = EditorGUIUtility.Load("console.infoicon") as Texture2D); break;
|
||||
case MessageType.Error: icon = errorIcon ?? (errorIcon = EditorGUIUtility.Load("console.erroricon") as Texture2D); break;
|
||||
}
|
||||
EditorGUILayout.LabelField(GUIContent.none, new GUIContent(message, icon), HelpBoxRichTextStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26306333afc273640814fd7a7b3968e0
|
||||
timeCreated: 1501149213
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user