一些特效
This commit is contained in:
57
Packages/XuanXuanRenderUtility/Runtime/ButtonAttributes.cs
Normal file
57
Packages/XuanXuanRenderUtility/Runtime/ButtonAttributes.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
public class InspectorButtonAttribute:PropertyAttribute
|
||||
{
|
||||
public string Label;
|
||||
public string MethodName;
|
||||
|
||||
public InspectorButtonAttribute(string label,string methodName)
|
||||
{
|
||||
this.Label = label;
|
||||
this.MethodName = methodName;
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[CustomPropertyDrawer(typeof(InspectorButtonAttribute))]
|
||||
public class InspectorButtonPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
|
||||
InspectorButtonAttribute buttonAttribute = (InspectorButtonAttribute)attribute;
|
||||
|
||||
|
||||
// 绘制按钮
|
||||
if (GUI.Button(position, buttonAttribute.Label))
|
||||
{
|
||||
// 获取包含该方法的对象
|
||||
var targetObject = property.serializedObject.targetObject;
|
||||
|
||||
// 获取方法信息
|
||||
var methodInfo = targetObject.GetType().GetMethod(buttonAttribute.MethodName,BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
|
||||
if (methodInfo != null)
|
||||
{
|
||||
// 调用方法
|
||||
methodInfo.Invoke(targetObject, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Method '{buttonAttribute.MethodName}' not found in {targetObject.name}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight; // 返回按钮的高度
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 45f557806bb54c4dbeaec7a2ded5be83
|
||||
timeCreated: 1737792133
|
||||
562
Packages/XuanXuanRenderUtility/Runtime/MaterialPropertyAgent.cs
Normal file
562
Packages/XuanXuanRenderUtility/Runtime/MaterialPropertyAgent.cs
Normal file
@@ -0,0 +1,562 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
//TODO增加一键去重功能。测试排查BUG
|
||||
[ExecuteInEditMode]
|
||||
public class MaterialPropertyAgent : MonoBehaviour,IMaterialModifier
|
||||
{
|
||||
[System.Serializable]
|
||||
public struct PropertyData
|
||||
{
|
||||
[HideInInspector] public int dataIndexInAgent;
|
||||
[HideInInspector] public MaterialPropertyAgent agent;
|
||||
[HideInInspector] public int id;
|
||||
|
||||
|
||||
public int index;
|
||||
[HideInInspector] public string propName;
|
||||
|
||||
public shaderPropertyType type;
|
||||
|
||||
|
||||
public string descripName;
|
||||
|
||||
|
||||
public Color colorValue;
|
||||
|
||||
public Vector4 vecValue;
|
||||
|
||||
public float floatValue;
|
||||
|
||||
[SerializeField] public IEnumerable propNameList;
|
||||
[HideInInspector] public bool isActive;
|
||||
[HideInInspector] public Shader shader;
|
||||
[HideInInspector] public Material mat;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public float rangMin { get; set; }
|
||||
public float rangMax { get; set; }
|
||||
|
||||
public void setValueByPropChange()
|
||||
{
|
||||
agent.refreshShderPropNameList();
|
||||
if (!agent.isCanUsedIndex(index))
|
||||
{
|
||||
index = agent.getCanUsedIndex();
|
||||
}
|
||||
|
||||
string propertyName = UnityEditor.ShaderUtil.GetPropertyName(shader, index);
|
||||
id = Shader.PropertyToID(propertyName);
|
||||
descripName = UnityEditor.ShaderUtil.GetPropertyDescription(shader, index);
|
||||
type = (shaderPropertyType) UnityEditor.ShaderUtil.GetPropertyType(shader, index);
|
||||
if (type == shaderPropertyType.TexEnv)
|
||||
{
|
||||
propName = UnityEditor.ShaderUtil.GetPropertyName(shader, index) + "_ST";
|
||||
}
|
||||
else
|
||||
{
|
||||
propName = UnityEditor.ShaderUtil.GetPropertyName(shader, index);
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case shaderPropertyType.Color:
|
||||
colorValue = mat.GetColor(id);
|
||||
break;
|
||||
case shaderPropertyType.Float:
|
||||
floatValue = mat.GetFloat(id);
|
||||
break;
|
||||
case shaderPropertyType.Range:
|
||||
rangMin = UnityEditor.ShaderUtil.GetRangeLimits(shader, index, 1);
|
||||
rangMax = UnityEditor.ShaderUtil.GetRangeLimits(shader, index, 2);
|
||||
floatValue = mat.GetFloat(id);
|
||||
break;
|
||||
case shaderPropertyType.Vector:
|
||||
vecValue = mat.GetVector(id);
|
||||
break;
|
||||
case shaderPropertyType.TexEnv:
|
||||
string stName = UnityEditor.ShaderUtil.GetPropertyName(shader, index) + "_ST";
|
||||
vecValue = mat.GetVector(stName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void inActivateThis()
|
||||
{
|
||||
isActive = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//因为ShaderUtil只是用于Editor,所以复制一个枚举对属性类型进行识别。
|
||||
|
||||
public enum shaderPropertyType
|
||||
{
|
||||
//
|
||||
// 摘要:
|
||||
// Color Property.
|
||||
Color = 0,
|
||||
|
||||
//
|
||||
// 摘要:
|
||||
// Vector Property.
|
||||
Vector = 1,
|
||||
|
||||
//
|
||||
// 摘要:
|
||||
// Float Property.
|
||||
Float = 2,
|
||||
|
||||
//
|
||||
// 摘要:
|
||||
// Range Property.
|
||||
Range = 3,
|
||||
|
||||
//
|
||||
// 摘要:
|
||||
// Texture Property.
|
||||
TexEnv = 4
|
||||
}
|
||||
|
||||
|
||||
public PropertyData data0 = new PropertyData();
|
||||
|
||||
public PropertyData data1 = new PropertyData();
|
||||
|
||||
public PropertyData data2 = new PropertyData();
|
||||
|
||||
public PropertyData data3 = new PropertyData();
|
||||
|
||||
public PropertyData data4 = new PropertyData();
|
||||
|
||||
public PropertyData data5 = new PropertyData();
|
||||
|
||||
public Shader shader;
|
||||
public Material mat;
|
||||
|
||||
|
||||
public int materialIndex = 0;
|
||||
public Renderer customRenderer;
|
||||
|
||||
void initMatAndShader(bool initMat = false)
|
||||
{
|
||||
if (!initMat)
|
||||
{
|
||||
if (mat != null) return;
|
||||
}
|
||||
|
||||
if (customRenderer || GetComponent<Renderer>())
|
||||
{
|
||||
Material[] materials;
|
||||
Renderer r;
|
||||
if (customRenderer)
|
||||
{
|
||||
r = customRenderer;
|
||||
}
|
||||
else
|
||||
{
|
||||
r = GetComponent<Renderer>();
|
||||
}
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
materials = r.materials;
|
||||
}
|
||||
else
|
||||
{
|
||||
materials = r.sharedMaterials;
|
||||
}
|
||||
|
||||
mat = materials[materialIndex];
|
||||
shader = mat.shader;
|
||||
}
|
||||
else if (this.GetComponent<Graphic>())
|
||||
{
|
||||
Graphic graphic = this.GetComponent<Graphic>();
|
||||
|
||||
//测试,要不要用IMaterialModifier来处理
|
||||
// if (Application.isPlaying)
|
||||
// {
|
||||
// graphic.material = Material.Instantiate(graphic.material);
|
||||
// }
|
||||
|
||||
mat = graphic.material;
|
||||
|
||||
|
||||
shader = mat.shader;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("MaterialPropertyAgent未找到材质", this.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
initMatAndShader(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
initMatAndShader(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (mat == null)
|
||||
{
|
||||
// initMatAndShader();
|
||||
return;
|
||||
}
|
||||
|
||||
updateData(data0);
|
||||
updateData(data1);
|
||||
updateData(data2);
|
||||
updateData(data3);
|
||||
updateData(data4);
|
||||
updateData(data5);
|
||||
}
|
||||
|
||||
void updateData(PropertyData data)
|
||||
{
|
||||
if (!data.isActive) return;
|
||||
if (mat == null) return;
|
||||
switch (data.type)
|
||||
{
|
||||
case shaderPropertyType.Color:
|
||||
mat.SetColor(data.propName, data.colorValue);
|
||||
break;
|
||||
case shaderPropertyType.Vector:
|
||||
case shaderPropertyType.TexEnv:
|
||||
mat.SetVector(data.propName, data.vecValue);
|
||||
break;
|
||||
case shaderPropertyType.Float:
|
||||
case shaderPropertyType.Range:
|
||||
mat.SetFloat(data.propName, data.floatValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//实际上是修改了graphic.materialForRendering
|
||||
public Material GetModifiedMaterial(Material baseMaterial)
|
||||
{
|
||||
if (mat)
|
||||
{
|
||||
return mat;
|
||||
}
|
||||
else
|
||||
{
|
||||
return baseMaterial;
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
private void OnRenderObject()
|
||||
{
|
||||
if (!UnityEditor.EditorApplication.isPlaying)
|
||||
{
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
||||
public void addProperteData()
|
||||
{
|
||||
refreshShderPropNameList();
|
||||
|
||||
if (!data0.isActive)
|
||||
{
|
||||
initData(ref data0, 0);
|
||||
}
|
||||
else if (!data1.isActive)
|
||||
{
|
||||
initData(ref data1, 1);
|
||||
}
|
||||
else if (!data2.isActive)
|
||||
{
|
||||
initData(ref data2, 2);
|
||||
}
|
||||
else if (!data3.isActive)
|
||||
{
|
||||
initData(ref data3, 3);
|
||||
}
|
||||
else if (!data4.isActive)
|
||||
{
|
||||
initData(ref data4, 4);
|
||||
}
|
||||
else if (!data5.isActive)
|
||||
{
|
||||
initData(ref data5, 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("已用掉可用的6个属性");
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAllProperty()
|
||||
{
|
||||
data0.isActive = false;
|
||||
data1.isActive = false;
|
||||
data2.isActive = false;
|
||||
data3.isActive = false;
|
||||
data4.isActive = false;
|
||||
data5.isActive = false;
|
||||
}
|
||||
|
||||
public void initData(ref PropertyData data, int dataIndexInAgent)
|
||||
{
|
||||
data.dataIndexInAgent = dataIndexInAgent;
|
||||
data.agent = this;
|
||||
data.shader = shader;
|
||||
data.mat = mat;
|
||||
data.isActive = true;
|
||||
|
||||
data.index = getCanUsedIndex();
|
||||
data.setValueByPropChange();
|
||||
}
|
||||
|
||||
#region TODO自动排除已用Property
|
||||
|
||||
List<string> usedPropertyName = new List<string>();
|
||||
|
||||
void collectUsedPropName()
|
||||
{
|
||||
usedPropertyName.Clear();
|
||||
if (data0.isActive)
|
||||
{
|
||||
usedPropertyName.Add(data0.propName);
|
||||
}
|
||||
|
||||
if (data1.isActive)
|
||||
{
|
||||
usedPropertyName.Add(data1.propName);
|
||||
}
|
||||
|
||||
if (data2.isActive)
|
||||
{
|
||||
usedPropertyName.Add(data2.propName);
|
||||
}
|
||||
|
||||
if (data3.isActive)
|
||||
{
|
||||
usedPropertyName.Add(data3.propName);
|
||||
}
|
||||
|
||||
if (data4.isActive)
|
||||
{
|
||||
usedPropertyName.Add(data4.propName);
|
||||
}
|
||||
|
||||
if (data5.isActive)
|
||||
{
|
||||
usedPropertyName.Add(data5.propName);
|
||||
}
|
||||
}
|
||||
|
||||
public int getCanUsedIndex()
|
||||
{
|
||||
int index = -1;
|
||||
collectUsedPropName();
|
||||
for (int i = 0; i < shaderPropNameArr.Length; i++)
|
||||
{
|
||||
string propertyName;
|
||||
if (UnityEditor.ShaderUtil.GetPropertyType(shader, i) == UnityEditor.ShaderUtil.ShaderPropertyType.TexEnv)
|
||||
{
|
||||
propertyName = shaderPropNameArr[i] + "_ST";
|
||||
}
|
||||
else
|
||||
{
|
||||
propertyName = shaderPropNameArr[i];
|
||||
}
|
||||
|
||||
if (usedPropertyName.Contains(propertyName)) continue;
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
public bool isCanUsedIndex(int i)
|
||||
{
|
||||
string propertyName;
|
||||
if (UnityEditor.ShaderUtil.GetPropertyType(shader, i) == UnityEditor.ShaderUtil.ShaderPropertyType.TexEnv)
|
||||
{
|
||||
propertyName = shaderPropNameArr[i] + "_ST";
|
||||
}
|
||||
else
|
||||
{
|
||||
propertyName = shaderPropNameArr[i];
|
||||
}
|
||||
|
||||
collectUsedPropName();
|
||||
if (usedPropertyName.Contains(propertyName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public string[] shaderPropNameArr;
|
||||
public string[] shaderPropDescripArr;
|
||||
public string[] shaderPropDescripsForSerch;
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
// if (XLuaManager.Instance != null)
|
||||
// {
|
||||
// if (XLuaManager.Instance.HasGameStart)//判断是游戏运行状态才进行实例化
|
||||
// {
|
||||
// return;//游戏进行中不允许编辑
|
||||
// }
|
||||
// }
|
||||
// Debug.Log("MaterialPropertyAgent : " + "OnValidate");
|
||||
refreshShderPropNameList();
|
||||
if (TryGetComponent<Renderer>(out Renderer r)||customRenderer)
|
||||
{
|
||||
isRendererMode = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isRendererMode = false;
|
||||
}
|
||||
|
||||
if (TryGetComponent<Renderer>(out Renderer r2) || TryGetComponent<Graphic>(out Graphic g))
|
||||
{
|
||||
isGetByComponet = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isGetByComponet = false;
|
||||
}
|
||||
}
|
||||
public bool isRendererMode = false;
|
||||
public bool isGetByComponet = false;
|
||||
public void initMatAndShaderByMaterialIndexChange()
|
||||
{
|
||||
initMatAndShader(true);
|
||||
refreshShderPropNameList();
|
||||
if (data0.isActive && data0.shader != mat.shader) {data0.shader = mat.shader;data0.mat = mat;}
|
||||
if (data1.isActive && data1.shader != mat.shader) {data1.shader = mat.shader;data1.mat = mat;}
|
||||
if (data2.isActive && data2.shader != mat.shader) {data2.shader = mat.shader;data2.mat = mat;}
|
||||
if (data3.isActive && data3.shader != mat.shader) {data3.shader = mat.shader;data3.mat = mat;}
|
||||
if (data4.isActive && data4.shader != mat.shader) {data4.shader = mat.shader;data4.mat = mat;}
|
||||
if (data5.isActive && data5.shader != mat.shader) {data5.shader = mat.shader;data5.mat = mat;}
|
||||
|
||||
}
|
||||
|
||||
|
||||
List<string> shaderPropNameList = new List<string>();
|
||||
private List<string> shaderPropDescripList = new List<string>();
|
||||
private List<string> shaderPropDescripListForSerch = new List<string>();
|
||||
public void refreshShderPropNameList()
|
||||
{
|
||||
initMatAndShader();
|
||||
if (shader == null) return;
|
||||
|
||||
shaderPropNameList.Clear();
|
||||
shaderPropDescripList.Clear();
|
||||
shaderPropDescripListForSerch.Clear();
|
||||
for (int i = 0; i < UnityEditor.ShaderUtil.GetPropertyCount(shader); i++)
|
||||
{
|
||||
shaderPropNameList.Add(UnityEditor.ShaderUtil.GetPropertyName(shader, i));
|
||||
string descript = UnityEditor.ShaderUtil.GetPropertyDescription(shader, i);
|
||||
shaderPropDescripList.Add(descript);
|
||||
string lowerDesc = descript.ToLower();
|
||||
if (!(lowerDesc.Contains("ignore") || lowerDesc.Contains("mode") || lowerDesc.Contains("toggle") ||
|
||||
lowerDesc.Contains("enable") || lowerDesc.Contains("flag")))
|
||||
{
|
||||
shaderPropDescripListForSerch.Add(descript);
|
||||
}
|
||||
}
|
||||
|
||||
shaderPropNameArr = shaderPropNameList.ToArray();
|
||||
shaderPropDescripArr = shaderPropDescripList.ToArray();
|
||||
shaderPropDescripsForSerch = shaderPropDescripListForSerch.ToArray();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
[CustomPropertyDrawer(typeof(MaterialPropertyAgent.PropertyData))]
|
||||
public class PropertyAgentPropertyDataDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
var isActive = property.FindPropertyRelative("isActive");
|
||||
if (isActive.boolValue)
|
||||
{
|
||||
EditorGUILayout.LabelField(label, EditorStyles.boldLabel);
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
var index = property.FindPropertyRelative("index");
|
||||
MaterialPropertyAgent agent = property.FindPropertyRelative("agent").objectReferenceValue as MaterialPropertyAgent;
|
||||
int preservedIndex = index.intValue;
|
||||
float originLabelWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = 80;
|
||||
index.intValue = EditorGUILayout.Popup("属性名:", index.intValue, agent.shaderPropNameArr);
|
||||
if (preservedIndex != index.intValue)//证明用户进行了更改
|
||||
{
|
||||
if (!agent.isCanUsedIndex(index.intValue))
|
||||
{
|
||||
//TODO给一个报错提示
|
||||
Debug.Log(ShaderUtil.GetPropertyDescription(agent.shader, index.intValue));
|
||||
index.intValue = agent.getCanUsedIndex();
|
||||
}
|
||||
//此处进行内容刷新
|
||||
data.setValueByPropChange();
|
||||
}
|
||||
|
||||
|
||||
EditorGUILayout.LabelField("属性类型:", data.type.ToString());
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUIUtility.labelWidth = originLabelWidth;
|
||||
switch (data.type)
|
||||
{
|
||||
case MaterialPropertyAgent.shaderPropertyType.Color:
|
||||
data.colorValue = EditorGUILayout.ColorField(data.descripName + " :", data.colorValue);
|
||||
break;
|
||||
case MaterialPropertyAgent.shaderPropertyType.Vector:
|
||||
data.vecValue = EditorGUILayout.Vector4Field(data.descripName + " :", data.vecValue);
|
||||
break;
|
||||
case MaterialPropertyAgent.shaderPropertyType.Float:
|
||||
data.floatValue = EditorGUILayout.FloatField(data.descripName + ":", data.floatValue);
|
||||
break;
|
||||
case MaterialPropertyAgent.shaderPropertyType.Range:
|
||||
data.floatValue = EditorGUILayout.Slider(data.descripName + ":", data.floatValue, data.rangMin, data.rangMax);
|
||||
break;
|
||||
case MaterialPropertyAgent.shaderPropertyType.TexEnv:
|
||||
data.vecValue = EditorGUILayout.Vector4Field(data.propName + "_ST:", data.vecValue);
|
||||
break;
|
||||
}
|
||||
|
||||
if (GUILayout.Button("删除", new[] { GUILayout.Width(200) }))
|
||||
{
|
||||
data.isActive = false;
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 781e80efab11a1d438f7c4d37603bdff
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
105
Packages/XuanXuanRenderUtility/Runtime/ShaderFlagsBase.cs
Normal file
105
Packages/XuanXuanRenderUtility/Runtime/ShaderFlagsBase.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class ShaderFlagsBase
|
||||
{
|
||||
|
||||
private Material _material;
|
||||
|
||||
public Material material
|
||||
{
|
||||
get
|
||||
{
|
||||
return _material;
|
||||
}
|
||||
}
|
||||
|
||||
protected ShaderFlagsBase(Material material)
|
||||
{
|
||||
_material = material;
|
||||
}
|
||||
|
||||
public void SetMaterial(Material material)
|
||||
{
|
||||
_material = material;
|
||||
}
|
||||
|
||||
public Material GetMaterial()
|
||||
{
|
||||
return _material;
|
||||
}
|
||||
|
||||
protected abstract int GetShaderFlagsId(int index = 0);
|
||||
protected abstract string GetShaderFlagsName(int index = 0);
|
||||
|
||||
private void SetIntValue(Material material, int flagBits,int index = 0)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// SerializedObject serializedObject = new SerializedObject(_material);
|
||||
// SerializedProperty serializedProperty = serializedObject.FindProperty("m_SavedProperties");
|
||||
// serializedProperty = serializedProperty.FindPropertyRelative("m_Floats");
|
||||
// for (int index = serializedProperty.arraySize - 1; index >= 0; index--)
|
||||
// {
|
||||
// var property = serializedProperty.GetArrayElementAtIndex(index);
|
||||
// string propertyName = property.displayName;
|
||||
// if (propertyName == "_W9PBRStandardShaderFlags")
|
||||
// {
|
||||
// var propertyType = property.propertyType;
|
||||
// Debug.Log("xxx: "+propertyType);
|
||||
//
|
||||
//
|
||||
// property.floatValue = (float) (flags | flagBits);
|
||||
// }
|
||||
// }
|
||||
// material.SetInt(GetShaderFlagsName(), flagBits);
|
||||
material.SetInteger(GetShaderFlagsId(index), flagBits);
|
||||
#else
|
||||
material.SetInteger(GetShaderFlagsId(index), flagBits);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SetFlagBits(int flagBits, MaterialPropertyBlock propertyBlock = null,int index = 0)
|
||||
{
|
||||
if (propertyBlock is null)
|
||||
{
|
||||
if (_material is null) return;
|
||||
int flags = _material.GetInteger(GetShaderFlagsId(index));
|
||||
SetIntValue(_material, flags | flagBits,index);
|
||||
}
|
||||
else
|
||||
{
|
||||
int flags = propertyBlock.GetInt(GetShaderFlagsId(index));
|
||||
propertyBlock.SetInt(GetShaderFlagsId(index), flags|flagBits);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearFlagBits(int flagBits, MaterialPropertyBlock propertyBlock = null,int index = 0)
|
||||
{
|
||||
if (propertyBlock is null)
|
||||
{
|
||||
if (_material is null) return;
|
||||
int flags = _material.GetInteger(GetShaderFlagsId(index));
|
||||
SetIntValue(_material, flags&~flagBits,index);
|
||||
}
|
||||
else
|
||||
{
|
||||
int flags = propertyBlock.GetInteger(GetShaderFlagsId(index));
|
||||
propertyBlock.SetInteger(GetShaderFlagsId(index), flags&~flagBits);
|
||||
}
|
||||
}
|
||||
|
||||
public bool CheckFlagBits(int flagBits, MaterialPropertyBlock propertyBlock = null,int index = 0)
|
||||
{
|
||||
int flags = 0;
|
||||
if (propertyBlock is null)
|
||||
{
|
||||
if (_material is null) throw new NullReferenceException("material");
|
||||
flags = _material.GetInteger(GetShaderFlagsId(index));
|
||||
}
|
||||
else
|
||||
{
|
||||
flags = propertyBlock.GetInteger(GetShaderFlagsId(index));
|
||||
}
|
||||
return (flags & flagBits) != 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3bcf591e67bd470e9375d72c63838643
|
||||
timeCreated: 1655437380
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "com.xuanxuan.render.utility",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:15fc0a57446b3144c949da3e2b9737a9"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": true,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f9e4d586616f13449cfeb86c5f704c2
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user