private void Init() { if (initialized) { return; } if (!_manuallyConfigured) { if (this.fieldInfo != null) { var attrib = this.fieldInfo.GetCustomAttributes(typeof(DNAEvaluatorList.ConfigAttribute), true).FirstOrDefault() as DNAEvaluatorList.ConfigAttribute; if (attrib != null) { _labelOption = attrib.labelOption; _defaultGraph = attrib.defaultGraph; } } } _aggregationLabelStyle = new GUIStyle(EditorStyles.label); _aggregationLabelStyle = new GUIStyle(EditorStyles.centeredGreyMiniLabel); _aggregationLabelStyle.alignment = TextAnchor.MiddleLeft; if (ROLDefaults == null) { ROLDefaults = new ReorderableList.Defaults(); } initialized = true; }
protected override void DrawElementsListFooterCallback(Rect rect) { var ROLDefaults = new ReorderableList.Defaults(); var padding = 4f; var _addBtnWidth = 50f; var _labelWidth = 78f; Rect addRect = rect; addRect.xMin = addRect.xMax - 420 > addRect.xMin ? addRect.xMax - 420 : addRect.xMin; addRect.height = (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing * 2); var addBtnRect = new Rect(rect.xMax - _addBtnWidth - (padding * 2), addRect.yMin, _addBtnWidth, EditorGUIUtility.singleLineHeight); var fieldRect = new Rect(addRect.xMin + (padding * 2), addRect.yMin, addRect.width - _addBtnWidth - (padding * 6), EditorGUIUtility.singleLineHeight); var labelRect = new Rect(fieldRect.xMin, fieldRect.yMin, _labelWidth, fieldRect.height); var boneNameRect = new Rect(labelRect.xMax + (padding * 2), fieldRect.yMin, ((fieldRect.width - _labelWidth) / 2) - (padding * 2), fieldRect.height); var propertyRect = new Rect(boneNameRect.xMax + (padding * 2), fieldRect.yMin, ((fieldRect.width - _labelWidth) / 2) - (padding * 2), fieldRect.height); if (Event.current.type == EventType.Repaint) { var prevFooterFixedHeight = ROLDefaults.footerBackground.fixedHeight; ROLDefaults.footerBackground.fixedHeight = addRect.height; ROLDefaults.footerBackground.Draw(addRect, false, false, false, false); ROLDefaults.footerBackground.fixedHeight = prevFooterFixedHeight; } EditorGUI.LabelField(labelRect, new GUIContent("Add Modifier:", "Add a Skeleton Modifier to the list")); GUI.SetNextControlName("BoneNameField"); _chosenBoneNameToAdd = EditorGUI.TextField(boneNameRect, _chosenBoneNameToAdd); if (_chosenBoneNameToAdd == "" && GUI.GetNameOfFocusedControl() != "BoneNameField") { EditorGUI.BeginDisabledGroup(true); EditorGUI.TextArea(boneNameRect, "Bone Name", _placeholderTextStyle); EditorGUI.EndDisabledGroup(); } _chosenPropertyToAdd = EditorGUI.Popup(propertyRect, _chosenPropertyToAdd, _propertyArray); //users need a message why they cant add (a warning icon in the button maybe? string warningMessage = CanAddBoneForProp(); GUIContent addBtnGUI = new GUIContent("Add", "Choose the bone name and property to add first"); if (warningMessage != "") { addBtnGUI.image = _warningIcon; } addBtnGUI.tooltip = warningMessage; EditorGUI.BeginDisabledGroup(warningMessage != ""); if (GUI.Button(addBtnRect, addBtnGUI)) { //do it! Debug.Log("Created a New Modifier"); var newModifier = new SkeletonModifier(_chosenBoneNameToAdd, UMAUtils.StringToHash(_chosenBoneNameToAdd), (SkeletonModifier.SkeletonPropType)_chosenPropertyToAdd); (_target as SkeletonDNAConverterPlugin).AddModifier(newModifier); _chosenBoneNameToAdd = ""; serializedObject.Update(); CacheArrayElementsByIndex(true); } EditorGUI.EndDisabledGroup(); }
private bool Init() { if (!_initialized) { bool stylesSet = false; if (EditorStyles.helpBox == null || EditorStyles.foldout == null || EditorStyles.label == null) { //Dont set any styles } else { //Style for subHeaders _subHeaderStyle = new GUIStyle(EditorStyles.helpBox); _subHeaderStyle.margin = new RectOffset(_subHeaderStyle.margin.left, _subHeaderStyle.margin.right, _subHeaderStyle.margin.top, 0); //Style for Tips _foldoutTipStyle = new GUIStyle(EditorStyles.foldout); _foldoutTipStyle.fontStyle = FontStyle.Bold; //Help Icon & style _helpIcon = EditorGUIUtility.FindTexture("_Help"); _helpStyle = new GUIStyle(EditorStyles.label); _helpStyle.fixedHeight = _helpIcon.height + 4f; _helpStyle.contentOffset = new Vector2(-4f, 0f); //Styles for the Add Converter area var reorderableListDefaults = new ReorderableList.Defaults(); _pluginChooserAreaStyle = new GUIStyle(reorderableListDefaults.boxBackground); _pluginChooserAreaStyle.margin = new RectOffset(4, 4, 2, 2); _pluginChooserAreaStyle.stretchHeight = false; _pluginChooserAreaStyle.padding = new RectOffset(8, 8, 4, 8); _pluginsByDNAAreaStyle = new GUIStyle(EditorStyles.textField); _pluginsByDNAAreaStyle.margin = new RectOffset(0, 0, 0, 0); _pluginsByDNAAreaStyle.padding = new RectOffset(4, 4, 4, 4); stylesSet = true; } _initialized = stylesSet; _target = target as DynamicDNAConverterController; _dnaAsset = _target.DNAAsset; InitPlugins(); } return(_initialized); }
private void CreateReorderable(SerializedProperty property, GUIContent label) { var actionsProp = property.FindPropertyRelative("actions"); var defaults = new ReorderableList.Defaults(); reorderable = new ReorderableList(property.serializedObject, actionsProp, false, true, true, true); reorderable.draggable = true; reorderable.drawHeaderCallback = rect => EditorGUI.LabelField(rect, label); reorderable.drawElementCallback = (rect, index, active, focused) => { rect.y += 2; rect.height -= 2; SerializableAction_SingleDrawer.DrawSerializableAction( rect, actionsProp.GetArrayElementAtIndex(index) ); }; reorderable.elementHeightCallback = index => { var height = SerializableAction_SingleDrawer.FindSerializableActionHeight( actionsProp.GetArrayElementAtIndex(index), GUIContent.none) + 4f; cachedHeights[index] = height; return(height); }; reorderable.showDefaultBackground = true; reorderable.drawElementBackgroundCallback = (rect, index, active, focused) => { var rectHeight = EditorGUIUtility.singleLineHeight; float height; if (cachedHeights.TryGetValue(index, out height)) { rectHeight = height; } rect.height = rectHeight; defaults.DrawElementBackground(rect, index, active, focused, true); }; reorderable.onAddCallback = list => { defaults.DoAddButton(list); //If this is the first element, set the call state to the correct default. Otherwise do what the reorderable always does, which is //copy from the element above if (list.index == 0) { var addedObj = actionsProp.GetArrayElementAtIndex(list.index); addedObj.FindPropertyRelative("callState").enumValueIndex = (int)UnityEventCallState.RuntimeOnly; } }; }
private void DrawFooterCallback(Rect rect) { var Names = _dnaNameList.serializedProperty; var ROLDefaults = new ReorderableList.Defaults(); var padding = 4f; var _addBtnWidth = 100f + padding; var _labelWidth = 68f; Rect addRect = rect; addRect.xMin = addRect.xMax - 420 > addRect.xMin ? addRect.xMax - 420 : addRect.xMin; addRect.height = (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing * 2); var addBtnRect = new Rect(rect.xMax - (_addBtnWidth) - (padding * 2), addRect.yMin, ((_addBtnWidth / 5) * 2) - padding, EditorGUIUtility.singleLineHeight); var fieldRect = new Rect(addRect.xMin + (padding * 2), addRect.yMin, addRect.width - _addBtnWidth - (padding * 6), EditorGUIUtility.singleLineHeight); var labelRect = new Rect(fieldRect.xMin, fieldRect.yMin, _labelWidth, fieldRect.height); fieldRect.xMin = labelRect.xMax + (padding); var clearBtnRect = new Rect(addBtnRect.xMax + padding, addRect.yMin, ((_addBtnWidth / 5) * 3), EditorGUIUtility.singleLineHeight); if (Event.current.type == EventType.Repaint) { var prevFooterFixedHeight = ROLDefaults.footerBackground.fixedHeight; ROLDefaults.footerBackground.fixedHeight = addRect.height; ROLDefaults.footerBackground.Draw(addRect, false, false, false, false); ROLDefaults.footerBackground.fixedHeight = prevFooterFixedHeight; } EditorGUI.LabelField(labelRect, new GUIContent("Add Name:", "Add a DNA Name to the list")); newDNAName = EditorGUI.TextField(fieldRect, newDNAName); if (newDNAName != "") { canAddNewDNAName = true; for (int ni = 0; ni < Names.arraySize; ni++) { if (Names.GetArrayElementAtIndex(ni).stringValue == newDNAName) { canAddNewDNAName = false; } } } if (GUI.Button(addBtnRect, "Add")) { if (newDNAName == "") { return; } if (canAddNewDNAName) { Names.arraySize = Names.arraySize + 1; Names.GetArrayElementAtIndex(Names.arraySize - 1).stringValue = newDNAName; Names.serializedObject.ApplyModifiedProperties(); newDNAName = ""; EditorGUIUtility.keyboardControl = 0; } } EditorGUI.BeginDisabledGroup(Names.arraySize == 0); if (GUI.Button(clearBtnRect, new GUIContent("Clear All", "Clears all the names from the list. Cannot be undone"))) { if (EditorUtility.DisplayDialog("Really Clear All Names?", "This will delete all the names in the list and cannot be undone. Are you sure?", "Yes", "Cancel")) { Names.arraySize = 0; Names.serializedObject.ApplyModifiedProperties(); } } EditorGUI.EndDisabledGroup(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { Event current = Event.current; label = EditorGUI.BeginProperty(position, label, property); //Try and get a DNAAsset from the serializedObject- this is used for showing a popup in the dna field rather than a text field CheckDynamicDNAPlugin(property); Init(); if (!_alwaysExpanded) { var foldoutPos = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight); property.isExpanded = EditorGUI.Foldout(foldoutPos, property.isExpanded, label); } var reorderableListDefaults = new ReorderableList.Defaults(); if (property.isExpanded || _alwaysExpanded) { EditorGUI.indentLevel++; position = EditorGUI.IndentedRect(position); if (!_alwaysExpanded) { position.yMin = position.yMin + EditorGUIUtility.singleLineHeight; } else { position.yMin += 2f; } position.xMin -= 15f; //make it the same width as a reorderable list if (_drawLabels) { //can we draw this so it looks like the header of a reorderable List? if (current.type == EventType.Repaint) { reorderableListDefaults.headerBackground.Draw(position, GUIContent.none, false, false, false, false); } var rect1 = new Rect(position.xMin + 6f, position.yMin + 1f, position.width - 12f, position.height); if (_alwaysExpanded) { position = DoLabelsInline(rect1, label); } else { position = DoLabelsInline(rect1, DNANAMELABEL); } position.xMin -= 6f; position.width += 6f; position.yMin -= 1f; position.height -= 3f; } if (current.type == EventType.Repaint) { reorderableListDefaults.boxBackground.Draw(position, GUIContent.none, false, false, false, false); } var rect2 = new Rect(position.xMin + 6f, position.yMin + 3f, position.width - 12f, position.height); DoFieldsInline(rect2, property); EditorGUI.indentLevel--; } EditorGUI.EndProperty(); }
private void DrawHeader(Rect rect) { ReorderableList.Defaults defaultBehaviours = ReorderableList.defaultBehaviours; if (defaultBehaviours != null) { defaultBehaviours.DrawHeaderBackground(rect); } Rect position = rect; int num = 20; GUIStyle rL_ListButton = plyEdGUI.Styles.RL_ListButton; Rect position2 = rect; position2.x = position2.xMax; Vector2 vector; if (((this.extraButtons != null) ? this.extraButtons.Length : 0) != 0) { for (int i = 0; i < this.extraButtons.Length; i++) { vector = rL_ListButton.CalcSize(this.extraButtons[i].label); if (vector.x < (float)num) { vector.x = (float)num; } position2.x -= vector.x; position2.width = vector.x; position.width -= position2.width; GUI.enabled = (!this.extraButtons[i].requireSelected || this.orderList.index >= 0); if (GUI.Button(position2, this.extraButtons[i].label, rL_ListButton)) { Action callback = this.extraButtons[i].callback; if (callback != null) { callback(); } } GUI.enabled = true; } } if (this.displayRemoveButton) { vector = rL_ListButton.CalcSize(ReorderableGroupedData <GroupT, ItemT> .GC_Remove); if (vector.x < (float)num) { vector.x = (float)num; } position2.x -= vector.x; position2.width = vector.x; position.width -= position2.width; GUI.enabled = (this.orderList.index >= 0); if (GUI.Button(position2, ReorderableGroupedData <GroupT, ItemT> .GC_Remove, rL_ListButton)) { this.OnRemove((ReorderableList)null); } GUI.enabled = true; } if (this.displayAddButton) { vector = rL_ListButton.CalcSize(ReorderableGroupedData <GroupT, ItemT> .GC_Add); if (vector.x < (float)num) { vector.x = (float)num; } position2.x -= vector.x; position2.width = vector.x; position.width -= position2.width; if (GUI.Button(position2, ReorderableGroupedData <GroupT, ItemT> .GC_Add, rL_ListButton)) { this.OnAdd((ReorderableList)null); } } int currGroupIdx = this.currGroupIdx; this.currGroupIdx = EditorGUI.Popup(position, this.currGroupIdx, this.groupLabels, EditorStyles.toolbarPopup); if (this.currGroupIdx >= this.groupedData.groups.Count) { int num2 = this.currGroupIdx - this.groupedData.groups.Count; if (this.groupedData.groups.Count == 0) { num2++; } this.currGroupIdx = currGroupIdx; if (num2 == 1) { plyTextInputWiz.ShowWiz("Add Group", "Enter a unique name for this group", "", this.AddGroup, null, 250f); } if (num2 == 3) { plyTextInputWiz.ShowWiz("Rename Group", "Enter a unique name for this group", ((GroupedDataGroup <ItemT>)(object) this.groupedData.groups[this.currGroupIdx]).ident, this.RenameGroup, null, 250f); } if (num2 == 2 && EditorUtility.DisplayDialog("Grouped List", "Removing this group will also remove all entries of this group. This can't be undone. Are you sure?", "Yes", "Cancel")) { this.groupedData.groups.RemoveAt(this.currGroupIdx); Action obj = this.onGroupChanged; if (obj != null) { obj(); } this.currGroupIdx--; if (this.currGroupIdx < 0 && this.groupedData.groups.Count > 0) { this.currGroupIdx = 0; } this.currList = ((this.currGroupIdx < 0) ? this.fakeList : ((GroupedDataGroup <ItemT>)(object) this.groupedData.groups[this.currGroupIdx]).items); this.orderList.list = this.currList; this.RefreshGroupLabels(); } } else if (this.currGroupIdx != currGroupIdx) { this.currList = ((GroupedDataGroup <ItemT>)(object) this.groupedData.groups[this.currGroupIdx]).items; this.orderList.list = this.currList; this.orderList.index = -1; } }
//Draws a popup showing the available plugins for the project private void DrawAddConverterPopup(Rect position) { var ROLDefaults = new ReorderableList.Defaults(); var padding = 4f; _availablePlugins = DynamicDNAPlugin.GetAvailablePluginTypes(); Rect addRect = Rect.zero; if (position == Rect.zero) { GUILayout.BeginVertical(_pluginChooserAreaStyle); addRect = EditorGUILayout.GetControlRect(); } else { addRect = position; } addRect.xMin = addRect.xMax - 190 > addRect.xMin ? addRect.xMax - 190 : addRect.xMin; var labelRect = new Rect(addRect.xMin + (padding * 2), addRect.yMin, addRect.width - (padding * 2), 0); var addPopupRect = new Rect(addRect.xMin + (padding * 2), labelRect.yMax, addRect.width - _addPluginBtnWidth - (padding * 2), EditorGUIUtility.singleLineHeight); var addBtnRect = new Rect(addPopupRect.xMax + padding, labelRect.yMax, _addPluginBtnWidth - (padding * 3), EditorGUIUtility.singleLineHeight); if (Event.current.type == EventType.Repaint) { var prevFooterFixedHeight = ROLDefaults.footerBackground.fixedHeight; ROLDefaults.footerBackground.fixedHeight = addRect.height; ROLDefaults.footerBackground.Draw(addRect, false, false, false, false); ROLDefaults.footerBackground.fixedHeight = prevFooterFixedHeight; } var dropdownLabel = _pluginToAdd != null ? _pluginToAdd.Name : "Add Converters..."; if (EditorGUI.DropdownButton(addPopupRect, new GUIContent(dropdownLabel, "Add converters of the selected type to the " + _dnaConvertersLabel + " list"), FocusType.Keyboard)) { // create the menu and add items to it GenericMenu popupMenu = new GenericMenu(); //add the choose entry- clears the selection AddMenuItemForAddConvertersPopup(popupMenu, null); //add the actual entries for (int i = 0; i < _availablePlugins.Count; i++) { AddMenuItemForAddConvertersPopup(popupMenu, _availablePlugins[i]); } // display the menu popupMenu.DropDown(addPopupRect); } EditorGUI.BeginDisabledGroup(_pluginToAdd == null); if (GUI.Button(addBtnRect, new GUIContent("Add", (_pluginToAdd == null ? "Choose converters to add first" : "")))) { //do it! _target.AddPlugin(_pluginToAdd); //reset the choice _pluginToAdd = null; //reInit the plugins InitPlugins(); } EditorGUI.EndDisabledGroup(); if (position == Rect.zero) { GUILayout.EndVertical(); } }