This commit is contained in:
SoulliesOfficial
2025-07-21 05:42:20 -04:00
parent e483cfe502
commit bae0bfbc20
533 changed files with 172709 additions and 125965 deletions

View File

@@ -0,0 +1,100 @@
using UnityEditor;
using UnityEngine;
using System;
// using Unity.Properties;
public class BinaryIntAttribute : PropertyAttribute
{
public int binaryBits;
public bool showInputFiled;
public int tabNums;
public BinaryIntAttribute(int Bits = 32,bool showInput = false,int tab = 0)
{
binaryBits = Bits;
showInputFiled = showInput;
tabNums = tab;
}
}
[CustomPropertyDrawer(typeof(BinaryIntAttribute))]
public class BinaryIntDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
GUIStyle richTextStyle = EditorStyles.label;
richTextStyle.richText = true;
BinaryIntAttribute binaryIntAttribute = (BinaryIntAttribute)attribute;
// int value = property.intValue;
// int largestBit = 0;
// for (int i = 0; i < 32; i++)
// {
// if ((~value & (1 << i)) == 0)
// {
// largestBit = i;
// }
// }
//
// int addZeroCount = 0;
// if (largestBit < binaryIntAttribute.binaryBits)
// {
// addZeroCount = binaryIntAttribute.binaryBits - largestBit - 1;
// }
//
// string addZeroString = "";
// for (int i = 0; i < addZeroCount; i++)
// {
// addZeroString += "0";
// }
// string binary = addZeroString+Convert.ToString(property.intValue, 2);
string binary = DrawBinaryInt(property.intValue, binaryIntAttribute.binaryBits);
string tabs = "";
for (int i = 0; i < binaryIntAttribute.tabNums; i++)
{
tabs += "\t";
}
if (binaryIntAttribute.showInputFiled)
{
string labelText = property.displayName + tabs + "<mspace=1em>" + binary + "</mspace>";
Rect intRect = EditorGUI.PrefixLabel(position,new GUIContent(labelText),richTextStyle);
property.intValue = EditorGUI.IntField( intRect,property.intValue);
}
else
{
EditorGUILayout.LabelField(property.displayName + tabs);
EditorGUILayout.LabelField(binary);
}
}
public static string DrawBinaryInt(int value ,int binaryBits)
{
int largestBit = 0;
for (int i = 0; i < 32; i++)
{
if ((~value & (1 << i)) == 0)
{
largestBit = i;
}
}
int addZeroCount = 0;
if (largestBit < binaryBits)
{
addZeroCount = binaryBits - largestBit - 1;
}
string addZeroString = "";
for (int i = 0; i < addZeroCount; i++)
{
addZeroString += "0";
}
string binary = addZeroString+Convert.ToString(value, 2);
return binary;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4517deaf5f31a5848b6a58304d1f516f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,236 @@
using UnityEditor;
using UnityEngine;
using UnityEditor.Experimental.GraphView;
using System;
using System.Collections.Generic;
// #if UNITY_EDITOR
[CustomEditor(typeof(MaterialPropertyAgent))]
public class MaterialPropertyAgentInspector : UnityEditor.Editor
{
private MaterialPropertyAgent agent;
private void OnEnable()
{
agent = (MaterialPropertyAgent)target;
}
private GUIContent materialIndexContent = new GUIContent("材质序号:", "只有模型模式下需要使用,谨慎修改");
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUI.BeginChangeCheck();
if (!agent.isGetByComponet)
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("customRenderer"),new GUIContent("指定Renderer"));
}
if (agent.isRendererMode)
{
EditorGUILayout.BeginHorizontal();
int lastIndex = agent.materialIndex;
agent.materialIndex = EditorGUILayout.IntField(materialIndexContent ,agent.materialIndex);
if (lastIndex != agent.materialIndex)
{
agent.initMatAndShaderByMaterialIndexChange();
}
EditorGUILayout.LabelField("材质名:"+agent.mat.name+"\t"+"Shader名"+agent.shader.name);
EditorGUILayout.EndHorizontal();
}
DrawPropertyData(ref agent.data0, "Data0", serializedObject.FindProperty("data0"));
DrawPropertyData(ref agent.data1, "Data1", serializedObject.FindProperty("data1"));
DrawPropertyData(ref agent.data2, "Data2", serializedObject.FindProperty("data2"));
DrawPropertyData(ref agent.data3, "Data3", serializedObject.FindProperty("data3"));
DrawPropertyData(ref agent.data4, "Data4", serializedObject.FindProperty("data4"));
DrawPropertyData(ref agent.data5, "Data5", serializedObject.FindProperty("data5"));
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("添加"))
{
agent.addProperteData();
}
if (GUILayout.Button("全部删除"))
{
agent.removeAllProperty();
}
EditorGUILayout.EndHorizontal();
serializedObject.ApplyModifiedProperties();
if (EditorGUI.EndChangeCheck())
{
PrefabUtility.RecordPrefabInstancePropertyModifications(agent);
if (!agent.isGetByComponet && agent.mat)
{
if(matEditor) DestroyImmediate(matEditor);
matEditor = (MaterialEditor)CreateEditor(agent.mat);
}
}
if (!agent.isGetByComponet && agent.mat)
{
DrawMaterialInspector(matEditor,agent.mat);
}
}
void DrawPropertyData(ref MaterialPropertyAgent.PropertyData data, string dataLabel, SerializedProperty property)
{
EditorGUI.BeginProperty(EditorGUILayout.GetControlRect(false, 0f), GUIContent.none, property);
if (data.isActive)
{
EditorGUILayout.LabelField(dataLabel, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.BeginHorizontal();
float originLabelWidth = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 80;
// data.index = EditorGUILayout.Popup("属性名:", data.index, agent.shaderPropNameArr);
// data.index = EditorGUILayout.Popup("属性名:", data.index, agent.shaderPropDescripArr);
// string dataDesript = data.descripName;
if (GUILayout.Button(data.descripName, EditorStyles.popup))
{
int dataIndexInAgent = data.dataIndexInAgent;
StringListSerchProvider provider = ScriptableObject.CreateInstance<StringListSerchProvider>();
provider.Initialize(agent.shaderPropDescripsForSerch, (x) =>
{
if (x != null)
{
AfterShaderPropSerch(dataIndexInAgent,x);
}
});
SearchWindow.Open(new SearchWindowContext(GUIUtility.GUIToScreenPoint(Event.current.mousePosition)), provider);
// SearchWindow.Open(new SearchWindowContext(GUIUtility.GUIToScreenPoint(Event.current.mousePosition)),
// new StringListSerchProvider(agent.shaderPropDescripsForSerch, (x) =>
// {
// if (x != null)
// {
// AfterShaderPropSerch(dataIndexInAgent,x);
// }
// }));
}
EditorGUILayout.LabelField("属性类型:", data.type.ToString());
EditorGUILayout.EndHorizontal();
EditorGUIUtility.labelWidth = originLabelWidth;
switch (data.type)
{
case MaterialPropertyAgent.shaderPropertyType.Color:
SerializedProperty colorProp = property.FindPropertyRelative("colorValue");
if (data.descripName.ToLower().Contains("hdr"))
{
colorProp.colorValue = EditorGUILayout.ColorField(new GUIContent(data.propName + " :") , colorProp.colorValue,true,true,true);
}
else
{
colorProp.colorValue = EditorGUILayout.ColorField(data.propName + " :", colorProp.colorValue);
}
break;
case MaterialPropertyAgent.shaderPropertyType.Vector:
case MaterialPropertyAgent.shaderPropertyType.TexEnv:
SerializedProperty vecProp = property.FindPropertyRelative("vecValue");
if (data.type == MaterialPropertyAgent.shaderPropertyType.Vector)
{
vecProp.vector4Value = EditorGUILayout.Vector4Field(data.propName + " :", vecProp.vector4Value);
}
else if (data.type == MaterialPropertyAgent.shaderPropertyType.TexEnv)
{
vecProp.vector4Value = EditorGUILayout.Vector4Field(data.propName + ":", vecProp.vector4Value);
}
break;
case MaterialPropertyAgent.shaderPropertyType.Float:
case MaterialPropertyAgent.shaderPropertyType.Range:
SerializedProperty floatProp = property.FindPropertyRelative("floatValue");
if (data.type == MaterialPropertyAgent.shaderPropertyType.Float)
{
floatProp.floatValue = EditorGUILayout.FloatField(data.propName + ":", floatProp.floatValue);
}
else if (data.type == MaterialPropertyAgent.shaderPropertyType.Range)
{
floatProp.floatValue = EditorGUILayout.Slider(data.propName + ":", floatProp.floatValue, data.rangMin, data.rangMax);
}
break;
}
if (GUILayout.Button("删除", new[] { GUILayout.Width(200) }))
{
data.isActive = false;
}
EditorGUI.indentLevel--;
// EditorGUILayout.Space();
}
EditorGUI.EndProperty();
}
//因为Action不能有Ref。所以有了这个丑陋的HardCode
public void AfterShaderPropSerch(int dataIndexInAgent, string propertyDesrpt)
{
switch (dataIndexInAgent)
{
case 0:
AfterShaderPropSerch(ref agent.data0,propertyDesrpt);
break;
case 1:
AfterShaderPropSerch(ref agent.data1,propertyDesrpt);
break;
case 2:
AfterShaderPropSerch(ref agent.data2,propertyDesrpt);
break;
case 3:
AfterShaderPropSerch(ref agent.data3,propertyDesrpt);
break;
case 4:
AfterShaderPropSerch(ref agent.data4,propertyDesrpt);
break;
case 5:
AfterShaderPropSerch(ref agent.data5,propertyDesrpt);
break;
}
}
public void AfterShaderPropSerch(ref MaterialPropertyAgent.PropertyData data, string propertyDesrpt)
{
int preservedIndex = data.index;
// string propname = data.propName;
data.index = Array.FindIndex(agent.shaderPropDescripArr, x=> x.Equals(propertyDesrpt) );
// Debug.Log();
if (preservedIndex != data.index)//证明用户进行了更改
{
if (!agent.isCanUsedIndex(data.index))
{
//TODO给一个报错提示
Debug.LogError("材质属性已经存在:" + ShaderUtil.GetPropertyDescription(agent.shader, data.index));
data.index = agent.getCanUsedIndex();
}
//此处进行内容刷新
data.setValueByPropChange();
}
}
private MaterialEditor matEditor;
void DrawMaterialInspector(MaterialEditor editor,Material mat)
{
if (editor != null && mat != null)
{
// Draw the material's foldout and the material shader field
// Required to call _materialEditor.OnInspectorGUI ();
editor.DrawHeader();
// We need to prevent the user to edit Unity default materials
bool isDefaultMaterial = !AssetDatabase.GetAssetPath (mat).StartsWith ("Assets");
using (new EditorGUI.DisabledGroupScope(isDefaultMaterial)) {
// Draw the material properties
// Works only if the foldout of _materialEditor.DrawHeader () is open
editor.OnInspectorGUI ();
}
}
}
}
// #endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b9544bec10c84ecca289bece4a630d65
timeCreated: 1702126025

View File

@@ -0,0 +1,732 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor.AnimatedValues;
// using UnityEditor.Rendering.Universal.ShaderGUI;
using UnityEngine;
using UnityEngine.Rendering;
namespace UnityEditor
{
public class ShaderGUIHelper
{
public class ShaderPropertyPack
{
public MaterialProperty property;
public string name;
}
private List<Material> mats;
private MaterialEditor matEditor;
public List<ShaderPropertyPack> ShaderPropertyPacks = new List<ShaderPropertyPack>();
public ShaderFlagsBase[] shaderFlags = null;
public void Init(MaterialEditor materialEditor, MaterialProperty[] properties,
ShaderFlagsBase[] shaderFlags_in = null, List<Material> mats_in = null)
{
shaderFlags = shaderFlags_in;
ShaderPropertyPacks.Clear();
mats = mats_in;
Shader shader = mats[0].shader;
matEditor = materialEditor;
for (int i = 0; i < ShaderUtil.GetPropertyCount(shader); i++)
{
ShaderPropertyPack pack = new ShaderPropertyPack();
pack.name = ShaderUtil.GetPropertyName(shader, i);
for (int index = 0; index < properties.Length; ++index)
{
if (properties[index] != null && properties[index].name == pack.name)
{
pack.property = properties[index];
break;
}
else
{
if (index == properties.Length - 1)
{
Debug.LogError(pack.name + "找不到Properties");
}
}
}
ShaderPropertyPacks.Add(pack);
}
}
AnimBool trueAnimBool = new AnimBool(true);
public void DrawBigBlock(String label, Action drawBlock)
{
EditorGUILayout.Space();
var origFontStyle = EditorStyles.label.fontStyle;
EditorStyles.label.fontStyle = FontStyle.Bold;
EditorGUILayout.LabelField(label);
EditorStyles.label.fontStyle = origFontStyle;
drawBlock();
GuiLine();
}
public void DrawBigBlockFoldOut(ref AnimBool foldOutAnimBool, String label, Action drawBlock)
{
EditorGUILayout.Space();
EditorGUILayout.BeginHorizontal();
var rect = EditorGUILayout.GetControlRect();
var foldoutRect = new Rect(rect.x, rect.y, rect.width, rect.height);
// EditorGUI.DrawRect(foldoutRect,Color.red);
var labelRect = new Rect(rect.x + 2f, rect.y, rect.width - 2f, rect.height);
// EditorGUILayout.LabelField(new GUIContent(label), EditorStyles.boldLabel);
foldOutAnimBool.target = EditorGUI.Foldout(foldoutRect, foldOutAnimBool.target, string.Empty, true);
FontStyle origFontStyle = EditorStyles.label.fontStyle;
EditorStyles.label.fontStyle = FontStyle.Bold;
EditorGUI.LabelField(labelRect, label);
EditorStyles.label.fontStyle = origFontStyle;
EditorGUILayout.EndHorizontal();
float faded = foldOutAnimBool.faded;
if (faded == 0) faded = 0.00001f;
EditorGUILayout.BeginFadeGroup(faded);
EditorGUI.indentLevel++;
drawBlock();
EditorGUI.indentLevel--;
EditorGUILayout.EndFadeGroup();
GuiLine();
}
public void DrawBigBlockWithToggle(String label, string propertyName, int flagBitsName = 0, int flagIndex = 0,
string shaderKeyword = null, string shaderPassName = null, string shaderPassName2 = null,
Action<bool> drawBlock = null)
{
DrawToggle(label, propertyName, flagBitsName, flagIndex, shaderKeyword, shaderPassName, shaderPassName2,
isIndentBlock: true, FontStyle.Bold, drawBlock: drawBlock);
GuiLine();
}
public void DrawToggleFoldOut(ref AnimBool foldOutAnimBool, String label, string propertyName = null,
int flagBitsName = 0,
int flagIndex = 0, string shaderKeyword = null, string shaderPassName = null, bool isIndentBlock = true,
FontStyle fontStyle = FontStyle.Normal,
Action<bool> drawBlock = null, Action<bool> drawEndChangeCheck = null)
{
if (fontStyle == FontStyle.Bold)
{
EditorGUILayout.Space();
}
EditorGUILayout.BeginHorizontal();
var rect = EditorGUILayout.GetControlRect();
var toggleRect = GetRectAfterLabelWidth(rect);
var foldoutRect = new Rect(rect.x, rect.y, rect.width, rect.height);
foldoutRect.width = toggleRect.x - foldoutRect.x;
var labelRect = new Rect(rect.x + 2f, rect.y, rect.width - 2f, rect.height);
bool isToggle = false;
// 必须先画Toggle不然按钮会被FoldOut和Label覆盖。
DrawToggle("", propertyName, flagBitsName, flagIndex, shaderKeyword, shaderPassName, isIndentBlock: false,
fontStyle: FontStyle.Normal, rect: toggleRect, drawBlock:
toggle => { isToggle = toggle; }, drawEndChangeCheck: isEndChangeToggle =>
{
if (drawEndChangeCheck != null)
{
drawEndChangeCheck(isEndChangeToggle);
}
});
// EditorGUI.DrawRect(foldoutRect,Color.red);
foldOutAnimBool.target = EditorGUI.Foldout(foldoutRect, foldOutAnimBool.target, string.Empty, true);
var origFontStyle = EditorStyles.label.fontStyle;
EditorStyles.label.fontStyle = fontStyle;
// EditorGUI.DrawRect(labelRect,Color.blue);
EditorGUI.LabelField(labelRect, label);
EditorStyles.label.fontStyle = origFontStyle;
EditorGUILayout.EndHorizontal();
if (isIndentBlock) EditorGUI.indentLevel++;
float faded = foldOutAnimBool.faded;
if (faded == 0) faded = 0.00001f; //用于欺骗FadeGroup不要让他真的关闭了。这样会藏不住相关的GUI。我们的目的是GUI藏住但是逻辑还是在跑。drawBlock要执行。
EditorGUILayout.BeginFadeGroup(faded);
{
EditorGUI.BeginDisabledGroup(!isToggle);
drawBlock?.Invoke(isToggle);
EditorGUI.EndDisabledGroup();
}
EditorGUILayout.EndFadeGroup();
if (isIndentBlock) EditorGUI.indentLevel--;
}
public void DrawToggle(String label, string propertyName = null, int flagBitsName = 0, int flagIndex = 0,
string shaderKeyword = null, string shaderPassName = null, string shaderPassName2 = null,
bool isIndentBlock = true, FontStyle fontStyle = FontStyle.Normal, Rect rect = new Rect(),
Action<bool> drawBlock = null, Action<bool> drawEndChangeCheck = null)
{
if (propertyName != null && GetProperty(propertyName) == null)
return;
if (fontStyle == FontStyle.Bold)
{
EditorGUILayout.Space();
}
bool isToggle = false;
if (propertyName != null)
{
isToggle = GetProperty(propertyName).floatValue > 0.5f ? true : false;
}
else if (flagBitsName != 0 && shaderFlags[0] != null)
{
isToggle = shaderFlags[0].CheckFlagBits(flagBitsName, index: flagIndex);
}
else if (shaderKeyword != null)
{
isToggle = mats[0].IsKeywordEnabled(shaderKeyword);
}
else if (shaderPassName != null)
{
isToggle = mats[0].GetShaderPassEnabled(shaderPassName);
}
else if (shaderPassName2 != null)
{
isToggle = mats[0].GetShaderPassEnabled(shaderPassName2);
}
if (propertyName != null)
{
EditorGUI.showMixedValue = GetProperty(propertyName).hasMixedValue;
}
for (int i = 0; i < mats.Count; i++)
{
if (isToggle)
{
if (shaderKeyword != null)
{
mats[i].EnableKeyword(shaderKeyword);
}
if (shaderPassName != null)
{
mats[i].SetShaderPassEnabled(shaderPassName, true);
}
if (shaderPassName2 != null)
{
mats[i].SetShaderPassEnabled(shaderPassName2, true);
}
}
else
{
if (shaderKeyword != null)
{
mats[i].DisableKeyword(shaderKeyword);
}
if (shaderPassName != null)
{
mats[i].SetShaderPassEnabled(shaderPassName, false);
}
if (shaderPassName2 != null)
{
mats[i].SetShaderPassEnabled(shaderPassName2, false);
}
}
}
EditorGUI.BeginChangeCheck();
var origFontStyle = EditorStyles.label.fontStyle;
EditorStyles.label.fontStyle = fontStyle;
if (rect.width > 0) //给FoldOut功能使用。
{
isToggle = EditorGUI.Toggle(rect, isToggle, EditorStyles.toggle);
}
else
{
isToggle = EditorGUILayout.Toggle(label, isToggle);
}
EditorStyles.label.fontStyle = origFontStyle;
if (EditorGUI.EndChangeCheck())
{
for (int i = 0; i < mats.Count; i++)
{
if (isToggle)
{
if (propertyName != null)
{
GetProperty(propertyName).floatValue = 1;
}
if (flagBitsName != 0 && shaderFlags[i] != null)
{
shaderFlags[i].SetFlagBits(flagBitsName, index: flagIndex);
}
if (shaderKeyword != null)
{
mats[i].EnableKeyword(shaderKeyword);
}
if (shaderPassName != null)
{
mats[i].SetShaderPassEnabled(shaderPassName, true);
}
if (shaderPassName2 != null)
{
mats[i].SetShaderPassEnabled(shaderPassName2, true);
}
}
else
{
if (propertyName != null)
{
GetProperty(propertyName).floatValue = 0;
}
if (flagBitsName != 0 && shaderFlags[i] != null)
{
shaderFlags[i].ClearFlagBits(flagBitsName, index: flagIndex);
}
if (shaderKeyword != null)
{
mats[i].DisableKeyword(shaderKeyword);
}
if (shaderPassName != null)
{
mats[i].SetShaderPassEnabled(shaderPassName, false);
}
if (shaderPassName2 != null)
{
mats[i].SetShaderPassEnabled(shaderPassName2, false);
}
}
}
drawEndChangeCheck?.Invoke(isToggle);
}
if (isIndentBlock) EditorGUI.indentLevel++;
drawBlock?.Invoke(isToggle);
if (isIndentBlock) EditorGUI.indentLevel--;
EditorGUI.showMixedValue = false;
}
public void DrawSlider(string label, string propertyName, float minValue, float maxValue,
Action<float> drawBlock = null)
{
EditorGUI.showMixedValue = GetProperty(propertyName).hasMixedValue;
float f = GetProperty(propertyName).floatValue;
EditorGUI.BeginChangeCheck();
f = EditorGUILayout.Slider(label, f, minValue, maxValue);
if (EditorGUI.EndChangeCheck())
{
GetProperty(propertyName).floatValue = f;
}
drawBlock?.Invoke(f);
EditorGUI.showMixedValue = false;
}
public void DrawFloat(string label, string propertyName, bool isReciprocal = false,
Action<float> drawBlock = null)
{
EditorGUI.showMixedValue = GetProperty(propertyName).hasMixedValue;
float f = GetProperty(propertyName).floatValue;
if (isReciprocal) f = 1 / f;
EditorGUI.BeginChangeCheck();
f = EditorGUILayout.FloatField(label, f);
if (isReciprocal) f = 1 / f;
if (EditorGUI.EndChangeCheck())
{
GetProperty(propertyName).floatValue = f;
}
drawBlock?.Invoke(f);
EditorGUI.showMixedValue = false;
}
public void DrawVector4In2Line(string propertyName, string firstLineLabel = null, string secondLineLabel = null,
Action drawBlock = null)
{
MaterialProperty property = GetProperty(propertyName);
EditorGUI.showMixedValue = property.hasMixedValue;
Vector2 xy = new Vector2(property.vectorValue.x, property.vectorValue.y);
Vector2 zw = new Vector2(property.vectorValue.z, property.vectorValue.w);
EditorGUI.BeginChangeCheck();
if (firstLineLabel != null)
{
xy = EditorGUILayout.Vector2Field(firstLineLabel, xy);
}
if (secondLineLabel != null)
{
zw = EditorGUILayout.Vector2Field(secondLineLabel, zw);
}
if (EditorGUI.EndChangeCheck())
{
property.vectorValue = new Vector4(xy.x, xy.y, zw.x, zw.y);
}
drawBlock?.Invoke();
EditorGUI.showMixedValue = false;
}
float GetCompInVec4(Vector4 vec, string comp)
{
float f = 0;
switch (comp)
{
case "x":
f = vec.x;
break;
case "y":
f = vec.y;
break;
case "z":
f = vec.z;
break;
case "w":
f = vec.w;
break;
}
return f;
}
Vector4 SetCompInVec4(Vector4 vec, string comp, float value)
{
switch (comp)
{
case "x":
vec.x = value;
break;
case "y":
vec.y = value;
break;
case "z":
vec.z = value;
break;
case "w":
vec.w = value;
break;
}
return vec;
}
public void DrawVector4MinMaxSlider(string propertyName, string Lable, string minChannel, string maxChanel,
float minValue = 0f, float maxValue = 1f, Action<float> drawBlock = null)
{
EditorGUI.showMixedValue = GetProperty(propertyName).hasMixedValue;
Vector4 vec = GetProperty(propertyName).vectorValue;
float minChannelVal = GetCompInVec4(vec, minChannel);
float maxChanelVal = GetCompInVec4(vec, maxChanel);
EditorGUI.BeginChangeCheck();
using (EditorGUILayout.HorizontalScope scope = new EditorGUILayout.HorizontalScope())
{
EditorGUILayout.PrefixLabel(Lable);
minChannelVal =
EditorGUILayout.FloatField(minChannelVal, new GUILayoutOption[] { GUILayout.Width(80) });
EditorGUILayout.MinMaxSlider(ref minChannelVal, ref maxChanelVal, minValue, maxValue);
maxChanelVal = EditorGUILayout.FloatField(maxChanelVal, new GUILayoutOption[] { GUILayout.Width(80) });
}
if (EditorGUI.EndChangeCheck())
{
vec = SetCompInVec4(vec, minChannel, minChannelVal);
vec = SetCompInVec4(vec, maxChanel, maxChanelVal);
GetProperty(propertyName).vectorValue = vec;
}
EditorGUI.showMixedValue = false;
}
public void DrawVector4Componet(string label, string propertyName, string channel, bool isSlider,
float minValue = 0, float maxValue = 1, float powerSlider = 1, float multiplier = 1,
bool isReciprocal = false, Action<float> drawBlock = null)
{
EditorGUI.showMixedValue = GetProperty(propertyName).hasMixedValue;
Vector4 vec = GetProperty(propertyName).vectorValue;
float f = GetCompInVec4(vec, channel);
f *= multiplier;
if (isReciprocal) f = 1 / f;
EditorGUI.BeginChangeCheck();
if (isSlider)
{
if (powerSlider > 1)
{
f = PowerSlider(EditorGUILayout.GetControlRect(new GUILayoutOption[] { GUILayout.Height(18) }),
new GUIContent(label), f, minValue, maxValue, powerSlider);
}
else
{
f = EditorGUILayout.Slider(label, f, minValue, maxValue);
}
}
else
{
f = EditorGUILayout.FloatField(label, f);
}
if (isReciprocal) f = 1 / f;
f /= multiplier;
if (EditorGUI.EndChangeCheck())
{
GetProperty(propertyName).vectorValue = SetCompInVec4(vec, channel, f);
}
drawBlock?.Invoke(f);
EditorGUI.showMixedValue = false;
}
public void DrawVector4XYZComponet(string label, string propertyName, Action<Vector3> drawBlock = null)
{
EditorGUI.showMixedValue = GetProperty(propertyName).hasMixedValue;
Vector4 originVec = GetProperty(propertyName).vectorValue;
Vector3 vec = originVec;
EditorGUI.BeginChangeCheck();
vec = EditorGUILayout.Vector3Field(label, vec);
if (EditorGUI.EndChangeCheck())
{
GetProperty(propertyName).vectorValue = new Vector4(vec.x, vec.y, vec.z, originVec.w);
}
drawBlock?.Invoke(vec);
EditorGUI.showMixedValue = false;
}
public enum SamplerWarpMode
{
Repeat,
Clamp,
RepeatX_ClampY,
ClampX_RepeatY
}
public Rect GetRectAfterLabelWidth(Rect rect, bool ignoreIndent = false)
{
Rect rectAfterLabelWidth = MaterialEditor.GetRectAfterLabelWidth(rect); //右边缘是准的。
Rect leftAlignedFieldRect = MaterialEditor.GetLeftAlignedFieldRect(rect); //左边缘是准的实际有2f空隙。
float x = leftAlignedFieldRect.x + 2f;
float width = rectAfterLabelWidth.x + rectAfterLabelWidth.width - x;
var newRec = new Rect(x, rectAfterLabelWidth.y, width, rectAfterLabelWidth.height);
if (ignoreIndent)
{
float indent = (float)EditorGUI.indentLevel * 15f;
newRec.x -= indent;
newRec.width += indent;
}
// // EditorGUI.DrawRect(leftRect,Color.red);
// float biasWidth = EditorGUI.indentLevel * 15f - 2f;
// leftRect.x -= biasWidth;
// leftRect.width += biasWidth;
// EditorGUI.DrawRect(leftRect,Color.green);
return newRec;
}
public void DrawTextureFoldOut(ref AnimBool foldOutAnimBool, string label, string texturePropertyName,
string colorPropertyName = null, bool drawScaleOffset = true, bool drawWrapMode = false,
int flagBitsName = 0, int flagIndex = 2, Action<Texture> drawBlock = null)
{
EditorGUILayout.BeginHorizontal();
var rect = EditorGUILayout.GetControlRect();
var foldoutRect = new Rect(rect.x, rect.y, rect.width - MaterialEditor.GetRectAfterLabelWidth(rect).width,
rect.height);
var textureThumbnialRect = new Rect(rect.x + 2f, rect.y, 14f, rect.height);
var labelRect = new Rect(rect.x + 35f, rect.y, rect.width - 18f, rect.height);
Texture texture =
matEditor.TexturePropertyMiniThumbnail(textureThumbnialRect, GetProperty(texturePropertyName), "", "");
EditorGUI.LabelField(labelRect, label);
foldOutAnimBool.target = EditorGUI.Foldout(foldoutRect, foldOutAnimBool.target, string.Empty, true);
if (colorPropertyName != null)
{
Rect colorPropRect = GetRectAfterLabelWidth(rect, true);
// colorPropRect.x -= EditorGUI.indentLevel
Color color = matEditor.ColorProperty(colorPropRect, GetProperty(colorPropertyName), "");
}
EditorGUILayout.EndHorizontal();
float faded = foldOutAnimBool.faded;
if (faded == 0) faded = 0.00001f;
EditorGUILayout.BeginFadeGroup(faded);
EditorGUI.BeginDisabledGroup(texture == null);
DrawAfterTexture(true, label, texturePropertyName, drawScaleOffset, drawWrapMode, flagBitsName, flagIndex,
drawBlock);
EditorGUI.EndDisabledGroup();
EditorGUILayout.EndFadeGroup();
}
public void DrawTexture(string label, string texturePropertyName, string colorPropertyName = null,
bool drawScaleOffset = true, bool drawWrapMode = false, int flagBitsName = 0, int flagIndex = 2,
Action<Texture> drawBlock = null)
{
bool hasTexture = mats[0].GetTexture(texturePropertyName) != null;
matEditor.TexturePropertySingleLine(new GUIContent(label), GetProperty(texturePropertyName),
GetProperty(colorPropertyName));
DrawAfterTexture(hasTexture, label, texturePropertyName, drawScaleOffset, drawWrapMode, flagBitsName,
flagIndex, drawBlock);
}
public void DrawAfterTexture(bool hasTexture, string label, string texturePropertyName,
bool drawScaleOffset = true, bool drawWrapMode = false, int flagBitsName = 0, int flagIndex = 2,
Action<Texture> drawBlock = null)
{
EditorGUI.indentLevel++;
EditorGUI.BeginDisabledGroup(!hasTexture);
if (drawWrapMode)
{
//这个多选材质就不出现了,不好处理
if (mats.Count == 1)
{
int tmpWrapMode = shaderFlags[0].CheckFlagBits(flagBitsName, index: flagIndex) ? 1 : 0;
tmpWrapMode = shaderFlags[0].CheckFlagBits(flagBitsName << 16, index: flagIndex)
? tmpWrapMode + 2
: tmpWrapMode;
tmpWrapMode = EditorGUILayout.Popup(new GUIContent(label + "循环模式"), tmpWrapMode,
Enum.GetNames(typeof(SamplerWarpMode)));
switch (tmpWrapMode)
{
case 0:
shaderFlags[0].ClearFlagBits(flagBitsName, index: flagIndex);
shaderFlags[0].ClearFlagBits(flagBitsName << 16, index: flagIndex);
break;
case 1:
shaderFlags[0].SetFlagBits(flagBitsName, index: flagIndex);
shaderFlags[0].ClearFlagBits(flagBitsName << 16, index: flagIndex);
break;
case 2:
shaderFlags[0].ClearFlagBits(flagBitsName, index: flagIndex);
shaderFlags[0].SetFlagBits(flagBitsName << 16, index: flagIndex);
break;
case 3:
shaderFlags[0].SetFlagBits(flagBitsName, index: flagIndex);
shaderFlags[0].SetFlagBits(flagBitsName << 16, index: flagIndex);
break;
}
}
}
if (drawScaleOffset)
{
matEditor.TextureScaleOffsetProperty(GetProperty(texturePropertyName));
}
drawBlock?.Invoke(GetProperty(texturePropertyName).textureValue);
EditorGUI.indentLevel--;
EditorGUI.EndDisabledGroup();
}
public void DrawPopUp(string label, string propertyName, string[] options, string[] toolTips = null,
Action<float> drawBlock = null)
{
MaterialProperty property = GetProperty(propertyName);
if (property == null) return;
EditorGUI.showMixedValue = property.hasMixedValue;
float mode = property.floatValue;
EditorGUI.BeginChangeCheck();
GUIContent[] optionGUIContents = new GUIContent[options.Length];
for (int i = 0; i < optionGUIContents.Length; i++)
{
if (toolTips != null && toolTips.Length == options.Length)
{
optionGUIContents[i] = new GUIContent(options[i], toolTips[i]);
}
else
{
optionGUIContents[i] = new GUIContent(options[i]);
}
}
mode = EditorGUILayout.Popup(new GUIContent(label), (int)mode, optionGUIContents);
if (EditorGUI.EndChangeCheck())
{
property.floatValue = mode;
}
drawBlock?.Invoke(mode);
EditorGUI.showMixedValue = false;
}
public MaterialProperty GetProperty(string propertyName)
{
foreach (ShaderPropertyPack pack in ShaderPropertyPacks)
{
if (pack.name == propertyName)
{
return pack.property;
}
}
// Debug.LogError("材质球" + mat.name + "找不到属性" + propertyName, mat);
return null;
}
public void DrawRenderQueue(MaterialProperty queueBiasProp)
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Queue" + mats[0].renderQueue);
int QueueBias = (int)queueBiasProp.floatValue;
QueueBias = EditorGUILayout.IntField("QueueBias:", QueueBias);
queueBiasProp.floatValue = QueueBias;
EditorGUILayout.EndHorizontal();
}
void GuiLine(int i_height = 1)
{
Rect rect = EditorGUILayout.GetControlRect(false, i_height);
rect.height = i_height;
EditorGUI.DrawRect(rect, new Color(0.5f, 0.5f, 0.5f, 0.5f));
}
public static float PowerSlider(Rect position, GUIContent label, float value, float leftValue, float rightValue,
float power)
{
var editorGuiType = typeof(EditorGUI);
var methodInfo = editorGuiType.GetMethod(
"PowerSlider",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static,
null,
new[] { typeof(Rect), typeof(GUIContent), typeof(float), typeof(float), typeof(float), typeof(float) },
null);
if (methodInfo != null)
{
return (float)methodInfo.Invoke(null,
new object[] { position, label, value, leftValue, rightValue, power });
}
return leftValue;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9279ba81938dc1548b9e9d8297bdcd57
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,147 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
// using Sirenix.OdinInspector;
// using Sirenix.OdinInspector.Editor;
using UnityEditor;
namespace stencilTestHelper
{
[Serializable]
public class StencilValues
{
public int DefaultQueue = 2000;
[BinaryInt(8,true,2)]
public int Ref = 0;
public CompareFunction Comp = CompareFunction.Always;
public StencilOp Pass = StencilOp.Keep;
public StencilOp Fail = StencilOp.Keep;
public StencilOp ZFail = StencilOp.Keep;
[BinaryInt(8,true,1)]
public int ReadMask = 255;
[BinaryInt(8,true,1)]
public int WriteMask = 255;
}
public static class StencilTestHelper
{
// private static StencilValuesConfig stencilValuesConfig;
public class StencilPropertyNames
{
public string stencil = "_Stencil";
public string stencilComp = "_StencilComp";
public string stencilOp = "_StencilOp";
public string stencilWriteMask = "_StencilWriteMask";
public string stencilReadMask = "_StencilReadMask";
public string stencilZFail = "_StencilZFail";
public string stencilFail = "_StencilFail";
public StencilPropertyNames()
{
}
public StencilPropertyNames(string stencilName, string stencilCompName, string stencilOpName,
string stencilWriteMaskName, string stencilReadMaskName, string stencilZFailName,
string stencilFailName)
{
if (!string.IsNullOrEmpty(stencilName))
{
stencil = stencilName;
}
if (!string.IsNullOrEmpty(stencilCompName))
{
stencilComp = stencilCompName;
}
if (!string.IsNullOrEmpty(stencilOpName))
{
stencilOp = stencilOpName;
}
if (!string.IsNullOrEmpty(stencilWriteMaskName))
{
stencilWriteMask = stencilWriteMaskName;
}
if (!string.IsNullOrEmpty(stencilReadMaskName))
{
stencilReadMask = stencilReadMaskName;
}
if (!string.IsNullOrEmpty(stencilZFailName))
{
stencilZFail = stencilZFailName;
}
if (!string.IsNullOrEmpty(stencilFailName))
{
stencilFail = stencilFailName;
}
}
}
private static StencilPropertyNames defaultStencilPropertyNames = new StencilPropertyNames();
// public static void SetMaterialStencil(Material mat,StencilValues stencilValues,out int defaultQueue)
public static void SetMaterialStencil(Material mat, string stencilConfigKey,StencilValuesConfig stencilValuesConfig, out int defaultQueue,StencilPropertyNames stencilPropertyNames = null)
{
if (stencilValuesConfig == null)
{
Debug.LogError(mat.name+": 缺少模板预设,设置Stencil失败");
// stencilValuesConfig =
// AssetDatabase.LoadAssetAtPath<StencilValuesConfig>(
// "Assets/AddressableAssets/Shader/StencilConfig.asset");
}
if (stencilPropertyNames == null)
{
stencilPropertyNames = defaultStencilPropertyNames;
}
StencilValues stencilValues;
if (stencilValuesConfig.ContainsKey(stencilConfigKey))
{
stencilValues = stencilValuesConfig[stencilConfigKey];
if (!string.IsNullOrEmpty(stencilPropertyNames.stencil))
{
mat.SetFloat(stencilPropertyNames.stencil, stencilValues.Ref);
}
if (!string.IsNullOrEmpty(stencilPropertyNames.stencilComp) )
{
mat.SetFloat(stencilPropertyNames.stencilComp, (float)stencilValues.Comp);
}
if (!string.IsNullOrEmpty(stencilPropertyNames.stencilOp))
{
mat.SetFloat(stencilPropertyNames.stencilOp, (float)stencilValues.Pass);
}
if (!string.IsNullOrEmpty(stencilPropertyNames.stencilWriteMask))
{
mat.SetFloat(stencilPropertyNames.stencilWriteMask, stencilValues.WriteMask);
}
if (!string.IsNullOrEmpty(stencilPropertyNames.stencilReadMask))
{
mat.SetFloat(stencilPropertyNames.stencilReadMask, stencilValues.ReadMask);
}
if (!string.IsNullOrEmpty(stencilPropertyNames.stencilZFail))
{
mat.SetFloat(stencilPropertyNames.stencilZFail, (float)stencilValues.ZFail);
}
if (!string.IsNullOrEmpty(stencilPropertyNames.stencilFail))
{
mat.SetFloat(stencilPropertyNames.stencilFail, (float)stencilValues.Fail);
}
defaultQueue = stencilValues.DefaultQueue;
}
else
{
Debug.LogError("无法设置材质模板参数,因为没有配置模板值", mat);
defaultQueue = mat.renderQueue;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a7d6268a1ca7d824d8da2adf4cb8f74a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace stencilTestHelper
{
public class StencilValuesConfig : ScriptableObject
{
// public Dictionary<string, StencilValues> Config = new Dictionary<string, StencilValues>();
// public StencilValuesConfigDictionary Config = new StencilValuesConfigDictionary();
[Serializable]
public class KeyStencilValues
{
public string key;
public StencilValues Values;
}
[SerializeField]
public List<KeyStencilValues> Config = new List<KeyStencilValues>();
public bool ContainsKey(string key)
{
if (GetStencilValues(key) != null)
{
return true;
}
else
{
return false;
}
}
public StencilValues GetStencilValues(string key)
{
foreach (var item in Config)
{
if (item.key == key)
{
return item.Values;
}
}
Debug.LogError("StencilValuesConfig: 不存在Key"+key);
return null;
}
public StencilValues this[string key]
{
get
{
return GetStencilValues(key);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9177edf81a5b2354490ec4d66c4c069d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,101 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEditor;
public class StringListSerchProvider : ScriptableObject , ISearchWindowProvider
// public class StringListSerchProvider
{
public List<SearchTreeEntry> CreateSearchTree(SearchWindowContext context)
{
List<SearchTreeEntry> serchList = new List<SearchTreeEntry>();
serchList.Add(new SearchTreeGroupEntry(new GUIContent("List"),0));
List<string> listItemAfterSort = listItems.ToList();
sortListItems(ref listItemAfterSort);
List<string> groups = new List<string>();
foreach (var item in listItemAfterSort)
{
string[] entryTitle = item.Split("/");
string groupName = "";
for (int i = 0; i < entryTitle.Length - 1; i++)
{
groupName += entryTitle[i];
if (!groups.Contains(groupName))
{
serchList.Add(new SearchTreeGroupEntry(new GUIContent(entryTitle[i]),i+1));
}
groupName += "/";
}
SearchTreeEntry entry = new SearchTreeEntry(new GUIContent(entryTitle.Last()));
entry.level = entryTitle.Length;
entry.userData = item;//这里是serch操作点击最后的返回值是什么都可以的。
// Debug.Log(entry.userData);
serchList.Add(entry);
}
return serchList;
}
public bool OnSelectEntry(SearchTreeEntry searchTreeEntry, SearchWindowContext context)
{
string data = (string)searchTreeEntry.userData;
onSetIndexCallback?.Invoke(data);
return true;
}
private string[] listItems;
private Action<string> onSetIndexCallback;
public StringListSerchProvider(string[] items, Action<string> callBack)
{
listItems = items;
onSetIndexCallback = callBack;
}
public void Initialize(string[] items, Action<string> callBack)
{
listItems = items;
onSetIndexCallback = callBack;
}
// private List<string> sortListItems;
void sortListItems(ref List<string> list)
{
// sortListItems = listItems.ToList();
list.Sort((a, b) =>
{
string[] splits1 = a.Split('/');
string[] splits2 = b.Split('/');
for (int i = 0; i < splits1.Length; i++)
{
if (i >= splits2.Length)
{
return 1;
}
int value = splits1[i].CompareTo(splits2[i]);
if (value != 0)
{
if (splits1.Length != splits2.Length && (i == splits1.Length - 1 || i == splits2.Length - 1))
{
return splits1.Length < splits2.Length ? 1 : -1;
}
return value;
}
}
return 0;
});
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: aec459410f5254c4bb4d42e7ec8b4b5e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
{
"name": "com.xuanxuan.render.utility.Editor",
"rootNamespace": "",
"references": [
"GUID:8f9e4d586616f13449cfeb86c5f704c2",
"GUID:df380645f10b7bc4b97d4f5eb6303d95"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8495541fcd41b0c40b5b6e6e7a7639d1
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,187 @@
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEditor;
public class RefreshMaterialInspectorWindow : EditorWindow
{
[MenuItem("ArtTools/刷新选中材质球面板")]
static void refershSelectMaterialInspector()
{
EditorWindow.GetWindow<RefreshMaterialInspectorWindow>("材质球刷新");
}
public static bool isRefreshing = false;
List<Material> materials = new List<Material>();
int i = 0;
private void OnGUI()
{
if (GUILayout.Button("开始刷新材质面板"))
{
materials.Clear();
foreach (UnityEngine.Object o in Selection.GetFiltered(typeof(Material), SelectionMode.DeepAssets))
{
string path = AssetDatabase.GetAssetPath(o);
string fileExtension = Path.GetExtension(path);
if (fileExtension == ".mat")
{
materials.Add((Material)o);
}
}
i = 0;
}
}
private void OnEnable()
{
Debug.Log("刷新材质打开");
isRefreshing = true;
}
private void Update()
{
if(materials.Count <= 0) return;
if (i < materials.Count)
{
// isRefreshing = true;
// SetNormalToUV1(materials[i]);
Selection.activeObject = materials[i];
Debug.Log(materials[i].name,materials[i]);
EditorUtility.DisplayProgressBar("材质球刷新", $"{i + 1}/{materials.Count}", (i + 1) / (float)materials.Count);
i++;
// isRefreshing = false;
}
if (i >= materials.Count)
{
EditorUtility.ClearProgressBar();
materials.Clear();
Debug.Log("材质刷新结束isRefreshing布尔值 = "+isRefreshing);
}
}
void OnDisable()
{
Debug.Log("刷新材质关闭");
isRefreshing = false;
}
// void SetNormalToUV1(Material mat)
// {
// if (mat.HasProperty("_NormalFrom"))
// {
// mat.SetInteger("_NormalFrom",1);
// }
// }
//
// // [MenuItem("Assets/测试刷新材质", priority = 1)]
// public static void TestRefeshMaterial()
// {
// W9ParticleShaderFlags flags = new W9ParticleShaderFlags();
// int id = Shader.PropertyToID("_Mask2_Toggle");
// foreach (UnityEngine.Object o in Selection.GetFiltered(typeof(Material), SelectionMode.DeepAssets))
// {
// Material mat = o as Material;
// if (mat.shader.name == "XuanXuan/Effects/Particle_NiuBi")
// {
// bool isToggle = mat.GetFloat(id) > 0.5f;
// if (isToggle)
// {
// mat.DisableKeyword("_MASKMAP2");
// flags.SetMaterial(mat);
// flags.SetFlagBits(W9ParticleShaderFlags.FLAG_BIT_PARTICLE_1_MASK_MAP2,index:1);
// }
// // flags.SetMaterial(mat);
// }
// }
// AssetDatabase.SaveAssets();
// }
//
// [MenuItem("Assets/Effect Tool/刷新选中文件夹内材质Wrap模式", priority = 1)]
// public static void SetSelectParticleMaterialWrapMode()
// {
// foreach (UnityEngine.Object o in Selection.GetFiltered(typeof(Material), SelectionMode.DeepAssets))
// {
// Material mat = (Material)o;
// // Debug.Log(mat.shader.name);
// SetParticleMaterialWrapMode((Material)o);
// }
// AssetDatabase.SaveAssets();
// }
//
// public static void SetParticleMaterialWrapMode(Material mat)
// {
//
// if (mat.shader.name == "XuanXuan/Effects/Particle_NiuBi")
// {
// W9ParticleShaderFlags flags = new W9ParticleShaderFlags(mat);
// SetWrapModeFlag(flags,mat,"_BaseMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_BASEMAP);
// SetWrapModeFlag(flags,mat,"_MaskMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_MASKMAP);
// SetWrapModeFlag(flags,mat,"_MaskMap2",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_MASKMAP2);
// SetWrapModeFlag(flags,mat,"_NoiseMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_NOISEMAP);
// SetWrapModeFlag(flags,mat,"_EmissionMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_EMISSIONMAP);
// SetWrapModeFlag(flags,mat,"_DissolveMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_DISSOLVE_MAP);
// SetWrapModeFlag(flags,mat,"_DissolveMaskMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_DISSOLVE_MASKMAP);
// SetWrapModeFlag(flags,mat,"_DissolveRampMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_DISSOLVE_RAMPMAP);
// SetWrapModeFlag(flags,mat,"_ColorBlendMap",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_COLORBLENDMAP);
// SetWrapModeFlag(flags,mat,"_VertexOffset_Map",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_VERTEXOFFSETMAP);
// SetWrapModeFlag(flags,mat,"_ParallaxMapping_Map",W9ParticleShaderFlags.FLAG_BIT_WRAPMODE_PARALLAXMAPPINGMAP);
// }
// }
//
// public static void SetParticleMaterialMaskStrenth(Material mat)
// {
// if (mat.shader.name == "XuanXuan/Effects/Particle_NiuBi")
// {
// Vector4 vec = mat.GetVector("_MaskMap3OffsetAnition");
// if (vec.z < 1)
// {
// Vector4 newVec = new Vector4(vec.x, vec.y, 1, vec.w);
// mat.SetVector("_MaskMap3OffsetAnition",newVec);
// }
// }
// }
//
// static void SetWrapModeFlag(W9ParticleShaderFlags flags, Material mat, string matTexPropertyName, int flagBit)
// {
// if (mat.GetTexture(matTexPropertyName) != null)
// {
// Texture tex = mat.GetTexture(matTexPropertyName);
// Debug.Log(tex.name);
// if (tex.wrapMode == TextureWrapMode.Clamp)
// {
// Debug.Log("This is Clamp");
// flags.SetFlagBits(flagBit,index:2);
// }
// else if (tex.wrapMode == TextureWrapMode.Repeat)
// {
// Debug.Log("This is Repeat");
// flags.ClearFlagBits(flagBit,index:2);
// }
// }
// }
// static IEnumerator refreshMaterialInspector(Material[] materials)
// {
// for (int i = 0; i < materials.Length; i++)
// {
// EditorUtility.DisplayProgressBar("材质球刷新", $"{i + 1}/{materials.Length}", (i + 1) / (float)materials.Length);
// Debug.Log(i);
// // Selection.activeObject = materials[i];
// yield return null;
// }
// EditorUtility.ClearProgressBar();
// // yield break;
// }
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 317bb692129be184ebd7249bba265210
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: