SFX added

This commit is contained in:
2023-08-06 16:46:05 +05:30
parent a0ebd1d3f3
commit 50a2bec854
61 changed files with 35177 additions and 34198 deletions

View File

@@ -1,275 +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;
}
}
//--------------------------------------------------------------------------------------------------------------------------------
// 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;
}
}
}

View File

@@ -1,362 +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);
}
}
}
//--------------------------------------------------------------------------------------------------------------------------------
// 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);
}
}
}