mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-04-24 13:29:01 +08:00
UI for sync mode configuration
This commit is contained in:
parent
7d316e780f
commit
4f9ccc75c5
@ -77,6 +77,9 @@ namespace net.fushizen.modular_avatar.core.editor
|
|||||||
internalParameter = false,
|
internalParameter = false,
|
||||||
isPrefix = param.IsPrefix,
|
isPrefix = param.IsPrefix,
|
||||||
nameOrPrefix = param.OriginalName,
|
nameOrPrefix = param.OriginalName,
|
||||||
|
syncType = param.syncType,
|
||||||
|
defaultValue = param.defaultValue,
|
||||||
|
saved = param.saved,
|
||||||
remapTo = "",
|
remapTo = "",
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -172,20 +175,29 @@ namespace net.fushizen.modular_avatar.core.editor
|
|||||||
|
|
||||||
private float ElementHeight(int index)
|
private float ElementHeight(int index)
|
||||||
{
|
{
|
||||||
|
float baseHeight = _devMode ? elemHeight * 2 : elemHeight;
|
||||||
|
|
||||||
|
var param = GetParamByIndex(_selectedIndices[index]);
|
||||||
|
var syncMode = param.FindPropertyRelative(nameof(ParameterConfig.syncType));
|
||||||
|
if (syncMode.enumValueIndex != (int) ParameterSyncType.NotSynced)
|
||||||
|
{
|
||||||
|
baseHeight += elemHeight;
|
||||||
|
}
|
||||||
|
|
||||||
if (_selectedIndices[index] == -1)
|
if (_selectedIndices[index] == -1)
|
||||||
{
|
{
|
||||||
return elemHeight * 2;
|
return elemHeight + baseHeight;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return elemHeight;
|
return baseHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawAutodetectHeader(ref Rect rect)
|
private void DrawAutodetectHeader(ref Rect rect)
|
||||||
{
|
{
|
||||||
Rect top = rect;
|
Rect top = rect;
|
||||||
top.height /= 2;
|
top.height = elemHeight;
|
||||||
Rect bottom = rect;
|
Rect bottom = rect;
|
||||||
bottom.y += top.height;
|
bottom.y += top.height;
|
||||||
bottom.height -= top.height;
|
bottom.height -= top.height;
|
||||||
@ -217,15 +229,24 @@ namespace net.fushizen.modular_avatar.core.editor
|
|||||||
DrawAutodetectHeader(ref rect);
|
DrawAutodetectHeader(ref rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
var margin = 20;
|
|
||||||
var halfMargin = margin / 2;
|
|
||||||
var leftHalf = new Rect(rect.x, rect.y, rect.width / 2 - halfMargin, rect.height);
|
|
||||||
var rightHalf = new Rect(rect.x + leftHalf.width + halfMargin, rect.y, leftHalf.width, rect.height);
|
|
||||||
|
|
||||||
var nameOrPrefix = elem.FindPropertyRelative(nameof(ParameterConfig.nameOrPrefix));
|
var nameOrPrefix = elem.FindPropertyRelative(nameof(ParameterConfig.nameOrPrefix));
|
||||||
var remapTo = elem.FindPropertyRelative(nameof(ParameterConfig.remapTo));
|
var remapTo = elem.FindPropertyRelative(nameof(ParameterConfig.remapTo));
|
||||||
var internalParameter = elem.FindPropertyRelative(nameof(ParameterConfig.internalParameter));
|
var internalParameter = elem.FindPropertyRelative(nameof(ParameterConfig.internalParameter));
|
||||||
var isPrefix = elem.FindPropertyRelative(nameof(ParameterConfig.isPrefix));
|
var isPrefix = elem.FindPropertyRelative(nameof(ParameterConfig.isPrefix));
|
||||||
|
var syncType = elem.FindPropertyRelative(nameof(ParameterConfig.syncType));
|
||||||
|
|
||||||
|
var isSynced = syncType.enumValueIndex != (int) ParameterSyncType.NotSynced;
|
||||||
|
|
||||||
|
var margin = 20;
|
||||||
|
var halfMargin = margin / 2;
|
||||||
|
var leftHalf = new Rect(rect.x, rect.y, rect.width / 2 - halfMargin, elemHeight);
|
||||||
|
var rightHalf = new Rect(rect.x + leftHalf.width + halfMargin, rect.y, leftHalf.width, elemHeight);
|
||||||
|
var rightHalfTop = new Rect(rect.x + leftHalf.width + halfMargin, rect.y, leftHalf.width, elemHeight);
|
||||||
|
var rightHalfSyncControlField = rightHalfTop;
|
||||||
|
rightHalfSyncControlField.y += _devMode ? elemHeight : 0;
|
||||||
|
|
||||||
|
var rightHalfDefaultValue = rightHalfSyncControlField;
|
||||||
|
rightHalfDefaultValue.y += elemHeight;
|
||||||
|
|
||||||
var indentLevel = EditorGUI.indentLevel;
|
var indentLevel = EditorGUI.indentLevel;
|
||||||
try
|
try
|
||||||
@ -238,14 +259,29 @@ namespace net.fushizen.modular_avatar.core.editor
|
|||||||
EditorGUI.PropertyField(leftHalf, nameOrPrefix, GUIContent.none);
|
EditorGUI.PropertyField(leftHalf, nameOrPrefix, GUIContent.none);
|
||||||
|
|
||||||
var toggleInternalWidth = EditorStyles.toggle.CalcSize(new GUIContent("Internal")).x;
|
var toggleInternalWidth = EditorStyles.toggle.CalcSize(new GUIContent("Internal")).x;
|
||||||
var toggleInternalRect = new Rect(rightHalf.x, rightHalf.y, toggleInternalWidth, rightHalf.height);
|
var toggleInternalRect = new Rect(rightHalfTop.x, rightHalfTop.y, toggleInternalWidth,
|
||||||
|
rightHalfTop.height);
|
||||||
|
|
||||||
internalParameter.boolValue =
|
internalParameter.boolValue =
|
||||||
EditorGUI.ToggleLeft(toggleInternalRect, "Internal", internalParameter.boolValue);
|
EditorGUI.ToggleLeft(toggleInternalRect, "Internal", internalParameter.boolValue);
|
||||||
|
|
||||||
var isPrefixRect = new Rect(rightHalf.x + toggleInternalWidth + halfMargin, rightHalf.y,
|
var isPrefixRect = new Rect(rightHalfTop.x + toggleInternalWidth + halfMargin, rightHalfTop.y,
|
||||||
rightHalf.width - toggleInternalWidth - halfMargin, rightHalf.height);
|
rightHalfTop.width - toggleInternalWidth - halfMargin, rightHalfTop.height);
|
||||||
isPrefix.boolValue = EditorGUI.ToggleLeft(isPrefixRect, "PhysBones Prefix", isPrefix.boolValue);
|
isPrefix.boolValue = EditorGUI.ToggleLeft(isPrefixRect, "PhysBones Prefix", isPrefix.boolValue);
|
||||||
|
|
||||||
|
var syncedContent = new GUIContent("Sync mode ");
|
||||||
|
var labelSize = EditorStyles.label.CalcSize(syncedContent);
|
||||||
|
var syncedWidth = labelSize.x;
|
||||||
|
|
||||||
|
var syncedRect = new Rect(rightHalfSyncControlField.x, rightHalfSyncControlField.y, syncedWidth,
|
||||||
|
rightHalfSyncControlField.height);
|
||||||
|
|
||||||
|
EditorGUI.LabelField(syncedRect, syncedContent);
|
||||||
|
|
||||||
|
rightHalfSyncControlField.x += syncedWidth;
|
||||||
|
rightHalfSyncControlField.width -= syncedWidth;
|
||||||
|
|
||||||
|
EditorGUI.PropertyField(rightHalfSyncControlField, syncType, GUIContent.none);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -268,6 +304,72 @@ namespace net.fushizen.modular_avatar.core.editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isSynced)
|
||||||
|
{
|
||||||
|
var saved = elem.FindPropertyRelative(nameof(ParameterConfig.saved));
|
||||||
|
|
||||||
|
var savedContents = new GUIContent("Saved");
|
||||||
|
var savedStyle = EditorStyles.toggle;
|
||||||
|
var savedSize = savedStyle.CalcSize(savedContents);
|
||||||
|
var savedLabelWidth = EditorStyles.label.CalcSize(savedContents).x;
|
||||||
|
var checkboxPad = EditorStyles.toggle.margin.right;
|
||||||
|
|
||||||
|
var savedPos = rightHalfDefaultValue;
|
||||||
|
savedPos.width = savedSize.x + checkboxPad * 2;
|
||||||
|
rightHalfDefaultValue.x += savedPos.width;
|
||||||
|
rightHalfDefaultValue.width -= savedPos.width;
|
||||||
|
//savedPos.x -= savedSize.x + checkboxPad * 2;
|
||||||
|
|
||||||
|
|
||||||
|
EditorGUI.LabelField(savedPos, savedContents);
|
||||||
|
savedPos.x += savedLabelWidth + checkboxPad;
|
||||||
|
savedPos.width -= savedLabelWidth - checkboxPad * 2;
|
||||||
|
saved.boolValue = EditorGUI.Toggle(savedPos, saved.boolValue);
|
||||||
|
|
||||||
|
var defaultValueProp = elem.FindPropertyRelative(nameof(ParameterConfig.defaultValue));
|
||||||
|
var label = new GUIContent("Default value ");
|
||||||
|
var labelSize = EditorStyles.label.CalcSize(label);
|
||||||
|
var labelWidth = labelSize.x;
|
||||||
|
|
||||||
|
var labelRect = new Rect(rightHalfDefaultValue.x, rightHalfDefaultValue.y, labelWidth,
|
||||||
|
rightHalfDefaultValue.height);
|
||||||
|
|
||||||
|
EditorGUI.LabelField(labelRect, label);
|
||||||
|
|
||||||
|
rightHalfDefaultValue.x += labelWidth;
|
||||||
|
rightHalfDefaultValue.width -= labelWidth;
|
||||||
|
|
||||||
|
switch ((ParameterSyncType) syncType.enumValueIndex)
|
||||||
|
{
|
||||||
|
case ParameterSyncType.Int:
|
||||||
|
{
|
||||||
|
int val = Mathf.RoundToInt(defaultValueProp.floatValue);
|
||||||
|
val = EditorGUI.IntField(rightHalfDefaultValue, val);
|
||||||
|
defaultValueProp.floatValue = val;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ParameterSyncType.Float:
|
||||||
|
{
|
||||||
|
float val = defaultValueProp.floatValue;
|
||||||
|
val = EditorGUI.FloatField(rightHalfDefaultValue, val);
|
||||||
|
defaultValueProp.floatValue = val;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ParameterSyncType.Bool:
|
||||||
|
{
|
||||||
|
bool val = defaultValueProp.floatValue > 0.1f;
|
||||||
|
val = EditorGUI.Toggle(rightHalfDefaultValue, val);
|
||||||
|
defaultValueProp.floatValue = val ? 1.0f : 0.0f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Maybe we just changed sync mode?
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (EditorGUI.EndChangeCheck() && index < 0)
|
if (EditorGUI.EndChangeCheck() && index < 0)
|
||||||
{
|
{
|
||||||
var target = (ModularAvatarParameters) this.target;
|
var target = (ModularAvatarParameters) this.target;
|
||||||
|
@ -14,6 +14,9 @@ namespace net.fushizen.modular_avatar.core.editor
|
|||||||
{
|
{
|
||||||
public string OriginalName;
|
public string OriginalName;
|
||||||
public bool IsPrefix;
|
public bool IsPrefix;
|
||||||
|
public ParameterSyncType syncType;
|
||||||
|
public float defaultValue;
|
||||||
|
public bool saved;
|
||||||
|
|
||||||
public string MapKey => IsPrefix ? OriginalName + "*" : OriginalName;
|
public string MapKey => IsPrefix ? OriginalName + "*" : OriginalName;
|
||||||
}
|
}
|
||||||
@ -229,6 +232,16 @@ namespace net.fushizen.modular_avatar.core.editor
|
|||||||
var dictKey = map.nameOrPrefix + (map.isPrefix ? "*" : "");
|
var dictKey = map.nameOrPrefix + (map.isPrefix ? "*" : "");
|
||||||
if (!parameters.ContainsKey(dictKey))
|
if (!parameters.ContainsKey(dictKey))
|
||||||
{
|
{
|
||||||
|
if (map.internalParameter || map.syncType == ParameterSyncType.NotSynced) continue;
|
||||||
|
var param = new DetectedParameter()
|
||||||
|
{
|
||||||
|
OriginalName = map.remapTo,
|
||||||
|
IsPrefix = map.isPrefix,
|
||||||
|
syncType = map.syncType,
|
||||||
|
defaultValue = map.defaultValue,
|
||||||
|
saved = map.saved,
|
||||||
|
};
|
||||||
|
newParams[param.MapKey] = param;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,10 +249,14 @@ namespace net.fushizen.modular_avatar.core.editor
|
|||||||
{
|
{
|
||||||
parameters.Remove(dictKey);
|
parameters.Remove(dictKey);
|
||||||
}
|
}
|
||||||
else if (!string.IsNullOrWhiteSpace(map.remapTo))
|
else
|
||||||
{
|
{
|
||||||
|
var exposedName = !string.IsNullOrWhiteSpace(map.remapTo) ? map.remapTo : map.nameOrPrefix;
|
||||||
var param = parameters[dictKey];
|
var param = parameters[dictKey];
|
||||||
param.OriginalName = map.remapTo;
|
param.OriginalName = exposedName;
|
||||||
|
param.syncType = map.syncType;
|
||||||
|
param.defaultValue = map.defaultValue;
|
||||||
|
param.saved = map.saved;
|
||||||
newParams[param.MapKey] = param;
|
newParams[param.MapKey] = param;
|
||||||
parameters.Remove(dictKey);
|
parameters.Remove(dictKey);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using VRC.SDK3.Avatars.ScriptableObjects;
|
||||||
|
|
||||||
namespace net.fushizen.modular_avatar.core
|
namespace net.fushizen.modular_avatar.core
|
||||||
{
|
{
|
||||||
@ -10,6 +11,17 @@ namespace net.fushizen.modular_avatar.core
|
|||||||
public string nameOrPrefix;
|
public string nameOrPrefix;
|
||||||
public string remapTo;
|
public string remapTo;
|
||||||
public bool internalParameter, isPrefix;
|
public bool internalParameter, isPrefix;
|
||||||
|
public ParameterSyncType syncType;
|
||||||
|
public float defaultValue;
|
||||||
|
public bool saved;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ParameterSyncType
|
||||||
|
{
|
||||||
|
NotSynced,
|
||||||
|
Int,
|
||||||
|
Float,
|
||||||
|
Bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user