123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- // Cristian Pop - https://boxophobic.com/
- using UnityEngine;
- using UnityEditor;
- using System;
- public class StyledRemapSliderDrawer : MaterialPropertyDrawer
- {
- public string nameMin = "";
- public string nameMax = "";
- public float min = 0;
- public float max = 0;
- public float top = 0;
- public float down = 0;
- public StyledRemapSliderDrawer(string nameMin, string nameMax, float min, float max)
- {
- this.nameMin = nameMin;
- this.nameMax = nameMax;
- this.min = min;
- this.max = max;
- this.top = 0;
- this.down = 0;
- }
- public StyledRemapSliderDrawer(string nameMin, string nameMax, float min, float max, float top, float down)
- {
- this.nameMin = nameMin;
- this.nameMax = nameMax;
- this.min = min;
- this.max = max;
- this.top = top;
- this.down = down;
- }
- public override void OnGUI(Rect position, MaterialProperty prop, String label, MaterialEditor editor)
- {
- var internalPropMin = MaterialEditor.GetMaterialProperty(editor.targets, nameMin);
- var internalPropMax = MaterialEditor.GetMaterialProperty(editor.targets, nameMax);
- if (internalPropMin.displayName != null && internalPropMax.displayName != null)
- {
- var internalValueMin = internalPropMin.floatValue;
- var internalValueMax = internalPropMax.floatValue;
- Vector4 propVector = prop.vectorValue;
- var stylePopup = new GUIStyle(EditorStyles.popup)
- {
- fontSize = 9,
- };
- EditorGUI.BeginChangeCheck();
- if (internalValueMin < internalValueMax)
- {
- propVector.w = 0;
- }
- else if(internalValueMin > internalValueMax)
- {
- propVector.w = 1;
- }
- if (propVector.w == 0)
- {
- propVector.x = internalValueMin;
- propVector.y = internalValueMax;
- }
- else
- {
- propVector.x = internalValueMax;
- propVector.y = internalValueMin;
- }
- GUILayout.Space(top);
- EditorGUI.showMixedValue = prop.hasMixedValue;
- GUILayout.BeginHorizontal();
- GUILayout.Space(-1);
- GUILayout.Label(label, GUILayout.Width(EditorGUIUtility.labelWidth - 1));
- EditorGUILayout.MinMaxSlider(ref propVector.x, ref propVector.y, min, max);
- GUILayout.Space(2);
- propVector.w = (float)EditorGUILayout.Popup((int)propVector.w, new string[] { "Remap", "Invert" }, stylePopup, GUILayout.Width(50));
- GUILayout.EndHorizontal();
- if (propVector.w == 0f)
- {
- internalValueMin = propVector.x;
- internalValueMax = propVector.y;
- }
- else if (propVector.w == 1f)
- {
- internalValueMin = propVector.y;
- internalValueMax = propVector.x;
- }
- EditorGUI.showMixedValue = false;
- if (EditorGUI.EndChangeCheck())
- {
- prop.vectorValue = propVector;
- internalPropMin.floatValue = internalValueMin;
- internalPropMax.floatValue = internalValueMax;
- }
- GUILayout.Space(down);
- }
- }
- public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor)
- {
- return -2;
- }
- }
|