260 lines
8.3 KiB
C#
260 lines
8.3 KiB
C#
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
#if UNITY_EDITOR
|
||
|
|
using UnityEditor;
|
||
|
|
|
||
|
|
[CanEditMultipleObjects]
|
||
|
|
[CustomEditor (typeof (characterHeightScaler))]
|
||
|
|
public class characterHeightScalerEditor : Editor
|
||
|
|
{
|
||
|
|
characterHeightScaler manager;
|
||
|
|
|
||
|
|
GUIStyle headerStyle;
|
||
|
|
GUIStyle boxStyle;
|
||
|
|
|
||
|
|
bool showDebugValues;
|
||
|
|
|
||
|
|
|
||
|
|
void OnEnable ()
|
||
|
|
{
|
||
|
|
manager = (characterHeightScaler)target;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public override void OnInspectorGUI ()
|
||
|
|
{
|
||
|
|
serializedObject.Update ();
|
||
|
|
|
||
|
|
setupStyles ();
|
||
|
|
|
||
|
|
GUILayout.BeginVertical ();
|
||
|
|
|
||
|
|
EditorGUILayout.Space (5);
|
||
|
|
|
||
|
|
// ==================== MAIN SECTION ====================
|
||
|
|
|
||
|
|
GUILayout.BeginVertical (boxStyle);
|
||
|
|
|
||
|
|
EditorGUILayout.LabelField ("CHARACTER HEIGHT SCALER", headerStyle);
|
||
|
|
EditorGUILayout.LabelField ("Scales model UP to match GKC standard size", EditorStyles.centeredGreyMiniLabel);
|
||
|
|
|
||
|
|
EditorGUILayout.Space (5);
|
||
|
|
|
||
|
|
manager.autoDetectHeight = EditorGUILayout.Toggle (
|
||
|
|
new GUIContent ("Auto-Detect Height",
|
||
|
|
"Automatically measures your FBX model and scales it to match GKC's standard height."),
|
||
|
|
manager.autoDetectHeight);
|
||
|
|
|
||
|
|
manager.gkcStandardHeight = EditorGUILayout.FloatField (
|
||
|
|
new GUIContent ("GKC Standard Height",
|
||
|
|
"Reference height for the default GKC character (usually 1.8 units)."),
|
||
|
|
manager.gkcStandardHeight);
|
||
|
|
|
||
|
|
EditorGUILayout.Space (3);
|
||
|
|
|
||
|
|
// Show detected info
|
||
|
|
if (manager.detectedModelHeight > 0.01f) {
|
||
|
|
string scaleDir = manager.modelScaleMultiplier > 1.01f ? "UP" :
|
||
|
|
(manager.modelScaleMultiplier < 0.99f ? "DOWN" : "—");
|
||
|
|
|
||
|
|
EditorGUILayout.HelpBox (
|
||
|
|
"Model Height: " + manager.detectedModelHeight.ToString ("F3") + " units\n" +
|
||
|
|
"GKC Standard: " + manager.gkcStandardHeight.ToString ("F3") + " units\n" +
|
||
|
|
"Scale Factor: " + manager.modelScaleMultiplier.ToString ("F3") + "x (model scaled " + scaleDir + ")",
|
||
|
|
MessageType.Info);
|
||
|
|
}
|
||
|
|
|
||
|
|
EditorGUILayout.Space (3);
|
||
|
|
|
||
|
|
// Main action buttons
|
||
|
|
EditorGUILayout.BeginHorizontal ();
|
||
|
|
|
||
|
|
Color defaultBgColor = GUI.backgroundColor;
|
||
|
|
|
||
|
|
GUI.backgroundColor = new Color (0.3f, 0.8f, 1.0f);
|
||
|
|
|
||
|
|
if (GUILayout.Button ("Detect Height", GUILayout.Height (28))) {
|
||
|
|
if (!Application.isPlaying) {
|
||
|
|
Undo.RecordObject (manager, "Detect Height");
|
||
|
|
manager.autoDetectAndSetScale ();
|
||
|
|
EditorUtility.SetDirty (manager);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
GUI.backgroundColor = new Color (0.4f, 1.0f, 0.6f);
|
||
|
|
|
||
|
|
GUIStyle boldButton = new GUIStyle (GUI.skin.button);
|
||
|
|
boldButton.fontStyle = FontStyle.Bold;
|
||
|
|
|
||
|
|
if (GUILayout.Button ("DETECT + APPLY", boldButton, GUILayout.Height (28))) {
|
||
|
|
if (!Application.isPlaying) {
|
||
|
|
Undo.RecordObject (manager, "Detect and Apply Height");
|
||
|
|
manager.autoDetectAndApply ();
|
||
|
|
EditorUtility.SetDirty (manager);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
GUI.backgroundColor = defaultBgColor;
|
||
|
|
|
||
|
|
EditorGUILayout.EndHorizontal ();
|
||
|
|
|
||
|
|
GUILayout.EndVertical ();
|
||
|
|
|
||
|
|
EditorGUILayout.Space (8);
|
||
|
|
|
||
|
|
// ==================== MANUAL / FINE-TUNE ====================
|
||
|
|
|
||
|
|
GUILayout.BeginVertical ("Manual Scale", "window");
|
||
|
|
|
||
|
|
if (!manager.heightBaseValuesCaptured) {
|
||
|
|
EditorGUILayout.HelpBox (
|
||
|
|
"Build your character first, then use 'DETECT + APPLY' above.\n" +
|
||
|
|
"The manual slider below is for fine-tuning after auto-detect.",
|
||
|
|
MessageType.Warning);
|
||
|
|
GUI.enabled = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
EditorGUILayout.Space ();
|
||
|
|
|
||
|
|
// Scale slider
|
||
|
|
EditorGUILayout.BeginHorizontal ();
|
||
|
|
|
||
|
|
float newScale = EditorGUILayout.Slider (
|
||
|
|
new GUIContent ("Model Scale", "Multiplier for the model transform. Auto-detect sets this automatically."),
|
||
|
|
manager.characterHeightScale,
|
||
|
|
manager.minHeightScale,
|
||
|
|
manager.maxHeightScale);
|
||
|
|
|
||
|
|
if (newScale != manager.characterHeightScale) {
|
||
|
|
Undo.RecordObject (manager, "Change Model Scale");
|
||
|
|
manager.characterHeightScale = newScale;
|
||
|
|
}
|
||
|
|
|
||
|
|
GUI.backgroundColor = Color.cyan;
|
||
|
|
|
||
|
|
if (GUILayout.Button ("1x", GUILayout.Width (35))) {
|
||
|
|
Undo.RecordObject (manager, "Reset Scale to 1x");
|
||
|
|
manager.characterHeightScale = 1.0f;
|
||
|
|
}
|
||
|
|
|
||
|
|
GUI.backgroundColor = defaultBgColor;
|
||
|
|
|
||
|
|
EditorGUILayout.EndHorizontal ();
|
||
|
|
|
||
|
|
// Foot alignment offset
|
||
|
|
EditorGUILayout.Space (2);
|
||
|
|
|
||
|
|
manager.footAlignmentOffset = EditorGUILayout.Slider (
|
||
|
|
new GUIContent ("Foot Offset", "Fine-tune vertical position. Positive = raise, Negative = lower."),
|
||
|
|
manager.footAlignmentOffset,
|
||
|
|
-0.2f, 0.2f);
|
||
|
|
|
||
|
|
EditorGUILayout.Space ();
|
||
|
|
|
||
|
|
// Apply / Reset row
|
||
|
|
EditorGUILayout.BeginHorizontal ();
|
||
|
|
|
||
|
|
GUI.backgroundColor = new Color (0.4f, 1.0f, 0.4f);
|
||
|
|
|
||
|
|
GUIStyle applyStyle = new GUIStyle (GUI.skin.button);
|
||
|
|
applyStyle.fontStyle = FontStyle.Bold;
|
||
|
|
applyStyle.fontSize = 13;
|
||
|
|
|
||
|
|
if (GUILayout.Button (" APPLY ", applyStyle, GUILayout.Height (30))) {
|
||
|
|
if (!Application.isPlaying) {
|
||
|
|
Undo.RecordObject (manager, "Apply Scale");
|
||
|
|
manager.applyHeightScale ();
|
||
|
|
EditorUtility.SetDirty (manager);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
GUI.backgroundColor = new Color (1.0f, 0.5f, 0.5f);
|
||
|
|
|
||
|
|
if (GUILayout.Button (" RESET ", applyStyle, GUILayout.Height (30))) {
|
||
|
|
if (!Application.isPlaying) {
|
||
|
|
Undo.RecordObject (manager, "Reset Scale");
|
||
|
|
manager.resetHeightScale ();
|
||
|
|
EditorUtility.SetDirty (manager);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
GUI.backgroundColor = defaultBgColor;
|
||
|
|
|
||
|
|
EditorGUILayout.EndHorizontal ();
|
||
|
|
|
||
|
|
GUI.enabled = true;
|
||
|
|
|
||
|
|
GUILayout.EndVertical ();
|
||
|
|
|
||
|
|
EditorGUILayout.Space ();
|
||
|
|
|
||
|
|
// ==================== DEBUG ====================
|
||
|
|
|
||
|
|
GUILayout.BeginVertical ("Debug", "window");
|
||
|
|
|
||
|
|
manager.showDebugLog = EditorGUILayout.Toggle ("Show Debug Log", manager.showDebugLog);
|
||
|
|
|
||
|
|
EditorGUILayout.Space ();
|
||
|
|
|
||
|
|
if (manager.heightBaseValuesCaptured) {
|
||
|
|
showDebugValues = EditorGUILayout.Foldout (showDebugValues, "Captured Base Values", true);
|
||
|
|
|
||
|
|
if (showDebugValues) {
|
||
|
|
GUI.enabled = false;
|
||
|
|
|
||
|
|
EditorGUILayout.ObjectField ("Model Transform", manager.modelTransform, typeof (Transform), true);
|
||
|
|
EditorGUILayout.Vector3Field ("Base Scale", manager.baseModelLocalScale);
|
||
|
|
EditorGUILayout.Vector3Field ("Base Position", manager.baseModelLocalPosition);
|
||
|
|
EditorGUILayout.FloatField ("Detected Height", manager.detectedModelHeight);
|
||
|
|
EditorGUILayout.FloatField ("Scale Multiplier", manager.modelScaleMultiplier);
|
||
|
|
EditorGUILayout.FloatField ("Foot Offset", manager.footAlignmentOffset);
|
||
|
|
|
||
|
|
GUI.enabled = true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Capture button
|
||
|
|
EditorGUILayout.Space ();
|
||
|
|
|
||
|
|
GUI.backgroundColor = manager.heightBaseValuesCaptured ? Color.yellow : Color.green;
|
||
|
|
|
||
|
|
if (GUILayout.Button (manager.heightBaseValuesCaptured ? "Re-Capture Base Values" : "Capture Base Values")) {
|
||
|
|
if (!Application.isPlaying) {
|
||
|
|
Undo.RecordObject (manager, "Capture Base Values");
|
||
|
|
manager.captureBaseValues ();
|
||
|
|
serializedObject.Update ();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
GUI.backgroundColor = defaultBgColor;
|
||
|
|
|
||
|
|
GUILayout.EndVertical ();
|
||
|
|
|
||
|
|
EditorGUILayout.Space ();
|
||
|
|
|
||
|
|
GUILayout.EndVertical ();
|
||
|
|
|
||
|
|
if (GUI.changed) {
|
||
|
|
EditorUtility.SetDirty (manager);
|
||
|
|
serializedObject.ApplyModifiedProperties ();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
void setupStyles ()
|
||
|
|
{
|
||
|
|
if (headerStyle == null) {
|
||
|
|
headerStyle = new GUIStyle (EditorStyles.boldLabel);
|
||
|
|
headerStyle.fontSize = 14;
|
||
|
|
headerStyle.alignment = TextAnchor.MiddleCenter;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (boxStyle == null) {
|
||
|
|
boxStyle = new GUIStyle ("box");
|
||
|
|
boxStyle.padding = new RectOffset (10, 10, 8, 8);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#endif
|