mirror of
https://github.com/muskit/H3VR-TNH-Quality-of-Life-Improvements.git
synced 2026-06-03 04:34:26 -07:00
Initial commit
This commit is contained in:
@@ -0,0 +1,214 @@
|
||||
// Alloy Physical Shader Framework
|
||||
// Copyright 2013-2017 RUST LLC.
|
||||
// http://www.alloy.rustltd.com/
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Alloy;
|
||||
using UnityEditor;
|
||||
using PropType = UnityEditor.MaterialProperty.PropType;
|
||||
|
||||
static class AlloySceneDrawer {
|
||||
static Dictionary<AlloyInspectorBase, MaterialEditor> s_inspectorKeeper = new Dictionary<AlloyInspectorBase, MaterialEditor>();
|
||||
static List<AlloyInspectorBase> s_removekeys = new List<AlloyInspectorBase>();
|
||||
|
||||
static AlloySceneDrawer() {
|
||||
EditorApplication.update += Update;
|
||||
}
|
||||
|
||||
static void Update() {
|
||||
var keys = s_inspectorKeeper.Keys;
|
||||
s_removekeys.Clear();
|
||||
|
||||
foreach (var key in keys) {
|
||||
if (s_inspectorKeeper[key] != null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
key.OnAlloyShaderDisable();
|
||||
s_removekeys.Add(key);
|
||||
}
|
||||
|
||||
foreach (var key in s_removekeys) {
|
||||
s_inspectorKeeper.Remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Register(AlloyInspectorBase inspector, MaterialEditor keeper) {
|
||||
if (!s_inspectorKeeper.ContainsKey(inspector)) {
|
||||
s_inspectorKeeper.Add(inspector, keeper);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class AlloyInspectorBase : ShaderGUI {
|
||||
public MaterialEditor MatEditor;
|
||||
protected AlloyTabGroup TabGroup;
|
||||
|
||||
public Object[] Targets { get { return MatEditor.targets; } }
|
||||
public Material Target { get { return (Material) MatEditor.target; } }
|
||||
|
||||
bool m_inited;
|
||||
bool m_isValid = true;
|
||||
|
||||
protected int MatInst {
|
||||
get {
|
||||
if (Selection.objects.Length == 1 && Selection.activeGameObject != null) {
|
||||
var sharedMaterials = Selection.activeGameObject.GetComponent<Renderer>().sharedMaterials;
|
||||
|
||||
if (sharedMaterials != null) {
|
||||
return ArrayUtility.IndexOf(sharedMaterials, Target);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void OnEnable(MaterialProperty[] properties) {
|
||||
if (HasMutlipleShaders()) {
|
||||
return;
|
||||
}
|
||||
|
||||
TabGroup = AlloyTabGroup.GetTabGroup();
|
||||
|
||||
if (Targets.Length > 1) {
|
||||
if (MaterialsAreMismatched()) {
|
||||
foreach (var target in Targets) {
|
||||
var so = new SerializedObject(target);
|
||||
so.Update();
|
||||
|
||||
|
||||
var textures = so.FindProperty("m_SavedProperties.m_TexEnvs");
|
||||
ClearMaterialArray(PropType.Texture, textures, properties);
|
||||
|
||||
var floats = so.FindProperty("m_SavedProperties.m_Floats");
|
||||
ClearMaterialArray(PropType.Float, floats, properties);
|
||||
|
||||
var colors = so.FindProperty("m_SavedProperties.m_Colors");
|
||||
ClearMaterialArray(PropType.Color, colors, properties);
|
||||
so.ApplyModifiedProperties();
|
||||
so.Dispose();
|
||||
}
|
||||
|
||||
m_isValid = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
SceneView.onSceneGUIDelegate += OnAlloySceneGUI;
|
||||
OnAlloyShaderEnable();
|
||||
}
|
||||
|
||||
bool HasMutlipleShaders() {
|
||||
if (MatEditor.targets.Length > 1) {
|
||||
|
||||
return Targets.Any(o => {
|
||||
var objMat = o as Material;
|
||||
return objMat != null && (Target != null && objMat.shader != Target.shader);
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected virtual void OnAlloyShaderGUI(MaterialProperty[] properties) {
|
||||
}
|
||||
|
||||
protected virtual void OnAlloyShaderEnable() {
|
||||
}
|
||||
|
||||
public virtual void OnAlloySceneGUI(SceneView sceneView) {
|
||||
}
|
||||
|
||||
|
||||
void ClearMaterialArray(PropType type, SerializedProperty props, MaterialProperty[] properties) {
|
||||
for (int i = 0; i < props.arraySize; ++i) {
|
||||
var prop = props.GetArrayElementAtIndex(i);
|
||||
var nameProp = prop.FindPropertyRelative("first");
|
||||
string propName = nameProp.stringValue;
|
||||
|
||||
MaterialProperty matProp = FindProperty(propName, properties, false);
|
||||
|
||||
if (matProp == null || matProp.type != type) {
|
||||
props.DeleteArrayElementAtIndex(i);
|
||||
--i;
|
||||
}
|
||||
}
|
||||
|
||||
MatEditor.OnEnable();
|
||||
}
|
||||
|
||||
bool MaterialsAreMismatched() {
|
||||
var textures = MatEditor.serializedObject.FindProperty("m_SavedProperties.m_TexEnvs");
|
||||
if (PropsInArrayMismatched(textures)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var floats = MatEditor.serializedObject.FindProperty("m_SavedProperties.m_Floats");
|
||||
if (PropsInArrayMismatched(floats)) {
|
||||
return true;
|
||||
}
|
||||
var colors = MatEditor.serializedObject.FindProperty("m_SavedProperties.m_Colors");
|
||||
if (PropsInArrayMismatched(colors)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PropsInArrayMismatched(SerializedProperty props) {
|
||||
string original = props.propertyPath;
|
||||
props.Next(true);
|
||||
props.Next(true);
|
||||
props.Next(true);
|
||||
|
||||
//some weird unity behaviour where it collapses the array
|
||||
if (!props.propertyPath.Contains(original)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
do {
|
||||
var nameProp = props.FindPropertyRelative("first");
|
||||
|
||||
if (nameProp.hasMultipleDifferentValues) {
|
||||
return true;
|
||||
}
|
||||
} while (props.NextVisible(false) && props.propertyPath.Contains(original));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) {
|
||||
MatEditor = materialEditor;
|
||||
m_isValid = true;
|
||||
|
||||
if (!m_inited) {
|
||||
AlloySceneDrawer.Register(this, MatEditor);
|
||||
OnEnable(properties);
|
||||
}
|
||||
|
||||
if (!m_isValid) {
|
||||
EditorGUILayout.LabelField("There's a problem with the inspector. Reselect the material to fix");
|
||||
EditorApplication.delayCall += () => MatEditor.Repaint();
|
||||
return;
|
||||
}
|
||||
|
||||
if (HasMutlipleShaders()) {
|
||||
EditorGUILayout.HelpBox("Can't edit materials with different shaders!", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
GUILayout.Space(10.0f);
|
||||
if (MatEditor.isVisible) {
|
||||
OnAlloyShaderGUI(properties);
|
||||
}
|
||||
|
||||
m_inited = true;
|
||||
}
|
||||
|
||||
public virtual void OnAlloyShaderDisable() {
|
||||
SceneView.onSceneGUIDelegate -= OnAlloySceneGUI;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b14f7264c7490be4e9efc64c33c313aa
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,162 @@
|
||||
// Alloy Physical Shader Framework
|
||||
// Copyright 2013-2017 RUST LLC.
|
||||
// http://www.alloy.rustltd.com/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Alloy
|
||||
{
|
||||
[Serializable]
|
||||
public class AlloyTabGroup : ScriptableObject
|
||||
{
|
||||
[SerializeField] private List<bool> m_open;
|
||||
[SerializeField] private List<string> m_names;
|
||||
private Action<Rect> m_defaultTabFunction = (r) => GUI.Label(r, "-", EditorStyles.whiteLabel);
|
||||
|
||||
|
||||
|
||||
public static AlloyTabGroup GetTabGroup() {
|
||||
var o = Resources.FindObjectsOfTypeAll<AlloyTabGroup>();
|
||||
AlloyTabGroup tab;
|
||||
|
||||
if (o.Length != 0) {
|
||||
tab = o[0];
|
||||
} else {
|
||||
tab = CreateInstance<AlloyTabGroup>();
|
||||
tab.hideFlags = HideFlags.HideAndDontSave;
|
||||
tab.name = "AlloyTabGroup";
|
||||
}
|
||||
|
||||
return tab;
|
||||
}
|
||||
|
||||
private void OnEnable() {
|
||||
if (m_open != null && m_names != null) return;
|
||||
|
||||
m_open = new List<bool>();
|
||||
m_names = new List<string>();
|
||||
}
|
||||
|
||||
private int DeclOpen(string nameDecl) {
|
||||
string actual = nameDecl + GUI.depth;
|
||||
|
||||
if (!m_names.Contains(actual)) {
|
||||
m_open.Add(false);
|
||||
m_names.Add(actual);
|
||||
}
|
||||
|
||||
return m_names.IndexOf(actual);
|
||||
}
|
||||
|
||||
public bool TabArea(string areaName, Color color, bool hasOptionalGui, out bool removed, string saveAs = "") {
|
||||
return TabArea(areaName, color, hasOptionalGui, m_defaultTabFunction, out removed, saveAs);
|
||||
}
|
||||
|
||||
public bool TabArea(string areaName, Color color, bool hasOptionalGui, Action<Rect> optionalGUI, out bool removed, string saveAs = "")
|
||||
{
|
||||
if (saveAs == "") {
|
||||
saveAs = areaName;
|
||||
}
|
||||
|
||||
Color oldGuiColor = GUI.color;
|
||||
Color oldBackgroundColor = GUI.backgroundColor;
|
||||
|
||||
GUI.color = Color.Lerp(color, Color.white, 0.8f);
|
||||
GUI.backgroundColor = color;
|
||||
|
||||
bool ret = TabArea(areaName, hasOptionalGui, optionalGUI, out removed, saveAs);
|
||||
GUI.color = oldGuiColor;
|
||||
GUI.backgroundColor = oldBackgroundColor;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public bool TabArea(string areaName, bool hasOptionalGui, out bool removed, string saveAs = "") {
|
||||
return TabArea(areaName, hasOptionalGui, m_defaultTabFunction, out removed, saveAs);
|
||||
}
|
||||
|
||||
public bool TabArea(string areaName, bool hasOptionalGui, Action<Rect> optionalGUI, out bool removed, string saveAs = "")
|
||||
{
|
||||
if (saveAs == "") {
|
||||
saveAs = areaName;
|
||||
}
|
||||
|
||||
int i = DeclOpen(saveAs);
|
||||
var tabTextColor = EditorGUIUtility.isProSkin ? new Color(0.7f, 0.7f, 0.7f) : new Color(0.9f, 0.9f, 0.9f);
|
||||
var oldCol = GUI.color;
|
||||
GUI.color = oldCol * (m_open[i] ? Color.white : new Color(0.8f, 0.8f, 0.8f));
|
||||
|
||||
GUILayout.Label("");
|
||||
|
||||
var rect = GUILayoutUtility.GetLastRect();
|
||||
rect.x -= 35.0f;
|
||||
rect.width += hasOptionalGui ? 10.0f : 50.0f;
|
||||
|
||||
m_open[i] = GUI.Toggle(rect, m_open[i], new GUIContent(""), "ShurikenModuleTitle");
|
||||
removed = false;
|
||||
|
||||
if (hasOptionalGui)
|
||||
{
|
||||
var delRect = rect;
|
||||
delRect.xMin = rect.xMax;
|
||||
delRect.xMax += 40.0f;
|
||||
|
||||
GUI.color = oldCol * (m_open[i] ? new Color(0.7f, 0.7f, 0.7f) : new Color(0.5f, 0.5f, 0.5f));
|
||||
|
||||
if (GUI.Button(delRect, "", "ShurikenModuleTitle")) {
|
||||
removed = true;
|
||||
}
|
||||
|
||||
GUI.color = tabTextColor;
|
||||
GUI.backgroundColor = Color.white;
|
||||
delRect.x += 10.0f;
|
||||
optionalGUI(delRect);
|
||||
}
|
||||
|
||||
rect.x += 35.0f;
|
||||
GUI.color = tabTextColor;
|
||||
GUI.Label(rect, areaName, EditorStyles.whiteLabel);
|
||||
GUI.color = oldCol;
|
||||
|
||||
if (GUI.changed) {
|
||||
EditorUtility.SetDirty(this);
|
||||
}
|
||||
|
||||
return m_open[i];
|
||||
}
|
||||
|
||||
public bool Foldout(string areaName, string saveName, params GUILayoutOption[] options) {
|
||||
int i = DeclOpen(saveName);
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
m_open[i] = EditorGUILayout.Toggle(new GUIContent(""), m_open[i], "foldout", options);
|
||||
|
||||
if (areaName != "")
|
||||
EditorGUILayout.LabelField(new GUIContent(areaName), GUILayout.ExpandWidth(false), GUILayout.Width(180.0f));
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
if (GUI.changed)
|
||||
EditorUtility.SetDirty(this);
|
||||
|
||||
return m_open[i];
|
||||
}
|
||||
|
||||
public bool IsOpen(string areaName) {
|
||||
int i = DeclOpen(areaName);
|
||||
return m_open[i];
|
||||
}
|
||||
|
||||
public void SetOpen(string areaName, bool open) {
|
||||
int i = DeclOpen(areaName);
|
||||
m_open[i] = open;
|
||||
}
|
||||
|
||||
public void Close(string areaName) {
|
||||
int i = DeclOpen(areaName);
|
||||
m_open[i] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 700e2ca720a367c41877be522b433566
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,6 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dadbee4584b61ec4792a816f7dfe5061
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
@@ -0,0 +1,167 @@
|
||||
// Alloy Physical Shader Framework
|
||||
// Copyright 2013-2017 RUST LLC.
|
||||
// http://www.alloy.rustltd.com/
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.AnimatedValues;
|
||||
|
||||
[CanEditMultipleObjects]
|
||||
public class AlloyFieldBasedEditor : AlloyInspectorBase {
|
||||
Dictionary<string, AnimBool> m_openCloseAnim = new Dictionary<string, AnimBool>();
|
||||
AlloyFieldDrawer[] m_fieldDrawers;
|
||||
|
||||
string[] m_allTabs;
|
||||
|
||||
public bool TabIsEnabled(MaterialProperty prop) {
|
||||
return !prop.hasMixedValue && prop.floatValue > 0.5f;
|
||||
}
|
||||
|
||||
public void EnableTab(string tab, MaterialProperty prop, int matInst) {
|
||||
m_openCloseAnim[prop.name].value = false;
|
||||
TabGroup.SetOpen(tab + matInst, true);
|
||||
|
||||
prop.floatValue = 1.0f;
|
||||
MaterialEditor.ApplyMaterialPropertyDrawers(Targets);
|
||||
RepaintScene();
|
||||
}
|
||||
|
||||
public void DisableTab(string tab, MaterialProperty prop, int matInst) {
|
||||
prop.floatValue = 0.0f;
|
||||
MaterialEditor.ApplyMaterialPropertyDrawers(Targets);
|
||||
RepaintScene();
|
||||
|
||||
m_openCloseAnim[prop.name].target = false;
|
||||
TabGroup.SetOpen(tab + matInst, false);
|
||||
}
|
||||
|
||||
protected override void OnAlloyShaderEnable() {
|
||||
Undo.undoRedoPerformed += OnUndo;
|
||||
}
|
||||
|
||||
public override void OnAlloyShaderDisable() {
|
||||
base.OnAlloyShaderDisable();
|
||||
|
||||
if (m_fieldDrawers != null) {
|
||||
foreach (var drawer in m_fieldDrawers) {
|
||||
if (drawer != null) {
|
||||
drawer.OnDisable();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnUndo() {
|
||||
MatEditor.Repaint();
|
||||
}
|
||||
|
||||
static HashSet<string> s_knownNulls = new HashSet<string>();
|
||||
|
||||
protected override void OnAlloyShaderGUI(MaterialProperty[] properties) {
|
||||
//Refresh drawer structure if needed
|
||||
bool structuralChange = false;
|
||||
if (m_fieldDrawers == null || m_fieldDrawers.Length != properties.Length) {
|
||||
m_fieldDrawers = new AlloyFieldDrawer[properties.Length];
|
||||
structuralChange = true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < properties.Length; ++i) {
|
||||
string propName = properties[i].name;
|
||||
|
||||
if (m_fieldDrawers[i] == null && !s_knownNulls.Contains(propName) || m_fieldDrawers[i] != null && m_fieldDrawers[i].Property.name != propName) {
|
||||
m_fieldDrawers[i] = AlloyFieldDrawerFactory.GetFieldDrawer(this, properties[i]);
|
||||
|
||||
if (m_fieldDrawers[i] == null) {
|
||||
s_knownNulls.Add(propName);
|
||||
}
|
||||
else {
|
||||
structuralChange = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//If changed, update the animation stuff
|
||||
if (structuralChange) {
|
||||
m_openCloseAnim.Clear();
|
||||
var allTabs = new List<string>();
|
||||
|
||||
for (var i = 0; i < m_fieldDrawers.Length; i++) {
|
||||
var drawer = m_fieldDrawers[i];
|
||||
|
||||
if (!(drawer is AlloyTabDrawer)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bool isOpenCur = TabGroup.IsOpen(drawer.DisplayName + MatInst);
|
||||
|
||||
var anim = new AnimBool(isOpenCur) {speed = 6.0f, value = isOpenCur};
|
||||
m_openCloseAnim.Add(properties[i].name, anim);
|
||||
allTabs.Add(drawer.DisplayName);
|
||||
}
|
||||
|
||||
m_allTabs = allTabs.ToArray();
|
||||
}
|
||||
|
||||
|
||||
//Formulate arguments to pass to drawing
|
||||
var args = new AlloyFieldDrawerArgs {
|
||||
Editor = this,
|
||||
Materials = Targets.Cast<Material>().ToArray(),
|
||||
Properties = properties,
|
||||
PropertiesSkip = new List<string>(),
|
||||
MatInst = MatInst,
|
||||
TabGroup = TabGroup,
|
||||
AllTabNames = m_allTabs,
|
||||
OpenCloseAnim = m_openCloseAnim
|
||||
};
|
||||
|
||||
|
||||
for (var i = 0; i < m_fieldDrawers.Length; i++) {
|
||||
var drawer = m_fieldDrawers[i];
|
||||
|
||||
if (drawer == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
drawer.Index = i;
|
||||
drawer.Property = properties[i];
|
||||
|
||||
if (drawer.ShouldDraw(args)) {
|
||||
drawer.Draw(args);
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(args.CurrentTab)) {
|
||||
EditorGUILayout.EndFadeGroup();
|
||||
}
|
||||
|
||||
GUILayout.Space(10.0f);
|
||||
|
||||
AlloyEditor.DrawAddTabGUI(args.TabsToAdd);
|
||||
|
||||
//If animating -> Repaint
|
||||
foreach (var animBool in m_openCloseAnim) {
|
||||
if (animBool.Value.isAnimating) {
|
||||
MatEditor.Repaint();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnAlloySceneGUI(SceneView sceneView) {
|
||||
foreach (var drawer in m_fieldDrawers) {
|
||||
if (drawer != null) {
|
||||
drawer.OnSceneGUI(Targets.Cast<Material>().ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RepaintScene() {
|
||||
var lastSceneView = SceneView.lastActiveSceneView;
|
||||
|
||||
if (lastSceneView != null)
|
||||
lastSceneView.Repaint();
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a42f0f341bef6df4c8093abde9d7e4f3
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
@@ -0,0 +1,327 @@
|
||||
// Alloy Physical Shader Framework
|
||||
// Copyright 2013-2017 RUST LLC.
|
||||
// http://www.alloy.rustltd.com/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class AlloyToken
|
||||
{
|
||||
public string Token;
|
||||
|
||||
protected AlloyToken(string field, AlloyFieldLexer currentLexer) {
|
||||
Token = field;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class AlloyCollectionToken : AlloyToken
|
||||
{
|
||||
public List<AlloyToken> SubTokens;
|
||||
|
||||
public const char CollectionOpen = '{';
|
||||
public const char CollectionClose = '}';
|
||||
|
||||
public AlloyCollectionToken(string field, AlloyFieldLexer currentLexer)
|
||||
: base(field, currentLexer) {
|
||||
|
||||
|
||||
SubTokens = currentLexer.GenerateTokens(field);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class AlloyArgumentToken : AlloyToken
|
||||
{
|
||||
public const char ArgumentChar = ':';
|
||||
|
||||
public string ArgumentName;
|
||||
public AlloyToken ArgumentToken;
|
||||
|
||||
public AlloyArgumentToken(string field, AlloyFieldLexer currentLexer)
|
||||
: base(field, currentLexer) {
|
||||
int index = field.IndexOf(':');
|
||||
ArgumentName = field.Substring(0, index);
|
||||
string valueStr = field.Substring(index + 1);
|
||||
|
||||
|
||||
int outInd;
|
||||
ArgumentToken = currentLexer.GenerateToken(valueStr, 0, out outInd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class AlloyValueToken : AlloyToken
|
||||
{
|
||||
private const string c_true = "True";
|
||||
private const string c_false = "False";
|
||||
|
||||
public enum ValueTypeEnum
|
||||
{
|
||||
Bool,
|
||||
Float,
|
||||
String
|
||||
}
|
||||
|
||||
|
||||
public ValueTypeEnum ValueType { get; private set; }
|
||||
private bool m_boolValue;
|
||||
private float m_floatValue;
|
||||
private string m_stringValue;
|
||||
|
||||
|
||||
public bool BoolValue {
|
||||
get {
|
||||
ExpectType(ValueTypeEnum.Bool);
|
||||
return m_boolValue;
|
||||
}
|
||||
}
|
||||
|
||||
public float FloatValue {
|
||||
get {
|
||||
ExpectType(ValueTypeEnum.Float);
|
||||
return m_floatValue;
|
||||
}
|
||||
}
|
||||
|
||||
public string StringValue {
|
||||
get {
|
||||
ExpectType(ValueTypeEnum.String);
|
||||
return m_stringValue;
|
||||
}
|
||||
}
|
||||
|
||||
private void ExpectType(ValueTypeEnum type) {
|
||||
if (ValueType != type) {
|
||||
Debug.LogError("Cant read " + type + " value from token!");
|
||||
}
|
||||
}
|
||||
|
||||
public AlloyValueToken(string field, AlloyFieldLexer currentLexer)
|
||||
: base(field, currentLexer) {
|
||||
|
||||
if (field == c_true) {
|
||||
ValueType = ValueTypeEnum.Bool;
|
||||
m_boolValue = true;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (field == c_false) {
|
||||
ValueType = ValueTypeEnum.Bool;
|
||||
m_boolValue = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
float val;
|
||||
if (float.TryParse(field, out val)) {
|
||||
ValueType = ValueTypeEnum.Float;
|
||||
m_floatValue = val;
|
||||
return;
|
||||
}
|
||||
|
||||
ValueType = ValueTypeEnum.String;
|
||||
m_stringValue = field;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//The language defines a few concepts
|
||||
|
||||
//A pure token will be intepreted as a value
|
||||
//MyString -> string value MyString
|
||||
//True -> bool True
|
||||
//1.03 -> float 1.03
|
||||
|
||||
|
||||
//A collection token defines a set of tokens
|
||||
//{1.03f True True {}}
|
||||
|
||||
//A argument token defines a name and an associated token
|
||||
//CollectionArgument:{True, False}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class AlloyFieldLexer
|
||||
{
|
||||
private AlloyToken[] m_tokens;
|
||||
private static char[] s_specialChars = { '.', ':', '_'};
|
||||
|
||||
|
||||
public List<AlloyToken> GenerateTokens(string parseString) {
|
||||
|
||||
|
||||
var ret = new List<AlloyToken>();
|
||||
int index = 0;
|
||||
|
||||
while (index != -1) {
|
||||
var token = GenerateToken(parseString, index, out index);
|
||||
|
||||
if (token == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
ret.Add(token);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public AlloyToken GenerateToken(string parseString, int startIndex, out int index) {
|
||||
parseString = PreprocessString(parseString);
|
||||
|
||||
for (int i = startIndex; i < parseString.Length; ++i) {
|
||||
char c = parseString[i];
|
||||
|
||||
if (c == ' ') {
|
||||
continue;
|
||||
}
|
||||
|
||||
string token;
|
||||
|
||||
switch (c) {
|
||||
case AlloyCollectionToken.CollectionOpen:
|
||||
token = ReadStackedUntil(parseString, i, AlloyCollectionToken.CollectionOpen, AlloyCollectionToken.CollectionClose);
|
||||
index = i + token.Length + 1;
|
||||
return new AlloyCollectionToken(token, this);
|
||||
}
|
||||
|
||||
bool charOpen = c == '\'';
|
||||
|
||||
if (char.IsLetterOrDigit(c) || charOpen || s_specialChars.Contains(c)) {
|
||||
bool argument;
|
||||
token = ReadWord(parseString, i, out argument);
|
||||
index = i + token.Length + 1;
|
||||
|
||||
if (charOpen) {
|
||||
++index;
|
||||
}
|
||||
|
||||
if (argument) {
|
||||
return new AlloyArgumentToken(token, this);
|
||||
}
|
||||
|
||||
return new AlloyValueToken(token, this);
|
||||
}
|
||||
}
|
||||
|
||||
index = -1;
|
||||
return null;
|
||||
}
|
||||
|
||||
private string PreprocessString(string parseString) {
|
||||
return parseString.Replace(',', ' ');
|
||||
}
|
||||
|
||||
protected string ReadStackedUntil(string parseString, int index, char openC, char closeC) {
|
||||
bool found = false;
|
||||
int stack = 0;
|
||||
int readIndex;
|
||||
|
||||
for (readIndex = index; readIndex < parseString.Length; ++readIndex) {
|
||||
char c = parseString[readIndex];
|
||||
|
||||
if (c == openC) {
|
||||
++stack;
|
||||
}
|
||||
else if (c == closeC) {
|
||||
--stack;
|
||||
}
|
||||
|
||||
|
||||
if (stack == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
Debug.LogError("Parsing fail. Could not find closing char" + closeC);
|
||||
Debug.Log(parseString);
|
||||
return null;
|
||||
}
|
||||
|
||||
return parseString.Substring(index + 1, readIndex - index);
|
||||
}
|
||||
|
||||
private string ReadWord(string parseString, int index, out bool isArgument) {
|
||||
int readIndex = index;
|
||||
bool found = false;
|
||||
int stack = 0;
|
||||
|
||||
bool inString = parseString[index] == '\'';
|
||||
|
||||
if (inString) {
|
||||
++index;
|
||||
}
|
||||
|
||||
isArgument = false;
|
||||
|
||||
|
||||
for (int i = index; i < parseString.Length; ++i) {
|
||||
char curChar = parseString[i];
|
||||
|
||||
readIndex = i;
|
||||
|
||||
|
||||
if (curChar == ':') {
|
||||
isArgument = true;
|
||||
}
|
||||
|
||||
if (!inString) {
|
||||
if (char.IsLetterOrDigit(curChar) || s_specialChars.Contains(curChar)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (curChar == AlloyCollectionToken.CollectionOpen) {
|
||||
++stack;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((curChar == AlloyCollectionToken.CollectionClose) && stack != 0) {
|
||||
--stack;
|
||||
|
||||
if (stack == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (stack != 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (curChar != '\'') {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
readIndex++;
|
||||
}
|
||||
|
||||
string ret = parseString.Substring(index, readIndex - index);
|
||||
|
||||
|
||||
//TODO: Handle argument:'StringToken'
|
||||
/*
|
||||
if (found) {
|
||||
|
||||
//if (readIndex < parseString.Length - 1 && parseString[readIndex + 1] == ':') {
|
||||
//ret += ReadWord(parseString, readIndex + 2);
|
||||
//}
|
||||
}
|
||||
*/
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52de48504b3bb25439b7013a009de5e9
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
@@ -0,0 +1,156 @@
|
||||
// Alloy Physical Shader Framework
|
||||
// Copyright 2013-2017 RUST LLC.
|
||||
// http://www.alloy.rustltd.com/
|
||||
|
||||
using UnityEditor.AnimatedValues;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Alloy;
|
||||
using UnityEditor;
|
||||
|
||||
|
||||
//Generates drawers for a certain field
|
||||
public abstract class AlloyFieldParser {
|
||||
protected List<AlloyToken> Tokens;
|
||||
|
||||
public bool HasSettings;
|
||||
public string DisplayName;
|
||||
|
||||
protected MaterialProperty MaterialProperty;
|
||||
protected AlloyArgumentToken[] Arguments;
|
||||
|
||||
protected AlloyFieldParser(MaterialProperty prop) {
|
||||
var lexer = new AlloyFieldLexer();
|
||||
Tokens = lexer.GenerateTokens(prop.displayName);
|
||||
|
||||
if (Tokens.Count == 0) {
|
||||
Debug.LogError("No tokens found!");
|
||||
return;
|
||||
}
|
||||
|
||||
MaterialProperty = prop;
|
||||
DisplayName = Tokens[0].Token;
|
||||
|
||||
if (Tokens.Count <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var settingsToken = Tokens[1] as AlloyCollectionToken;
|
||||
if (settingsToken == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
HasSettings = true;
|
||||
Arguments = settingsToken.SubTokens.OfType<AlloyArgumentToken>().ToArray();
|
||||
}
|
||||
|
||||
public AlloyFieldDrawer GetDrawer(AlloyInspectorBase editor) {
|
||||
if (!HasSettings) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var drawer = GenerateDrawer(editor);
|
||||
if (drawer != null) {
|
||||
drawer.DisplayName = DisplayName;
|
||||
}
|
||||
|
||||
return drawer;
|
||||
}
|
||||
|
||||
protected abstract AlloyFieldDrawer GenerateDrawer(AlloyInspectorBase editor);
|
||||
}
|
||||
|
||||
public class AlloyFieldDrawerArgs {
|
||||
public AlloyFieldBasedEditor Editor;
|
||||
public AlloyTabGroup TabGroup;
|
||||
public Material[] Materials;
|
||||
public MaterialProperty[] Properties;
|
||||
public List<string> PropertiesSkip = new List<string>();
|
||||
public string CurrentTab;
|
||||
public int MatInst;
|
||||
public bool DoDraw = true;
|
||||
public List<AlloyTabAdd> TabsToAdd = new List<AlloyTabAdd>();
|
||||
public string[] AllTabNames;
|
||||
public Dictionary<string, AnimBool> OpenCloseAnim;
|
||||
|
||||
public MaterialProperty GetMaterialProperty(string velName) {
|
||||
return Properties.FirstOrDefault(p => p.name == velName);
|
||||
}
|
||||
}
|
||||
|
||||
public class AlloyTabAdd {
|
||||
public string Name;
|
||||
public Color Color;
|
||||
|
||||
public GenericMenu.MenuFunction Enable;
|
||||
}
|
||||
|
||||
public abstract class AlloyFieldDrawer {
|
||||
public MaterialProperty Property;
|
||||
public int Index;
|
||||
|
||||
public string DisplayName;
|
||||
public abstract void Draw(AlloyFieldDrawerArgs args);
|
||||
|
||||
protected MaterialEditor MatEditor;
|
||||
|
||||
protected void BeginMaterialProperty(MaterialProperty property) {
|
||||
MatEditor.BeginAnimatedCheck(Property);
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.showMixedValue = Property.hasMixedValue;
|
||||
}
|
||||
|
||||
protected bool EndMaterialProperty() {
|
||||
bool change = EditorGUI.EndChangeCheck();
|
||||
MatEditor.EndAnimatedCheck();
|
||||
EditorGUI.showMixedValue = false;
|
||||
return change;
|
||||
}
|
||||
|
||||
public AlloyFieldDrawer(AlloyInspectorBase editor, MaterialProperty property) {
|
||||
Property = property;
|
||||
MatEditor = editor.MatEditor;
|
||||
}
|
||||
|
||||
protected void FloatFieldMin(string displayName, float min) {
|
||||
BeginMaterialProperty(Property);
|
||||
float newVal = EditorGUILayout.FloatField(displayName, Property.floatValue);
|
||||
|
||||
if (EndMaterialProperty()) {
|
||||
Property.floatValue = Mathf.Max(newVal, min);
|
||||
}
|
||||
}
|
||||
|
||||
protected void FloatFieldMax(string displayName, float max) {
|
||||
BeginMaterialProperty(Property);
|
||||
float newVal = EditorGUILayout.FloatField(displayName, Property.floatValue);
|
||||
|
||||
if (EndMaterialProperty()) {
|
||||
Property.floatValue = Mathf.Min(newVal, max);
|
||||
}
|
||||
}
|
||||
|
||||
protected void FloatFieldSlider(string displayName, float min, float max) {
|
||||
BeginMaterialProperty(Property);
|
||||
float newVal = EditorGUILayout.Slider(displayName, Property.floatValue, min, max, GUILayout.MinWidth(20.0f));
|
||||
|
||||
if (EndMaterialProperty()) {
|
||||
Property.floatValue = Mathf.Clamp(newVal, min, max);
|
||||
}
|
||||
}
|
||||
|
||||
public void PropField(string displayName) {
|
||||
MatEditor.ShaderProperty(Property, displayName);
|
||||
}
|
||||
|
||||
public virtual bool ShouldDraw(AlloyFieldDrawerArgs args) {
|
||||
return args.DoDraw && !args.PropertiesSkip.Contains(Property.name);
|
||||
}
|
||||
|
||||
public virtual void OnSceneGUI(Material[] materials) {
|
||||
}
|
||||
|
||||
public virtual void OnDisable() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23f0b2f9bd608954ca3ef47baea748b7
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8a42743b4a4aee4d901f3b88bbf641f
|
||||
folderAsset: yes
|
||||
timeCreated: 1430261445
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
// Alloy Physical Shader Framework
|
||||
// Copyright 2013-2017 RUST LLC.
|
||||
// http://www.alloy.rustltd.com/
|
||||
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
public static class AlloyFieldDrawerFactory {
|
||||
private static AlloyFieldParser GetFieldParser(MaterialProperty prop) {
|
||||
|
||||
switch (prop.type) {
|
||||
case MaterialProperty.PropType.Texture:
|
||||
if (prop.textureDimension == UnityEngine.Rendering.TextureDimension.Cube) {
|
||||
return new AlloyCubeParser(prop);
|
||||
}
|
||||
|
||||
return new AlloyTextureParser(prop);
|
||||
|
||||
case MaterialProperty.PropType.Range:
|
||||
case MaterialProperty.PropType.Float:
|
||||
return new AlloyFloatParser(prop);
|
||||
|
||||
case MaterialProperty.PropType.Color:
|
||||
return new AlloyColorParser(prop);
|
||||
|
||||
case MaterialProperty.PropType.Vector:
|
||||
return new AlloyVectorParser(prop);
|
||||
|
||||
default:
|
||||
Debug.LogError("No appopriate parser found to generate a drawer");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static AlloyFieldDrawer GetFieldDrawer(AlloyInspectorBase editor, MaterialProperty prop) {
|
||||
AlloyFieldParser parser = GetFieldParser(prop);
|
||||
|
||||
if (parser != null) {
|
||||
return parser.GetDrawer(editor);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92100f25eeaa5f14c882772983cb2592
|
||||
timeCreated: 1430261698
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+189
@@ -0,0 +1,189 @@
|
||||
// Alloy Physical Shader Framework
|
||||
// Copyright 2013-2017 RUST LLC.
|
||||
// http://www.alloy.rustltd.com/
|
||||
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
public class AlloyDefaultDrawer : AlloyFieldDrawer
|
||||
{
|
||||
public override void Draw(AlloyFieldDrawerArgs args) {
|
||||
PropField(DisplayName);
|
||||
}
|
||||
|
||||
public AlloyDefaultDrawer(AlloyInspectorBase editor, MaterialProperty property) : base(editor, property) {
|
||||
}
|
||||
}
|
||||
|
||||
public class AlloyLightmapEmissionDrawer : AlloyFieldDrawer {
|
||||
public override void Draw(AlloyFieldDrawerArgs args) {
|
||||
args.Editor.MatEditor.LightmapEmissionProperty();
|
||||
|
||||
foreach (var material in args.Materials) {
|
||||
// Setup lightmap emissive flags
|
||||
MaterialGlobalIlluminationFlags flags = material.globalIlluminationFlags;
|
||||
if ((flags & (MaterialGlobalIlluminationFlags.BakedEmissive | MaterialGlobalIlluminationFlags.RealtimeEmissive)) != 0) {
|
||||
flags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack;
|
||||
|
||||
|
||||
material.globalIlluminationFlags = flags;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public AlloyLightmapEmissionDrawer(AlloyInspectorBase editor, MaterialProperty property) : base(editor, property) {
|
||||
}
|
||||
}
|
||||
|
||||
public class AlloyRenderQueueDrawer : AlloyFieldDrawer {
|
||||
public override void Draw(AlloyFieldDrawerArgs args) {
|
||||
args.Editor.MatEditor.RenderQueueField();
|
||||
}
|
||||
|
||||
public AlloyRenderQueueDrawer(AlloyInspectorBase editor, MaterialProperty property) : base(editor, property) {
|
||||
}
|
||||
}
|
||||
|
||||
public class AlloyEnableInstancingDrawer : AlloyFieldDrawer {
|
||||
public override void Draw(AlloyFieldDrawerArgs args) {
|
||||
args.Editor.MatEditor.EnableInstancingField();
|
||||
}
|
||||
|
||||
public AlloyEnableInstancingDrawer(AlloyInspectorBase editor, MaterialProperty property) : base(editor, property) {
|
||||
}
|
||||
}
|
||||
|
||||
public class AlloyRenderingModeDrawer : AlloyBlendModeDropdownDrawer {
|
||||
private enum RenderingMode {
|
||||
Opaque,
|
||||
Cutout,
|
||||
Fade,
|
||||
Transparent
|
||||
}
|
||||
|
||||
private static readonly BlendModeOptionConfig[] s_renderingModes = {
|
||||
new BlendModeOptionConfig() {
|
||||
Type = (int)RenderingMode.Opaque,
|
||||
OverrideTag = "",
|
||||
SrcBlend = UnityEngine.Rendering.BlendMode.One,
|
||||
DstBlend = UnityEngine.Rendering.BlendMode.Zero,
|
||||
ZWrite = 1,
|
||||
Keyword = "",
|
||||
RenderQueue = -1
|
||||
},
|
||||
new BlendModeOptionConfig() {
|
||||
Type = (int)RenderingMode.Cutout,
|
||||
OverrideTag = "TransparentCutout",
|
||||
SrcBlend = UnityEngine.Rendering.BlendMode.One,
|
||||
DstBlend = UnityEngine.Rendering.BlendMode.Zero,
|
||||
ZWrite = 1,
|
||||
Keyword = "_ALPHATEST_ON",
|
||||
RenderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest,
|
||||
},
|
||||
new BlendModeOptionConfig() {
|
||||
Type = (int)RenderingMode.Fade,
|
||||
OverrideTag = "Transparent",
|
||||
SrcBlend = UnityEngine.Rendering.BlendMode.SrcAlpha,
|
||||
DstBlend = UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha,
|
||||
ZWrite = 0,
|
||||
Keyword = "_ALPHABLEND_ON",
|
||||
RenderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent
|
||||
},
|
||||
new BlendModeOptionConfig() {
|
||||
Type = (int)RenderingMode.Transparent,
|
||||
OverrideTag = "Transparent",
|
||||
SrcBlend = UnityEngine.Rendering.BlendMode.One,
|
||||
DstBlend = UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha,
|
||||
ZWrite = 0,
|
||||
Keyword = "_ALPHAPREMULTIPLY_ON",
|
||||
RenderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent
|
||||
},
|
||||
};
|
||||
|
||||
public AlloyRenderingModeDrawer(AlloyInspectorBase editor, MaterialProperty property)
|
||||
: base(editor, property, s_renderingModes) {
|
||||
}
|
||||
}
|
||||
|
||||
public class AlloySpeedTreeGeometryTypeDrawer : AlloyBlendModeDropdownDrawer {
|
||||
private enum SpeedTreeGeometryType {
|
||||
Branch,
|
||||
BranchDetail,
|
||||
Frond,
|
||||
Leaf,
|
||||
Mesh,
|
||||
}
|
||||
|
||||
private static readonly BlendModeOptionConfig[] s_geometryTypes = {
|
||||
new BlendModeOptionConfig() {
|
||||
Type = (int)SpeedTreeGeometryType.Branch,
|
||||
OverrideTag = "",
|
||||
SrcBlend = UnityEngine.Rendering.BlendMode.One,
|
||||
DstBlend = UnityEngine.Rendering.BlendMode.Zero,
|
||||
ZWrite = 1,
|
||||
Keyword = "GEOM_TYPE_BRANCH",
|
||||
RenderQueue = -1
|
||||
},
|
||||
new BlendModeOptionConfig() {
|
||||
Type = (int)SpeedTreeGeometryType.BranchDetail,
|
||||
OverrideTag = "",
|
||||
SrcBlend = UnityEngine.Rendering.BlendMode.One,
|
||||
DstBlend = UnityEngine.Rendering.BlendMode.Zero,
|
||||
ZWrite = 1,
|
||||
Keyword = "GEOM_TYPE_BRANCH_DETAIL",
|
||||
RenderQueue = -1
|
||||
},
|
||||
new BlendModeOptionConfig() {
|
||||
Type = (int)SpeedTreeGeometryType.Frond,
|
||||
OverrideTag = "TransparentCutout",
|
||||
SrcBlend = UnityEngine.Rendering.BlendMode.One,
|
||||
DstBlend = UnityEngine.Rendering.BlendMode.Zero,
|
||||
ZWrite = 1,
|
||||
Keyword = "GEOM_TYPE_FROND",
|
||||
RenderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest
|
||||
},
|
||||
new BlendModeOptionConfig() {
|
||||
Type = (int)SpeedTreeGeometryType.Leaf,
|
||||
OverrideTag = "TransparentCutout",
|
||||
SrcBlend = UnityEngine.Rendering.BlendMode.One,
|
||||
DstBlend = UnityEngine.Rendering.BlendMode.Zero,
|
||||
ZWrite = 1,
|
||||
Keyword = "GEOM_TYPE_LEAF",
|
||||
RenderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest
|
||||
},
|
||||
new BlendModeOptionConfig() {
|
||||
Type = (int)SpeedTreeGeometryType.Mesh,
|
||||
OverrideTag = "",
|
||||
SrcBlend = UnityEngine.Rendering.BlendMode.One,
|
||||
DstBlend = UnityEngine.Rendering.BlendMode.Zero,
|
||||
ZWrite = 1,
|
||||
Keyword = "GEOM_TYPE_MESH",
|
||||
RenderQueue = -1
|
||||
},
|
||||
};
|
||||
|
||||
public AlloySpeedTreeGeometryTypeDrawer(AlloyInspectorBase editor, MaterialProperty property)
|
||||
: base(editor, property, s_geometryTypes)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class AlloyColorParser : AlloyFieldParser{
|
||||
protected override AlloyFieldDrawer GenerateDrawer(AlloyInspectorBase editor) {
|
||||
var ret = new AlloyColorDrawer(editor, MaterialProperty);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public AlloyColorParser(MaterialProperty field) : base(field) {
|
||||
}
|
||||
}
|
||||
|
||||
public class AlloyColorDrawer : AlloyFieldDrawer {
|
||||
public override void Draw(AlloyFieldDrawerArgs args) {
|
||||
PropField(DisplayName);
|
||||
}
|
||||
|
||||
public AlloyColorDrawer(AlloyInspectorBase editor, MaterialProperty property) : base(editor, property) {
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce2d4023424d8b24e830bed4c9fb55f5
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
+511
@@ -0,0 +1,511 @@
|
||||
// Alloy Physical Shader Framework
|
||||
// Copyright 2013-2017 RUST LLC.
|
||||
// http://www.alloy.rustltd.com/
|
||||
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
|
||||
public class AlloyDropdownOption {
|
||||
public string Name;
|
||||
public string[] HideFields;
|
||||
}
|
||||
|
||||
public class AlloyFloatParser : AlloyFieldParser {
|
||||
private readonly Color32 c_defaultSectionColor = new Color32(97, 97, 97, 255);
|
||||
|
||||
protected override AlloyFieldDrawer GenerateDrawer(AlloyInspectorBase editor) {
|
||||
AlloyFieldDrawer retDrawer = null;
|
||||
|
||||
foreach (var token in Arguments) {
|
||||
var argName = token.ArgumentName;
|
||||
var argToken = token.ArgumentToken;
|
||||
|
||||
switch (argName) {
|
||||
case "Min":
|
||||
AlloyFloatDrawer minDrawer = null;
|
||||
var minValToken = argToken as AlloyValueToken;
|
||||
|
||||
if (retDrawer != null)
|
||||
minDrawer = retDrawer as AlloyFloatDrawer;
|
||||
|
||||
if (minDrawer == null)
|
||||
minDrawer = new AlloyFloatDrawer(editor, MaterialProperty);
|
||||
|
||||
minDrawer.HasMin = true;
|
||||
minDrawer.MinValue = minValToken.FloatValue;
|
||||
retDrawer = minDrawer;
|
||||
break;
|
||||
|
||||
case "Max":
|
||||
AlloyFloatDrawer maxDrawer = null;
|
||||
var maxValToken = argToken as AlloyValueToken;
|
||||
|
||||
if (retDrawer != null)
|
||||
maxDrawer = retDrawer as AlloyFloatDrawer;
|
||||
|
||||
if (maxDrawer == null)
|
||||
maxDrawer = new AlloyFloatDrawer(editor, MaterialProperty);
|
||||
|
||||
maxDrawer.HasMax = true;
|
||||
maxDrawer.MaxValue = maxValToken.FloatValue;
|
||||
retDrawer = maxDrawer;
|
||||
break;
|
||||
|
||||
case "Section":
|
||||
retDrawer = new AlloySectionDrawer(editor, MaterialProperty);
|
||||
SetSectionOption(retDrawer, argToken);
|
||||
break;
|
||||
|
||||
case "Feature":
|
||||
retDrawer = new AlloyFeatureDrawer(editor, MaterialProperty);
|
||||
SetSectionOption(retDrawer, argToken);
|
||||
break;
|
||||
|
||||
case "Toggle":
|
||||
retDrawer = new AlloyToggleDrawer(editor, MaterialProperty);
|
||||
SetToggleOption(retDrawer, argToken);
|
||||
break;
|
||||
|
||||
case "SpeedTreeGeometryType":
|
||||
retDrawer = new AlloySpeedTreeGeometryTypeDrawer(editor, MaterialProperty);
|
||||
SetDropdownOption(retDrawer, argToken);
|
||||
break;
|
||||
|
||||
case "RenderingMode":
|
||||
retDrawer = new AlloyRenderingModeDrawer(editor, MaterialProperty);
|
||||
SetDropdownOption(retDrawer, argToken);
|
||||
break;
|
||||
|
||||
case "Dropdown":
|
||||
retDrawer = new AlloyDropdownDrawer(editor, MaterialProperty);
|
||||
SetDropdownOption(retDrawer, argToken);
|
||||
break;
|
||||
|
||||
case "LightmapEmissionProperty":
|
||||
retDrawer = new AlloyLightmapEmissionDrawer(editor, MaterialProperty);
|
||||
break;
|
||||
|
||||
case "RenderQueue":
|
||||
retDrawer = new AlloyRenderQueueDrawer(editor, MaterialProperty);
|
||||
break;
|
||||
|
||||
case "EnableInstancing":
|
||||
retDrawer = new AlloyEnableInstancingDrawer(editor, MaterialProperty);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (retDrawer == null)
|
||||
retDrawer = new AlloyFloatDrawer(editor, MaterialProperty);
|
||||
|
||||
return retDrawer;
|
||||
}
|
||||
|
||||
private static void SetDropdownOption(AlloyFieldDrawer retDrawer, AlloyToken argToken) {
|
||||
var drawer = retDrawer as AlloyDropdownDrawer;
|
||||
|
||||
if (drawer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var options = argToken as AlloyCollectionToken;
|
||||
|
||||
if (options == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var dropOptions = new List<AlloyDropdownOption>();
|
||||
|
||||
for (int i = 0; i < options.SubTokens.Count; i++) {
|
||||
AlloyArgumentToken arg = (AlloyArgumentToken)options.SubTokens[i];
|
||||
var collection = arg.ArgumentToken as AlloyCollectionToken;
|
||||
|
||||
if (collection == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// Split PascalCase name into words separated by spaces while skipping acronyms.
|
||||
var dropOption = new AlloyDropdownOption {
|
||||
Name = Regex.Replace(arg.ArgumentName, @"(?<=[A-Za-z])(?=[A-Z][a-z])|(?<=[a-z0-9])(?=[0-9]?[A-Z])", " "),
|
||||
HideFields = collection.SubTokens.Select(alloyToken => alloyToken.Token).ToArray()
|
||||
};
|
||||
dropOptions.Add(dropOption);
|
||||
}
|
||||
|
||||
drawer.DropOptions = dropOptions.ToArray();
|
||||
}
|
||||
|
||||
private static void SetToggleOption(AlloyFieldDrawer retDrawer, AlloyToken argToken) {
|
||||
var drawer = retDrawer as AlloyToggleDrawer;
|
||||
|
||||
if (drawer == null) {
|
||||
return;
|
||||
}
|
||||
var collectionToken = argToken as AlloyCollectionToken;
|
||||
|
||||
if (collectionToken == null) {
|
||||
return;
|
||||
}
|
||||
foreach (var token in collectionToken.SubTokens) {
|
||||
var arg = token as AlloyArgumentToken;
|
||||
|
||||
if (arg != null && arg.ArgumentName == "On") {
|
||||
var onToken = arg.ArgumentToken as AlloyCollectionToken;
|
||||
|
||||
if (onToken != null) {
|
||||
drawer.OnHideFields = onToken.SubTokens.Select(colToken => colToken.Token).ToArray();
|
||||
}
|
||||
}
|
||||
else if (arg != null && arg.ArgumentName == "Off") {
|
||||
var offToken = arg.ArgumentToken as AlloyCollectionToken;
|
||||
|
||||
if (offToken != null) {
|
||||
drawer.OffHideFields = offToken.SubTokens.Select(colToken => colToken.Token).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetMinOption(AlloyFieldDrawer retDrawer, AlloyToken argToken) {
|
||||
var floatDrawer = retDrawer as AlloyFloatDrawer;
|
||||
var minValToken = argToken as AlloyValueToken;
|
||||
|
||||
if (floatDrawer != null) {
|
||||
floatDrawer.HasMin = true;
|
||||
|
||||
if (minValToken != null) {
|
||||
floatDrawer.MinValue = minValToken.FloatValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetSectionOption(AlloyFieldDrawer retDrawer, AlloyToken argToken) {
|
||||
var sectionDrawer = retDrawer as AlloyTabDrawer;
|
||||
|
||||
if (sectionDrawer != null) {
|
||||
var collectionToken = argToken as AlloyCollectionToken;
|
||||
|
||||
if (collectionToken == null) {
|
||||
sectionDrawer.Color = c_defaultSectionColor;
|
||||
}
|
||||
else {
|
||||
foreach (var token in collectionToken.SubTokens) {
|
||||
var arg = token as AlloyArgumentToken;
|
||||
|
||||
if (arg != null && arg.ArgumentName == "Color") {
|
||||
var value = arg.ArgumentToken as AlloyValueToken;
|
||||
|
||||
// Calculate color from section index and HSV scale factor.
|
||||
if (value != null) {
|
||||
var hueIndex = value.FloatValue;
|
||||
|
||||
if (hueIndex > -0.1f)
|
||||
sectionDrawer.Color = Color.HSVToRGB((hueIndex / AlloyUtils.SectionColorMax) * 0.6f, 0.75f, 0.5f);
|
||||
}
|
||||
else {
|
||||
// Manually specify color.
|
||||
var colCollection = arg.ArgumentToken as AlloyCollectionToken;
|
||||
|
||||
if (colCollection != null) {
|
||||
var r = colCollection.SubTokens[0] as AlloyValueToken;
|
||||
var g = colCollection.SubTokens[1] as AlloyValueToken;
|
||||
var b = colCollection.SubTokens[2] as AlloyValueToken;
|
||||
|
||||
if (r != null && g != null && b != null) {
|
||||
sectionDrawer.Color = new Color32((byte)r.FloatValue, (byte)g.FloatValue, (byte)b.FloatValue, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (arg != null && arg.ArgumentName == "Hide") {
|
||||
var featureDrawer = sectionDrawer as AlloyFeatureDrawer;
|
||||
var offToken = arg.ArgumentToken as AlloyCollectionToken;
|
||||
|
||||
if (offToken != null) {
|
||||
featureDrawer.HideFields = offToken.SubTokens.Select(colToken => colToken.Token).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public AlloyFloatParser(MaterialProperty field)
|
||||
: base(field) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public abstract class AlloyTabDrawer : AlloyFieldDrawer
|
||||
{
|
||||
public Color Color;
|
||||
Func<bool, Action<Rect>> m_foldoutAction;
|
||||
|
||||
protected void SetAllTabsOpenedTo(bool open, AlloyFieldDrawerArgs args) {
|
||||
foreach (var tab in args.AllTabNames) {
|
||||
args.TabGroup.SetOpen(tab + args.MatInst, open);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool ShouldDraw(AlloyFieldDrawerArgs args) {
|
||||
return !args.PropertiesSkip.Contains(Property.name);
|
||||
}
|
||||
|
||||
protected void DrawNow(AlloyFieldDrawerArgs args, bool optional) {
|
||||
var firstDrawer = Index == 0;
|
||||
var firstTab = string.IsNullOrEmpty(args.CurrentTab);
|
||||
|
||||
if (firstDrawer) {
|
||||
GUILayout.Space(-10.0f);
|
||||
}
|
||||
else if (firstTab) {
|
||||
GUILayout.Space(5.0f);
|
||||
}
|
||||
else {
|
||||
if (args.DoDraw) {
|
||||
GUILayout.Space(8.0f);
|
||||
}
|
||||
|
||||
EditorGUILayout.EndFadeGroup();
|
||||
}
|
||||
|
||||
if (!optional || args.Editor.TabIsEnabled(Property)) {
|
||||
bool open;
|
||||
|
||||
if (firstTab && !optional) {
|
||||
bool openAll = args.AllTabNames.All(tab => args.TabGroup.IsOpen(tab + args.MatInst));
|
||||
bool closeOpen;
|
||||
bool all = openAll;
|
||||
|
||||
open = args.TabGroup.TabArea(DisplayName, Color, true, m_foldoutAction(all), out closeOpen, DisplayName + args.MatInst);
|
||||
|
||||
if (closeOpen) {
|
||||
openAll = !openAll;
|
||||
SetAllTabsOpenedTo(openAll, args);
|
||||
}
|
||||
}
|
||||
else {
|
||||
bool removed;
|
||||
open = args.TabGroup.TabArea(DisplayName, Color, optional, out removed, DisplayName + args.MatInst);
|
||||
|
||||
if (removed) {
|
||||
args.Editor.DisableTab(DisplayName, Property, args.MatInst);
|
||||
}
|
||||
}
|
||||
|
||||
var anim = args.OpenCloseAnim[Property.name];
|
||||
anim.target = open;
|
||||
|
||||
args.CurrentTab = Property.name;
|
||||
args.DoDraw = EditorGUILayout.BeginFadeGroup(anim.faded);
|
||||
}
|
||||
else {
|
||||
args.DoDraw = false;
|
||||
|
||||
args.TabsToAdd.Add(new AlloyTabAdd { Color = Color, Name = DisplayName, Enable = () => args.Editor.EnableTab(DisplayName, Property, args.MatInst) });
|
||||
}
|
||||
}
|
||||
|
||||
protected AlloyTabDrawer(AlloyInspectorBase editor, MaterialProperty property)
|
||||
: base(editor, property) {
|
||||
m_foldoutAction = all => r => GUI.Label(r, all ? "v" : ">", EditorStyles.whiteLabel);
|
||||
}
|
||||
}
|
||||
|
||||
public class AlloySectionDrawer : AlloyTabDrawer {
|
||||
public override void Draw(AlloyFieldDrawerArgs args) {
|
||||
DrawNow(args, false);
|
||||
}
|
||||
|
||||
public AlloySectionDrawer(AlloyInspectorBase editor, MaterialProperty property) : base(editor, property) {
|
||||
}
|
||||
}
|
||||
|
||||
public class AlloyFeatureDrawer : AlloyTabDrawer {
|
||||
public string[] HideFields;
|
||||
|
||||
public override bool ShouldDraw(AlloyFieldDrawerArgs args) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Draw(AlloyFieldDrawerArgs args) {
|
||||
bool current = Property.floatValue > 0.5f;
|
||||
|
||||
DrawNow(args, true);
|
||||
|
||||
if (!current) {
|
||||
if (HideFields != null) {
|
||||
args.PropertiesSkip.AddRange(HideFields);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public AlloyFeatureDrawer(AlloyInspectorBase editor, MaterialProperty property) : base(editor, property) {
|
||||
}
|
||||
}
|
||||
|
||||
public class AlloyFloatDrawer : AlloyFieldDrawer
|
||||
{
|
||||
public bool HasMin;
|
||||
public float MinValue;
|
||||
|
||||
public bool HasMax;
|
||||
public float MaxValue;
|
||||
|
||||
int m_selectedIndex;
|
||||
|
||||
public override void Draw(AlloyFieldDrawerArgs args) {
|
||||
if (HasMin || HasMax) {
|
||||
if (HasMin && HasMax) {
|
||||
FloatFieldSlider(DisplayName, MinValue, MaxValue);
|
||||
}
|
||||
else if (HasMin) {
|
||||
FloatFieldMin(DisplayName, MinValue);
|
||||
}
|
||||
else {
|
||||
FloatFieldMax(DisplayName, MaxValue);
|
||||
}
|
||||
}
|
||||
else {
|
||||
PropField(DisplayName);
|
||||
}
|
||||
}
|
||||
|
||||
public AlloyFloatDrawer(AlloyInspectorBase editor, MaterialProperty property) : base(editor, property) {
|
||||
}
|
||||
}
|
||||
|
||||
public class AlloyDropdownDrawer : AlloyFieldDrawer {
|
||||
public AlloyDropdownOption[] DropOptions;
|
||||
|
||||
protected virtual bool OnSetOption(int newOption, AlloyFieldDrawerArgs args) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Draw(AlloyFieldDrawerArgs args) {
|
||||
int current = (int)Property.floatValue;
|
||||
var label = new GUIContent(DisplayName);
|
||||
|
||||
BeginMaterialProperty(Property);
|
||||
|
||||
int newVal = EditorGUILayout.Popup(label, current, DropOptions.Select(option => new GUIContent(option.Name)).ToArray());
|
||||
EditorGUI.showMixedValue = false;
|
||||
|
||||
if (!OnSetOption(newVal, args) && EditorGUI.EndChangeCheck()) {
|
||||
Property.floatValue = newVal;
|
||||
MaterialEditor.ApplyMaterialPropertyDrawers(args.Materials);
|
||||
}
|
||||
|
||||
MatEditor.EndAnimatedCheck();
|
||||
args.PropertiesSkip.AddRange(DropOptions[current].HideFields);
|
||||
}
|
||||
|
||||
public AlloyDropdownDrawer(AlloyInspectorBase editor, MaterialProperty property) : base(editor, property) {
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class AlloyBlendModeDropdownDrawer : AlloyDropdownDrawer {
|
||||
public struct BlendModeOptionConfig {
|
||||
public int Type;
|
||||
public string OverrideTag;
|
||||
public UnityEngine.Rendering.BlendMode SrcBlend;
|
||||
public UnityEngine.Rendering.BlendMode DstBlend;
|
||||
public int ZWrite;
|
||||
public string Keyword;
|
||||
public int RenderQueue;
|
||||
}
|
||||
|
||||
protected BlendModeOptionConfig[] BlendModeOptionConfigs = null;
|
||||
|
||||
public AlloyBlendModeDropdownDrawer(AlloyInspectorBase editor, MaterialProperty property, BlendModeOptionConfig[] blendModeOptionConfigs) : base(editor, property) {
|
||||
BlendModeOptionConfigs = blendModeOptionConfigs;
|
||||
|
||||
// Get default from keyword.
|
||||
var keywords = editor.Target.shaderKeywords;
|
||||
property.floatValue = 0.0f;
|
||||
|
||||
foreach (var setting in BlendModeOptionConfigs) {
|
||||
if (keywords.Contains(setting.Keyword)) {
|
||||
property.floatValue = setting.Type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool OnSetOption(int newOption, AlloyFieldDrawerArgs args) {
|
||||
base.OnSetOption(newOption, args);
|
||||
|
||||
foreach (var material in args.Materials) {
|
||||
if (Property.floatValue != newOption) {
|
||||
foreach (var setting in BlendModeOptionConfigs) {
|
||||
var keyword = setting.Keyword;
|
||||
|
||||
if (newOption != setting.Type) {
|
||||
material.DisableKeyword(keyword);
|
||||
}
|
||||
else {
|
||||
material.SetOverrideTag("RenderType", setting.OverrideTag);
|
||||
material.SetInt("_SrcBlend", (int)setting.SrcBlend);
|
||||
material.SetInt("_DstBlend", (int)setting.DstBlend);
|
||||
material.SetInt("_ZWrite", setting.ZWrite);
|
||||
material.EnableKeyword(keyword);
|
||||
material.renderQueue = setting.RenderQueue;
|
||||
}
|
||||
}
|
||||
|
||||
material.SetInt(Property.name, newOption);
|
||||
EditorUtility.SetDirty(material);
|
||||
}
|
||||
}
|
||||
|
||||
Undo.RecordObjects(args.Materials, "set " + Property.name);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class AlloyToggleDrawer : AlloyFieldDrawer {
|
||||
public string[] OnHideFields;
|
||||
public string[] OffHideFields;
|
||||
|
||||
public override void Draw(AlloyFieldDrawerArgs args) {
|
||||
bool current = Property.floatValue > 0.5f;
|
||||
var label = new GUIContent(DisplayName);
|
||||
|
||||
|
||||
//EditorGUI.BeginProperty(new Rect(), label, Serialized);
|
||||
|
||||
EditorGUI.showMixedValue = Property.hasMixedValue;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
current = EditorGUILayout.Toggle(label, current);
|
||||
|
||||
if (EditorGUI.EndChangeCheck()) {
|
||||
Property.floatValue = current ? 1.0f : 0.0f;
|
||||
MaterialEditor.ApplyMaterialPropertyDrawers(args.Materials);
|
||||
}
|
||||
|
||||
//EditorGUI.EndProperty();
|
||||
|
||||
EditorGUI.showMixedValue = false;
|
||||
|
||||
|
||||
if (!current) {
|
||||
if (OffHideFields != null) {
|
||||
args.PropertiesSkip.AddRange(OffHideFields);
|
||||
}
|
||||
} else {
|
||||
if (OnHideFields != null) {
|
||||
args.PropertiesSkip.AddRange(OnHideFields);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public AlloyToggleDrawer(AlloyInspectorBase editor, MaterialProperty property) : base(editor, property) {
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 70c021998d433f440868615e1d5d09e2
|
||||
timeCreated: 1430261565
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+400
@@ -0,0 +1,400 @@
|
||||
// Alloy Physical Shader Framework
|
||||
// Copyright 2013-2017 RUST LLC.
|
||||
// http://www.alloy.rustltd.com/
|
||||
|
||||
using Alloy;
|
||||
using UnityEditor;
|
||||
using UnityEditor.AnimatedValues;
|
||||
using UnityEngine;
|
||||
|
||||
public class AlloyTextureFieldDrawer : AlloyFieldDrawer {
|
||||
public enum TextureVisualizeMode {
|
||||
None,
|
||||
RGB,
|
||||
R,
|
||||
G,
|
||||
B,
|
||||
A,
|
||||
NRM
|
||||
}
|
||||
|
||||
public string ParentTexture {
|
||||
get { return m_parentTexture; }
|
||||
set {
|
||||
m_parentTexture = value;
|
||||
m_hasParentTexture = !string.IsNullOrEmpty(value);
|
||||
}
|
||||
}
|
||||
|
||||
public TextureVisualizeMode[] DisplayModes;
|
||||
public bool Controls = true;
|
||||
|
||||
protected int TexInst;
|
||||
|
||||
string m_parentTexture = string.Empty;
|
||||
bool m_hasParentTexture;
|
||||
|
||||
protected AlloyTabGroup TabGroup;
|
||||
|
||||
AnimBool m_tabOpen = new AnimBool(false);
|
||||
bool m_firstDraw = true;
|
||||
int m_vizIndex;
|
||||
|
||||
Material m_visualizeMat;
|
||||
Renderer m_oldSelect;
|
||||
|
||||
static GUIContent[] s_uvModes = {new GUIContent("UV0"), new GUIContent("UV1")};
|
||||
static GUILayoutOption[] s_texLayout = new GUILayoutOption[2];
|
||||
|
||||
Material VisualizeMaterial {
|
||||
get {
|
||||
if (m_visualizeMat == null) {
|
||||
m_visualizeMat = new Material(Shader.Find("Hidden/Alloy Visualize")) {hideFlags = HideFlags.HideAndDontSave};
|
||||
}
|
||||
|
||||
return m_visualizeMat;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual string TextureProp { get { return "m_Texture"; } }
|
||||
|
||||
TextureVisualizeMode Mode {
|
||||
get { return m_vizIndex == 0 ? TextureVisualizeMode.None : DisplayModes[m_vizIndex - 1]; }
|
||||
}
|
||||
|
||||
protected string SaveName { get { return Property.name + TexInst; } }
|
||||
protected bool IsOpen { get { return TabGroup.IsOpen(SaveName); } }
|
||||
|
||||
//Passed in by the base editor
|
||||
public AlloyTextureFieldDrawer(AlloyInspectorBase editor, MaterialProperty property)
|
||||
: base(editor, property) {
|
||||
TabGroup = AlloyTabGroup.GetTabGroup();
|
||||
|
||||
m_tabOpen.value = TabGroup.IsOpen(SaveName);
|
||||
m_tabOpen.speed = 4.0f;
|
||||
}
|
||||
|
||||
|
||||
void AdvanceMode() {
|
||||
m_vizIndex = (m_vizIndex + 1) % (DisplayModes.Length + 1);
|
||||
}
|
||||
|
||||
string GetVisualizeButtonText() {
|
||||
return Mode == TextureVisualizeMode.None ? "Visualize" : Mode.ToString();
|
||||
}
|
||||
|
||||
void TextureField(float size, MaterialProperty prop, AlloyFieldDrawerArgs args) {
|
||||
var rawRef = prop.textureValue;
|
||||
|
||||
if (rawRef == null
|
||||
&& !prop.hasMixedValue
|
||||
&& (!IsOpen || m_hasParentTexture)) {
|
||||
|
||||
s_texLayout[0] = GUILayout.Width(100.0f);
|
||||
s_texLayout[1] = GUILayout.Height(16.0f);
|
||||
}
|
||||
else {
|
||||
s_texLayout[0] = GUILayout.Width(size - 20.0f);
|
||||
s_texLayout[1] = GUILayout.Height((size - 20.0f) * 0.9f);
|
||||
}
|
||||
|
||||
BeginMaterialProperty(Property);
|
||||
|
||||
var tex = EditorGUILayout.ObjectField(rawRef, typeof(Texture), false, s_texLayout) as Texture;
|
||||
|
||||
if (EndMaterialProperty()) {
|
||||
prop.textureValue = tex;
|
||||
}
|
||||
}
|
||||
|
||||
bool DrawWarningString(MaterialProperty texture) {
|
||||
//normal map warning
|
||||
if (DisplayModes == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ArrayUtility.Contains(DisplayModes, TextureVisualizeMode.NRM)) {
|
||||
if (texture.hasMixedValue || texture.textureValue == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
string path = AssetDatabase.GetAssetPath(texture.textureValue);
|
||||
|
||||
if (!string.IsNullOrEmpty(path)) {
|
||||
var imp = AssetImporter.GetAtPath(path);
|
||||
var importer = imp as TextureImporter;
|
||||
|
||||
// If the texture isn't a Normal Map, offer to convert it.
|
||||
if (importer != null && importer.textureType != TextureImporterType.NormalMap) {
|
||||
GUILayout.BeginHorizontal();
|
||||
EditorGUILayout.HelpBox("Texture not marked as normal map", MessageType.Warning, true);
|
||||
|
||||
var rect = GUILayoutUtility.GetLastRect();
|
||||
|
||||
rect.xMin += rect.width / 2;
|
||||
|
||||
GUILayout.BeginVertical();
|
||||
|
||||
GUILayout.Space(14.0f);
|
||||
|
||||
if (GUILayout.Button("Fix now", EditorStyles.toolbarButton, GUILayout.Width(60.0f))) {
|
||||
importer.textureType = TextureImporterType.NormalMap;
|
||||
AssetDatabase.ImportAsset(path);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void DrawVisualizeButton() {
|
||||
if (DisplayModes != null && DisplayModes.Length > 0
|
||||
&& Selection.activeGameObject && Selection.objects.Length == 1) {
|
||||
if (GUILayout.Button(GetVisualizeButtonText(), EditorStyles.toolbarButton, GUILayout.Width(70.0f))) {
|
||||
AdvanceMode();
|
||||
EditorApplication.delayCall += SceneView.RepaintAll;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnDisable() {
|
||||
if (Mode != TextureVisualizeMode.None) {
|
||||
if (m_oldSelect != null) {
|
||||
EditorUtility.SetSelectedRenderState(m_oldSelect, EditorSelectedRenderState.Highlight);
|
||||
}
|
||||
|
||||
m_vizIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnSceneGUI(Material[] materials) {
|
||||
if (materials.Length > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var material = materials[0];
|
||||
|
||||
if (Mode == TextureVisualizeMode.None || Selection.activeGameObject == null || Selection.objects.Length != 1) {
|
||||
if (m_oldSelect != null) {
|
||||
EditorUtility.SetSelectedRenderState(m_oldSelect, EditorSelectedRenderState.Highlight);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var curTex = Property.textureValue;
|
||||
|
||||
if (Mode == TextureVisualizeMode.None) {
|
||||
return;
|
||||
}
|
||||
|
||||
var trans = Property.textureScaleAndOffset;
|
||||
|
||||
var uvMode = 0.0f;
|
||||
var uvName = !m_hasParentTexture ? Property.name + "UV" : m_parentTexture + "UV";
|
||||
|
||||
if (material.HasProperty(uvName)) {
|
||||
uvMode = material.GetFloat(uvName);
|
||||
}
|
||||
|
||||
VisualizeMaterial.SetTexture("_MainTex", curTex);
|
||||
VisualizeMaterial.SetFloat("_Mode", (int) Mode);
|
||||
VisualizeMaterial.SetVector("_Trans", trans);
|
||||
VisualizeMaterial.SetFloat("_UV", uvMode);
|
||||
|
||||
var target = Selection.activeGameObject.GetComponent<Renderer>();
|
||||
|
||||
if (target != m_oldSelect && m_oldSelect != null) {
|
||||
EditorApplication.delayCall += SceneView.RepaintAll;
|
||||
EditorUtility.SetSelectedRenderState(target, EditorSelectedRenderState.Highlight);
|
||||
return;
|
||||
}
|
||||
|
||||
m_oldSelect = target;
|
||||
|
||||
Mesh mesh = null;
|
||||
var meshFilter = target.GetComponent<MeshFilter>();
|
||||
var meshRenderer = target.GetComponent<MeshRenderer>();
|
||||
|
||||
if (meshFilter != null && meshRenderer != null) {
|
||||
mesh = meshFilter.sharedMesh;
|
||||
}
|
||||
|
||||
if (mesh == null) {
|
||||
var skinnedMeshRenderer = target.GetComponent<SkinnedMeshRenderer>();
|
||||
|
||||
if (skinnedMeshRenderer != null) {
|
||||
mesh = skinnedMeshRenderer.sharedMesh;
|
||||
}
|
||||
}
|
||||
|
||||
if (mesh != null) {
|
||||
EditorUtility.SetSelectedRenderState(target, EditorSelectedRenderState.Hidden);
|
||||
Graphics.DrawMesh(mesh, target.localToWorldMatrix, VisualizeMaterial, 0, SceneView.currentDrawingSceneView.camera,
|
||||
TexInst);
|
||||
SceneView.currentDrawingSceneView.Repaint();
|
||||
}
|
||||
else {
|
||||
Debug.LogError("Game object does not have a mesh source.");
|
||||
}
|
||||
}
|
||||
|
||||
public override void Draw(AlloyFieldDrawerArgs args) {
|
||||
TexInst = args.MatInst;
|
||||
|
||||
if (m_firstDraw) {
|
||||
OnFirstDraw();
|
||||
m_firstDraw = false;
|
||||
}
|
||||
|
||||
var curTex = Property.textureValue;
|
||||
GUILayout.Space(9.0f);
|
||||
GUILayout.BeginHorizontal();
|
||||
EditorGUILayout.BeginVertical();
|
||||
|
||||
float oldWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = 80.0f;
|
||||
|
||||
bool drewOpen = false;
|
||||
|
||||
if (m_hasParentTexture || !Controls) {
|
||||
GUILayout.Label(DisplayName);
|
||||
}
|
||||
else {
|
||||
bool isOpen = TabGroup.Foldout(DisplayName, SaveName, GUILayout.Width(10.0f));
|
||||
m_tabOpen.target = isOpen;
|
||||
|
||||
if (EditorGUILayout.BeginFadeGroup(m_tabOpen.faded)) {
|
||||
drewOpen = true;
|
||||
DrawTextureControls(args);
|
||||
}
|
||||
|
||||
EditorGUILayout.EndFadeGroup();
|
||||
}
|
||||
|
||||
if ((EditorGUILayout.BeginFadeGroup(1.0f - m_tabOpen.faded)
|
||||
|| !Controls)
|
||||
&& curTex != null
|
||||
&& !Property.hasMixedValue) {
|
||||
|
||||
if (!DrawWarningString(Property)) {
|
||||
var oldCol = GUI.color;
|
||||
GUI.color = EditorGUIUtility.isProSkin ? Color.gray : new Color(0.3f, 0.3f, 0.3f);
|
||||
|
||||
string name = curTex.name;
|
||||
if (name.Length > 17) {
|
||||
name = name.Substring(0, 14) + "..";
|
||||
}
|
||||
GUILayout.Label(name + " (" + curTex.width + "x" + curTex.height + ")", EditorStyles.whiteLabel);
|
||||
GUI.color = oldCol;
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.EndFadeGroup();
|
||||
|
||||
if (curTex != null
|
||||
&& (!m_hasParentTexture || Controls)
|
||||
&& !Property.hasMixedValue) {
|
||||
DrawVisualizeButton();
|
||||
}
|
||||
|
||||
if (drewOpen) {
|
||||
EditorGUILayout.EndVertical();
|
||||
TextureField(Mathf.Lerp(74.0f, 100.0f, m_tabOpen.faded), Property, args);
|
||||
}
|
||||
else {
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
TextureField(74.0f, Property, args);
|
||||
}
|
||||
|
||||
EditorGUIUtility.labelWidth = oldWidth;
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
if (IsOpen) {
|
||||
GUILayout.Space(10.0f);
|
||||
}
|
||||
|
||||
|
||||
if (m_tabOpen.isAnimating) {
|
||||
args.Editor.MatEditor.Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawTextureControls(AlloyFieldDrawerArgs args) {
|
||||
|
||||
string velName = Property.name + "Velocity";
|
||||
var scrollProp = args.GetMaterialProperty(velName);
|
||||
|
||||
string spinName = Property.name + "Spin";
|
||||
var spinProp = args.GetMaterialProperty(spinName);
|
||||
|
||||
string uvName = Property.name + "UV";
|
||||
var uvProp = args.GetMaterialProperty(uvName);
|
||||
|
||||
|
||||
BeginMaterialProperty(Property);
|
||||
var trans = Property.textureScaleAndOffset;
|
||||
|
||||
Vector2 tileVal = EditorGUILayout.Vector2Field("Tiling", new Vector2(trans.x, trans.y));
|
||||
Vector2 offsetVal = EditorGUILayout.Vector2Field("Offset", new Vector2(trans.z, trans.w));
|
||||
|
||||
trans.x = tileVal.x;
|
||||
trans.y = tileVal.y;
|
||||
trans.z = offsetVal.x;
|
||||
trans.w = offsetVal.y;
|
||||
|
||||
|
||||
if (scrollProp != null) {
|
||||
BeginMaterialProperty(scrollProp);
|
||||
Vector2 curScroll = EditorGUILayout.Vector2Field("Scroll", scrollProp.vectorValue);
|
||||
|
||||
if (EndMaterialProperty()) {
|
||||
scrollProp.vectorValue = curScroll;
|
||||
}
|
||||
}
|
||||
|
||||
float old = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = 75.0f;
|
||||
|
||||
if (spinProp != null) {
|
||||
BeginMaterialProperty(spinProp);
|
||||
|
||||
float spin = spinProp.floatValue * Mathf.Rad2Deg;
|
||||
spin = EditorGUILayout.FloatField(new GUIContent("Spin"), spin, GUILayout.Width(180.0f));
|
||||
|
||||
if (EndMaterialProperty()) {
|
||||
spinProp.floatValue = spin * Mathf.Deg2Rad;
|
||||
}
|
||||
}
|
||||
|
||||
if (uvProp != null) {
|
||||
BeginMaterialProperty(uvProp);
|
||||
|
||||
float newVal = EditorGUILayout.Popup(new GUIContent("UV Set"), (int) uvProp.floatValue, s_uvModes,
|
||||
GUILayout.Width(180.0f));
|
||||
|
||||
if (EndMaterialProperty()) {
|
||||
uvProp.floatValue = newVal;
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUIUtility.labelWidth = old;
|
||||
|
||||
if (EndMaterialProperty()) {
|
||||
Property.textureScaleAndOffset = trans;
|
||||
}
|
||||
}
|
||||
|
||||
void OnFirstDraw() {
|
||||
m_tabOpen.value = IsOpen;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26f92e852a911224cbd5f29a496d6698
|
||||
timeCreated: 1430261489
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
// Alloy Physical Shader Framework
|
||||
// Copyright 2013-2017 RUST LLC.
|
||||
// http://www.alloy.rustltd.com/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
|
||||
public class AlloyTextureParser : AlloyFieldParser
|
||||
{
|
||||
protected override AlloyFieldDrawer GenerateDrawer(AlloyInspectorBase editor) {
|
||||
var ret = new AlloyTextureFieldDrawer(editor, MaterialProperty);
|
||||
|
||||
foreach (var token in Arguments) {
|
||||
var argName = token.ArgumentName;
|
||||
var argToken = token.ArgumentToken;
|
||||
|
||||
switch (argName) {
|
||||
case "Visualize": {
|
||||
var container = argToken as AlloyCollectionToken;
|
||||
if (container != null) {
|
||||
ret.DisplayModes = container.SubTokens.Select(t => (AlloyTextureFieldDrawer.TextureVisualizeMode)Enum.Parse(typeof(AlloyTextureFieldDrawer.TextureVisualizeMode), t.Token)).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "Parent": {
|
||||
ret.ParentTexture = argToken.Token;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "Controls":
|
||||
var valueToken = argToken as AlloyValueToken;
|
||||
if (valueToken != null) {
|
||||
ret.Controls = valueToken.BoolValue;
|
||||
}
|
||||
break;
|
||||
|
||||
// case "Keyword":
|
||||
// ret.Keyword = argToken.Token;
|
||||
// break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public AlloyTextureParser(MaterialProperty field)
|
||||
: base(field) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class AlloyCubeParser : AlloyFieldParser
|
||||
{
|
||||
public AlloyCubeParser(MaterialProperty field)
|
||||
: base(field) {
|
||||
|
||||
}
|
||||
|
||||
protected override AlloyFieldDrawer GenerateDrawer(AlloyInspectorBase editor) {
|
||||
return new AlloyDefaultDrawer(editor, MaterialProperty);
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5767db00543c76746b04f3bf27442325
|
||||
timeCreated: 1430261463
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
// Alloy Physical Shader Framework
|
||||
// Copyright 2013-2017 RUST LLC.
|
||||
// http://www.alloy.rustltd.com/
|
||||
|
||||
using Alloy;
|
||||
using UnityEditor;
|
||||
using UnityEditor.AnimatedValues;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class AlloyVectorParser : AlloyFieldParser {
|
||||
protected override AlloyFieldDrawer GenerateDrawer(AlloyInspectorBase editor) {
|
||||
AlloyFieldDrawer ret = null;
|
||||
|
||||
for (int i = 0; i < Arguments.Length; i++) {
|
||||
var argument = Arguments[i];
|
||||
var valProp = argument.ArgumentToken as AlloyValueToken;
|
||||
|
||||
switch (argument.ArgumentName) {
|
||||
case "Vector":
|
||||
|
||||
if (valProp != null) {
|
||||
ret = SetupVectorDrawer(editor, valProp, ret);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == null) {
|
||||
ret = new AlloyVectorDrawer(editor, MaterialProperty);
|
||||
((AlloyVectorDrawer) ret).Mode = AlloyVectorDrawer.VectorMode.Vector4;
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
AlloyFieldDrawer SetupVectorDrawer(AlloyInspectorBase editor,
|
||||
AlloyValueToken valProp,
|
||||
AlloyFieldDrawer ret) {
|
||||
if (valProp.ValueType == AlloyValueToken.ValueTypeEnum.String) {
|
||||
switch (valProp.StringValue) {
|
||||
case "Euler":
|
||||
ret = new AlloyVectorDrawer(editor, MaterialProperty);
|
||||
((AlloyVectorDrawer) ret).Mode = AlloyVectorDrawer.VectorMode.Euler;
|
||||
break;
|
||||
|
||||
case "TexCoord":
|
||||
ret = new AlloyTexCoordDrawer(editor, MaterialProperty);
|
||||
break;
|
||||
|
||||
case "Channels":
|
||||
ret = new AlloyMaskDrawer(editor, MaterialProperty);
|
||||
break;
|
||||
|
||||
default:
|
||||
Debug.LogError("Non supported vector property!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (valProp.ValueType == AlloyValueToken.ValueTypeEnum.Float) {
|
||||
switch ((int) valProp.FloatValue) {
|
||||
case 2:
|
||||
ret = new AlloyVectorDrawer(editor, MaterialProperty);
|
||||
((AlloyVectorDrawer) ret).Mode = AlloyVectorDrawer.VectorMode.Vector2;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
ret = new AlloyVectorDrawer(editor, MaterialProperty);
|
||||
((AlloyVectorDrawer) ret).Mode = AlloyVectorDrawer.VectorMode.Vector3;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
ret = new AlloyVectorDrawer(editor, MaterialProperty);
|
||||
((AlloyVectorDrawer) ret).Mode = AlloyVectorDrawer.VectorMode.Vector4;
|
||||
break;
|
||||
|
||||
default:
|
||||
Debug.LogError("Non supported vector property!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public AlloyVectorParser(MaterialProperty field)
|
||||
: base(field) {
|
||||
}
|
||||
}
|
||||
|
||||
public class AlloyVectorDrawer : AlloyFieldDrawer {
|
||||
public enum VectorMode {
|
||||
Vector2,
|
||||
Vector3,
|
||||
Vector4,
|
||||
Euler
|
||||
}
|
||||
|
||||
public VectorMode Mode = VectorMode.Vector4;
|
||||
|
||||
public override void Draw(AlloyFieldDrawerArgs args) {
|
||||
Vector4 newVal = Vector4.zero;
|
||||
var label = new GUIContent(DisplayName);
|
||||
|
||||
BeginMaterialProperty(Property);
|
||||
|
||||
switch (Mode) {
|
||||
case VectorMode.Vector4:
|
||||
newVal = EditorGUILayout.Vector4Field(label.text, Property.vectorValue);
|
||||
break;
|
||||
|
||||
case VectorMode.Vector3:
|
||||
newVal = EditorGUILayout.Vector3Field(label.text, Property.vectorValue);
|
||||
break;
|
||||
|
||||
case VectorMode.Vector2:
|
||||
newVal = EditorGUILayout.Vector2Field(label.text, Property.vectorValue);
|
||||
break;
|
||||
|
||||
case VectorMode.Euler:
|
||||
var value = args.GetMaterialProperty(Property.name + "EulerUI").vectorValue;
|
||||
//var value = (Vector4)args.Editor.GetProperty(MaterialProperty.PropType.Vector, Property.name + "EulerUI").colorValue;
|
||||
newVal = Quaternion.Euler(value) * Vector3.up;
|
||||
GUI.changed = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (EndMaterialProperty()) {
|
||||
Property.vectorValue = newVal;
|
||||
}
|
||||
}
|
||||
|
||||
public AlloyVectorDrawer(AlloyInspectorBase editor, MaterialProperty property) : base(editor, property) {
|
||||
}
|
||||
}
|
||||
|
||||
public class AlloyTexCoordDrawer : AlloyTextureFieldDrawer {
|
||||
AnimBool m_tabOpen = new AnimBool(false);
|
||||
|
||||
public AlloyTexCoordDrawer(AlloyInspectorBase editor, MaterialProperty property) : base(editor, property) {
|
||||
}
|
||||
|
||||
public override void Draw(AlloyFieldDrawerArgs args) {
|
||||
TexInst = args.MatInst;
|
||||
|
||||
bool isOpen = TabGroup.Foldout(DisplayName, SaveName, GUILayout.Width(10.0f));
|
||||
m_tabOpen.target = isOpen;
|
||||
|
||||
if (m_tabOpen.value) {
|
||||
EditorGUILayout.BeginFadeGroup(m_tabOpen.faded);
|
||||
DrawTextureControls(args);
|
||||
EditorGUILayout.EndFadeGroup();
|
||||
}
|
||||
|
||||
if (m_tabOpen.isAnimating) {
|
||||
args.Editor.MatEditor.Repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class AlloyMaskDrawer : AlloyFieldDrawer {
|
||||
public AlloyMaskDrawer(AlloyInspectorBase editor, MaterialProperty property) : base(editor, property) {
|
||||
}
|
||||
|
||||
public override void Draw(AlloyFieldDrawerArgs args) {
|
||||
Vector4 newVal = Property.vectorValue;
|
||||
var label = new GUIContent(DisplayName);
|
||||
|
||||
BeginMaterialProperty(Property);
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label(label);
|
||||
|
||||
newVal.x = GUILayout.Toggle(newVal.x > 0.5f, "R", EditorStyles.toolbarButton) ? 1.0f : 0.0f;
|
||||
newVal.y = GUILayout.Toggle(newVal.y > 0.5f, "G", EditorStyles.toolbarButton) ? 1.0f : 0.0f;
|
||||
newVal.z = GUILayout.Toggle(newVal.z > 0.5f, "B", EditorStyles.toolbarButton) ? 1.0f : 0.0f;
|
||||
newVal.w = GUILayout.Toggle(newVal.w > 0.5f, "A", EditorStyles.toolbarButton) ? 1.0f : 0.0f;
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
if (EndMaterialProperty()) {
|
||||
Property.vectorValue = newVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c2ebab9324a76547a9d5df7b45cd747
|
||||
timeCreated: 1430261728
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user