You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
5.5 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using uc;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(ComposerSettings))]
[CanEditMultipleObjects]
public class ComposerSettingsEditor : Editor {
SerializedProperty TrackedObjectOffset;
SerializedProperty horizontalSoftDamping;
SerializedProperty verticalSoftDamping;
SerializedProperty dutchDamping;
SerializedProperty softLeft;
SerializedProperty softRight;
SerializedProperty softTop;
SerializedProperty softBottom;
SerializedProperty hardLeft;
SerializedProperty hardRight;
SerializedProperty hardTop;
SerializedProperty hardBottom;
SerializedProperty dutch;
private void OnEnable()
{
TrackedObjectOffset = serializedObject.FindProperty("TrackedObjectOffset");
horizontalSoftDamping = serializedObject.FindProperty("horizontalSoftDamping");
verticalSoftDamping = serializedObject.FindProperty("verticalSoftDamping");
dutchDamping = serializedObject.FindProperty("dutchDamping");
softLeft = serializedObject.FindProperty("softLeft");
softRight = serializedObject.FindProperty("softRight");
softTop = serializedObject.FindProperty("softTop");
softBottom = serializedObject.FindProperty("softBottom");
hardLeft = serializedObject.FindProperty("hardLeft");
hardRight = serializedObject.FindProperty("hardRight");
hardTop = serializedObject.FindProperty("hardTop");
hardBottom = serializedObject.FindProperty("hardBottom");
dutch = serializedObject.FindProperty("dutch");
}
//private Editor _editor;
delegate void DrawMinMax(string label, SerializedProperty minV, SerializedProperty maxV, float min, float max);
public override void OnInspectorGUI()
{
//ComposerSettings cs = target as ComposerSettings;
serializedObject.Update();
EditorGUILayout.PropertyField(TrackedObjectOffset);
EditorGUILayout.PropertyField(horizontalSoftDamping);
EditorGUILayout.PropertyField(verticalSoftDamping);
EditorGUILayout.PropertyField(dutchDamping);
DrawMinMax drawMinMax = (string label, SerializedProperty minV, SerializedProperty maxV, float min, float max) =>
{
float sl = minV.floatValue;
float sr = maxV.floatValue;
EditorGUILayout.MinMaxSlider(label, ref sl, ref sr, 0, 1);
minV.floatValue = sl;
maxV.floatValue = sr;
};
EditorGUILayout.Separator();
EditorGUILayout.LabelField("Left Right");
float[] prevMin = { hardLeft.floatValue, softLeft.floatValue };
float[] prevMax = { softRight.floatValue, hardRight.floatValue };
drawMinMax("Soft", softLeft, softRight, 0, 1);
drawMinMax("Hard", hardLeft, hardRight, 0, 1);
if(hardLeft.floatValue > softLeft.floatValue)
{
if (prevMin[0] != hardLeft.floatValue)
{
softLeft.floatValue = hardLeft.floatValue;
}
else if (prevMin[1] != softLeft.floatValue)
{
hardLeft.floatValue = softLeft.floatValue;
}
}
if (hardRight.floatValue < softRight.floatValue)
{
if (prevMax[0] != softRight.floatValue)
{
hardRight.floatValue = softRight.floatValue;
}
else if (prevMax[1] != hardRight.floatValue)
{
softRight.floatValue = hardRight.floatValue;
}
}
EditorGUILayout.BeginHorizontal();
hardLeft.floatValue = EditorGUILayout.FloatField(hardLeft.floatValue);
softLeft.floatValue = EditorGUILayout.FloatField(softLeft.floatValue);
softRight.floatValue = EditorGUILayout.FloatField(softRight.floatValue);
hardRight.floatValue = EditorGUILayout.FloatField(hardRight.floatValue);
EditorGUILayout.EndHorizontal();
EditorGUILayout.Separator();
EditorGUILayout.LabelField("Botton Top");
prevMin = new float[]{ hardBottom.floatValue, softBottom.floatValue };
prevMax = new float[] { softTop.floatValue, hardTop.floatValue };
drawMinMax("Soft", softBottom, softTop, 0, 1);
drawMinMax("Hard", hardBottom, hardTop, 0, 1);
if (hardBottom.floatValue > softBottom.floatValue)
{
if (prevMin[0] != hardBottom.floatValue)
{
softBottom.floatValue = hardBottom.floatValue;
}
else if (prevMin[1] != softBottom.floatValue)
{
hardBottom.floatValue = softBottom.floatValue;
}
}
if (hardTop.floatValue < softTop.floatValue)
{
if (prevMax[0] != softTop.floatValue)
{
hardTop.floatValue = softTop.floatValue;
}
else if (prevMax[1] != hardTop.floatValue)
{
softTop.floatValue = hardTop.floatValue;
}
}
EditorGUILayout.BeginHorizontal();
hardBottom.floatValue = EditorGUILayout.FloatField(hardBottom.floatValue);
softBottom.floatValue = EditorGUILayout.FloatField(softBottom.floatValue);
softTop.floatValue = EditorGUILayout.FloatField(softTop.floatValue);
hardTop.floatValue = EditorGUILayout.FloatField(hardTop.floatValue);
EditorGUILayout.EndHorizontal();
EditorGUILayout.Separator();
EditorGUILayout.PropertyField(dutch);
serializedObject.ApplyModifiedProperties();
}
}