Init
This commit is contained in:
commit
c76d89b51b
598 files changed
+633020
No files matched your search
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb78b2aeec65c2f409fb24df62a53831
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,405 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using CSRUtilities;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
public class CSRGlobalController : MonoBehaviour
|
||||
{
|
||||
[Serializable]
|
||||
private class CycleData
|
||||
{
|
||||
[SerializeField] private string name = string.Empty;
|
||||
[SerializeField] private Light light = null;
|
||||
[Tooltip("value of -1 infinite repeat")][SerializeField] private int repeat = -1;
|
||||
[SerializeField] private List<CycleStepData> steps = new List<CycleStepData>();
|
||||
public string Name => name;
|
||||
|
||||
public void ExecuteCycling(MonoBehaviour monoBehaviour)
|
||||
{
|
||||
monoBehaviour.StartCoroutine(InternalExecuteCycling());
|
||||
}
|
||||
|
||||
private IEnumerator InternalExecuteCycling()
|
||||
{
|
||||
int counter = 0;
|
||||
while (counter < repeat || repeat == -1)
|
||||
{
|
||||
for (var index = 0; index < steps.Count; index++)
|
||||
{
|
||||
var step = steps[index];
|
||||
var nextStep = index < steps.Count - 1 ? index + 1 : 0;
|
||||
yield return step.ApplyCycling(steps[nextStep], light);
|
||||
}
|
||||
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
public object FindState(string stateName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void ApplyShaderValues(int stateIndex, int shaderIndex)
|
||||
{
|
||||
if (stateIndex >= steps.Count){return;}
|
||||
|
||||
var state = steps[stateIndex];
|
||||
state.ApplyShaderGroupValues(shaderIndex);
|
||||
state.ApplyLightValues(light);
|
||||
}
|
||||
|
||||
public void ApplyShaderValues(int stateIndex)
|
||||
{
|
||||
if (stateIndex >= steps.Count){return;}
|
||||
|
||||
var state = steps[stateIndex];
|
||||
state.ApplyShaderGroupValues();
|
||||
state.ApplyLightValues(light);
|
||||
}
|
||||
|
||||
public CycleStepData GetState(int stateIndex)
|
||||
{
|
||||
return steps[stateIndex];
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
private class CycleStepData
|
||||
{
|
||||
[Serializable]
|
||||
private class AudioData
|
||||
{
|
||||
[SerializeField] private AudioSource audioSource;
|
||||
[SerializeField] private float initialVolume;
|
||||
[SerializeField] private float endVolume;
|
||||
|
||||
public void Update(float lerpValue)
|
||||
{
|
||||
audioSource.volume = Mathf.Lerp(initialVolume, endVolume, lerpValue);
|
||||
}
|
||||
}
|
||||
[SerializeField] private string name= string.Empty;
|
||||
[Tooltip("The time it would take to transition to the next state")]
|
||||
[FormerlySerializedAs("duration")] [SerializeField] private float transitionTime = 0f;
|
||||
[Tooltip("The time between update of the shader values")]
|
||||
[FormerlySerializedAs("updateInterval")] [SerializeField] private float transitionTimeStep = 0.01f;
|
||||
[Tooltip("The duration of this state")]
|
||||
[FormerlySerializedAs("delay")] [SerializeField] private float time = 0f;
|
||||
[SerializeField] private int repeat = -1;
|
||||
[SerializeField] private List<ShaderData> shaderDataList = new List<ShaderData>();
|
||||
[SerializeField] private ParticleSystem[] particles = new ParticleSystem[0];
|
||||
[SerializeField] private GameObject[] gameObjects = new GameObject[0];
|
||||
[SerializeField] private AudioData[] audioSources = new AudioData[0];
|
||||
[SerializeField] private float lightIntensity = 0f;
|
||||
[SerializeField] private Color lightColor = Color.white;
|
||||
public object Name => name;
|
||||
|
||||
public void ApplyShaderGroupValues(int shaderIndex)
|
||||
{
|
||||
if (shaderIndex >= shaderDataList.Count){return;}
|
||||
var data = shaderDataList[shaderIndex];
|
||||
data.ApplyGroupValues();
|
||||
}
|
||||
|
||||
public IEnumerator ApplyCycling(CycleStepData nextStep, Light light)
|
||||
{
|
||||
EnableParticles();
|
||||
SetActiveGameObjects(true);
|
||||
|
||||
foreach (var data in shaderDataList)
|
||||
{
|
||||
data.SetNextCycle(nextStep.shaderDataList);
|
||||
}
|
||||
|
||||
if (light != null)
|
||||
{
|
||||
light.intensity = lightIntensity;
|
||||
light.color = lightColor;
|
||||
}
|
||||
|
||||
UpdateAudioDataArray(0f);
|
||||
UpdateShaders(0f);
|
||||
|
||||
var delayWFS = new WaitForSeconds(time);
|
||||
yield return delayWFS;
|
||||
var startingTime = Time.time;
|
||||
var cyclingWaitForSeconds = new WaitForSeconds(transitionTimeStep);
|
||||
while (Time.time - startingTime < transitionTime * Mathf.Max(repeat,1))
|
||||
{
|
||||
//var lerpValue = Mathf.InverseLerp(-1f, 1f, Mathf.Sin((Time.time - startingTime) / duration * 2f * Mathf.PI - Mathf.PI * 0.5f));
|
||||
var lerpValue = Mathf.InverseLerp(0, transitionTime, Time.time - startingTime);
|
||||
|
||||
UpdateShaders(lerpValue);
|
||||
Update(lerpValue);
|
||||
UpdateAudioDataArray(lerpValue);
|
||||
yield return cyclingWaitForSeconds;
|
||||
}
|
||||
|
||||
UpdateShaders(1f);
|
||||
UpdateAudioDataArray(1f);
|
||||
|
||||
OnCompleted();
|
||||
|
||||
void Update(float lerpValue)
|
||||
{
|
||||
if (light == null) {return;}
|
||||
light.intensity = Mathf.Lerp(lightIntensity, nextStep.lightIntensity, lerpValue);
|
||||
light.color = Color.Lerp(lightColor, nextStep.lightColor, lerpValue);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateAudioDataArray(float lerpValue)
|
||||
{
|
||||
foreach (var audioData in audioSources)
|
||||
{
|
||||
audioData.Update(lerpValue);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateShaders(float lerpValue)
|
||||
{
|
||||
foreach (var shaderData in shaderDataList)
|
||||
{
|
||||
shaderData.Apply(lerpValue);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetActiveGameObjects(bool active)
|
||||
{
|
||||
foreach (var gameObject in gameObjects)
|
||||
{
|
||||
gameObject.SetActive(active);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCompleted()
|
||||
{
|
||||
DisableParticles();
|
||||
SetActiveGameObjects(false);
|
||||
}
|
||||
|
||||
private void EnableParticles()
|
||||
{
|
||||
foreach (var particle in particles)
|
||||
{
|
||||
particle.Play(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void DisableParticles()
|
||||
{
|
||||
foreach (var particle in particles)
|
||||
{
|
||||
particle.Stop(true, ParticleSystemStopBehavior.StopEmitting);
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyShaderGroupValues()
|
||||
{
|
||||
foreach (var shaderData in shaderDataList)
|
||||
{
|
||||
shaderData.ApplyGroupValues();
|
||||
}
|
||||
}
|
||||
|
||||
public ShaderData GetShader(int shaderIndex)
|
||||
{
|
||||
return shaderDataList[shaderIndex];
|
||||
}
|
||||
public void SetShader(int shaderIndex, ShaderData shaderPropertyCopy)
|
||||
{
|
||||
shaderDataList[shaderIndex] = shaderPropertyCopy.DeepCopy();
|
||||
}
|
||||
|
||||
public void ApplyLightValues(Light light)
|
||||
{
|
||||
if (light == null){return;}
|
||||
|
||||
light.intensity = lightIntensity;
|
||||
light.color = lightColor;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class ShaderData: IEquatable<ShaderData>
|
||||
{
|
||||
public string shaderName = string.Empty;
|
||||
|
||||
[Header("Affected Materials")] [SerializeField]
|
||||
private List<Material> materials = new List<Material>();
|
||||
|
||||
[SerializeField] private ShaderPropertyGroup shaderPropertyGroups = null;
|
||||
public List<Material> Materials => materials;
|
||||
|
||||
public void AutoPopulateMaterials()
|
||||
{
|
||||
materials.Clear();
|
||||
var shader = Shader.Find(shaderName);
|
||||
|
||||
foreach (var renderer in FindObjectsOfType<Renderer>())
|
||||
{
|
||||
foreach (var material in renderer.sharedMaterials)
|
||||
{
|
||||
if (materials.Contains(material) == false && material.shader == shader)
|
||||
{
|
||||
materials.Add(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyDefault()
|
||||
{
|
||||
shaderPropertyGroups.ApplyDefault(materials);
|
||||
}
|
||||
|
||||
public void SetNextCycle(List<ShaderData> shaderDataArray)
|
||||
{
|
||||
var data = shaderDataArray.Find(shader => shader.Equals(this));
|
||||
var group = data?.shaderPropertyGroups;
|
||||
|
||||
shaderPropertyGroups.SetNextGroupInCycle(group);
|
||||
}
|
||||
|
||||
public void Apply(float lerpValue)
|
||||
{
|
||||
shaderPropertyGroups.Apply(lerpValue, materials);
|
||||
}
|
||||
|
||||
public void ApplyGroupValues()
|
||||
{
|
||||
shaderPropertyGroups.ApplyDefault(materials);
|
||||
}
|
||||
|
||||
public bool Equals(ShaderData other)
|
||||
{
|
||||
return other.shaderName == shaderName && materials.TrueForAll(material => other.materials.Contains(material));
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
private class ShaderPropertyGroup
|
||||
{
|
||||
[SerializeField] private string groupName = string.Empty;
|
||||
[SerializeField] private List<ShaderProperty> properties = new List<ShaderProperty>();
|
||||
public string Name => groupName;
|
||||
|
||||
public void ApplyDefault(List<Material> materials)
|
||||
{
|
||||
Apply(0f, materials);
|
||||
}
|
||||
|
||||
public void Apply(float lerpValue, List<Material> materials)
|
||||
{
|
||||
foreach (var property in properties)
|
||||
{
|
||||
property.Apply(lerpValue, materials);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetNextGroupInCycle(ShaderPropertyGroup nextPropertyGroup)
|
||||
{
|
||||
if (nextPropertyGroup == null){ return;}
|
||||
foreach (var property in properties)
|
||||
{
|
||||
var nextProperty = nextPropertyGroup.properties.Find(item => item.Name == property.Name);
|
||||
if (nextProperty != null)
|
||||
{
|
||||
property.SetNextStepValues(nextProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
private class ShaderProperty
|
||||
{
|
||||
public string Name => name;
|
||||
[SerializeField] private string name = string.Empty;
|
||||
[SerializeField] private PropertyType type = PropertyType.Float;
|
||||
[SerializeField] private Color colorDefault = Color.white;
|
||||
[SerializeField] private float floatDefault = 0f;
|
||||
[SerializeField] private bool boolean = false;
|
||||
[SerializeField] private string keyword = String.Empty;
|
||||
private ShaderProperty _nextInCycle;
|
||||
|
||||
private enum PropertyType
|
||||
{
|
||||
Float = 0,
|
||||
Bool = 1,
|
||||
Color = 2
|
||||
}
|
||||
|
||||
public void Apply(float lerpValue, List<Material> materials)
|
||||
{
|
||||
foreach (var material in materials)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case PropertyType.Float:
|
||||
material.SetFloat(name, Mathf.Lerp(floatDefault, _nextInCycle?.floatDefault ?? floatDefault, lerpValue));
|
||||
break;
|
||||
case PropertyType.Bool:
|
||||
material.SetInt(name, (lerpValue < 1f? boolean: _nextInCycle?.boolean ?? boolean) ? 1 : 0);
|
||||
if (boolean)
|
||||
{
|
||||
material.EnableKeyword(keyword);
|
||||
}
|
||||
else
|
||||
{
|
||||
material.DisableKeyword(keyword);
|
||||
}
|
||||
|
||||
break;
|
||||
case PropertyType.Color:
|
||||
material.SetColor(name, Color.Lerp(colorDefault, _nextInCycle?.colorDefault ?? colorDefault, lerpValue));
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetNextStepValues(ShaderProperty shaderProperty)
|
||||
{
|
||||
_nextInCycle = shaderProperty;
|
||||
}
|
||||
}
|
||||
|
||||
[FormerlySerializedAs("_cycles")] [SerializeField] private List<CycleData> cycles = new List<CycleData>();
|
||||
|
||||
public void ApplyShaderProperty(int cycleIndex, int stateIndex, int shaderIndex)
|
||||
{
|
||||
if (cycleIndex >= cycles.Count){return;}
|
||||
var cycle = cycles[cycleIndex];
|
||||
cycle.ApplyShaderValues(stateIndex, shaderIndex);
|
||||
}
|
||||
|
||||
public void ApplyShaderProperty(int cycleIndex, int stateIndex)
|
||||
{
|
||||
if (cycleIndex >= cycles.Count){return;}
|
||||
var cycle = cycles[cycleIndex];
|
||||
cycle.ApplyShaderValues(stateIndex);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
foreach (var data in cycles)
|
||||
{
|
||||
data.ExecuteCycling(this);
|
||||
}
|
||||
}
|
||||
|
||||
public ShaderData GetShaderData(int cycleIndex, int stateIndex, int shaderIndex)
|
||||
{
|
||||
return cycles[cycleIndex].GetState(stateIndex).GetShader(shaderIndex);
|
||||
}
|
||||
|
||||
public void SetShaderData(int cycleIndex, int stateIndex, int shaderIndex, ShaderData shaderPropertyCopy)
|
||||
{
|
||||
cycles[cycleIndex].GetState(stateIndex).SetShader(shaderIndex, shaderPropertyCopy);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2714c633998ae4740a9b4ce7c01e4d86
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 975a5e8627be48148be9d2eb8555b840
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+512
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11643bebf3926034fbe73558d37b847c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using UnityEngine;
|
||||
|
||||
namespace CSRUtilities
|
||||
{
|
||||
public static class EditorUtilities
|
||||
{
|
||||
public static T DeepCopy<T>(this T a)
|
||||
{
|
||||
var serialized = JsonUtility.ToJson(a);
|
||||
return (T) JsonUtility.FromJson(serialized, typeof(T));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba6e8d4f7beda654788fba5599ea0d25
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user