This commit is contained in:
Mrhongxing committed 2026-09-20 16:52:21 +08:00
commit c76d89b51b
598 files changed
+633020

No files matched your search

@@ -0,0 +1,512 @@
using System;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Rendering;
[CustomEditor(typeof(CSRGlobalController))]
public class CRSGlobalControllerCustomEditor : Editor
{
private static CSRGlobalController.ShaderData _shaderPropertyCopy;
private ShaderInfo[] _shaderNames;
private GUIContent _iconToolbarPlus;
private GUIContent _iconToolbarMinus;
private const string HeaderBackground = "RL Header";
private CSRGlobalController _controller;
private void OnEnable()
{
_shaderNames = ShaderUtil.GetAllShaderInfo();
_iconToolbarPlus = EditorGUIUtility.TrIconContent("Toolbar Plus", "Add to list");
_iconToolbarMinus = EditorGUIUtility.TrIconContent("Toolbar Minus", "Remove selection from list");
_controller = (CSRGlobalController)target;
}
public override void OnInspectorGUI()
{
serializedObject.UpdateIfRequiredOrScript();
EditorGUI.BeginChangeCheck();
// EditorGUILayout.BeginHorizontal();
CyclesOnGUI();
// EditorGUILayout.EndHorizontal();
if (EditorGUI.EndChangeCheck())
{
serializedObject.ApplyModifiedProperties();
}
}
private void ShaderOnGUI(SerializedProperty property, int cycleIndex, int stateIndex)
{
var shaderDataSerializedProperty = property.FindPropertyRelative("shaderDataList");
//EditorGUI.indentLevel++;
EditorGUILayout.BeginVertical(HeaderBackground);
shaderDataSerializedProperty.isExpanded = EditorGUILayout.Foldout(shaderDataSerializedProperty.isExpanded,"Shaders");
EditorGUILayout.EndVertical();
if (shaderDataSerializedProperty.isExpanded == false)
{
return;
}
EditorGUI.indentLevel++;
for (int i = 0; i < shaderDataSerializedProperty.arraySize; i++)
{
var dataProperty = shaderDataSerializedProperty.GetArrayElementAtIndex(i);
var shaderNameProperty = dataProperty.FindPropertyRelative("shaderName");
EditorGUILayout.BeginVertical(HeaderBackground);
dataProperty.isExpanded = EditorGUILayout.Foldout(dataProperty.isExpanded,shaderNameProperty.stringValue);
EditorGUILayout.EndVertical();
if (dataProperty.isExpanded== false){continue;}
EditorGUILayout.BeginVertical("RL Background");
EditorGUILayout.BeginHorizontal();
ShaderNameOnGUI(shaderNameProperty);
if (GUILayout.Button("Copy"))
{
_shaderPropertyCopy = _controller.GetShaderData(cycleIndex, stateIndex, i);
}
EditorGUI.BeginDisabledGroup(_shaderPropertyCopy == null);
if (GUILayout.Button("Paste"))
{
serializedObject.Update();
_controller.SetShaderData(cycleIndex, stateIndex, i, _shaderPropertyCopy);
_shaderPropertyCopy = null;
serializedObject.ApplyModifiedProperties();
serializedObject.Update();
return;
}
EditorGUI.EndDisabledGroup();
if (DrawRemoveButton(shaderDataSerializedProperty, i))
{
return;
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.PropertyField(dataProperty.FindPropertyRelative("materials"));
EditorGUILayout.Space(15);
ShaderGroupOnGUI(dataProperty, shaderNameProperty, cycleIndex, stateIndex, i);
EditorGUILayout.Space(15);
EditorGUILayout.EndVertical();
}
EditorGUI.indentLevel--;
// EditorGUI.indentLevel--;
if (shaderDataSerializedProperty.arraySize == 0)
{
EditorGUILayout.BeginVertical("RL Background");
EditorGUILayout.Space(15);
EditorGUILayout.EndVertical();
}
DrawAddButton(shaderDataSerializedProperty);
//EditorGUI.indentLevel--;
}
private void ShaderGroupOnGUI(SerializedProperty dataProperty, SerializedProperty shaderNameProperty, int cycleIndex, int stateIndex, int shaderIndex)
{
var shaderPropertyGroupProperty = dataProperty.FindPropertyRelative("shaderPropertyGroups");
ShaderGroupElementOnGui(shaderPropertyGroupProperty, shaderNameProperty, cycleIndex, stateIndex, shaderIndex);
}
private void ShaderGroupElementOnGui(SerializedProperty shaderPropertyGroupProperty, SerializedProperty shaderNameProperty, int cycleIndex, int stateIndex, int shaderIndex)
{
var groupProperty = shaderPropertyGroupProperty;
var groupNameProperty = groupProperty.FindPropertyRelative("groupName");
EditorGUILayout.BeginHorizontal();
EditorGUILayout.BeginVertical();
ShaderGroupPropertiesOnGUI(groupProperty,shaderNameProperty);
EditorGUILayout.EndVertical();
if (GUILayout.Button("Apply"))
{
_controller.ApplyShaderProperty(cycleIndex, stateIndex, shaderIndex);
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space(15);
}
private void ShaderGroupPropertiesOnGUI(SerializedProperty dataProperty, SerializedProperty shaderNameProperty)
{
var propertiesProperty = dataProperty.FindPropertyRelative("properties");
EditorGUILayout.BeginHorizontal();
EditorGUILayout.Space(15);
EditorGUILayout.BeginVertical("RL Background");
EditorGUILayout.BeginHorizontal(HeaderBackground);
EditorGUILayout.LabelField("Properties");
EditorGUILayout.EndHorizontal();
// EditorGUI.indentLevel++;
for (int i = 0; i < propertiesProperty.arraySize; i++)
{
ShaderPropertyElementOnGui(propertiesProperty, i, shaderNameProperty);
}
// EditorGUI.indentLevel--;
EditorGUILayout.EndVertical();
EditorGUILayout.EndHorizontal();
DrawAddButton(propertiesProperty);
}
private void ShaderPropertyElementOnGui(SerializedProperty propertiesProperty, int i,SerializedProperty shaderNameProperty)
{
var serializedProperty = propertiesProperty.GetArrayElementAtIndex(i);
var shader = Shader.Find(shaderNameProperty.stringValue);
if (shader == null){return;}
EditorGUILayout.BeginVertical("RL Background");
EditorGUILayout.BeginHorizontal();
ShaderPropertyNameOnGUI(serializedProperty, shader);
PropertyValuesOnGUI(serializedProperty, shader);
if (DrawRemoveButton(propertiesProperty, i))
{
return;
}
EditorGUILayout.EndHorizontal();
if (i == propertiesProperty.arraySize-1){ EditorGUILayout.Space(15);}
EditorGUILayout.EndVertical();
}
private void PropertyValuesOnGUI(SerializedProperty serializedProperty, Shader shader)
{
var stringValue = serializedProperty.FindPropertyRelative("name").stringValue;
if (string.IsNullOrEmpty(stringValue)){return;}
var propertyIndex = shader.FindPropertyIndex(stringValue);
if (propertyIndex == -1){return;}
var propertyType = shader.GetPropertyType(propertyIndex);
var isToggle = false;
var keyword = string.Empty;
foreach (var VARIABLE in shader.GetPropertyAttributes(propertyIndex))
{
if (VARIABLE.ToLower().Contains("toggle"))
{
isToggle = true;
keyword = VARIABLE.Replace("Toggle(", "").Replace(")", "");
}
}
switch (propertyType)
{
case ShaderPropertyType.Color:
EditorGUILayout.PropertyField(serializedProperty.FindPropertyRelative("colorDefault"));
serializedProperty.FindPropertyRelative("type").enumValueIndex = 2;
break;
case ShaderPropertyType.Vector:
break;
case ShaderPropertyType.Float:
if (isToggle)
{
var property = serializedProperty.FindPropertyRelative("boolean");
//EditorGUILayout.PropertyField(property);
property.boolValue = EditorGUILayout.ToggleLeft("", property.boolValue);
serializedProperty.FindPropertyRelative("keyword").stringValue = keyword;
serializedProperty.FindPropertyRelative("type").enumValueIndex = 1;
}
else
{
EditorGUILayout.PropertyField(serializedProperty.FindPropertyRelative("floatDefault"));
serializedProperty.FindPropertyRelative("type").enumValueIndex = 0;
}
break;
case ShaderPropertyType.Range:
var limits = shader.GetPropertyRangeLimits(propertyIndex);
var floatDefaultProperty = (serializedProperty.FindPropertyRelative("floatDefault"));
serializedProperty.FindPropertyRelative("type").enumValueIndex = 0;
var floatDefault = floatDefaultProperty.floatValue;
//EditorGUILayout.BeginHorizontal();
floatDefault = EditorGUILayout.Slider(floatDefault, limits.x, limits.y);
//EditorGUILayout.MinMaxSlider(ref floatDefault, ref floatCycleEnd,limits.x, limits.y);
//EditorGUILayout.EndHorizontal();
floatDefaultProperty.floatValue = floatDefault;
break;
case ShaderPropertyType.Texture:
break;
default:
throw new ArgumentOutOfRangeException();
}
}
private void ShaderNameOnGUI(SerializedProperty shaderNameProperty)
{
if (!EditorGUILayout.DropdownButton(new GUIContent(shaderNameProperty.stringValue), FocusType.Keyboard, GUILayout.MinWidth(200), GUILayout.MaxWidth(400))) { return; }
var shaderDropDown = new GenericMenu();
foreach (var shaderName in _shaderNames)
{
shaderDropDown.AddItem(new GUIContent(shaderName.name), shaderNameProperty.stringValue == shaderName.name,
(data) =>
{
shaderNameProperty.stringValue = shaderName.name;
serializedObject.ApplyModifiedProperties();
}, shaderName);
}
shaderDropDown.ShowAsContext();
}
private void ShaderPropertyNameOnGUI(SerializedProperty property, Shader shader)
{
var propertyNameProperty = property.FindPropertyRelative("name");
if (!EditorGUILayout.DropdownButton(new GUIContent(propertyNameProperty.stringValue), FocusType.Keyboard, GUILayout.MaxWidth(150))) { return; }
var propertyDropDown = new GenericMenu();
var propertyCount = ShaderUtil.GetPropertyCount(shader);
for (int i = 0; i < propertyCount ;++i)
{
var propertyName = shader.GetPropertyName(i);
propertyDropDown.AddItem(new GUIContent(propertyName), propertyNameProperty.stringValue == propertyName,
(data) =>
{
propertyNameProperty.stringValue = propertyName;
serializedObject.ApplyModifiedProperties();
}, propertyName);
}
propertyDropDown.ShowAsContext();
}
private bool DrawRemoveButton(SerializedProperty serializedProperty, int index)
{
EditorGUILayout.BeginHorizontal("RL Element");
GUILayout.FlexibleSpace();
if (GUILayout.Button(_iconToolbarMinus, GUILayout.Width(35)))
{
serializedProperty.DeleteArrayElementAtIndex(index);
return true;
}
EditorGUILayout.EndHorizontal();
return false;
}
private void DrawAddButton(SerializedProperty shaderPropertyGroupProperty)
{
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
EditorGUILayout.BeginHorizontal("RL Footer",GUILayout.Width(40));
if (GUILayout.Button(_iconToolbarPlus, "RL FooterButton", GUILayout.Width(35)))
{
++shaderPropertyGroupProperty.arraySize;
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.EndHorizontal();
}
private void CyclesOnGUI()
{
// EditorGUILayout.BeginVertical();
var cycleSerializedProperty = serializedObject.FindProperty("cycles");
EditorGUILayout.BeginVertical(HeaderBackground);
cycleSerializedProperty.isExpanded = GUILayout.Button("Transition groups", EditorStyles.label)?!cycleSerializedProperty.isExpanded:cycleSerializedProperty.isExpanded;
EditorGUILayout.EndVertical();
if (cycleSerializedProperty.isExpanded== false){return;}
EditorGUILayout.BeginVertical("RL Background");
EditorGUI.indentLevel++;
for (int i = 0; i < cycleSerializedProperty.arraySize; i++)
{
var dataProperty = cycleSerializedProperty.GetArrayElementAtIndex(i);
var nameProperty = dataProperty.FindPropertyRelative("name");
EditorGUILayout.BeginVertical(HeaderBackground);
dataProperty.isExpanded = EditorGUILayout.Foldout(dataProperty.isExpanded,nameProperty.stringValue);
EditorGUILayout.EndVertical();
if (dataProperty.isExpanded== false){continue;}
EditorGUILayout.BeginVertical("RL Background");
EditorGUILayout.Space(5);
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PropertyField(nameProperty, GUILayout.MinWidth(200),GUILayout.MinWidth(400));
if (DrawRemoveButton(cycleSerializedProperty, i))
{
return;
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.PropertyField(dataProperty.FindPropertyRelative("repeat"));
EditorGUILayout.PropertyField(dataProperty.FindPropertyRelative("light"));
//EditorGUI.indentLevel++;
var stepsProperty = dataProperty.FindPropertyRelative("steps");
StepsOnGUI(stepsProperty, i);
//EditorGUI.indentLevel--;
if (i == cycleSerializedProperty.arraySize-1){EditorGUILayout.Space(15);}
EditorGUILayout.EndVertical();
}
//EditorGUI.indentLevel--;
EditorGUILayout.EndVertical();
if (cycleSerializedProperty.arraySize == 0)
{
EditorGUILayout.BeginVertical("RL Background");
EditorGUILayout.Space(15);
EditorGUILayout.EndVertical();
}
DrawAddButton(cycleSerializedProperty);
// EditorGUILayout.EndVertical();
}
private void StepsOnGUI(SerializedProperty stepsProperty, int cycleIndex)
{
// EditorGUILayout.BeginHorizontal();
// EditorGUILayout.Space(5);
// EditorGUILayout.BeginVertical();
EditorGUILayout.BeginVertical(HeaderBackground);
EditorGUILayout.LabelField("States", EditorStyles.boldLabel);
EditorGUILayout.EndVertical();
EditorGUI.indentLevel++;
EditorGUI.indentLevel++;
for (int i = 0; i < stepsProperty.arraySize; i++)
{
var property = stepsProperty.GetArrayElementAtIndex(i);
var nameProperty = property.FindPropertyRelative("name");
EditorGUILayout.BeginVertical(HeaderBackground);
property.isExpanded = EditorGUILayout.Foldout(property.isExpanded,nameProperty.stringValue);
EditorGUILayout.EndVertical();
if (property.isExpanded== false){continue;}
EditorGUILayout.BeginVertical("RL Background");
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("↓", EditorStyles.miniButton, GUILayout.Width(25)))
{
stepsProperty.MoveArrayElement(i, i+1);
serializedObject.ApplyModifiedProperties();
return;
}
if (GUILayout.Button("↑", EditorStyles.miniButton, GUILayout.Width(25)))
{
stepsProperty.MoveArrayElement(i, i-1);
serializedObject.ApplyModifiedProperties();
return;
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space(5);
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PropertyField(nameProperty, GUILayout.MinWidth(200), GUILayout.MaxWidth(400));
if (GUILayout.Button("Apply"))
{
_controller.ApplyShaderProperty(cycleIndex, i);
}
if (DrawRemoveButton(stepsProperty, i))
{
return;
}
EditorGUILayout.EndHorizontal();
ShaderOnGUI(property, cycleIndex, i);
var transitionTimeProperty = property.FindPropertyRelative("transitionTime");
transitionTimeProperty.isExpanded = EditorGUILayout.Foldout(transitionTimeProperty.isExpanded, "Settings");
if (transitionTimeProperty.isExpanded == false)
{
EditorGUILayout.Space(15);
EditorGUILayout.EndVertical();
continue;
}
EditorGUILayout.PropertyField(transitionTimeProperty);
EditorGUILayout.PropertyField(property.FindPropertyRelative("transitionTimeStep"));
EditorGUILayout.PropertyField(property.FindPropertyRelative("time"));
EditorGUILayout.PropertyField(property.FindPropertyRelative("repeat"));
EditorGUILayout.PropertyField(property.FindPropertyRelative("particles"));
EditorGUILayout.PropertyField(property.FindPropertyRelative("gameObjects"));
EditorGUILayout.PropertyField(property.FindPropertyRelative("audioSources"));
EditorGUILayout.Space(5);
EditorGUILayout.LabelField("Light Settings", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(property.FindPropertyRelative("lightIntensity"));
EditorGUILayout.PropertyField(property.FindPropertyRelative("lightColor"));
EditorGUILayout.Space(15);
EditorGUILayout.EndVertical();
}
EditorGUI.indentLevel--;
EditorGUI.indentLevel--;
if (stepsProperty.arraySize == 0)
{
EditorGUILayout.BeginVertical("RL Background");
EditorGUILayout.Space(15);
EditorGUILayout.EndVertical();
}
// EditorGUILayout.EndVertical();
// EditorGUILayout.EndHorizontal();
DrawAddButton(stepsProperty);
}
private void CycleShaderSelectionOnGUI(SerializedProperty property)
{
var stepShaderNameProperty = property.FindPropertyRelative("shaderDataName");
if (EditorGUILayout.DropdownButton(new GUIContent($"Shader-{stepShaderNameProperty.stringValue}"),
FocusType.Keyboard))
{
var propertyDropDown = new GenericMenu();
var shaderDataProperty = serializedObject.FindProperty("_shaderData");
var propertyCount = shaderDataProperty.arraySize;
for (int j = 0; j < propertyCount; ++j)
{
var shaderDataElementProperty = shaderDataProperty.GetArrayElementAtIndex(j);
var shaderNameProperty = shaderDataElementProperty.FindPropertyRelative("shaderName");
var selectedShader = stepShaderNameProperty.stringValue == shaderNameProperty.stringValue;
propertyDropDown.AddItem(new GUIContent(shaderNameProperty.stringValue), selectedShader,
(data) =>
{
stepShaderNameProperty.stringValue = shaderNameProperty.stringValue;
serializedObject.ApplyModifiedProperties();
}, stepShaderNameProperty);
if (selectedShader)
{
}
}
propertyDropDown.ShowAsContext();
}
}
private void CycleShaderGroupSelectionOnGUI(SerializedProperty property)
{
var stepShaderGroupNameProperty = property.FindPropertyRelative("shaderPropertyGroupsName");
var stepShaderNameProperty = property.FindPropertyRelative("shaderDataName");
if (EditorGUILayout.DropdownButton(new GUIContent($"Property Group-{stepShaderGroupNameProperty.stringValue}"),
FocusType.Keyboard))
{
var propertyDropDown = new GenericMenu();
var shaderDataProperty = serializedObject.FindProperty("_shaderData");
var propertyCount = shaderDataProperty.arraySize;
for (int j = 0; j < propertyCount; ++j)
{
var shaderDataElementProperty = shaderDataProperty.GetArrayElementAtIndex(j);
var shaderNameProperty = shaderDataElementProperty.FindPropertyRelative("shaderName");
var selectedShader = stepShaderNameProperty.stringValue == shaderNameProperty.stringValue;
if (selectedShader)
{
var shaderGroupListProperty = shaderDataElementProperty.FindPropertyRelative("shaderPropertyGroups");
for (int i = 0; i < shaderGroupListProperty.arraySize; i++)
{
var shaderGroupElementProperty = shaderGroupListProperty.GetArrayElementAtIndex(i);
var groupNameProperty = shaderGroupElementProperty.FindPropertyRelative("groupName");
propertyDropDown.AddItem(new GUIContent(groupNameProperty.stringValue), groupNameProperty.stringValue == stepShaderGroupNameProperty.stringValue,
(data) =>
{
stepShaderGroupNameProperty.stringValue = groupNameProperty.stringValue;
serializedObject.ApplyModifiedProperties();
}, stepShaderGroupNameProperty);
}
break;
}
}
propertyDropDown.ShowAsContext();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 11643bebf3926034fbe73558d37b847c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: