public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { MemberData variable = PropertyDrawerUtility.GetActualObjectForSerializedProperty <MemberData>(property); FilterAttribute filter = null; if (fieldInfo.IsDefined(typeof(ObjectTypeAttribute), true)) { object pVariable = PropertyDrawerUtility.GetParentObjectFromSerializedProperty <object>(property); var fieldAttributes = fieldInfo.GetCustomAttributes(true); if (pVariable != null && ReflectionUtils.TryCorrectingAttribute(pVariable, ref fieldAttributes)) { filter = ReflectionUtils.GetAttribute <FilterAttribute>(fieldAttributes); } else { return; } } else if (fieldInfo.GetCustomAttributes(typeof(FilterAttribute), false).Length > 0) { filter = (FilterAttribute)fieldInfo.GetCustomAttributes(typeof(FilterAttribute), false)[0]; } if (fieldInfo.GetCustomAttributes(typeof(TooltipAttribute), false).Length > 0) { label.tooltip = ((TooltipAttribute)fieldInfo.GetCustomAttributes(typeof(TooltipAttribute), false)[0]).tooltip; } EditorReflectionUtility.RenderVariable(position, variable, label, property.serializedObject.targetObject, filter); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); var indent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; var value = PropertyDrawerUtility.GetActualObjectForSerializedProperty <StatesEnum>(fieldInfo, property); if (value != null) { EditorGUI.BeginChangeCheck(); var newSelectedIndex = EditorGUI.Popup(position, value.SelectedIndex, value.Values); if (EditorGUI.EndChangeCheck()) { value.SelectedIndex = newSelectedIndex; PropertyDrawerUtility.SetActualObjectForSerializedProperty(fieldInfo, property, value); property.serializedObject.ApplyModifiedProperties(); } EditorGUI.indentLevel = indent; EditorGUI.EndProperty(); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { ControllerKeyMap target = PropertyDrawerUtility.GetActualObjectForSerializedProperty <ControllerKeyMap>(fieldInfo, property); // Outline box GUI.Box(position, GUIContent.none, "HelpBox"); for (int i = 0; i < target.keyMaps.Length; i++) { Rect r = new Rect(position.xMin + padding, position.yMin + 16 * i + padding, position.width - padding * 2, 16); target.keyMaps[i] = (KeyCode)EditorGUI.EnumPopup(r, Enum.GetName(typeof(InputAxis), (InputAxis)i), target.keyMaps[i]); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (fieldInfo.IsDefined(typeof(TooltipAttribute), true)) { label.tooltip = ((TooltipAttribute)fieldInfo.GetCustomAttributes(typeof(TooltipAttribute), true)[0]).tooltip; } var value = PropertyDrawerUtility.GetActualObjectForSerializedProperty <FunctionModifier>(property); EditorGUI.BeginProperty(position, label, property); uNodeGUIUtility.EditValue(position, label, value, null, new uNodeUtility.EditValueSettings() { unityObject = property.serializedObject.targetObject, }); VariableEditorUtility.DrawMultipurposeMember(position, property, label); EditorGUI.EndProperty(); }
public void Toggle(bool open, SerializedProperty property) { AnimationGroup target = PropertyDrawerUtility.GetActualObjectForSerializedProperty <AnimationGroup>(fieldInfo, property); target.isOpen = open; foreach (UIAnimation.RectMoveAnimation item in target.moveAnimations) { item.rect.anchoredPosition = (open) ? item.open : item.close; } foreach (UIAnimation.RectScaleAnimation item in target.scaleAnimations) { item.rect.localScale = (open) ? item.open : item.close; } foreach (UIAnimation.RectRotateAnimation item in target.rotateAnimation) { Vector3 rot = (open) ? item.open : item.close; item.rect.rotation = Quaternion.Euler(rot); } foreach (UIAnimation.TextFadeAnimation item in target.textFadeAnimations) { item.text.color = (open) ? item.open : item.close; } foreach (UIAnimation.ImageFadeAnimation item in target.imageFadeAnimations) { item.image.color = (open) ? item.open : item.close; } foreach (UIAnimation.ImageFillAnimation item in target.imageFillAnimations) { item.image.fillAmount = (open) ? item.open : item.close; } foreach (UIAnimation.CanvasGroupFadeAnimation item in target.canvasGroupFadeAnimation) { item.cg.alpha = (open) ? item.open : item.close; item.cg.interactable = open; item.cg.blocksRaycasts = open; } }
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) { MouseInputAxis _target = PropertyDrawerUtility.GetActualObjectForSerializedProperty <MouseInputAxis>(fieldInfo, property); Rect r2 = new Rect(r.xMin, r.yMin, r.width, r.height + 2); GUI.Box(r2, GUIContent.none, "HelpBox"); r2 = new Rect(r.xMin - 4, r.yMin, 4, r.height + 2); Color color = (_target.axisId == 0) ? Color.red : (_target.axisId == 1) ? Color.green : Color.blue; EditorGUI.DrawRect(r2, color); float labelwidth = EditorGUIUtility.labelWidth; float fieldwidth = r.width - labelwidth - padding; r2 = new Rect(r.xMin + padding, r.yMin + padding, labelwidth, 16); string labeltext = (_target.axisId == 0) ? "X - Pitch" : (_target.axisId == 1) ? "Y - Yaw" : "Z - Roll"; GUI.Label(r2, labeltext); r2 = new Rect(r.xMin + labelwidth, r.yMin + padding, fieldwidth - 40, 16); _target.mouseAxis = (MouseAxes)EditorGUI.EnumPopup(r2, GUIContent.none, _target.mouseAxis); r2 = new Rect(r.width - 18 + padding, r.yMin + padding, 30, 16); GUI.Label(r2, "Inv"); r2 = new Rect(r.width - 32 + padding, r.yMin + padding, 50, 16); _target.invert = EditorGUI.Toggle(r2, _target.invert); r2 = new Rect(r.xMin + labelwidth, r.yMin + padding + 17, fieldwidth, 16); _target.sensitivity = EditorGUI.Slider(r2, GUIContent.none, _target.sensitivity, 0f, (_target.mouseAxis > MouseAxes.MouseY) ? 20f : 5f); r2 = new Rect(r.xMin + padding, r.yMin + padding + 17, labelwidth, 16); EditorGUI.LabelField(r2, "Sensitivity"); }
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(r, label, property); property.serializedObject.ApplyModifiedProperties(); property.serializedObject.Update(); var par = PropertyDrawerUtility.GetParent(property); GameObject parGO; // the parent may be an NST or a TransformElement if (par is NSTElementComponent) { parGO = (par as NSTElementComponent).gameObject; } else { parGO = (par as NetworkSyncTransform).gameObject; } TransformElement te = PropertyDrawerUtility.GetActualObjectForSerializedProperty <TransformElement>(fieldInfo, property); name = property.FindPropertyRelative("name"); isRoot = property.FindPropertyRelative("isRoot"); keyRate = property.FindPropertyRelative("keyRate"); sendCullMask = property.FindPropertyRelative("sendCullMask"); gameobject = property.FindPropertyRelative("gameobject"); extrapolation = property.FindPropertyRelative("extrapolation"); maxExtrapolates = property.FindPropertyRelative("maxExtrapolates"); teleportOverride = property.FindPropertyRelative("teleportOverride"); isPos = (te is IPositionElement); isRot = (te is IRotationElement); string typeLabel = (isPos) ? "Position" : (isRot) ? "Rotation" : "Scale"; margin = 4; realwidth = r.width + 16 - 4; colwidths = realwidth / 4f; colwidths = Mathf.Max(colwidths, 65); // limit the smallest size so things like sliders aren't shrunk too small to draw. currentLine = r.yMin + margin * 2; Color headerblockcolor = (isPos ? positionHeaderBarColor : isRot ? rotationHeaderBarColor : scaleHeaderBarColor); if (!isRoot.boolValue) { EditorGUI.DrawRect(new Rect(margin + 3, r.yMin + 2 + 2, realwidth - 6, LINEHEIGHT + 8), headerblockcolor); } savedIndentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; if (!isRoot.boolValue) { string headerLabel = typeLabel + " Element"; EditorGUI.LabelField(new Rect(r.xMin, currentLine, colwidths * 4, LINEHEIGHT), new GUIContent(headerLabel), "WhiteBoldLabel"); NSTElementComponentEditor.MakeAllNamesUnique(parGO, te); EditorGUI.PropertyField(new Rect(r.xMin, currentLine, r.width - 4, LINEHEIGHT), name, new GUIContent(" ")); currentLine += LINEHEIGHT + 8; } // The only element that will be found on the root (the actual NST component) is rotation else { EditorGUI.LabelField(new Rect(r.xMin, currentLine, r.width, LINEHEIGHT), new GUIContent("Root Rotation Updates"), "BoldLabel"); currentLine += LINEHEIGHT + 4; } EditorGUI.indentLevel = 0; // Section for Send Culling enum flags left = 13; realwidth -= 16; sendCullMask.intValue = System.Convert.ToInt32(EditorGUI.EnumMaskField(new Rect(left, currentLine, realwidth, LINEHEIGHT), new GUIContent("Send On Events:"), (SendCullMask)sendCullMask.intValue)); currentLine += LINEHEIGHT + 4; if (!isRoot.boolValue) { EditorGUI.PropertyField(new Rect(left, currentLine, realwidth, LINEHEIGHT), gameobject, new GUIContent("GameObject:")); currentLine += LINEHEIGHT + 4; } if (((SendCullMask)sendCullMask.intValue).EveryTick() == false) { EditorGUI.PropertyField(new Rect(left, currentLine, realwidth, LINEHEIGHT), keyRate, new GUIContent("Key Every:")); currentLine += LINEHEIGHT + 2; } if (keyRate.intValue == 0 && sendCullMask.intValue == 0) { //noUpdates = true; EditorGUI.HelpBox(new Rect(left, currentLine, realwidth, 48), "Element Disabled. Select one or more 'Send On Events' event to trigger on, and/or set Key Every to a number greater than 0.", MessageType.Warning); currentLine += 50; property.serializedObject.ApplyModifiedProperties(); return; } else { //noUpdates = false; EditorGUI.PropertyField(new Rect(left, currentLine, realwidth, LINEHEIGHT), extrapolation, new GUIContent("Extrapolation:")); currentLine += LINEHEIGHT + 2; EditorGUI.PropertyField(new Rect(left, currentLine, realwidth, LINEHEIGHT), maxExtrapolates, new GUIContent("Max Extrapolations:")); currentLine += LINEHEIGHT + 2; EditorGUI.PropertyField(new Rect(left, currentLine, realwidth, LINEHEIGHT), teleportOverride, new GUIContent("Teleport Override:")); currentLine += LINEHEIGHT + 2; } property.serializedObject.ApplyModifiedProperties(); property.serializedObject.Update(); SerializedProperty crusher = property.FindPropertyRelative("crusher"); float ch = EditorGUI.GetPropertyHeight(crusher); EditorGUI.PropertyField(new Rect(r.xMin, currentLine - 2, r.width, ch), crusher); currentLine += ch; property.serializedObject.ApplyModifiedProperties(); SerializedProperty drawerHeight = property.FindPropertyRelative("drawerHeight"); // revert to original indent level. EditorGUI.indentLevel = savedIndentLevel; // Record the height of this instance of drawer drawerHeight.floatValue = currentLine - r.yMin; EditorGUI.EndProperty(); }
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(r, label, property); var par = PropertyDrawerUtility.GetParent(property); GameObject parGO; // the parent may be an NST or a TransformElement if (par is NSTElementComponent) { parGO = (par as NSTElementComponent).gameObject; } else { parGO = (par as NetworkSyncTransform).gameObject; } TransformElement te = PropertyDrawerUtility.GetActualObjectForSerializedProperty <TransformElement>(fieldInfo, property); name = property.FindPropertyRelative("name"); isRoot = property.FindPropertyRelative("isRoot"); elementType = property.FindPropertyRelative("elementType"); keyRate = property.FindPropertyRelative("keyRate"); sendCullMask = property.FindPropertyRelative("sendCullMask"); gameobject = property.FindPropertyRelative("gameobject"); extrapolation = property.FindPropertyRelative("extrapolation"); maxExtrapolates = property.FindPropertyRelative("maxExtrapolates"); teleportOverride = property.FindPropertyRelative("teleportOverride"); isPos = (ElementType)elementType.intValue == ElementType.Position; string typeLabel = (isPos) ? "Position" : "Rotation"; margin = 4; realwidth = r.width + 16 - 4; colwidths = realwidth / 4f; colwidths = Mathf.Max(colwidths, 65); // limit the smallest size so things like sliders aren't shrunk too small to draw. currentLine = r.yMin + margin * 2; Color headerblockcolor = (isPos ? positionHeaderBarColor : rotationHeaderBarColor); //GUI.Box(new Rect(margin, r.yMin + 2, realwidth, r.height - margin), GUIContent.none, "ProjectBrowserTextureIconDropShadow"); //GUI.Box(new Rect(margin, r.yMin + 2, realwidth, r.height - margin), GUIContent.none, "HelpBox"); //"ProjectBrowserTextureIconDropShadow"); if (!isRoot.boolValue) { EditorGUI.DrawRect(new Rect(margin + 3, r.yMin + 2 + 2, realwidth - 6, LINEHEIGHT + 8), headerblockcolor); } savedIndentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; if (!isRoot.boolValue) { string headerLabel = typeLabel + " Element"; EditorGUI.LabelField(new Rect(r.xMin, currentLine, colwidths * 4, LINEHEIGHT), new GUIContent(headerLabel), "WhiteBoldLabel"); NSTElementComponentEditor.MakeAllNamesUnique(parGO, te); EditorGUI.PropertyField(new Rect(r.xMin, currentLine, r.width - 4, LINEHEIGHT), name, new GUIContent(" ")); currentLine += LINEHEIGHT + 8; } else { EditorGUI.LabelField(new Rect(r.xMin, currentLine, r.width, LINEHEIGHT), new GUIContent("Root Rotation Updates"), "BoldLabel"); currentLine += LINEHEIGHT + 4; } EditorGUI.indentLevel = 0; // Section for Send Culling enum flags left = 13; realwidth -= 16; sendCullMask.intValue = System.Convert.ToInt32(EditorGUI.EnumMaskPopup(new Rect(left, currentLine, realwidth, LINEHEIGHT), new GUIContent("Send On Events:"), (SendCullMask)sendCullMask.intValue)); currentLine += LINEHEIGHT + 4; if (!isRoot.boolValue) { EditorGUI.PropertyField(new Rect(left, currentLine, realwidth, LINEHEIGHT), gameobject, new GUIContent("GameObject:")); currentLine += LINEHEIGHT + 4; } if (((SendCullMask)sendCullMask.intValue).EveryTick() == false) { EditorGUI.PropertyField(new Rect(left, currentLine, realwidth, LINEHEIGHT), keyRate, new GUIContent("Key Every:")); currentLine += LINEHEIGHT + 2; } if (keyRate.intValue == 0 && sendCullMask.intValue == 0) { noUpdates = true; EditorGUI.HelpBox(new Rect(left, currentLine, realwidth, 48), typeLabel + " Element Disabled. Select one ore more Send On Events, and/or set Key Every to a number greater than 0.", MessageType.Warning); currentLine += 50; return; } else { noUpdates = false; EditorGUI.PropertyField(new Rect(left, currentLine, realwidth, LINEHEIGHT), extrapolation, new GUIContent("Extrapolation:")); currentLine += LINEHEIGHT + 2; EditorGUI.PropertyField(new Rect(left, currentLine, realwidth, LINEHEIGHT), maxExtrapolates, new GUIContent("Max Extrapolations:")); currentLine += LINEHEIGHT + 2; EditorGUI.PropertyField(new Rect(left, currentLine, realwidth, LINEHEIGHT), teleportOverride, new GUIContent("Teleport Override:")); currentLine += LINEHEIGHT + 2; } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { object variable = PropertyDrawerUtility.GetParentObjectFromSerializedProperty <object>(property); if (variable != null) { if (uNodeGUIUtility.IsHide(fieldInfo, variable)) { return; } } else { if (fieldInfo.IsDefined(typeof(HideAttribute), true)) { HideAttribute[] hide = fieldInfo.GetCustomAttributes(typeof(HideAttribute), true) as HideAttribute[]; foreach (HideAttribute ha in hide) { if (string.IsNullOrEmpty(ha.targetField)) { return; } } } } if (fieldInfo.IsDefined(typeof(TooltipAttribute), true)) { label.tooltip = ((TooltipAttribute)fieldInfo.GetCustomAttributes(typeof(TooltipAttribute), true)[0]).tooltip; } System.Type type = fieldInfo.FieldType; if (fieldInfo.FieldType.IsArray) { type = fieldInfo.FieldType.GetElementType(); } else if (fieldInfo.FieldType.IsGenericType) { System.Type[] gType = fieldInfo.FieldType.GetGenericArguments(); if (gType.Length == 1) { type = gType[0]; } } if (type == typeof(MemberData)) { MemberData obj = PropertyDrawerUtility.GetActualObjectForSerializedProperty <MemberData>(property); FilterAttribute filter = null; if (fieldInfo.GetCustomAttributes(typeof(FilterAttribute), false).Length > 0) { filter = (FilterAttribute)fieldInfo.GetCustomAttributes(typeof(FilterAttribute), false)[0]; } else if (fieldInfo.IsDefined(typeof(ObjectTypeAttribute), true)) { var fieldAttributes = fieldInfo.GetCustomAttributes(true); object pVariable = PropertyDrawerUtility.GetParentObjectFromSerializedProperty <object>(property); if (pVariable != null && ReflectionUtils.TryCorrectingAttribute(pVariable, ref fieldAttributes)) { filter = ReflectionUtils.GetAttribute <FilterAttribute>(fieldAttributes); } else { return; } } EditorReflectionUtility.RenderVariable(position, obj, label, property.serializedObject.targetObject, filter); } else { EditorGUI.PropertyField(position, property, label, true); } }
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) { InputSelector _target = null; EditorGUI.BeginProperty(r, label, property); // Very roundabout way of getting this target if is part of a list. var _parent = PropertyDrawerUtility.GetParent(property); int index = PropertyDrawerUtility.GetIndexOfDrawerObject(property); if (_parent != null && _parent is InputSelectors && index != -1) { _target = (_parent as InputSelectors).selectors [index]; } // This is not part of a list... if (_target == null) { _target = PropertyDrawerUtility.GetActualObjectForSerializedProperty <InputSelector>(fieldInfo, property); } if (_target != null) { _target.UpdateToSelectedType(); } // This will need to be an interface in order to be useable on more than just NSTCastDefinition //NSTCastDefinition nstCastDef = property.serializedObject.targetObject as NSTCastDefinition; SerializedProperty inputType = property.FindPropertyRelative("inputType"); //SerializedProperty inputSelection = property.FindPropertyRelative("triggers"); labelWidth = EditorGUIUtility.labelWidth - 36; fieldWidth = r.width - labelWidth; halfFieldWidth = fieldWidth * .5f; fieldAreaLeft = r.xMin + labelWidth; int val = (int)(InputType)EditorGUI.EnumPopup(new Rect(r.xMin, r.yMin, labelWidth - 2, 16), GUIContent.none, (InputType)inputType.enumValueIndex); inputType.enumValueIndex = val; Rect rightrect = new Rect(fieldAreaLeft, r.yMin, fieldWidth, r.height); InputType enumVal = (InputType)val; // Only show the derived input class that we are actually using if (enumVal == InputType.Axis) { EditorGUI.PropertyField(rightrect, property.FindPropertyRelative("inputAxis")); } else if (enumVal == InputType.KeyCode) { EditorGUI.PropertyField(rightrect, property.FindPropertyRelative("inputKeyCode")); } else if (enumVal == InputType.Keys) { EditorGUI.PropertyField(rightrect, property.FindPropertyRelative("inputKeys")); } else if (enumVal == InputType.UIZone) { EditorGUI.PropertyField(rightrect, property.FindPropertyRelative("inputUIZone")); } else if (enumVal == InputType.TouchArea) { EditorGUI.PropertyField(rightrect, property.FindPropertyRelative("inputTouchArea")); } EditorGUI.EndProperty(); }
/// <summary> /// Everything belows are helpers /// </summary> public void CopyValues(bool toOpen, SerializedProperty property) { AnimationGroup target = PropertyDrawerUtility.GetActualObjectForSerializedProperty <AnimationGroup>(fieldInfo, property); foreach (UIAnimation.RectMoveAnimation item in target.moveAnimations) { if (toOpen) { item.open = item.rect.anchoredPosition; } else { item.close = item.rect.anchoredPosition; } } foreach (UIAnimation.RectRotateAnimation item in target.rotateAnimation) { Vector3 rot = item.rect.rotation.eulerAngles; if (toOpen) { item.open = rot; } else { item.close = rot; } } foreach (UIAnimation.RectScaleAnimation item in target.scaleAnimations) { if (toOpen) { item.open = item.rect.localScale; } else { item.close = item.rect.localScale; } } foreach (UIAnimation.TextFadeAnimation item in target.textFadeAnimations) { if (toOpen) { item.open = item.text.color; } else { item.close = item.text.color; } } foreach (UIAnimation.ImageFadeAnimation item in target.imageFadeAnimations) { if (toOpen) { item.open = item.image.color; } else { item.close = item.image.color; } } foreach (UIAnimation.ImageFillAnimation item in target.imageFillAnimations) { if (toOpen) { item.open = item.image.fillAmount; } else { item.close = item.image.fillAmount; } } foreach (UIAnimation.CanvasGroupFadeAnimation item in target.canvasGroupFadeAnimation) { if (toOpen) { item.open = item.cg.alpha; } else { item.close = item.cg.alpha; } } }