public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { IVitals vitals = (PropertyDrawerUtility.GetParent(property) as IVitals); bool isAnArray = PropertyDrawerUtility.GetIndexOfDrawerObject(property) != -1; return((isAnArray && vitals != null) ? 194 : 172); }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { property.serializedObject.Update(); SerializedProperty vitalDefs = property.FindPropertyRelative("vitalDefs"); Vitals ivitals = (PropertyDrawerUtility.GetParent(vitalDefs) as Vitals); int vitalsCount = ivitals.vitalDefs.Count; float h = 0; for (int i = 0; i < vitalsCount; ++i) { h += EditorGUI.GetPropertyHeight(vitalDefs.GetArrayElementAtIndex(i)); h += ADD_BUTTON_HGHT + VitalDefinitionDrawer.PAD * 2 + 2; } return(h); }
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(r, label, property); InputSelector par = (InputSelector)PropertyDrawerUtility.GetParent(property); // Initialize constantly to apply changes par.inputSelection.Initialize(par); //var _target = PropertyDrawerUtility.GetActualObjectForSerializedProperty<InputSelectorKeyCode>(fieldInfo, property); //Debug.Log(_target); //int id = PropertyDrawerUtility.GetIndexOfDrawerObject(property); //Debug.Log(par); index = property.FindPropertyRelative("index"); modKeys = property.FindPropertyRelative("modKeys"); castInputType = property.FindPropertyRelative("inputType"); halfFieldWidth = r.width * .5f; firstFieldLeft = r.xMin; secondFieldLeft = r.xMin + halfFieldWidth; if (!isTouch) { int oldVal = modKeys.intValue; int newVal = (int)(ModKeys)EditorGUI.EnumMaskPopup(new Rect(r.xMin, r.yMin, halfFieldWidth, r.height), GUIContent.none, (ModKeys)modKeys.intValue); // if UnModded has just been selected - clamp to clear all other mods if (newVal - oldVal >= (int)ModKeys.UnModded) { newVal = (int)ModKeys.UnModded; } // else if a mod has been selected, clear unmodded else if (newVal > (int)ModKeys.UnModded) { newVal = newVal & ~((int)ModKeys.UnModded); } modKeys.intValue = newVal; } EditorGUI.EndProperty(); }
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(r, label, property); InputSelector par = (InputSelector)PropertyDrawerUtility.GetParent(property); // Initialize constantly to apply changes par.inputSelection.Initialize(par); index = property.FindPropertyRelative("index"); modKeys = property.FindPropertyRelative("modKeys"); castInputType = property.FindPropertyRelative("inputType"); halfFieldWidth = r.width * .5f; firstFieldLeft = r.xMin; secondFieldLeft = r.xMin + halfFieldWidth; if (!isTouch) { int oldVal = modKeys.intValue; #if UNITY_2017_3_OR_NEWER int newVal = (int)(ModKeys)EditorGUI.EnumFlagsField(new Rect(r.xMin, r.yMin, halfFieldWidth, r.height), GUIContent.none, (ModKeys)modKeys.intValue); #else int newVal = (int)(ModKeys)EditorGUI.EnumMaskField(new Rect(r.xMin, r.yMin, halfFieldWidth, r.height), GUIContent.none, (ModKeys)modKeys.intValue); #endif // if UnModded has just been selected - clamp to clear all other mods if (newVal - oldVal >= (int)ModKeys.UnModded) { newVal = (int)ModKeys.UnModded; } // else if a mod has been selected, clear unmodded else if (newVal > (int)ModKeys.UnModded) { newVal = newVal & ~((int)ModKeys.UnModded); } modKeys.intValue = newVal; } EditorGUI.EndProperty(); }
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) { InputSelector inputSelector = PropertyDrawerUtility.GetParent(property) as InputSelector; InputSelectorUIZone _target = inputSelector.inputSelection as InputSelectorUIZone; // Tell the base class that this is a touch/click item - so the modkeys are not needed. isTouch = true; base.OnGUI(r, property, label); SerializedProperty touchTypes = property.FindPropertyRelative("touchType"); SerializedProperty zoneSelector = property.FindPropertyRelative("zoneSelector"); { if (_target != null) { touchTypes.enumValueIndex = (int)(ClickTypes)EditorGUI.EnumPopup(new Rect(firstFieldLeft, r.yMin, halfFieldWidth, 16), GUIContent.none, (ClickTypes)touchTypes.enumValueIndex); EditorGUI.PropertyField(new Rect(secondFieldLeft, r.yMin, halfFieldWidth, 16), zoneSelector); } } }
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) { InputSelectorUIZone inputSelector = PropertyDrawerUtility.GetParent(property) as InputSelectorUIZone; //int index = PropertyDrawerUtility.GetIndexOfDrawerObject(property); UIZoneSelector _target = inputSelector.zoneSelector; // Get the array of zoneNames List <string> zonesnamelist = UIZone.names; // GetListOfZoneNames(); // only resize the string array when it doesn't match the number of UIZones in scene if (zonesnamelist.Count != zonenames.Length) { zonenames = new string[zonesnamelist.Count]; } for (int i = 0; i < zonesnamelist.Count; i++) { zonenames[i] = zonesnamelist[i]; } if (zonesnamelist.Count == 0) { EditorUtils.CreateErrorIconF(r.xMin, r.yMin, "Add a UIZone component to a UI object to define a touch/mouse area. Any added zones will appear in a list here for you to select from."); EditorGUI.LabelField(r, " No UIZones found in scene.", new GUIStyle("MiniLabel")); } else { if (_target != null) { _target.ZoneId = EditorGUI.Popup(r, _target.ZoneId, zonenames); _target.ZoneName = UIZone.list[_target.ZoneId].itemName; } //selectedZoneName.stringValue = zonenames[selectedZoneId.intValue]; } }
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); SerializedProperty bitsForStat = property.FindPropertyRelative("bitsForStat"); SerializedProperty startValue = property.FindPropertyRelative("startValue"); SerializedProperty maxValue = property.FindPropertyRelative("maxValue"); IVitals vitals = (PropertyDrawerUtility.GetParent(property) as IVitals); int index = PropertyDrawerUtility.GetIndexOfDrawerObject(property); bool isAnArray = index >= 0 && vitals != null; float margin = 4; float padding = 6; float width = r.width + r.xMin + 5; float topbarHeight = 74; EditorGUI.indentLevel = 0; Rect outer = new Rect(0 + margin, r.yMin, width - margin * 2, r.height - margin - (isAnArray ? 24 : 2)); GUI.Box(outer, GUIContent.none, "flow overlay box"); GUI.Box(outer, GUIContent.none, "HelpBox"); Color boxcolor = index == 0 ? new Color(.4f, .2f, .2f) : new Color(.3f, .3f, .3f); EditorGUI.DrawRect(new Rect(margin + 1, r.yMin + 1, width - margin * 2 - 2, topbarHeight), boxcolor); Rect inner = new Rect(outer.xMin + padding, outer.yMin, outer.width - padding * 2, outer.height); inner.yMin += padding; inner.height = 16; string vitalnum = isAnArray ? "[" + index + "]" : "Name"; EditorGUI.LabelField(inner, "Vital " + vitalnum + ((index == 0) ? " (Root)" : ""), (GUIStyle)"WhiteBoldLabel"); Rect namerect = index > 0 ? new Rect(inner.xMin, inner.yMin, inner.width - 17, inner.height) : inner; EditorGUI.PropertyField(namerect, property.FindPropertyRelative("name"), new GUIContent(" ")); if (index > 0 && vitals != null) { if (GUI.Button(new Rect(inner.xMin + inner.width - 16, inner.yMin, 16, 16), "X")) { vitals.Vitals.RemoveAt(index); } } inner.yMin += 19; inner.height = 64; EditorGUI.PropertyField(inner, bitsForStat); inner.yMin += EditorGUI.GetPropertyHeight(bitsForStat) + padding; // 64; inner.height = 16; startValue.floatValue = EditorGUI.IntSlider(inner, "Start Value", (int)startValue.floatValue, 0, (1 << bitsForStat.intValue)); inner.yMin += 17; inner.height = 16; maxValue.floatValue = EditorGUI.IntSlider(inner, "Max Value", (int)maxValue.floatValue, 0, (1 << bitsForStat.intValue)); inner.yMin += 17; inner.height = 16; EditorGUI.PropertyField(inner, property.FindPropertyRelative("absorption")); inner.yMin += 17; inner.height = 16; EditorGUI.PropertyField(inner, property.FindPropertyRelative("regenDelay")); inner.yMin += 17; inner.height = 16; EditorGUI.PropertyField(inner, property.FindPropertyRelative("regenRate")); // Add new vital button (only available if this belongs to a list) if (index > -1 && vitals != null) { inner.yMin += 28; inner.height = 16; if (GUI.Button(new Rect(inner.xMin + 64, inner.yMin, inner.width - 128, 16), "Add New Vital")) { vitals.Vitals.Insert(index + 1, new Vital()); } } EditorGUI.EndProperty(); }
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) { property.serializedObject.Update(); SerializedProperty vitalDefs = property.FindPropertyRelative("vitalDefs"); Vitals ivitals = (PropertyDrawerUtility.GetParent(vitalDefs) as Vitals); int vitalsCount = vitalDefs.arraySize; int addIndex = -1; //int delIndex = -1; for (int i = 0; i < vitalsCount; ++i) { var element = vitalDefs.GetArrayElementAtIndex(i); r.height = EditorGUI.GetPropertyHeight(element); EditorGUI.PropertyField(new Rect(r), element, false); if (i > 0) { const int XWIDTH = 18; Rect xr = r; xr.xMin = xr.xMax - XWIDTH - VitalDefinitionDrawer.PAD; xr.yMin += VitalDefinitionDrawer.PAD; xr.height = ADD_BUTTON_HGHT; xr.width = XWIDTH; if (GUI.Button(xr, "X")) { Undo.RecordObject(vitalDefs.serializedObject.targetObject, "Delete Vital"); ivitals.VitalDefs.Remove(ivitals.VitalDefs[i]); EditorUtility.SetDirty(vitalDefs.serializedObject.targetObject); AssetDatabase.Refresh(); break; } } r.yMin += r.height + VitalDefinitionDrawer.PAD + 2; r.height = ADD_BUTTON_HGHT; const int ADDMARGIN = 80; Rect addrect = new Rect(r) { xMin = r.xMin + 4 + ADDMARGIN, xMax = r.xMax - ADDMARGIN }; if (GUI.Button(addrect, "Add Vital", (GUIStyle)"MiniToolbarButton")) { addIndex = i + 1; } r.yMin += r.height + VitalDefinitionDrawer.PAD; } if (addIndex != -1) { Undo.RecordObject(vitalDefs.serializedObject.targetObject, "Add Vital"); vitalDefs.InsertArrayElementAtIndex(addIndex); EditorUtility.SetDirty(vitalDefs.serializedObject.targetObject); property.serializedObject.ApplyModifiedProperties(); AssetDatabase.Refresh(); } }
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 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(); }