更新
This commit is contained in:
@@ -0,0 +1,249 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
//因为GradientPicker窗口,在窗口打开时使用的是Gradient对象的Cache。
|
||||
//如果有Undo操作,导致MaterialProperty更新了,但Gradient却更新不到ColorPicer里。所以在这里进行强制更新。
|
||||
//后续需要强制更新Picker的时候,也可以用这里。
|
||||
//DeepSeek写的。谨慎用。
|
||||
public static class GradientReflectionHelper
|
||||
{
|
||||
#region GradientPicker 相关
|
||||
|
||||
private static Type _gradientPickerType;
|
||||
|
||||
// SetCurrentGradient 方法
|
||||
private static MethodInfo _setGradientMethod;
|
||||
private static Action<Gradient> _setGradientDelegate;
|
||||
|
||||
// RefreshGradientData 方法
|
||||
private static MethodInfo _refreshMethod;
|
||||
private static Action _refreshDelegate;
|
||||
|
||||
#endregion
|
||||
|
||||
#region GradientPreviewCache 相关
|
||||
|
||||
private static Type _gradientCacheType;
|
||||
private static MethodInfo _clearCacheMethod;
|
||||
private static Action _clearCacheDelegate;
|
||||
|
||||
#endregion
|
||||
|
||||
// 初始化状态
|
||||
private static bool _initialized;
|
||||
private static bool _isValid;
|
||||
private static readonly object _initLock = new object();
|
||||
|
||||
#region 公共API
|
||||
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void SetCurrentGradient(Gradient gradient)
|
||||
{
|
||||
ExecuteAction(() =>
|
||||
{
|
||||
if (_setGradientDelegate != null)
|
||||
_setGradientDelegate(gradient);
|
||||
else if (_setGradientMethod != null)
|
||||
_setGradientMethod.Invoke(null, new object[] { gradient });
|
||||
}, "SetCurrentGradient");
|
||||
}
|
||||
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void RefreshGradientData()
|
||||
{
|
||||
ExecuteAction(() =>
|
||||
{
|
||||
if (_refreshDelegate != null)
|
||||
_refreshDelegate();
|
||||
else if (_refreshMethod != null)
|
||||
_refreshMethod.Invoke(null, null);
|
||||
}, "RefreshGradientData");
|
||||
}
|
||||
|
||||
[System.Diagnostics.Conditional("UNITY_EDITOR")]
|
||||
public static void ClearGradientCache()
|
||||
{
|
||||
ExecuteAction(() =>
|
||||
{
|
||||
if (_clearCacheDelegate != null)
|
||||
_clearCacheDelegate();
|
||||
else if (_clearCacheMethod != null)
|
||||
_clearCacheMethod.Invoke(null, null);
|
||||
}, "ClearGradientCache");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 核心实现
|
||||
|
||||
private static void ExecuteAction(Action action, string methodName)
|
||||
{
|
||||
if (!Application.isEditor) return;
|
||||
|
||||
EnsureInitialized();
|
||||
if (!_isValid) return;
|
||||
|
||||
try
|
||||
{
|
||||
action?.Invoke();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"[GradientReflection] {methodName} failed: {ex.Message}");
|
||||
// 可选择性地禁用后续调用
|
||||
// _isValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void EnsureInitialized()
|
||||
{
|
||||
if (_initialized) return;
|
||||
|
||||
lock (_initLock)
|
||||
{
|
||||
if (_initialized) return;
|
||||
|
||||
try
|
||||
{
|
||||
// 1. 初始化 GradientPicker 类型
|
||||
_gradientPickerType = Type.GetType("UnityEditor.GradientPicker, UnityEditor");
|
||||
if (_gradientPickerType != null)
|
||||
{
|
||||
// 初始化 SetCurrentGradient
|
||||
_setGradientMethod = GetStaticMethod(
|
||||
_gradientPickerType,
|
||||
"SetCurrentGradient",
|
||||
new[] { typeof(Gradient) }
|
||||
);
|
||||
if (_setGradientMethod != null)
|
||||
{
|
||||
_setGradientDelegate = CreateActionDelegate<Gradient>(_setGradientMethod);
|
||||
}
|
||||
|
||||
// 初始化 RefreshGradientData
|
||||
_refreshMethod = GetStaticMethod(
|
||||
_gradientPickerType,
|
||||
"RefreshGradientData",
|
||||
Type.EmptyTypes
|
||||
);
|
||||
if (_refreshMethod != null)
|
||||
{
|
||||
_refreshDelegate = CreateActionDelegate(_refreshMethod);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("[GradientReflection] GradientPicker type not found");
|
||||
}
|
||||
|
||||
// 2. 初始化 GradientPreviewCache
|
||||
_gradientCacheType = Type.GetType("UnityEditorInternal.GradientPreviewCache, UnityEditor");
|
||||
if (_gradientCacheType != null)
|
||||
{
|
||||
_clearCacheMethod = GetStaticMethod(
|
||||
_gradientCacheType,
|
||||
"ClearCache",
|
||||
Type.EmptyTypes
|
||||
);
|
||||
if (_clearCacheMethod != null)
|
||||
{
|
||||
_clearCacheDelegate = CreateActionDelegate(_clearCacheMethod);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("[GradientReflection] GradientPreviewCache type not found");
|
||||
}
|
||||
|
||||
// 3. 验证初始化状态
|
||||
_isValid = (_setGradientMethod != null || _refreshMethod != null) &&
|
||||
_clearCacheMethod != null;
|
||||
|
||||
if (!_isValid)
|
||||
{
|
||||
Debug.LogWarning($"[GradientReflection] Initialization incomplete. " +
|
||||
$"SetCurrentGradient: {(_setGradientMethod != null ? "OK" : "Missing")}, " +
|
||||
$"RefreshGradientData: {(_refreshMethod != null ? "OK" : "Missing")}, " +
|
||||
$"ClearCache: {(_clearCacheMethod != null ? "OK" : "Missing")}");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Debug.Log("[GradientReflection] Initialized successfully");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError($"[GradientReflection] Initialization failed: {e}");
|
||||
_isValid = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_initialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static MethodInfo GetStaticMethod(Type type, string methodName, Type[] parameterTypes)
|
||||
{
|
||||
if (type == null) return null;
|
||||
|
||||
return type.GetMethod(
|
||||
methodName,
|
||||
BindingFlags.Public | BindingFlags.Static,
|
||||
null,
|
||||
parameterTypes,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
private static Action CreateActionDelegate(MethodInfo method)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (Action)Delegate.CreateDelegate(typeof(Action), method);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogWarning($"[GradientReflection] Failed to create delegate for {method.Name}: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Action<T> CreateActionDelegate<T>(MethodInfo method)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (Action<T>)Delegate.CreateDelegate(typeof(Action<T>), method);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogWarning($"[GradientReflection] Failed to create delegate for {method.Name}: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 辅助功能
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否所有反射方法都可用
|
||||
/// </summary>
|
||||
public static bool IsFullySupported => _isValid;
|
||||
|
||||
/// <summary>
|
||||
/// 获取反射初始化状态
|
||||
/// </summary>
|
||||
public static string GetReflectionStatus()
|
||||
{
|
||||
if (!_initialized) return "Not Initialized";
|
||||
|
||||
return $"GradientPicker: {(_gradientPickerType != null ? "Found" : "Missing")}\n" +
|
||||
$"- SetCurrentGradient: {(_setGradientMethod != null ? "OK" : "Missing")}\n" +
|
||||
$"- RefreshGradientData: {(_refreshMethod != null ? "OK" : "Missing")}\n" +
|
||||
$"GradientPreviewCache: {(_gradientCacheType != null ? "Found" : "Missing")}\n" +
|
||||
$"- ClearCache: {(_clearCacheMethod != null ? "OK" : "Missing")}";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ebe6cf7ae30f4357bae940f8ce409628
|
||||
timeCreated: 1753589587
|
||||
File diff suppressed because it is too large
Load Diff
399
Packages/XuanXuanRenderUtility/Editor/ShaderGUIResetTool.cs
Normal file
399
Packages/XuanXuanRenderUtility/Editor/ShaderGUIResetTool.cs
Normal file
@@ -0,0 +1,399 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using PlasticGui;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using ShaderPropertyPack = NBShaderEditor.ShaderGUIHelper.ShaderPropertyPack;
|
||||
using UnityEditor;
|
||||
namespace NBShaderEditor
|
||||
{
|
||||
public class ShaderGUIResetTool
|
||||
{
|
||||
private ShaderGUIHelper _helper;
|
||||
private Shader _shader;
|
||||
public bool IsInitResetData = false;
|
||||
|
||||
private Stack<(string,string)> _scopeContextStack = new Stack<(string,string)>();
|
||||
|
||||
public void CheckAllModifyOnValueChange()
|
||||
{
|
||||
foreach (var item in ResetItemDict.Values)
|
||||
{
|
||||
item.HasModified = item.CheckHasModifyOnValueChange();
|
||||
}
|
||||
}
|
||||
public void Init(ShaderGUIHelper helper)
|
||||
{
|
||||
_helper = helper;
|
||||
_shader = helper.shader;
|
||||
IsInitResetData = true;
|
||||
ResetItemDict.Clear();
|
||||
_scopeContextStack.Clear();
|
||||
}
|
||||
|
||||
public void EndInit()
|
||||
{
|
||||
IsInitResetData = false;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (_needUpdate)
|
||||
{
|
||||
_needUpdate = false;
|
||||
CheckAllModifyOnValueChange();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _needUpdate = false;
|
||||
public void NeedUpdate()
|
||||
{
|
||||
_needUpdate = true;
|
||||
}
|
||||
|
||||
public ShaderGUIResetTool(ShaderGUIHelper helper)
|
||||
{
|
||||
Init(helper);
|
||||
}
|
||||
|
||||
public Dictionary<(string, string), ResetItem> ResetItemDict = new Dictionary<(string, string), ResetItem>();
|
||||
|
||||
public class ResetItem
|
||||
{
|
||||
public ResetItem Parent;
|
||||
public List<ResetItem> ChildResetItems = new List<ResetItem>();
|
||||
public Action ResetCallBack;
|
||||
public Action OnValueChangedCallBack;
|
||||
public Func<bool> CheckHasModifyOnValueChange;
|
||||
public Func<bool> CheckHasMixedValueOnValueChange;
|
||||
public (string, string) NameTuple;
|
||||
public bool HasModified = false;
|
||||
public bool HasMixedValue =false;
|
||||
public bool ChildHasModified = false;
|
||||
public bool ChildHasMixedValue = false;
|
||||
|
||||
|
||||
public void Init((string, string) nameTuple,Action resetCallBack,Action onValueChangedCallBack,Func<bool> checkHasModifyOnValueChange,Func<bool> checkHasMixedValueOnValueChange)
|
||||
{
|
||||
NameTuple = nameTuple;
|
||||
ResetCallBack = resetCallBack;
|
||||
OnValueChangedCallBack = onValueChangedCallBack;
|
||||
CheckHasModifyOnValueChange = checkHasModifyOnValueChange;
|
||||
CheckHasMixedValueOnValueChange = checkHasMixedValueOnValueChange;
|
||||
}
|
||||
|
||||
public void Execute(bool isParentCall = false)
|
||||
{
|
||||
ResetCallBack?.Invoke();
|
||||
OnValueChangedCallBack?.Invoke();
|
||||
HasModified = CheckHasModifyOnValueChange();
|
||||
HasMixedValue = CheckHasMixedValueOnValueChange();
|
||||
CheckOnValueChange(isParentCall);
|
||||
foreach (var item in ChildResetItems)
|
||||
{
|
||||
item.Execute(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void CheckOnValueChange(bool isParentCall = false)
|
||||
{
|
||||
HasModified = CheckHasModifyOnValueChange();
|
||||
HasMixedValue = CheckHasMixedValueOnValueChange();
|
||||
foreach (var childItem in ChildResetItems)
|
||||
{
|
||||
HasMixedValue |= childItem.HasMixedValue;
|
||||
HasModified |= childItem.HasModified;
|
||||
}
|
||||
|
||||
if (!isParentCall && Parent != null)
|
||||
{
|
||||
Parent.CheckOnValueChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckOnValueChange((string,string) nameTuple)
|
||||
{
|
||||
if (ResetItemDict.ContainsKey(nameTuple))
|
||||
{
|
||||
ResetItemDict[nameTuple].CheckOnValueChange();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("不包含ResetItemDict:"+nameTuple);
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawResetModifyButton(Rect rect,(string, string) nameTuple, Action resetCallBack,
|
||||
Action onValueChangedCallBack,Func<bool> checkHasModifyOnValueChange,Func<bool> checkHasMixedValueOnValueChange,bool isSharedGlobalParent = false)
|
||||
{
|
||||
ConstructResetItem(nameTuple,resetCallBack,onValueChangedCallBack,checkHasModifyOnValueChange,checkHasMixedValueOnValueChange,isSharedGlobalParent);
|
||||
DrawResetModifyButtonFinal(rect,nameTuple);
|
||||
}
|
||||
public void DrawResetModifyButton(Rect rect,(string,string)nameTuple,ShaderPropertyPack pack, Action resetAction,Action onValueChangedCallBack,VectorValeType vectorValeType = VectorValeType.Undefine,bool isSharedGlobalParent = false)
|
||||
{
|
||||
|
||||
// (string, string) nameTuple = (label, pack.property.name);
|
||||
ConstructResetItem(nameTuple,
|
||||
resetAction: ()=>{
|
||||
SetPropertyToDefaultValue(pack,vectorValeType);
|
||||
resetAction?.Invoke();
|
||||
},onValueChangedCallBack:onValueChangedCallBack,
|
||||
checkHasModifyOnValueChange: () => IsPropertyModified(pack,vectorValeType),
|
||||
checkHasMixedValueOnValueChange: () => pack.property.hasMixedValue,
|
||||
isSharedGlobalParent: isSharedGlobalParent
|
||||
);
|
||||
if (ResetItemDict.ContainsKey(nameTuple))
|
||||
{
|
||||
DrawResetModifyButtonFinal(rect,nameTuple);
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawResetModifyButton(Rect rect, string label)
|
||||
{
|
||||
//大部分功能都是触发子类
|
||||
ConstructResetItem((label, ""), resetAction: () => { },onValueChangedCallBack: () => { }, () => false, () => false);
|
||||
DrawResetModifyButtonFinal(rect,(label,""));
|
||||
}
|
||||
|
||||
//isSharedGlobalParent==>有些组件是公用的,比如极坐标一类。这些是不会设置父Item的。
|
||||
public void ConstructResetItem((string,string) nameTuple, Action resetAction,
|
||||
Action onValueChangedCallBack,Func<bool> checkHasModifyOnValueChange,Func<bool> checkHasMixedValueOnValueChange,bool isSharedGlobalParent = false)
|
||||
{
|
||||
if(!IsInitResetData) return;
|
||||
if (!ResetItemDict.ContainsKey(nameTuple))
|
||||
{
|
||||
ResetItem item = new ResetItem();
|
||||
item.Init(nameTuple,resetAction,onValueChangedCallBack,checkHasModifyOnValueChange,checkHasMixedValueOnValueChange);
|
||||
ResetItemDict.Add(nameTuple,item);
|
||||
|
||||
if (_scopeContextStack.Count > 0 && !isSharedGlobalParent)
|
||||
{
|
||||
var contextNameTuple = _scopeContextStack.Peek();
|
||||
ResetItem parentItem = ResetItemDict[contextNameTuple];
|
||||
parentItem.ChildResetItems.Add(item);
|
||||
item.Parent = parentItem;
|
||||
}
|
||||
item.CheckOnValueChange();//Init
|
||||
}
|
||||
else
|
||||
{
|
||||
// Debug.LogError("ResetItem已经存在:"+nameTuple.ToString());
|
||||
}
|
||||
//就算是已经ContainsKey了,也Push和Pop一下。没有作用,但让写法更简单。
|
||||
_scopeContextStack.Push(nameTuple);
|
||||
}
|
||||
|
||||
|
||||
public void EndResetModifyButtonScope()
|
||||
{
|
||||
if(!IsInitResetData) return;
|
||||
if(_scopeContextStack.Count == 0) return;
|
||||
_scopeContextStack.Pop();
|
||||
}
|
||||
|
||||
public float ResetButtonSize => EditorGUIUtility.singleLineHeight;
|
||||
|
||||
private GUIContent resetIconContent = new GUIContent();
|
||||
//仅仅只是Drawer
|
||||
private void DrawResetModifyButtonFinal(Rect position, (string, string) nameTuple)
|
||||
{
|
||||
ResetItem item;
|
||||
// GUILayout.FlexibleSpace();
|
||||
if (ResetItemDict.ContainsKey(nameTuple))
|
||||
{
|
||||
item = ResetItemDict[nameTuple];
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
float btnSize = ResetButtonSize;
|
||||
string iconText;
|
||||
bool isDisabled = true;
|
||||
GUIStyle iconStyle;
|
||||
if (item.HasModified || item.HasMixedValue)
|
||||
{
|
||||
isDisabled = false;
|
||||
iconText = "R";
|
||||
iconStyle = GUI.skin.button;
|
||||
}
|
||||
else
|
||||
{
|
||||
isDisabled = true;
|
||||
iconText = "";
|
||||
iconStyle = GUI.skin.label;
|
||||
}
|
||||
|
||||
resetIconContent.text = iconText;
|
||||
EditorGUI.BeginDisabledGroup(isDisabled);
|
||||
// if (GUILayout.Button(iconTexture, GUILayout.Width(btnSize), GUILayout.Height(btnSize)))
|
||||
if (position.width <= 0)
|
||||
{
|
||||
position = GUILayoutUtility.GetRect(resetIconContent, GUI.skin.button, GUILayout.Width(btnSize),
|
||||
GUILayout.Height(btnSize));
|
||||
}
|
||||
if(GUI.Button(position,resetIconContent,iconStyle))
|
||||
{
|
||||
item.Execute();
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
|
||||
public void SetPropertyToDefaultValue(ShaderPropertyPack pack,VectorValeType vectorValeType = VectorValeType.Undefine)
|
||||
{
|
||||
MaterialProperty property = pack.property;
|
||||
MaterialProperty.PropType propertyType = property.type;
|
||||
if (pack.property.type == MaterialProperty.PropType.Texture && vectorValeType != VectorValeType.Undefine)
|
||||
{
|
||||
propertyType = MaterialProperty.PropType.Vector;//Tilling or Offset
|
||||
}
|
||||
switch (propertyType)
|
||||
{
|
||||
case MaterialProperty.PropType.Color:
|
||||
Vector4 colorValue = _shader.GetPropertyDefaultVectorValue(pack.index);
|
||||
property.colorValue = new Color(colorValue.x, colorValue.y, colorValue.z, colorValue.x);
|
||||
break;
|
||||
|
||||
case MaterialProperty.PropType.Vector:
|
||||
Vector4 defaultVecValue;
|
||||
Vector4 vecValue;
|
||||
if (vectorValeType == VectorValeType.Tilling || vectorValeType == VectorValeType.Offset)
|
||||
{
|
||||
defaultVecValue = new Vector4(1f, 1f, 0f, 0f);
|
||||
vecValue = property.textureScaleAndOffset;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultVecValue = _shader.GetPropertyDefaultVectorValue(pack.index);
|
||||
vecValue = property.vectorValue;
|
||||
}
|
||||
switch (vectorValeType)
|
||||
{
|
||||
case VectorValeType.Undefine: Debug.LogError("VectorValeType is undefined"); break;
|
||||
case VectorValeType.X: vecValue.x = defaultVecValue.x;property.vectorValue = vecValue;break;
|
||||
case VectorValeType.Y: vecValue.y = defaultVecValue.y;property.vectorValue = vecValue;break;
|
||||
case VectorValeType.Z: vecValue.z = defaultVecValue.z;property.vectorValue = vecValue;break;
|
||||
case VectorValeType.W: vecValue.w = defaultVecValue.w;property.vectorValue = vecValue;break;
|
||||
case VectorValeType.XY:vecValue.x = defaultVecValue.x; vecValue.y = defaultVecValue.y;
|
||||
property.vectorValue = vecValue;break;
|
||||
case VectorValeType.Tilling:vecValue.x = defaultVecValue.x; vecValue.y = defaultVecValue.y;
|
||||
property.textureScaleAndOffset = vecValue;break;
|
||||
case VectorValeType.ZW:vecValue.z = defaultVecValue.z; vecValue.w = defaultVecValue.w;
|
||||
property.vectorValue = vecValue;break;
|
||||
case VectorValeType.Offset:vecValue.z = defaultVecValue.z; vecValue.w = defaultVecValue.w;
|
||||
property.textureScaleAndOffset = vecValue;break;
|
||||
case VectorValeType.XYZ:vecValue.x = defaultVecValue.x; vecValue.y = defaultVecValue.y;
|
||||
vecValue.z = defaultVecValue.z; property.vectorValue = vecValue;break;
|
||||
case VectorValeType.XYZW: property.vectorValue = defaultVecValue;break;
|
||||
}
|
||||
break;
|
||||
|
||||
case MaterialProperty.PropType.Float or MaterialProperty.PropType.Range:
|
||||
float value = _shader.GetPropertyDefaultFloatValue(pack.index);
|
||||
property.floatValue = value;
|
||||
break;
|
||||
|
||||
case MaterialProperty.PropType.Texture:
|
||||
if (property.textureValue == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
property.textureValue = null;
|
||||
break;
|
||||
}
|
||||
// return property.textureValue.name == shader.GetPropertyTextureDefaultName(pack.index) ? false : true;
|
||||
|
||||
default:
|
||||
// 如果不属于上述类型,输出提示信息
|
||||
Debug.Log($"{property.displayName} has no default value or unsupported type");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsPropertyModified(ShaderPropertyPack pack,VectorValeType vectorValeType = VectorValeType.Undefine)
|
||||
{
|
||||
MaterialProperty property = pack.property;
|
||||
MaterialProperty.PropType propertyType = property.type;
|
||||
if (pack.property.type == MaterialProperty.PropType.Texture && vectorValeType != VectorValeType.Undefine)
|
||||
{
|
||||
propertyType = MaterialProperty.PropType.Vector;//Tilling or Offset
|
||||
}
|
||||
switch (propertyType)
|
||||
{
|
||||
case MaterialProperty.PropType.Color:
|
||||
Vector4 colorValue = _shader.GetPropertyDefaultVectorValue(pack.index);
|
||||
Color color = new Color(colorValue.x, colorValue.y, colorValue.z, colorValue.w);
|
||||
return property.colorValue == color ? false : true;
|
||||
|
||||
case MaterialProperty.PropType.Vector:
|
||||
|
||||
Vector4 defaultVecValue;
|
||||
Vector4 vecValue;
|
||||
if (vectorValeType == VectorValeType.Tilling || vectorValeType == VectorValeType.Offset)
|
||||
{
|
||||
defaultVecValue = new Vector4(1f, 1f, 0f, 0f);
|
||||
vecValue = property.textureScaleAndOffset;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultVecValue = _shader.GetPropertyDefaultVectorValue(pack.index);
|
||||
vecValue = property.vectorValue;
|
||||
}
|
||||
|
||||
|
||||
Vector2 defaultVecXYValue = new Vector2(defaultVecValue.x, defaultVecValue.y);
|
||||
Vector2 defaultVecZWValue = new Vector2(defaultVecValue.z, defaultVecValue.w);
|
||||
Vector2 vecXYValue = new Vector2(vecValue.x, vecValue.y);
|
||||
Vector2 vecZWValue = new Vector2(vecValue.z, vecValue.w);
|
||||
Vector2 defaultVecXYZValue = new Vector3(defaultVecValue.x, defaultVecValue.y,defaultVecValue.z);
|
||||
Vector2 vecXYZValue = new Vector3(vecValue.x, vecValue.y,vecValue.z);
|
||||
|
||||
|
||||
bool isVecModified = false;
|
||||
switch (vectorValeType)
|
||||
{
|
||||
case VectorValeType.Undefine: Debug.LogError("VectorValeType is undefined"); break;
|
||||
case VectorValeType.X: isVecModified = Mathf.Approximately(vecValue.x,defaultVecValue.x) ? false : true;break;
|
||||
case VectorValeType.Y: isVecModified = Mathf.Approximately(vecValue.y,defaultVecValue.y) ? false : true;break;
|
||||
case VectorValeType.Z: isVecModified = Mathf.Approximately(vecValue.z,defaultVecValue.z) ? false : true;break;
|
||||
case VectorValeType.W: isVecModified = Mathf.Approximately(vecValue.w,defaultVecValue.w) ? false : true;break;
|
||||
case VectorValeType.XY:case VectorValeType.Tilling:
|
||||
isVecModified = vecXYValue == defaultVecXYValue ? false : true;break;
|
||||
case VectorValeType.ZW:case VectorValeType.Offset:
|
||||
isVecModified = vecZWValue == defaultVecZWValue ? false : true;break;
|
||||
case VectorValeType.XYZ:isVecModified = vecXYZValue == defaultVecXYZValue ? false : true ; break;
|
||||
case VectorValeType.XYZW:isVecModified= vecValue == defaultVecValue? false : true ; break;
|
||||
}
|
||||
return isVecModified;
|
||||
|
||||
case MaterialProperty.PropType.Float or MaterialProperty.PropType.Range:
|
||||
return Mathf.Approximately(property.floatValue, _shader.GetPropertyDefaultFloatValue(pack.index)) ? false : true;
|
||||
|
||||
case MaterialProperty.PropType.Texture:
|
||||
if (property.textureValue == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return property.textureValue.name == "textureExternal" ? false : true;
|
||||
}
|
||||
// return property.textureValue.name == shader.GetPropertyTextureDefaultName(pack.index) ? false : true;
|
||||
|
||||
default:
|
||||
// 如果不属于上述类型,输出提示信息
|
||||
return false;
|
||||
// Debug.Log($"{property.displayName} has no default value or unsupported type");
|
||||
// break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73135babda09451c9e5798b36897637b
|
||||
timeCreated: 1754727843
|
||||
248
Packages/XuanXuanRenderUtility/Editor/ShaderGUIToolBar.cs
Normal file
248
Packages/XuanXuanRenderUtility/Editor/ShaderGUIToolBar.cs
Normal file
@@ -0,0 +1,248 @@
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
namespace NBShaderEditor
|
||||
{
|
||||
|
||||
public class ShaderGUIToolBar
|
||||
{
|
||||
public ShaderGUIHelper Helper;
|
||||
|
||||
private int viewModeIndex;
|
||||
private readonly string[] viewModes = { "List", "Grid" };
|
||||
// private string searchText = "";
|
||||
private MaterialEditor _editor=>Helper.matEditor;
|
||||
public ShaderGUIToolBar(ShaderGUIHelper helper)
|
||||
{
|
||||
Helper = helper;
|
||||
}
|
||||
|
||||
private static Material copiedMaterial;
|
||||
private static Shader copiedShader;
|
||||
|
||||
// 帮助链接URL
|
||||
private const string HELP_URL = "https://owejt9diz2c.feishu.cn/wiki/BHz8wHHSjiYJagk7WrmcAcconlb?from=from_copylink";
|
||||
|
||||
private Vector2 imagePos;
|
||||
private Texture2D icon;
|
||||
private Texture2D image;
|
||||
|
||||
public void DrawToolbar()
|
||||
{
|
||||
|
||||
float BtnWidth = 30f;
|
||||
// 开始工具栏区域 (背景)
|
||||
EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
|
||||
|
||||
// 1. 选择当前材质
|
||||
if (GUILayout.Button(EditorGUIUtility.IconContent("Material On Icon","跳到当前材质|跳到当前材质"), EditorStyles.toolbarButton,GUILayout.Width(BtnWidth)))
|
||||
{
|
||||
EditorGUIUtility.PingObject(Helper.mats[0]);
|
||||
}
|
||||
|
||||
if (GUILayout.Button(EditorGUIUtility.IconContent("TreeEditor.Trash","清除没有使用的贴图|清除没有使用的贴图"), EditorStyles.toolbarButton,GUILayout.Width(BtnWidth)))
|
||||
{
|
||||
foreach (var mat in Helper.mats)
|
||||
{
|
||||
CleanUnusedTextureProperties(Helper.mats[0]);//先清理不属于当前Shader的贴图
|
||||
}
|
||||
Helper.isClearUnUsedTexture = true;
|
||||
}
|
||||
|
||||
if (GUILayout.Button(new GUIContent("C","复制材质属性"), EditorStyles.toolbarButton,GUILayout.Width(BtnWidth)))
|
||||
{
|
||||
copiedMaterial = Helper.mats[0];
|
||||
copiedShader = copiedMaterial.shader;
|
||||
}
|
||||
|
||||
if (GUILayout.Button(new GUIContent("V","粘贴材质属性"), EditorStyles.toolbarButton,GUILayout.Width(BtnWidth)))
|
||||
{
|
||||
if (copiedShader)
|
||||
{
|
||||
Helper.mats[0].shader = copiedShader;
|
||||
}
|
||||
|
||||
if (copiedMaterial)
|
||||
{
|
||||
Helper.mats[0].CopyPropertiesFromMaterial(copiedMaterial);
|
||||
}
|
||||
}
|
||||
if (GUILayout.Button(new GUIContent("R","特殊重置功能"), EditorStyles.toolbarButton,GUILayout.Width(BtnWidth)))
|
||||
{
|
||||
ShowResetPopupMenu();
|
||||
}
|
||||
if (GUILayout.Button(EditorGUIUtility.IconContent("d_UnityEditor.HierarchyWindow","折叠所有控件|折叠所有控件"), EditorStyles.toolbarButton,GUILayout.Width(BtnWidth)))
|
||||
{
|
||||
for (int i = 0;i<Helper.shaderFlags.Length;i++)
|
||||
{
|
||||
W9ParticleShaderFlags shaderFlags = (W9ParticleShaderFlags)Helper.shaderFlags[i];
|
||||
for (int j = 3; j <= 5; j++)
|
||||
{
|
||||
Helper.mats[i].SetInteger(shaderFlags.GetShaderFlagsId(j),0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 添加下拉菜单
|
||||
// viewModeIndex = EditorGUILayout.Popup(viewModeIndex, viewModes, EditorStyles.toolbarPopup, GUILayout.Width(BtnWidth));
|
||||
|
||||
// 3. 添加搜索框
|
||||
GUILayout.FlexibleSpace(); // 将搜索框推到中间
|
||||
|
||||
// // 搜索框样式
|
||||
// GUIStyle searchField = new GUIStyle("SearchTextField");
|
||||
// GUIStyle cancelButton = new GUIStyle("SearchCancelButton");
|
||||
//
|
||||
// EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(300));
|
||||
// {
|
||||
// EditorGUI.BeginChangeCheck();
|
||||
// searchText = EditorGUILayout.TextField(searchText, searchField);
|
||||
// if (EditorGUI.EndChangeCheck())
|
||||
// {
|
||||
// Helper.isSearchText = searchText.Length > 0;
|
||||
// Helper.searchText = searchText;
|
||||
// }
|
||||
//
|
||||
// // 清除搜索按钮
|
||||
// if (GUILayout.Button("", cancelButton))
|
||||
// {
|
||||
// searchText = "";
|
||||
// GUI.FocusControl(null); // 移除焦点
|
||||
// }
|
||||
// }
|
||||
// EditorGUILayout.EndHorizontal();
|
||||
|
||||
// // 4. 右侧按钮组
|
||||
// if (GUILayout.Button(EditorGUIUtility.IconContent("TreeEditor.Refresh"), EditorStyles.toolbarButton))
|
||||
// {
|
||||
// Debug.Log("Refresh clicked");
|
||||
// }
|
||||
//
|
||||
// // 选项菜单
|
||||
// if (GUILayout.Button(EditorGUIUtility.IconContent("_Popup"), EditorStyles.toolbarButton))
|
||||
// {
|
||||
// // 创建下拉菜单
|
||||
// GenericMenu menu = new GenericMenu();
|
||||
// menu.AddItem(new GUIContent("Option 1"), false, () => Debug.Log("Option 1"));
|
||||
// menu.AddItem(new GUIContent("Option 2"), false, () => Debug.Log("Option 2"));
|
||||
// menu.ShowAsContext();
|
||||
// }
|
||||
// 贴图加载
|
||||
if (icon == null)
|
||||
icon = AssetDatabase.LoadAssetAtPath<Texture2D>(AssetDatabase.GUIDToAssetPath("eaa39f504c2ce7646aece103ba9c4766"));
|
||||
if (image == null)
|
||||
image = AssetDatabase.LoadAssetAtPath<Texture2D>(AssetDatabase.GUIDToAssetPath("cc6c30349a33a1d4c8242a9ef1a68830"));
|
||||
if (GUILayout.Button(new GUIContent(icon,"爸爸!"), EditorStyles.toolbarButton,GUILayout.Width(BtnWidth)))
|
||||
{
|
||||
// 弹出 PopupWindow
|
||||
// 弹出浮动窗口
|
||||
FloatingImageWindow.ShowWindow(image);
|
||||
}
|
||||
|
||||
|
||||
if (GUILayout.Button(EditorGUIUtility.IconContent("d__Help@2x","说明文档|说明文档"), EditorStyles.toolbarButton,GUILayout.Width(BtnWidth)))
|
||||
{
|
||||
// 打开浏览器跳转到帮助链接
|
||||
Application.OpenURL(HELP_URL);
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal(); // 结束工具栏
|
||||
}
|
||||
|
||||
private void ShowResetPopupMenu()
|
||||
{
|
||||
GenericMenu menu = new GenericMenu();
|
||||
|
||||
menu.AddItem(new GUIContent("重置特殊UV通道"), false, () =>
|
||||
{
|
||||
Helper.ResetTool.ResetItemDict[("特殊UV通道选择","_SpecialUVChannelMode")].Execute();
|
||||
});
|
||||
menu.AddItem(new GUIContent("重置旋转扭曲"), false, () =>
|
||||
{
|
||||
Helper.ResetTool.ResetItemDict[("","_UTwirlEnabled")].Execute();
|
||||
});
|
||||
menu.AddItem(new GUIContent("重置极坐标"), false, () =>
|
||||
{
|
||||
Helper.ResetTool.ResetItemDict[("","_PolarCoordinatesEnabled")].Execute();
|
||||
});
|
||||
|
||||
// 弹出位置可以用 Event.current.mousePosition
|
||||
menu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
|
||||
}
|
||||
|
||||
private void CleanUnusedTextureProperties(Material mat)
|
||||
{
|
||||
if (mat == null || mat.shader == null) return;
|
||||
|
||||
Shader shader = mat.shader;
|
||||
|
||||
// 收集 Shader 里声明过的贴图属性
|
||||
var shaderTexProps = new HashSet<string>();
|
||||
int count = ShaderUtil.GetPropertyCount(shader);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (ShaderUtil.GetPropertyType(shader, i) == ShaderUtil.ShaderPropertyType.TexEnv)
|
||||
{
|
||||
shaderTexProps.Add(ShaderUtil.GetPropertyName(shader, i));
|
||||
}
|
||||
}
|
||||
|
||||
// 遍历材质所有贴图属性,找到 shader 不再声明的
|
||||
var allProps = mat.GetTexturePropertyNames();
|
||||
foreach (var propName in allProps)
|
||||
{
|
||||
if (!shaderTexProps.Contains(propName))
|
||||
{
|
||||
if (mat.GetTexture(propName) != null)
|
||||
{
|
||||
mat.SetTexture(propName, null);
|
||||
Debug.Log($"清理 {mat.name} 的无效贴图属性: {propName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// EditorWindow 显示图片
|
||||
public class FloatingImageWindow : EditorWindow
|
||||
{
|
||||
private Texture2D popupImage;
|
||||
|
||||
public static void ShowWindow(Texture2D image)
|
||||
{
|
||||
// 创建窗口
|
||||
FloatingImageWindow window = CreateInstance<FloatingImageWindow>();
|
||||
window.titleContent = new GUIContent("谢谢爸爸");
|
||||
window.popupImage = image;
|
||||
|
||||
// 设置初始尺寸
|
||||
if (image != null)
|
||||
window.position = new Rect(Screen.width / 2f - image.width / 2f,
|
||||
Screen.height / 2f - image.height / 2f,
|
||||
image.width,
|
||||
image.height);
|
||||
else
|
||||
window.position = new Rect(Screen.width / 2f - 100, Screen.height / 2f - 100, 200, 200);
|
||||
|
||||
window.ShowUtility(); // 浮动窗口
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
if (popupImage != null)
|
||||
{
|
||||
// 绘制图片
|
||||
Rect rect = new Rect(0, 0, position.width, position.height);
|
||||
GUI.DrawTexture(rect, popupImage, ScaleMode.ScaleToFit);
|
||||
}
|
||||
|
||||
// 可选:增加关闭按钮
|
||||
if (GUI.Button(new Rect(position.width - 25, 5, 20, 20), "X"))
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: deccdbc6963a48b2ace3358cbba67689
|
||||
timeCreated: 1754406958
|
||||
@@ -40,6 +40,7 @@ namespace stencilTestHelper
|
||||
public string stencilReadMask = "_StencilReadMask";
|
||||
public string stencilZFail = "_StencilZFail";
|
||||
public string stencilFail = "_StencilFail";
|
||||
public string stencilKexIndex = "_StencilKeyIndex";
|
||||
|
||||
public StencilPropertyNames()
|
||||
{
|
||||
@@ -47,7 +48,7 @@ namespace stencilTestHelper
|
||||
|
||||
public StencilPropertyNames(string stencilName, string stencilCompName, string stencilOpName,
|
||||
string stencilWriteMaskName, string stencilReadMaskName, string stencilZFailName,
|
||||
string stencilFailName)
|
||||
string stencilFailName,string stencilKexIndexName)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(stencilName))
|
||||
{
|
||||
@@ -77,6 +78,11 @@ namespace stencilTestHelper
|
||||
{
|
||||
stencilFail = stencilFailName;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(stencilKexIndexName))
|
||||
{
|
||||
stencilKexIndex = stencilKexIndexName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,6 +141,11 @@ namespace stencilTestHelper
|
||||
mat.SetFloat(stencilPropertyNames.stencilFail, (float)stencilValues.Fail);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(stencilPropertyNames.stencilKexIndex))
|
||||
{
|
||||
mat.SetFloat(stencilPropertyNames.stencilKexIndex,stencilValuesConfig.GetKeyIndex(stencilConfigKey));
|
||||
}
|
||||
|
||||
defaultQueue = stencilValues.DefaultQueue;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -44,6 +44,24 @@ namespace stencilTestHelper
|
||||
Debug.LogError("StencilValuesConfig: 不存在Key"+key);
|
||||
return null;
|
||||
}
|
||||
|
||||
public int GetKeyIndex(string key)
|
||||
{
|
||||
for (int i = 0; i < Config.Count; i++)
|
||||
{
|
||||
if (Config[i].key == key)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
Debug.LogError("StencilValuesConfig: 不存在Key"+key);
|
||||
return -1;
|
||||
}
|
||||
|
||||
public string GetKeyByIndex(int index)
|
||||
{
|
||||
return Config[index].key;
|
||||
}
|
||||
|
||||
|
||||
public StencilValues this[string key]
|
||||
|
||||
8
Packages/XuanXuanRenderUtility/Editor/Textures.meta
Normal file
8
Packages/XuanXuanRenderUtility/Editor/Textures.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37a388ed2acdda44cba962b4f9196106
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Packages/XuanXuanRenderUtility/Editor/Textures/GiveMeMoney.jpg
Normal file
BIN
Packages/XuanXuanRenderUtility/Editor/Textures/GiveMeMoney.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 50 KiB |
@@ -0,0 +1,127 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc6c30349a33a1d4c8242a9ef1a68830
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 13
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
flipGreenChannel: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
ignoreMipmapLimit: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 1
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 0
|
||||
wrapV: 0
|
||||
wrapW: 0
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 0
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 0
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
swizzle: 50462976
|
||||
cookieLightType: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 2
|
||||
compressionQuality: 20
|
||||
crunchedCompression: 1
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
nameFileIdTable: {}
|
||||
mipmapLimitGroupName:
|
||||
pSDRemoveMatte: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Packages/XuanXuanRenderUtility/Editor/Textures/alipayLogo.png
Normal file
BIN
Packages/XuanXuanRenderUtility/Editor/Textures/alipayLogo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.9 KiB |
@@ -0,0 +1,127 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eaa39f504c2ce7646aece103ba9c4766
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 13
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
flipGreenChannel: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
ignoreMipmapLimit: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 1
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 0
|
||||
wrapV: 0
|
||||
wrapW: 0
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 0
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
swizzle: 50462976
|
||||
cookieLightType: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
nameFileIdTable: {}
|
||||
mipmapLimitGroupName:
|
||||
pSDRemoveMatte: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -3,7 +3,8 @@
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:8f9e4d586616f13449cfeb86c5f704c2",
|
||||
"GUID:df380645f10b7bc4b97d4f5eb6303d95"
|
||||
"GUID:df380645f10b7bc4b97d4f5eb6303d95",
|
||||
"GUID:0e3b0e6ce60c7a34094f8f9822c0b7f2"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
|
||||
@@ -29,29 +29,12 @@ public abstract class ShaderFlagsBase
|
||||
return _material;
|
||||
}
|
||||
|
||||
protected abstract int GetShaderFlagsId(int index = 0);
|
||||
public 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);
|
||||
|
||||
@@ -21,6 +21,12 @@ inline half NB_Remap(half x, half inMin, half inMax, half outMin, half outMax)
|
||||
return saturate((x - inMin) / (inMax - inMin)) * (outMax - outMin) + outMin;
|
||||
}
|
||||
|
||||
inline half NB_Remap01(half x, half inMin, half inMax)
|
||||
{
|
||||
// x= clamp(x,inMin,inMax);
|
||||
return saturate((x - inMin) / (inMax - inMin));
|
||||
}
|
||||
|
||||
inline half NB_RemapNoClamp(half x, half inMin, half inMax, half outMin, half outMax)
|
||||
{
|
||||
// x= clamp(x,inMin,inMax);
|
||||
@@ -240,6 +246,14 @@ void Unity_Blend_HardLight_half(half Base, half Blend, half Opacity, out half Ou
|
||||
Out = lerp(Base, Out, Opacity);
|
||||
}
|
||||
|
||||
void Blend_HardLight_half(half Base, half Blend, out half Out)
|
||||
{
|
||||
half result1 = 1.0 - 2.0 * (1.0 - Base) * (1.0 - Blend);
|
||||
half result2 = 2.0 * Base * Blend;
|
||||
half zeroOrOne = step(Blend, 0.5);
|
||||
Out = result2 * zeroOrOne + (1 - zeroOrOne) * result1;
|
||||
}
|
||||
|
||||
float2 randomGradient(float2 p) {
|
||||
p = p + 0.02;
|
||||
float x = dot(p, float2(123.4, 234.5));
|
||||
@@ -348,4 +362,10 @@ half2 Rotate(half2 v, half cos0, half sin0)
|
||||
return half2(v.x * cos0 - v.y * sin0,
|
||||
v.x * sin0 + v.y * cos0);
|
||||
}
|
||||
|
||||
half SmoothStep01(half interval)//让01线性过渡变成SmoothStep过渡,但是控制计算量。
|
||||
{
|
||||
interval = saturate(interval);
|
||||
return interval * interval * ( 3 - 2 * interval );
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user