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:
+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