public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (property.name == "data" && property.depth > 0) { EditorGUI.PropertyField(position, property, label); return; } var fieldType = property.serializedObject.targetObject.GetType().GetField(property.name).FieldType; var source = UTUtils.GetValueThroughAttribute(property, methodName, out var sourceValType); if (sourceType == PopupSource.Method && fieldType != sourceValType || property.type != "string") { EditorGUI.PropertyField(position, property, label); return; } if (sourceType == PopupSource.Animator) { options = UTUtils.GetAnimatorTriggers(source as Animator).Select(o => new GUIContent(o)).ToArray(); } else if (sourceType == PopupSource.UdonBehaviour) { options = UTUtils.GetUdonEvents(source as UdonSharpBehaviour).Select(o => new GUIContent(o)).ToArray(); } else if (sourceType == PopupSource.Shader) { options = UTUtils.GetShaderPropertiesByType(source, shaderPropType).Select(o => new GUIContent(o)).ToArray(); } else { options = ((string[])source).Select(o => new GUIContent(o)).ToArray(); } selectedIndex = options.ToList().FindIndex(i => i.text == property.stringValue); if (selectedIndex >= options.Length || selectedIndex < 0) { selectedIndex = 0; } var finalLabel = hideLabel ? new GUIContent() : label; selectedIndex = EditorGUI.Popup(position, finalLabel, selectedIndex, options); property.stringValue = options[selectedIndex].text; }
public UTBehaviourInfo(UdonSharpBehaviour targetBeh) { var targetType = targetBeh.GetType(); name = targetBeh.name; var cNameAttr = targetType.GetCustomAttributes(typeof(CustomNameAttribute)) .Select(i => i as CustomNameAttribute).ToArray(); customName = cNameAttr.Any() ? cNameAttr.First().name : null; var helpUrlAttr = targetType.GetCustomAttributes(typeof(HelpURLAttribute)) .Select(i => i as HelpURLAttribute).ToArray(); helpUrl = helpUrlAttr.Any() ? helpUrlAttr.First().URL : null; var helpMsgAttr = targetType.GetCustomAttributes(typeof(HelpMessageAttribute)) .Select(i => i as HelpMessageAttribute).ToArray(); helpMsg = helpMsgAttr.Any() ? helpMsgAttr.First().helpMessage : null; var onValChangedAttr = targetType.GetCustomAttributes(typeof(OnValuesChangedAttribute)) .Select(i => i as OnValuesChangedAttribute).ToArray(); onValuesChanged = onValChangedAttr.Any() ? targetType.GetMethod(onValChangedAttr.First().methodName) : null; var onBeforeEditorAttr = targetType.GetCustomAttributes(typeof(OnBeforeEditorAttribute)) .Select(i => i as OnBeforeEditorAttribute).ToArray(); onBeforeEditor = onBeforeEditorAttr.Any() ? targetType.GetMethod(onBeforeEditorAttr.First().methodName) : null; var onAfterEditorAttr = targetType.GetCustomAttributes(typeof(OnAfterEditorAttribute)) .Select(i => i as OnAfterEditorAttribute).ToArray(); onAfterEditor = onAfterEditorAttr.Any() ? targetType.GetMethod(onAfterEditorAttr.First().methodName) : null; udonCustomEvents = UTUtils.GetUdonEvents(targetBeh); if (udonCustomEvents.Length == 1 && udonCustomEvents.First() == "no events found") { udonCustomEvents = new string[0]; } buttons = targetType.GetMethods() .Where(i => i.GetCustomAttributes(typeof(ButtonAttribute)).Any()).ToArray(); }
public override void OnGUI(SerializedProperty property) { var source = UTUtils.GetValueThroughAttribute(property, methodName, out var sourceValType); if (property.name == "data" && sourceType == PopupSource.Method && property.type != "string" && property.type != "int") { EditorGUILayout.PropertyField(property, new GUIContent(property.displayName)); return; } if (property.name != "data") { var fieldType = property.serializedObject.targetObject.GetType().GetField(property.name).FieldType; if (sourceType == PopupSource.Method && fieldType != sourceValType && property.type != "string" && property.type != "int") { EditorGUILayout.PropertyField(property, new GUIContent(property.displayName)); return; } } var numericPopup = property.type == "int" && sourceValType == typeof(int) || property.type == "float" && sourceValType == typeof(float); if (sourceType == PopupSource.AnimatorTrigger) { options = UTUtils.GetAnimatorTriggers(source as Animator).Select(o => new GUIContent(o)).ToArray(); } else if (sourceType == PopupSource.AnimatorBool) { options = UTUtils.GetAnimatorBools(source as Animator).Select(o => new GUIContent(o)).ToArray(); } else if (sourceType == PopupSource.AnimatorFloat) { options = UTUtils.GetAnimatorFloats(source as Animator).Select(o => new GUIContent(o)).ToArray(); } else if (sourceType == PopupSource.AnimatorInt) { options = UTUtils.GetAnimatorInts(source as Animator).Select(o => new GUIContent(o)).ToArray(); } else if (sourceType == PopupSource.UdonBehaviour) { options = UTUtils.GetUdonEvents(source as UdonSharpBehaviour).Select(o => new GUIContent(o)).ToArray(); } else if (sourceType == PopupSource.UdonProgramVariable) { options = UTUtils.GetUdonVariables(source as UdonSharpBehaviour).Select(o => new GUIContent(o)).ToArray(); } else if (sourceType == PopupSource.Shader) { if (shaderPropType == ShaderPropType.All) { options = UTUtils.GetAllShaderProperties(source).Select(o => new GUIContent(o)).ToArray(); } else { options = UTUtils.GetShaderPropertiesByType(source, shaderPropType).Select(o => new GUIContent(o)).ToArray(); } } else { if (sourceValType == typeof(int)) { options = ((int[])source).Select(i => new GUIContent(i.ToString())).ToArray(); } else if (sourceValType == typeof(float)) { options = ((float[])source).Select(i => new GUIContent(i.ToString())).ToArray(); } else { options = ((string[])source).Select(o => new GUIContent(o)).ToArray(); } } // we want to still support int[] -> int[] and float[] -> float[] mapping if (property.type == "int" && !numericPopup) { selectedIndex = property.intValue; } else if (numericPopup) { if (property.type == "int") { selectedIndex = options.ToList().FindIndex(i => i.text == property.intValue.ToString()); } else { selectedIndex = options.ToList().FindIndex(i => i.text == property.floatValue.ToString()); } if (selectedIndex >= options.Length || selectedIndex < 0) { selectedIndex = 0; } } else { selectedIndex = options.ToList().FindIndex(i => i.text == property.stringValue); if (selectedIndex >= options.Length || selectedIndex < 0) { selectedIndex = 0; } } var finalLabel = hideLabel || property.name == "data" ? new GUIContent() : new GUIContent(property.displayName); selectedIndex = EditorGUILayout.Popup(finalLabel, selectedIndex, options); if (property.type == "int" && !numericPopup) { property.intValue = selectedIndex; } else if (numericPopup) { if (property.type == "int") { property.intValue = Convert.ToInt32(options[selectedIndex].text); } else { property.floatValue = Convert.ToSingle(options[selectedIndex].text); } } else { property.stringValue = options[selectedIndex].text; } }