public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { SerializedProperty prop_SpriteName = property.FindPropertyRelative("m_Name"); SerializedProperty prop_SpriteNameHashCode = property.FindPropertyRelative("m_HashCode"); SerializedProperty prop_SpriteUnicode = property.FindPropertyRelative("m_Unicode"); SerializedProperty prop_SpriteGlyphIndex = property.FindPropertyRelative("m_GlyphIndex"); SerializedProperty prop_SpriteScale = property.FindPropertyRelative("m_Scale"); GUIStyle style = new GUIStyle(EditorStyles.label); style.richText = true; EditorGUIUtility.labelWidth = 40f; EditorGUIUtility.fieldWidth = 50; Rect rect = new Rect(position.x + 60, position.y, position.width, 49); // Display non-editable fields if (GUI.enabled == false) { int spriteCharacterIndex; // Sprite Character Index int.TryParse(property.displayName.Split(' ')[1], out spriteCharacterIndex); EditorGUI.LabelField(new Rect(rect.x, rect.y, 75f, 18), new GUIContent("Index: <color=#FFFF80>" + spriteCharacterIndex + "</color>"), style); EditorGUI.LabelField(new Rect(rect.x + 75f, rect.y, 120f, 18), new GUIContent("Unicode: <color=#FFFF80>0x" + prop_SpriteUnicode.intValue.ToString("X") + "</color>"), style); EditorGUI.LabelField(new Rect(rect.x + 195f, rect.y, rect.width - 255, 18), new GUIContent("Name: <color=#FFFF80>" + prop_SpriteName.stringValue + "</color>"), style); EditorGUI.LabelField(new Rect(rect.x, rect.y + 18, 120, 18), new GUIContent("Glyph ID: <color=#FFFF80>" + prop_SpriteGlyphIndex.intValue + "</color>"), style); // Draw Sprite Glyph (if exists) DrawSpriteGlyph(position, property); EditorGUI.LabelField(new Rect(rect.x, rect.y + 36, 80, 18), new GUIContent("Scale: <color=#FFFF80>" + prop_SpriteScale.floatValue + "</color>"), style); } else // Display editable fields { // Get a reference to the underlying Sprite Asset TMP_SpriteAsset spriteAsset = property.serializedObject.targetObject as TMP_SpriteAsset; int spriteCharacterIndex; // Sprite Character Index int.TryParse(property.displayName.Split(' ')[1], out spriteCharacterIndex); EditorGUI.LabelField(new Rect(rect.x, rect.y, 75f, 18), new GUIContent("Index: <color=#FFFF80>" + spriteCharacterIndex + "</color>"), style); EditorGUIUtility.labelWidth = 55f; GUI.SetNextControlName("Unicode Input"); EditorGUI.BeginChangeCheck(); string unicode = EditorGUI.DelayedTextField(new Rect(rect.x + 75f, rect.y, 120, 18), "Unicode:", prop_SpriteUnicode.intValue.ToString("X")); if (GUI.GetNameOfFocusedControl() == "Unicode Input") { //Filter out unwanted characters. char chr = Event.current.character; if ((chr < '0' || chr > '9') && (chr < 'a' || chr > 'f') && (chr < 'A' || chr > 'F')) { Event.current.character = '\0'; } } if (EditorGUI.EndChangeCheck()) { // Update Unicode value prop_SpriteUnicode.intValue = TMP_TextUtilities.StringHexToInt(unicode); spriteAsset.m_IsSpriteAssetLookupTablesDirty = true; } EditorGUIUtility.labelWidth = 41f; EditorGUI.BeginChangeCheck(); EditorGUI.DelayedTextField(new Rect(rect.x + 195f, rect.y, rect.width - 255, 18), prop_SpriteName, new GUIContent("Name:")); if (EditorGUI.EndChangeCheck()) { // Recompute hashCode for new name prop_SpriteNameHashCode.intValue = TMP_TextUtilities.GetSimpleHashCode(prop_SpriteName.stringValue); spriteAsset.m_IsSpriteAssetLookupTablesDirty = true; } EditorGUIUtility.labelWidth = 59f; EditorGUI.BeginChangeCheck(); EditorGUI.DelayedIntField(new Rect(rect.x, rect.y + 18, 100, 18), prop_SpriteGlyphIndex, new GUIContent("Glyph ID:")); if (EditorGUI.EndChangeCheck()) { spriteAsset.m_IsSpriteAssetLookupTablesDirty = true; } // Draw Sprite Glyph (if exists) DrawSpriteGlyph(position, property); int glyphIndex = prop_SpriteGlyphIndex.intValue; // Reset glyph selection if new character has been selected. if (GUI.enabled && m_GlyphSelectedForEditing != glyphIndex) { m_GlyphSelectedForEditing = -1; } // Display button to edit the glyph data. if (GUI.Button(new Rect(rect.x + 120, rect.y + 18, 75, 18), new GUIContent("Edit Glyph"))) { if (m_GlyphSelectedForEditing == -1) { m_GlyphSelectedForEditing = glyphIndex; } else { m_GlyphSelectedForEditing = -1; } // Button clicks should not result in potential change. GUI.changed = false; } // Show the glyph property drawer if selected if (glyphIndex == m_GlyphSelectedForEditing && GUI.enabled) { if (spriteAsset != null) { // Lookup glyph and draw glyph (if available) int elementIndex = spriteAsset.spriteGlyphTable.FindIndex(item => item.index == glyphIndex); if (elementIndex != -1) { // Get a reference to the Sprite Glyph Table SerializedProperty prop_SpriteGlyphTable = property.serializedObject.FindProperty("m_SpriteGlyphTable"); SerializedProperty prop_SpriteGlyph = prop_SpriteGlyphTable.GetArrayElementAtIndex(elementIndex); SerializedProperty prop_GlyphMetrics = prop_SpriteGlyph.FindPropertyRelative("m_Metrics"); SerializedProperty prop_GlyphRect = prop_SpriteGlyph.FindPropertyRelative("m_GlyphRect"); Rect newRect = EditorGUILayout.GetControlRect(false, 115); EditorGUI.DrawRect(new Rect(newRect.x + 62, newRect.y - 20, newRect.width - 62, newRect.height - 5), new Color(0.1f, 0.1f, 0.1f, 0.45f)); EditorGUI.DrawRect(new Rect(newRect.x + 63, newRect.y - 19, newRect.width - 64, newRect.height - 7), new Color(0.3f, 0.3f, 0.3f, 0.8f)); // Display GlyphRect newRect.x += 65; newRect.y -= 18; newRect.width += 5; EditorGUI.PropertyField(newRect, prop_GlyphRect); // Display GlyphMetrics newRect.y += 45; EditorGUI.PropertyField(newRect, prop_GlyphMetrics); rect.y += 120; } } } EditorGUIUtility.labelWidth = 39f; EditorGUI.PropertyField(new Rect(rect.x, rect.y + 36, 80, 18), prop_SpriteScale, new GUIContent("Scale:")); } }
void CellGUI(Rect cellRect, TreeViewItem <VariablesElement> item, MyColumns column, ref RowGUIArgs args) { // Center cell rect vertically (makes it easier to place controls, icons etc in the cells) CenterRectUsingSingleLineHeight(ref cellRect); switch (column) { case MyColumns.Id: { if (editing) { EditorGUI.BeginChangeCheck(); _variableID = EditorGUI.DelayedTextField(cellRect, item.data.variable.name).Trim().Replace(" ", "").Replace("_", ""); if (EditorGUI.EndChangeCheck()) { AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(item.data.variable), _variableID); } } else { DefaultGUI.Label(cellRect, item.data.variable.name, args.selected, args.focused); } } break; case MyColumns.Group: { if (editing) { EditorGUI.BeginChangeCheck(); _variableGroup = EditorGUI.DelayedTextField(cellRect, item.data.variable.group).Trim().Replace(" ", "").Replace("_", ""); if (EditorGUI.EndChangeCheck()) { item.data.variable.group = _variableGroup; } } else { DefaultGUI.Label(cellRect, item.data.variable.group, args.selected, args.focused); } } break; case MyColumns.Type: if (editing) { EditorGUI.BeginChangeCheck(); _variableType = (Variable.VariableType)EditorGUI.EnumPopup(cellRect, item.data.variable.Type); if (EditorGUI.EndChangeCheck()) { item.data.variable.Type = _variableType; EditorUtility.SetDirty(item.data.variable); } } else { DefaultGUI.Label(cellRect, item.data.variable.Type.ToString(), args.selected, args.focused); } break; case MyColumns.Default: { if (editing) { EditorGUI.BeginChangeCheck(); _serializedVariable = VariableEditor.DrawSerializedVariable(cellRect, item.data.variable.Type, item.data.variable.DefaultValue); if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(item.data.variable); } } else { DefaultGUI.Label(cellRect, item.data.variable.DefaultValue.ToString(), args.selected, args.focused); } } break; case MyColumns.InGame: { if (editing) { EditorGUI.BeginChangeCheck(); _serializedVariable = VariableEditor.DrawSerializedVariable(cellRect, item.data.variable.Type, item.data.variable.InGameValue); if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(item.data.variable); } } else { DefaultGUI.Label(cellRect, item.data.variable.InGameValue.ToString(), args.selected, args.focused); } } break; case MyColumns.Description: { if (editing) { EditorGUI.BeginChangeCheck(); _description = EditorGUI.DelayedTextField(cellRect, item.data.variable.description); if (EditorGUI.EndChangeCheck()) { item.data.variable.description = _description; } } else { DefaultGUI.Label(cellRect, item.data.variable.description, args.selected, args.focused); } } break; } }
public override bool OnGUI() { if (!base.OnGUI()) { return(true); } if (window == null) { Init(); } int startX = 0; int startY = 0; if (!DamageTable_DB.UpdatedToPost_2018_3()) { GUI.color = new Color(0, 1f, 1f, 1f); if (GUI.Button(new Rect(window.position.width - 110, 10, 100, 30), "Copy Old DB")) { DamageTable_DB.CopyFromOldDB(); } GUI.color = Color.white; } if (GUI.Button(new Rect(10, 10, 100, 30), "New Armor")) { ArmorType armorType = new ArmorType(); armorType.name = "New Armor"; damageTableDB.armorTypeList.Add(armorType); UpdateLabel_DamageTable(); } if (GUI.Button(new Rect(120, 10, 100, 30), "New Damage")) { DamageType damageType = new DamageType(); damageType.name = "New Damage"; damageTableDB.damageTypeList.Add(damageType); UpdateLabel_DamageTable(); } List <DamageType> damageTypeList = damageTableDB.damageTypeList; List <ArmorType> armorTypeList = damageTableDB.armorTypeList; Rect visibleRect = new Rect(10, 50, window.position.width - 20, 185); Rect contentRect = new Rect(10, 50, 118 + damageTypeList.Count * 105, 5 + (armorTypeList.Count + 1) * 25); GUI.Box(visibleRect, ""); scrollPos = GUI.BeginScrollView(visibleRect, scrollPos, contentRect); startY = 60; startX = 20; for (int i = 0; i < damageTypeList.Count; i++) { DamageType dmgType = damageTypeList[i]; if (selectID == i && tab == _Tab.Damage) { GUI.color = new Color(0, 1, 1, 1); } if (GUI.Button(new Rect(startX += 105, startY, 100, 20), dmgType.name)) { selectID = i; tab = _Tab.Damage; delete = false; GUI.FocusControl(""); } GUI.color = Color.white; } startY = 60; for (int i = 0; i < armorTypeList.Count; i++) { startX = 20; ArmorType armorType = armorTypeList[i]; if (selectID == i && tab == _Tab.Armor) { GUI.color = new Color(0, 1, 1, 1); } if (GUI.Button(new Rect(startX, startY += 25, 100, 20), armorType.name)) { selectID = i; tab = _Tab.Armor; delete = false; GUI.FocusControl(""); } GUI.color = Color.white; if (armorType.modifiers.Count != damageTypeList.Count) { while (armorType.modifiers.Count < damageTypeList.Count) { armorType.modifiers.Add(1); } while (armorType.modifiers.Count > damageTypeList.Count) { armorType.modifiers.RemoveAt(armorType.modifiers.Count - 1); } SetDirtyTDS(); } startX += 110; for (int j = 0; j < damageTypeList.Count; j++) { armorType.modifiers[j] = EditorGUI.FloatField(new Rect(startX, startY, 90, 20), armorType.modifiers[j]); startX += 105; } } GUI.EndScrollView(); startX = 10; startY = 250; if (selectID >= 0) { DAType daInstance = null; if (tab == _Tab.Damage) { selectID = Mathf.Min(selectID, damageTypeList.Count - 1); if (selectID <= -1) { return(true); } daInstance = damageTypeList[selectID]; } if (tab == _Tab.Armor) { selectID = Mathf.Min(selectID, armorTypeList.Count - 1); if (selectID <= -1) { return(true); } daInstance = armorTypeList[selectID]; } GUI.Label(new Rect(startX, startY, 200, 17), "Name:"); daInstance.name = EditorGUI.DelayedTextField(new Rect(startX + 80, startY, 150, 17), daInstance.name); GUIStyle styleL = new GUIStyle(GUI.skin.textArea); styleL.wordWrap = true; styleL.clipping = TextClipping.Clip; styleL.alignment = TextAnchor.UpperLeft; EditorGUI.LabelField(new Rect(startX, startY += 25, 150, 17), "Description: "); daInstance.desp = EditorGUI.DelayedTextField(new Rect(startX, startY += 17, window.position.width - 20, 50), daInstance.desp, styleL); string label = ""; if (tab == _Tab.Damage) { for (int i = 0; i < armorTypeList.Count; i++) { label += " - cause " + (armorTypeList[i].modifiers[selectID] * 100).ToString("f0") + "% damage to " + armorTypeList[i].name + "\n"; } } if (tab == _Tab.Armor) { for (int i = 0; i < damageTypeList.Count; i++) { label += " - take " + (armorTypeList[selectID].modifiers[i] * 100).ToString("f0") + "% damage from " + damageTypeList[i].name + "\n"; } } GUI.Label(new Rect(startX, startY += 60, window.position.width - 20, 100), label); startX = 300; startY = 250; if (!delete) { if (GUI.Button(new Rect(startX, startY, 80, 20), "delete")) { delete = true; } } else if (delete) { if (GUI.Button(new Rect(startX, startY, 80, 20), "cancel")) { delete = false; } GUI.color = Color.red; if (GUI.Button(new Rect(startX += 90, startY, 80, 20), "confirm")) { if (tab == _Tab.Damage) { //damageTableDB.RemoveDamageType(selectID); damageTypeList.RemoveAt(selectID); } if (tab == _Tab.Armor) { //damageTableDB.RemoveArmorType(selectID); armorTypeList.RemoveAt(selectID); } UpdateLabel_DamageTable(); selectID = -1; } GUI.color = Color.white; } } if (GUI.changed) { SetDirtyTDS(); } return(true); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); SerializedProperty localisationkeyProperty = property.FindPropertyRelative("_localisationKey"); SerializedProperty editorTextProperty = property.FindPropertyRelative("_editorText"); SerializedProperty editorFoldoutProp = property.FindPropertyRelative("_editorFoldout"); SerializedProperty editorHeightProp = property.FindPropertyRelative("_editorHeight"); Rect foldoutPosition = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight); editorFoldoutProp.boolValue = EditorGUI.Foldout(foldoutPosition, editorFoldoutProp.boolValue, property.displayName + " (Localised String)"); editorHeightProp.floatValue = EditorGUIUtility.singleLineHeight; if (editorFoldoutProp.boolValue) { int origIndent = EditorGUI.indentLevel; EditorGUI.indentLevel++; //Draw list of possible keys int currentKey = 0; { string[] keys = Localisation.GetStringKeys(); for (int i = 0; i < keys.Length; i++) { if (keys[i] == localisationkeyProperty.stringValue) { currentKey = i; break; } } Rect typePosition = new Rect(position.x, position.y + editorHeightProp.floatValue, position.width, EditorGUIUtility.singleLineHeight); EditorGUI.BeginChangeCheck(); currentKey = EditorGUI.Popup(typePosition, "Localisation Key", currentKey, keys); editorHeightProp.floatValue += EditorGUIUtility.singleLineHeight; if (EditorGUI.EndChangeCheck()) { if (currentKey == 0) { localisationkeyProperty.stringValue = null; editorTextProperty.stringValue = ""; } else { localisationkeyProperty.stringValue = keys[currentKey]; editorTextProperty.stringValue = Localisation.GetString(localisationkeyProperty.stringValue); } } } //Draw button for adding new key if (currentKey == 0) { float buttonWidth = 48.0f; Rect addKeyText = new Rect(position.x, position.y + editorHeightProp.floatValue, position.width - buttonWidth, EditorGUIUtility.singleLineHeight); localisationkeyProperty.stringValue = EditorGUI.DelayedTextField(addKeyText, "New Key", localisationkeyProperty.stringValue); Rect addKeyButton = new Rect(position.x + (position.width - buttonWidth), position.y + editorHeightProp.floatValue, buttonWidth, EditorGUIUtility.singleLineHeight); editorHeightProp.floatValue += EditorGUIUtility.singleLineHeight; if (GUI.Button(addKeyButton, "Add") && !string.IsNullOrEmpty(localisationkeyProperty.stringValue)) { //Add new string for new key Localisation.UpdateString(localisationkeyProperty.stringValue, Localisation.GetCurrentLanguage(), editorTextProperty.stringValue); string[] keys = Localisation.GetStringKeys(); for (int i = 0; i < keys.Length; i++) { if (keys[i] == localisationkeyProperty.stringValue) { currentKey = i; break; } } } } //Draw displayed text (can be edited to update localisation file) { int numLines = StringUtils.GetNumberOfLines(editorTextProperty.stringValue); float height = (EditorGUIUtility.singleLineHeight - 2.0f) * numLines + 4.0f; Rect textPosition = new Rect(position.x, position.y + editorHeightProp.floatValue, position.width, height); editorHeightProp.floatValue += height; EditorGUI.BeginChangeCheck(); editorTextProperty.stringValue = EditorGUI.TextArea(textPosition, editorTextProperty.stringValue); if (EditorGUI.EndChangeCheck() && currentKey != 0) { Localisation.UpdateString(localisationkeyProperty.stringValue, Localisation.GetCurrentLanguage(), editorTextProperty.stringValue); } } EditorGUI.indentLevel = origIndent; } EditorGUI.EndProperty(); }
void AddCallbacks() { if (!(shaderInput is ShaderKeyword keyword)) { return; } // Draw Header m_ReorderableList.drawHeaderCallback = (Rect rect) => { int indent = 14; var displayRect = new Rect(rect.x + indent, rect.y, (rect.width - indent) / 2, rect.height); EditorGUI.LabelField(displayRect, "Display Name"); var referenceRect = new Rect((rect.x + indent) + (rect.width - indent) / 2, rect.y, (rect.width - indent) / 2, rect.height); EditorGUI.LabelField(referenceRect, "Reference Suffix"); }; // Draw Element m_ReorderableList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { KeywordEntry entry = ((KeywordEntry)m_ReorderableList.list[index]); EditorGUI.BeginChangeCheck(); var displayName = EditorGUI.DelayedTextField(new Rect(rect.x, rect.y, rect.width / 2, EditorGUIUtility.singleLineHeight), entry.displayName, EditorStyles.label); var referenceName = EditorGUI.DelayedTextField(new Rect(rect.x + rect.width / 2, rect.y, rect.width / 2, EditorGUIUtility.singleLineHeight), entry.referenceName, EditorStyles.label); displayName = GetDuplicateSafeDisplayName(entry.id, displayName); referenceName = GetDuplicateSafeReferenceName(entry.id, referenceName.ToUpper()); if (EditorGUI.EndChangeCheck()) { keyword.entries[index] = new KeywordEntry(index + 1, displayName, referenceName); // Rebuild(); this._postChangeValueCallback(true); } }; // Element height m_ReorderableList.elementHeightCallback = (int indexer) => { return(m_ReorderableList.elementHeight); }; // Can add m_ReorderableList.onCanAddCallback = (ReorderableList list) => { return(list.count < 8); }; // Can remove m_ReorderableList.onCanRemoveCallback = (ReorderableList list) => { return(list.count > 2); }; // Add callback delegates m_ReorderableList.onSelectCallback += SelectEntry; m_ReorderableList.onAddCallback += AddEntry; m_ReorderableList.onRemoveCallback += RemoveEntry; m_ReorderableList.onReorderCallback += ReorderEntries; }
/* * GUI */ override public void OnInspectorGUI() { var singleHeight = EditorGUIUtility.singleLineHeight; var unitHeight = singleHeight * 5 + 5f; var controlRect = EditorGUILayout.GetControlRect(false, unitHeight * assets.Length); controlRect.height = unitHeight; var labelWidth = 100f; var otherWidth = controlRect.width - labelWidth; var noGUIContent = GUIContent.none; var fileMoved = false; for (int i = 0; i < assets.Length; i++) { serializedObjects[i].Update(); var fileNameLabelTotalRect = new Rect(controlRect.x, controlRect.y, labelWidth + otherWidth, singleHeight); var fileNameLabelRect = new Rect(controlRect.x, controlRect.y, labelWidth, singleHeight); var descriptionLabelTotalRect = new Rect(controlRect.x, controlRect.y + singleHeight, labelWidth + otherWidth, singleHeight); var descriptionLabelRect = new Rect(controlRect.x, controlRect.y + singleHeight, labelWidth, singleHeight); var fileNameRect = new Rect(controlRect.x + labelWidth, controlRect.y, otherWidth, singleHeight); var descriptionRect = new Rect(controlRect.x + labelWidth, controlRect.y + singleHeight, otherWidth, 4 * singleHeight); var selectRect = new Rect(controlRect.x, controlRect.y + unitHeight - singleHeight - 8, labelWidth, singleHeight + 2); EditorGUI.HandlePrefixLabel(fileNameLabelTotalRect, fileNameLabelRect, fileNameGUIContent); EditorGUI.BeginChangeCheck(); var newFileName = EditorGUI.DelayedTextField(fileNameRect, noGUIContent, fileNameProps[i].stringValue); if (EditorGUI.EndChangeCheck()) { fileNameProps[i].stringValue = newFileName; AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(assets[i]), newFileName); fileMoved = true; } EditorGUI.HandlePrefixLabel(descriptionLabelTotalRect, descriptionLabelRect, descriptionGUIContent); EditorGUI.PropertyField(descriptionRect, descriptionProps[i], noGUIContent); if (GUI.Button(selectRect, "Ping")) { EditorGUIUtility.PingObject(serializedObjects[i].targetObject); } serializedObjects[i].ApplyModifiedProperties(); controlRect.y += unitHeight; } if (GUILayout.Button("Add")) { var newInstance = ScriptableObject.CreateInstance <MyAsset>(); var standardPath = Path.Combine(AssetDatabase.GetAssetPath(target), "MyAsset 1.asset"); var newPath = AssetDatabase.GenerateUniqueAssetPath(standardPath); AssetDatabase.CreateAsset(newInstance, newPath); Read(); } else if (fileMoved) { Read(); } }
private void AddCallbacks() { m_ReorderableList.drawHeaderCallback = (Rect rect) => { var labelRect = new Rect(rect.x, rect.y, rect.width - 10, rect.height); EditorGUI.LabelField(labelRect, label); }; // Draw Element m_ReorderableList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { rect.y += 2; // Slot is guaranteed to exist in this UI state MaterialSlot oldSlot = m_Node.FindSlot <MaterialSlot>((int)m_ReorderableList.list[index]); EditorGUI.BeginChangeCheck(); var displayName = EditorGUI.DelayedTextField(new Rect(rect.x, rect.y, labelWidth, EditorGUIUtility.singleLineHeight), oldSlot.RawDisplayName(), labelStyle); var shaderOutputName = NodeUtils.GetHLSLSafeName(displayName); var concreteValueType = (ConcreteSlotValueType)EditorGUI.IntPopup(new Rect(rect.x + labelWidth, rect.y, rect.width - labelWidth, EditorGUIUtility.singleLineHeight), (int)oldSlot.concreteValueType, m_ValueTypeNames, m_ValueTypeIndices); if (displayName != oldSlot.RawDisplayName()) { displayName = NodeUtils.GetDuplicateSafeNameForSlot(m_Node, oldSlot.id, displayName); } if (EditorGUI.EndChangeCheck()) { // Cant modify existing slots so need to create new and copy values var newSlot = MaterialSlot.CreateMaterialSlot(concreteValueType.ToSlotValueType(), oldSlot.id, displayName, shaderOutputName, m_SlotType, Vector4.zero); newSlot.CopyValuesFrom(oldSlot); m_Node.AddSlot(newSlot); // Need to get all current slots as everything after the edited slot in the list must be added again List <MaterialSlot> slots = new List <MaterialSlot>(); if (m_SlotType == SlotType.Input) { m_Node.GetInputSlots <MaterialSlot>(slots); } else { m_Node.GetOutputSlots <MaterialSlot>(slots); } // Iterate all the slots foreach (MaterialSlot slot in slots) { // Because the list doesnt match the slot IDs (reordering) // Need to get the index in the list of every slot int listIndex = 0; for (int i = 0; i < m_ReorderableList.list.Count; i++) { if ((int)m_ReorderableList.list[i] == slot.id) { listIndex = i; } } // Then for everything after the edited slot if (listIndex <= index) { continue; } // Remove and re-add m_Node.AddSlot(slot); } RecreateList(); m_Node.ValidateNode(); } }; // Element height m_ReorderableList.elementHeightCallback = (int indexer) => { return(m_ReorderableList.elementHeight); }; // Add callback delegates m_ReorderableList.onSelectCallback += SelectEntry; m_ReorderableList.onAddCallback += AddEntry; m_ReorderableList.onRemoveCallback += RemoveEntry; m_ReorderableList.onReorderCallback += ReorderEntries; }
private void _drawValue(ref Rect rect, ValueS valueS) { rect.size = new Vector2(rect.width - (70 + 30 + 10 + 30) // subtract EditValue and Refresh and Remove Button , rect.height); //todo draw Value if (valueS.IsUnity) { var offset = new Vector2(15, 0); rect.position -= offset; //subtract offset rect.size += new Vector2(70, 0); // no Edit Value Button Object obj; EditorGUI.BeginChangeCheck(); { obj = EditorGUI.ObjectField(rect, valueS.UValue, valueS.ValueType, false); } if (EditorGUI.EndChangeCheck()) { valueS.SetValue(obj); Save(); } } else { //todo non Unity Type var value = valueS.GetValue(); if (value == null) { valueS.SetValue(Activator.CreateInstance(valueS.ValueType)); Save(); } _drawNonUnityValue <int>(ref rect, valueS, (pos, x) => EditorGUI.DelayedIntField(pos, (int)x.GetValue())); _drawNonUnityValue <float>(ref rect, valueS, (pos, x) => EditorGUI.DelayedFloatField(pos, (float)x.GetValue())); _drawNonUnityValue <double>(ref rect, valueS, (pos, x) => EditorGUI.DelayedDoubleField(pos, (double)x.GetValue())); _drawNonUnityValue <long>(ref rect, valueS, (pos, x) => EditorGUI.LongField(pos, (long)x.GetValue())); _drawNonUnityValue <string>(ref rect, valueS, (pos, x) => EditorGUI.DelayedTextField(pos, (string)x.GetValue())); _drawNonUnityValue <Vector2>(ref rect, valueS, (pos, x) => EditorGUI.Vector2Field(pos, "", (Vector2)x.GetValue())); _drawNonUnityValue <Vector2Int>(ref rect, valueS, (pos, x) => EditorGUI.Vector2IntField(pos, "", (Vector2Int)x.GetValue())); _drawNonUnityValue <Vector3>(ref rect, valueS, (pos, x) => EditorGUI.Vector3Field(pos, "", (Vector3)x.GetValue())); _drawNonUnityValue <Vector3Int>(ref rect, valueS, (pos, x) => EditorGUI.Vector3IntField(pos, "", (Vector3Int)x.GetValue())); _drawNonUnityValue <Vector4>(ref rect, valueS, (pos, x) => EditorGUI.Vector4Field(pos, "", (Vector4)x.GetValue())); _drawNonUnityValue <Color>(ref rect, valueS, (pos, x) => EditorGUI.ColorField(pos, (Color)x.GetValue())); _drawNonUnityValue <AnimationCurve>(ref rect, valueS, (pos, x) => EditorGUI.CurveField(pos, (AnimationCurve)x.GetValue())); _drawNonUnityValue <Bounds>(ref rect, valueS, (pos, x) => EditorGUI.BoundsField(pos, (Bounds)x.GetValue())); _drawNonUnityValue <BoundsInt>(ref rect, valueS, (pos, x) => EditorGUI.BoundsIntField(pos, (BoundsInt)x.GetValue())); _drawNonUnityValue <Rect>(ref rect, valueS, (pos, x) => EditorGUI.RectField(pos, (Rect)x.GetValue())); _drawNonUnityValue <RectInt>(ref rect, valueS, (pos, x) => EditorGUI.RectIntField(pos, (RectInt)x.GetValue())); _drawNonUnityValue <Enum>(ref rect, valueS, (pos, x) => EditorGUI.EnumFlagsField(pos, (Enum)x.GetValue())); _drawNonUnityValue <Gradient>(ref rect, valueS, (pos, x) => EditorGUI.GradientField(pos, (Gradient)x.GetValue())); rect.size = new Vector2(70, 26); if (GUI.Button(rect, "Edit Value")) { _valueEditPopup.ValueS = valueS; var pos = rect; PopupWindow.Show(pos, _valueEditPopup); } } rect.position += new Vector2(rect.size.x + 10, 0); }
protected override float DrawItem(Rect rect, SerializationDict <string, ValueS> map, KeyValuePair <string, ValueS> item) { if (_valueEditPopup == null || _simpleTypeSelectPopup == null) { _valueEditPopup = new ValueEditPopupWindow(); _simpleTypeSelectPopup = new SimpleTypeSelectPopupWindow(true); } var keyRect = rect; keyRect.size = new Vector2(Position.width / 4, ItemHeight()); var valueRect = keyRect; valueRect.position += new Vector2(keyRect.size.x + 10, 0); valueRect.size = rect.size - keyRect.size; valueRect.size += new Vector2(0, keyRect.height); { string newKey; var key = item.Key; var value = item.Value; if (value == null) { value = new ValueS(); map[key] = value; } EditorGUI.BeginChangeCheck(); { newKey = EditorGUI.DelayedTextField(keyRect, key); } if (EditorGUI.EndChangeCheck()) { if (!string.IsNullOrEmpty(newKey)) { map.Remove(key); map.Add(newKey, item.Value); Save(); } } if (value.ValueType == null) { _drawValueTypeSelect(ref valueRect, value); } else { _drawValue(ref valueRect, value); } var buttonRect = valueRect; buttonRect.size = new Vector2(26, 26); if (value.ValueType != null) { if (GUI.Button(buttonRect, new GUIContent(EditorGUIUtility.FindTexture("Refresh"), $"Change Type,Current Type '{value.ValueType.FullName}'"))) { value.ValueType = null; value.SetValue(null); Save(); return(0); } buttonRect.position += new Vector2(30, 0); } buttonRect.position = new Vector2(rect.width - 10, buttonRect.position.y); if (GUI.Button(buttonRect, new GUIContent(EditorGUIUtility.FindTexture("d_P4_DeletedLocal"), "Remove Item"))) { map.Remove(key); Save(); } } return(0); }
public ScenesWindowActiveAreas(Rect aStartPos, GUIContent aContent, GUIStyle aStyle, SceneEditor sceneEditor, params GUILayoutOption[] aOptions) : base(aStartPos, aContent, aStyle, sceneEditor, aOptions) { new ActiveAreaActionsComponent(Rect.zero, new GUIContent(""), aStyle); new ActiveAreaDescriptionsComponent(Rect.zero, new GUIContent(""), aStyle); PreviewTitle = "Scene.Preview".Traslate(); conditionsTex = Resources.Load <Texture2D>("EAdventureData/img/icons/conditions-24x24"); noConditionsTex = Resources.Load <Texture2D>("EAdventureData/img/icons/no-conditions-24x24"); activeAreasList = new DataControlList() { RequestRepaint = Repaint, elementHeight = 20, Columns = new List <ColumnList.Column>() { new ColumnList.Column() // Layer column { Text = TC.get("ElementList.Layer"), SizeOptions = new GUILayoutOption[] { GUILayout.Width(50) } }, new ColumnList.Column() // Element name { Text = TC.get("ElementList.Title"), SizeOptions = new GUILayoutOption[] { GUILayout.ExpandWidth(true) } }, new ColumnList.Column() // Enabled Column { Text = TC.get("Conditions.Title"), SizeOptions = new GUILayoutOption[] { GUILayout.ExpandWidth(true) } } }, drawCell = (columnRect, row, column, isActive, isFocused) => { var element = activeAreasList.list[row] as ActiveAreaDataControl; switch (column) { case 0: GUI.Label(columnRect, row.ToString()); break; case 1: if (isActive) { EditorGUI.BeginChangeCheck(); var newId = EditorGUI.DelayedTextField(columnRect, element.getId()); if (EditorGUI.EndChangeCheck()) { element.renameElement(newId); } } else { GUI.Label(columnRect, element.getId()); } break; case 2: if (GUI.Button(columnRect, element.getConditions().getBlocksCount() > 0 ? conditionsTex : noConditionsTex)) { ConditionEditorWindow window = (ConditionEditorWindow)ScriptableObject.CreateInstance(typeof(ConditionEditorWindow)); window.Init(element.getConditions()); } break; } }, onSelectCallback = (list) => { sceneEditor.SelectedElement = activeAreasList.list[list.index] as ExitDataControl; }, onRemoveCallback = (list) => { sceneEditor.SelectedElement = null; } }; sceneEditor.onSelectElement += (element) => { if (element is ActiveAreaDataControl) { activeAreasList.index = activeAreasList.list.IndexOf(element as ActiveAreaDataControl); } else { activeAreasList.index = -1; } }; }
private static eString DelayedTextFieldMaster(Rect rect, GUICon guiCon, string value, GUIStyle style) => new eString { Event = new Event(Event.current), Rect = rect, Value = EditorGUI.DelayedTextField(rect, guiCon, value, style) };
private void OnValidate() { m_RenderPasses = serializedObject.FindProperty("m_RendererFeatures"); CreateFoldoutBools(); m_PassesList = new ReorderableList(m_RenderPasses.serializedObject, m_RenderPasses, true, true, true, true); m_PassesList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { EditorGUI.BeginChangeCheck(); var element = m_PassesList.serializedProperty.GetArrayElementAtIndex(index); var propRect = new Rect(rect.x, rect.y + EditorGUIUtility.standardVerticalSpacing, rect.width, EditorGUIUtility.singleLineHeight); var headerRect = new Rect(rect.x + EditorUtils.Styles.defaultIndentWidth, rect.y + EditorGUIUtility.standardVerticalSpacing, rect.width - EditorUtils.Styles.defaultIndentWidth, EditorGUIUtility.singleLineHeight); if (element.objectReferenceValue != null) { Styles.RenderFeatureHeader.text = element.objectReferenceValue.name; Styles.RenderFeatureHeader.tooltip = element.objectReferenceValue.GetType().Name; m_Foldouts[index].value = EditorGUI.Foldout(headerRect, m_Foldouts[index].value, Styles.RenderFeatureHeader, true); if (m_Foldouts[index].value) { propRect.y += EditorUtils.Styles.defaultLineSpace; EditorGUI.BeginChangeCheck(); element.objectReferenceValue.name = EditorGUI.DelayedTextField(propRect, "Pass Name", element.objectReferenceValue.name); if (EditorGUI.EndChangeCheck()) { AssetDatabase.SaveAssets(); } var elementSO = GetElementSO(index); SerializedProperty settings = elementSO.FindProperty("settings"); EditorGUI.BeginChangeCheck(); if (settings != null) { propRect.y += EditorUtils.Styles.defaultLineSpace; EditorGUI.PropertyField(propRect, settings, true); } if (EditorGUI.EndChangeCheck()) { elementSO.ApplyModifiedProperties(); } } } else { EditorGUI.ObjectField(propRect, element, GUIContent.none); } if (EditorGUI.EndChangeCheck()) { element.serializedObject.ApplyModifiedProperties(); } }; m_PassesList.elementHeightCallback = (index) => { var height = EditorUtils.Styles.defaultLineSpace + (EditorGUIUtility.standardVerticalSpacing * 2); var element = m_PassesList.serializedProperty.GetArrayElementAtIndex(index); if (element.objectReferenceValue == null) { return(height); } if (m_Foldouts[index].value) { height += EditorUtils.Styles.defaultLineSpace; var serializedObject = GetElementSO(index); var settingsProp = serializedObject.FindProperty("settings"); if (settingsProp != null) { return(height + EditorGUI.GetPropertyHeight(settingsProp) + EditorGUIUtility.standardVerticalSpacing); } } return(height); }; m_PassesList.onAddCallback += AddPass; m_PassesList.onRemoveCallback = RemovePass; m_PassesList.onReorderCallbackWithDetails += ReorderPass; m_PassesList.drawHeaderCallback = (Rect testHeaderRect) => { EditorGUI.LabelField(testHeaderRect, Styles.RenderFeatures); }; }
public static void DrawEditableList(SerializedProperty listSP, bool lockZero, string labelPrefix = null, float labelwidth = -1, int maxCount = 32, bool forceUnique = true, GUIStyle guiStyle = null) { const int PAD = 12; const float BTTN_WIDTH = 20; if (guiStyle == null) { if (listBoxStyle == null) { listBoxStyle = new GUIStyle("HelpBox") { margin = new RectOffset(0, 0, 0, 0), padding = new RectOffset(PAD, PAD, PAD, PAD) } } ; guiStyle = listBoxStyle; } if (labelwidth < 0) { labelwidth = 64; } EditorGUILayout.BeginVertical(guiStyle); EditorGUI.BeginChangeCheck(); int cnt = listSP.arraySize; int delete = -1; int add = -1; for (int i = 0; i < cnt; i++) { EditorGUILayout.BeginHorizontal(GUILayout.Height(18)); // Add [+] button var addbtnrect = EditorGUILayout.GetControlRect(GUILayout.MaxWidth(BTTN_WIDTH)); if (lockZero && i != 0) { EditorGUI.BeginDisabledGroup(cnt >= maxCount); if (GUI.Button(addbtnrect, "+", (GUIStyle)"minibutton")) { add = i; } EditorGUI.EndDisabledGroup(); } // Label EditorGUI.BeginDisabledGroup(lockZero && i == 0); string label = labelPrefix == null ? "[" + i + "]" : labelPrefix + " " + i; EditorGUILayout.LabelField(label, GUILayout.MaxWidth(labelwidth)); EditorGUI.EndDisabledGroup(); // Field SerializedProperty item = listSP.GetArrayElementAtIndex(i); var fieldrect = EditorGUILayout.GetControlRect(GUILayout.MinWidth(64)); if (lockZero && i == 0) { EditorGUI.BeginDisabledGroup(true); EditorGUI.LabelField(fieldrect, item.stringValue); EditorGUI.EndDisabledGroup(); } else { if (item.propertyType == SerializedPropertyType.String) { item.stringValue = EditorGUI.DelayedTextField(fieldrect, GUIContent.none, item.stringValue); } else { EditorGUILayout.PropertyField(item); } // Delete [x] Button var delbuttonrect = EditorGUILayout.GetControlRect(GUILayout.MaxWidth(BTTN_WIDTH)); if (GUI.Button(delbuttonrect, "X", (GUIStyle)"minibutton")) { delete = i; } } EditorGUILayout.EndHorizontal(); } // space EditorGUILayout.GetControlRect(false, 4); // Bottom [add] Button EditorGUI.BeginDisabledGroup(cnt >= maxCount); if (GUI.Button(EditorGUILayout.GetControlRect(false, 20), labelPrefix != null ? "Add " + labelPrefix : "Add")) { add = cnt; } EditorGUI.EndDisabledGroup(); if (add != -1) { listSP.InsertArrayElementAtIndex(add); if (forceUnique && !(listSP.propertyType == SerializedPropertyType.String)) { EnforceUnique(listSP, add); } } if (delete != -1) { listSP.DeleteArrayElementAtIndex(delete); } EditorGUILayout.EndVertical(); if (EditorGUI.EndChangeCheck()) { if (forceUnique && !(listSP.propertyType == SerializedPropertyType.String)) { EnforceUnique(listSP); } listSP.serializedObject.ApplyModifiedProperties(); } }
private void DrawElementCallback(ReorderableList list, Rect rect, int index, bool isactive, bool isfocused) { Event e = Event.current; if (_editMode) { if (_editMode && (_lastIndex != index || _lastList != list) && isactive) { if (_lastList != null) { _lastList.ReleaseKeyboardFocus(); _lastList.index = -1; } _clearEdit(); _lastIndex = index; _lastList = list; } if (e.type == EventType.KeyDown) { if (e.keyCode == KeyCode.Escape) { list.ReleaseKeyboardFocus(); _clearEdit(); e.Use(); return; } } } if (isactive) { if (e.type == EventType.MouseDown) { if (e.button == 0) { if (e.clickCount >= 2 && !_editMode) { _setEdit(list, index); e.Use(); } } } } if (_editMode && isactive) { NodePort oldPort = ((NodePort)list.list[index]); GUI.SetNextControlName(index.ToString()); EditorGUI.FocusTextInControl(index.ToString()); string newName = oldPort.fieldName; EditorGUI.BeginChangeCheck(); { bool contains = false; Rect lastRect; try { newName = EditorGUI.DelayedTextField(rect, oldPort.fieldName); lastRect = new Rect(GUILayoutUtility.GetLastRect()); var y = lastRect.yMax - list.GetHeight(); // ReorderableList start Y pos y += 20; // add ReorderableList title pos y += index * 20f; //add element y pos lastRect.position = new Vector2(lastRect.position.x, y); contains = lastRect.Contains(e.mousePosition); if (e.type == EventType.MouseDown && !contains) { _clearEdit(); Event.current.Use(); } } catch (ArgumentException) { if (!contains) { _clearEdit(); } } } if (EditorGUI.EndChangeCheck()) { _clearEdit(); string oldName = oldPort.fieldName; target.PortRename(oldPort, newName); //update all use this group of graph GetChildGroup Node _updateGetChildNodeGroup((group, node) => { node.PortRename(node.GetPort(oldName), newName); }); } } }
public override void Draw(Rect headerRect, Rect contentRect, WindowState state) { if (track == null) { return; } if (m_IsRoot) { return; } if (m_MustRecomputeUnions) { RecomputeRectUnions(); } if (depth == 1) { Graphics.DrawBackgroundRect(state, headerRect); } var background = headerRect; background.height = expandedRect.height; var groupColor = TrackResourceCache.GetTrackColor(track); m_TreeViewRect = contentRect; var col = groupColor; var isSelected = SelectionManager.Contains(track); if (isSelected) { col = DirectorStyles.Instance.customSkin.colorSelection; } else if (isDropTarget) { col = DirectorStyles.Instance.customSkin.colorDropTarget; } else { if (m_GroupDepth % 2 == 1) { float h, s, v; Color.RGBToHSV(col, out h, out s, out v); v += 0.06f; col = Color.HSVToRGB(h, s, v); } } // Draw Rounded Rectangle of the group... using (new GUIColorOverride(col)) GUI.Box(background, GUIContent.none, m_Styles.groupBackground); var trackRectBackground = headerRect; trackRectBackground.xMin += background.width; trackRectBackground.width = contentRect.width; trackRectBackground.height = background.height; if (isSelected) { col = state.IsEditingASubTimeline() ? m_Styles.customSkin.colorTrackSubSequenceBackgroundSelected : m_Styles.customSkin.colorTrackBackgroundSelected; } else { col = m_Styles.customSkin.colorGroupTrackBackground; } EditorGUI.DrawRect(trackRectBackground, col); if (!isExpanded && children != null && children.Count > 0) { var collapsedTrackRect = contentRect; foreach (var u in m_Unions) { u.Draw(collapsedTrackRect, state); } } // Draw the name of the Group... var labelRect = headerRect; labelRect.xMin += 20; var actorName = track != null ? track.name : "missing"; labelRect.width = m_Styles.groupFont.CalcSize(new GUIContent(actorName)).x; labelRect.width = Math.Max(labelRect.width, 50.0f); // if we aren't bound to anything, we show a text field that allows to rename the actor // otherwise we show a ObjectField to allow binding to a go if (track != null && track is GroupTrack) { var textColor = m_Styles.groupFont.normal.textColor; if (isSelected) { textColor = Color.white; } string newName; EditorGUI.BeginChangeCheck(); using (new StyleNormalColorOverride(m_Styles.groupFont, textColor)) { newName = EditorGUI.DelayedTextField(labelRect, GUIContent.none, track.GetInstanceID(), track.name, m_Styles.groupFont); } if (EditorGUI.EndChangeCheck() && !string.IsNullOrEmpty(newName)) { track.name = newName; displayName = track.name; } } DrawTrackButtons(headerRect, state); if (IsTrackRecording(state)) { using (new GUIColorOverride(DirectorStyles.Instance.customSkin.colorTrackBackgroundRecording)) GUI.Label(background, GUIContent.none, m_Styles.displayBackground); } // is this a referenced track? if (m_IsReferencedTrack) { var refRect = contentRect; refRect.x = state.timeAreaRect.xMax - 20.0f; refRect.y += 5.0f; refRect.width = 30.0f; GUI.Label(refRect, DirectorStyles.referenceTrackLabel, EditorStyles.label); } Rect bgRect = contentRect; if (track as GroupTrack != null || AllChildrenMuted(this)) { bgRect.height = expandedRect.height; } DrawTrackState(contentRect, bgRect, track); }
private void OnEnable() { m_customPropertyList = serializedObject.FindProperty("customPropertyList"); m_reorderableList = new ReorderableList(serializedObject, m_customPropertyList, false, true, true, true) { drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { rect.y += 2; float height = EditorGUIUtility.singleLineHeight; float half = rect.width / 2; var element = m_customPropertyList.GetArrayElementAtIndex(index); var name = element.FindPropertyRelative("name"); var description = element.FindPropertyRelative("description"); var outputType = element.FindPropertyRelative("outputType"); var floatPropertyType = element.FindPropertyRelative("floatPropertyType"); var colorPropertyType = element.FindPropertyRelative("colorPropertyType"); Rect fieldRect = new Rect(rect.x + 15, rect.y, rect.width - 18, height); element.isExpanded = EditorGUI.BeginFoldoutHeaderGroup(fieldRect, element.isExpanded, name.stringValue); if (element.isExpanded) { // Output type fieldRect = new Rect(rect.x, rect.y + height + 2, rect.width, height); EditorGUI.PropertyField(fieldRect, outputType); // Property type fieldRect = new Rect(rect.x, rect.y + height * 2 + 4, rect.width, height); switch (outputType.enumValueIndex) { case 0: EditorGUI.PropertyField(fieldRect, floatPropertyType, new GUIContent("Customization Mode", "")); break; case 1: EditorGUI.PropertyField(fieldRect, colorPropertyType, new GUIContent("Customization Mode", "")); break; } // Name fieldRect = new Rect(rect.x, rect.y + height * 3 + 6, rect.width, height); if (name.stringValue == "") { name.stringValue = "Custom Name"; } name.stringValue = EditorGUI.DelayedTextField(fieldRect, "Property Name", name.stringValue); // Description fieldRect = new Rect(rect.x, rect.y + height * 4 + 8, rect.width, height * 2.7f); if (description.stringValue == "") { description.stringValue = "Description:"; } description.stringValue = EditorGUI.TextArea(fieldRect, description.stringValue); } EditorGUILayout.EndFoldoutHeaderGroup(); }, onAddCallback = (ReorderableList l) => { ReorderableList.defaultBehaviours.DoAddButton(l); var element = m_customPropertyList.GetArrayElementAtIndex(l.index); element.FindPropertyRelative("outputType").enumValueIndex = 0; element.FindPropertyRelative("floatPropertyType").enumValueIndex = 0; element.FindPropertyRelative("colorPropertyType").enumValueIndex = 0; element.FindPropertyRelative("name").stringValue = "My Name..."; element.FindPropertyRelative("description").stringValue = "Description:"; element.isExpanded = true; // Find all weather profiles in the project and resize their property list List <AzureWeatherProfile> weathers = FindAssetsByType <AzureWeatherProfile>(); foreach (var weather in weathers) { if (weather.overrideObject == m_target) { weather.ResizeList(l.serializedProperty.arraySize); EditorUtility.SetDirty(weather); } } }, onRemoveCallback = (ReorderableList l) => { ReorderableList.defaultBehaviours.DoRemoveButton(l); // Find all weather profiles in the project and resize their property list List <AzureWeatherProfile> weathers = FindAssetsByType <AzureWeatherProfile>(); foreach (var weather in weathers) { if (weather.overrideObject == m_target) { weather.ResizeList(l.serializedProperty.arraySize); EditorUtility.SetDirty(weather); } } }, drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, m_guiContent[0], EditorStyles.boldLabel); }, elementHeightCallback = (int index) => { var element = m_customPropertyList.GetArrayElementAtIndex(index); var elementHeight = EditorGUI.GetPropertyHeight(element); var margin = EditorGUIUtility.standardVerticalSpacing + 4f; if (element.isExpanded) { return(elementHeight + 16f); } else { return(elementHeight + margin); } }, drawElementBackgroundCallback = (rect, index, active, focused) => { if (active) { GUI.Box(new Rect(rect.x + 2, rect.y - 1, rect.width - 4, rect.height), "", "selectionRect"); } } }; }
void OnGUI() { CacheGUI(); if (!current) { return; } using (new EditorGUILayout.HorizontalScope()) { Rect rLabel = EditorGUILayout.GetControlRect(GUILayout.Width(80)); GUI.Toggle(rLabel, true, "<b>Main Asset</b>", "IN Foldout"); Rect rLock = EditorGUILayout.GetControlRect(GUILayout.Width(20)); rLock.y += 2; if (GUI.Toggle(rLock, isLocked, GUIContent.none, "IN LockButton") != isLocked) { isLocked = !isLocked; } GUILayout.FlexibleSpace(); } EditorGUI.indentLevel++; using (new EditorGUILayout.HorizontalScope()) { Rect r = EditorGUILayout.GetControlRect(true); r.width -= 20; EditorGUI.ObjectField(r, current, current.GetType(), false); r.x += r.width; r.width = 20; r.height = 20; if (GUI.Button(r, contentDelete, EditorStyles.label)) { DeleteSubAsset(current); } } EditorGUI.indentLevel--; GUILayout.Space(10); using (new EditorGUILayout.HorizontalScope()) { Rect rLabel = EditorGUILayout.GetControlRect(GUILayout.Width(80)); GUI.Toggle(rLabel, true, "<b>Sub Asset</b>", "IN Foldout"); Rect rRename = EditorGUILayout.GetControlRect(GUILayout.Width(60)); isRenaming = GUI.Toggle(rRename, isRenaming, "Rename", EditorStyles.miniButton); GUILayout.FlexibleSpace(); } EditorGUI.indentLevel++; foreach (var asset in subAssets) { Rect r = EditorGUILayout.GetControlRect(true); r.width -= 60; Rect rField = new Rect(r); if (isRenaming) { rField.width = 12; rField.height = 12; //Draw icon of current object. EditorGUI.LabelField(r, new GUIContent(AssetPreview.GetMiniThumbnail(asset))); EditorGUI.BeginChangeCheck(); rField.x += rField.width + 4; rField.width = r.width - rField.width; rField.height = r.height; asset.name = EditorGUI.DelayedTextField(rField, asset.name); if (EditorGUI.EndChangeCheck()) { AssetDatabase.SaveAssets(); } } else { EditorGUI.ObjectField(rField, asset, asset.GetType(), false); } r.x += r.width; r.width = 20; r.height = 20; if (!referencingAssets.Contains(asset)) { GUI.Label(r, contentNoRef); } r.x += r.width; if (GetFileExtention(asset).Length != 0 && GUI.Button(r, contentExport, EditorStyles.label)) { ExportSubAsset(asset); } r.x += r.width; if (GUI.Button(r, contentDelete, EditorStyles.label)) { DeleteSubAsset(asset); } } EditorGUI.indentLevel--; GUILayout.Space(10); GUILayout.Toggle(true, "<b>Referencing Objects</b>", "IN Foldout"); EditorGUI.indentLevel++; EditorGUILayout.HelpBox("Sub assets are excluded.", MessageType.None); foreach (var asset in referencingAssets.Except(subAssets)) { Rect r = EditorGUILayout.GetControlRect(); r.width -= 20; EditorGUI.ObjectField(r, asset, asset.GetType(), false); r.x += r.width; r.y -= 1; r.width = 20; r.height = 20; // Add object to sub asset. if (GUI.Button(r, contentAdd, EditorStyles.label)) { var addAsset = asset; EditorApplication.delayCall += () => AddSubAsset(addAsset); } } EditorGUI.indentLevel--; DrawImportArea(); if (hasSelectionChanged) { hasSelectionChanged = false; AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); OnSelectionChanged(current); } }
void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused) { if (index % 2 != 0) { EditorGUI.DrawRect(new Rect(rect.x - 19f, rect.y, rect.width + 23f, rect.height), new Color(0, 0, 0, 0.1f)); } EditorGUI.BeginChangeCheck(); var element = m_PassesList.serializedProperty.GetArrayElementAtIndex(index); var propRect = new Rect(rect.x, rect.y + EditorGUIUtility.standardVerticalSpacing, rect.width, EditorGUIUtility.singleLineHeight); var headerRect = new Rect(rect.x, rect.y + EditorGUIUtility.standardVerticalSpacing, rect.width, EditorGUIUtility.singleLineHeight); if (element.objectReferenceValue != null) { // Get the type and append that to the name name = $"{element.objectReferenceValue.name} ({element.objectReferenceValue.GetType().Name})"; GUIContent header = new GUIContent(name, element.objectReferenceValue.GetType().Name); m_Foldouts[index].value = EditorGUI.Foldout(headerRect, m_Foldouts[index].value, GUIContent.none, true, Styles.BoldLabelSimple); GUI.Label(headerRect, header, Styles.BoldLabelSimple); if (m_Foldouts[index].value) { EditorGUI.indentLevel++; propRect.y += EditorUtils.Styles.defaultLineSpace; EditorGUI.BeginChangeCheck(); var objName = EditorGUI.DelayedTextField(propRect, Styles.PassNameField, element.objectReferenceValue.name); if (EditorGUI.EndChangeCheck()) { objName = ValidatePassName(objName); element.objectReferenceValue.name = objName; AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target)); } var elementSO = GetElementSO(index); SerializedProperty settings = elementSO.FindProperty("settings"); EditorGUI.BeginChangeCheck(); if (settings != null) { propRect.y += EditorUtils.Styles.defaultLineSpace; EditorGUI.PropertyField(propRect, settings, true); } if (EditorGUI.EndChangeCheck()) { elementSO.ApplyModifiedProperties(); } EditorGUI.indentLevel--; } } else { EditorGUI.ObjectField(propRect, element, GUIContent.none); } if (EditorGUI.EndChangeCheck()) { element.serializedObject.ApplyModifiedProperties(); } }
public AdvancedFeaturesWindowGlobalStates(Rect aStartPos, GUIContent aContent, GUIStyle aStyle, params GUILayoutOption[] aOptions) : base(aStartPos, aContent, aStyle, aOptions) { conditionsTex = Resources.Load <Texture2D>("EAdventureData/img/icons/conditions-24x24"); noConditionsTex = Resources.Load <Texture2D>("EAdventureData/img/icons/no-conditions-24x24"); globalStateList = new DataControlList() { RequestRepaint = Repaint, footerHeight = 25, elementHeight = 40, Columns = new System.Collections.Generic.List <ColumnList.Column>() { new ColumnList.Column() { Text = TC.get("GlobalStatesList.ID"), SizeOptions = new GUILayoutOption[] { GUILayout.Width(150) } }, new ColumnList.Column() { Text = TC.get("GlobalState.Documentation"), SizeOptions = new GUILayoutOption[] { GUILayout.ExpandWidth(true) } }, new ColumnList.Column() { Text = TC.get("GlobalState.Conditions"), SizeOptions = new GUILayoutOption[] { GUILayout.Width(220) } } }, drawCell = (rect, index, column, isActive, isFocused) => { var globalState = globalStateList.list[index] as GlobalStateDataControl; switch (column) { case 0: EditorGUI.BeginChangeCheck(); var id = EditorGUI.DelayedTextField(rect, globalState.getId()); if (EditorGUI.EndChangeCheck()) { globalState.setId(id); } break; case 1: EditorGUI.BeginChangeCheck(); var documentation = EditorGUI.TextArea(rect, globalState.getDocumentation() ?? string.Empty); if (EditorGUI.EndChangeCheck()) { globalState.setDocumentation(documentation); } break; case 2: if (GUI.Button(rect, globalState.getController().getBlocksCount() > 0 ? conditionsTex : noConditionsTex)) { ConditionEditorWindow window = ScriptableObject.CreateInstance <ConditionEditorWindow>(); window.Init(globalState.getController()); } break; } } }; }
void DrawLabel(int index, SerializedProperty spriteListProp, SerializedProperty spriteOverrideProperty, SpriteCategoryGridState gridState, bool spriteOverride, bool entryFromMain, Rect backgroundSelectedRect, Rect spriteObjectFieldRect, Rect labelTextfieldRect, ref bool canRemoveSelectedEntry, ref bool selectedEntryIsOverwrite) { var element = spriteListProp.GetArrayElementAtIndex(index); if (gridState.selectedIndex == index) { canRemoveSelectedEntry = entryFromMain && spriteOverride || !entryFromMain; selectedEntryIsOverwrite = entryFromMain && spriteOverride; if (Event.current.type == EventType.Repaint) { m_Style.gridList.Draw(backgroundSelectedRect, true, true, true, false); } } spriteOverrideProperty.objectReferenceValue = EditorGUI.ObjectField(spriteObjectFieldRect, spriteOverrideProperty.objectReferenceValue, typeof(Sprite), false) as Sprite; if (Event.current.type == EventType.MouseUp && backgroundSelectedRect.Contains(Event.current.mousePosition)) { gridState.selectedIndex = index; } if (!entryFromMain || spriteOverride) { var overrideIconRect = spriteObjectFieldRect; overrideIconRect.x -= 12; overrideIconRect.y -= 12; overrideIconRect.width = 20; overrideIconRect.height = 20; GUI.Label(overrideIconRect, m_Style.overrideIcon); } //disable m_Name editing if the entry is from main using (new EditorGUI.DisabledScope(entryFromMain)) { EditorGUI.BeginChangeCheck(); var oldName = element.FindPropertyRelative(SpriteLibraryPropertyString.name).stringValue; if (string.IsNullOrEmpty(oldName) && spriteOverrideProperty.objectReferenceValue != null && entryFromMain) { oldName = spriteOverrideProperty.name; SetPropertyName(element, oldName); } var nameRect = labelTextfieldRect; bool nameDuplicate = IsEntryNameUsed(oldName, spriteListProp, 1); if (nameDuplicate) { nameRect.width -= 20; } var newName = EditorGUI.DelayedTextField( nameRect, GUIContent.none, oldName); if (nameDuplicate) { nameRect.x += nameRect.width; nameRect.width = 20; GUI.Label(nameRect, m_Style.duplicateWarning); } if (EditorGUI.EndChangeCheck() && !string.IsNullOrEmpty(newName)) { newName = newName.Trim(); SetPropertyName(element, newName); } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { SerializedProperty = property; if (property.propertyType != SerializedPropertyType.String) { EditorGUI.LabelField(position, "ERROR:", "May only apply to type string"); return; } // Handle multi-editing when instances don't use the same SkeletonDataAsset. if (!SpineInspectorUtility.TargetsUseSameData(property.serializedObject)) { EditorGUI.DelayedTextField(position, property, label); return; } SerializedProperty dataField = property.FindBaseOrSiblingProperty(TargetAttribute.dataField); if (dataField != null) { var objectReferenceValue = dataField.objectReferenceValue; if (objectReferenceValue is SkeletonDataAsset) { skeletonDataAsset = (SkeletonDataAsset)objectReferenceValue; } else if (objectReferenceValue is IHasSkeletonDataAsset) { var hasSkeletonDataAsset = (IHasSkeletonDataAsset)objectReferenceValue; if (hasSkeletonDataAsset != null) { skeletonDataAsset = hasSkeletonDataAsset.SkeletonDataAsset; } } else if (objectReferenceValue != null) { EditorGUI.LabelField(position, "ERROR:", "Invalid reference type"); return; } } else { var targetObject = property.serializedObject.targetObject; IHasSkeletonDataAsset hasSkeletonDataAsset = targetObject as IHasSkeletonDataAsset; if (hasSkeletonDataAsset == null) { var component = targetObject as Component; if (component != null) { hasSkeletonDataAsset = component.GetComponentInChildren(typeof(IHasSkeletonDataAsset)) as IHasSkeletonDataAsset; } } if (hasSkeletonDataAsset != null) { skeletonDataAsset = hasSkeletonDataAsset.SkeletonDataAsset; } } if (skeletonDataAsset == null) { if (TargetAttribute.fallbackToTextField) { EditorGUI.PropertyField(position, property); //EditorGUI.TextField(position, label, property.stringValue); } else { EditorGUI.LabelField(position, "ERROR:", "Must have reference to a SkeletonDataAsset"); } skeletonDataAsset = property.serializedObject.targetObject as SkeletonDataAsset; if (skeletonDataAsset == null) { return; } } position = EditorGUI.PrefixLabel(position, label); Texture2D image = Icon; string propertyStringValue = (property.hasMultipleDifferentValues) ? SpineInspectorUtility.EmDash : property.stringValue; if (GUI.Button(position, string.IsNullOrEmpty(propertyStringValue) ? NoneLabel(image) : SpineInspectorUtility.TempContent(propertyStringValue, image), EditorStyles.popup)) { Selector(property); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { ParamSelectorAttribute attr = (ParamSelectorAttribute)attribute; Rect initialRect = position; if (attr.providers == null || attr.providers.Length == 0) { attr.GetProvidersFromStrategy(GetStrategy(property)); } else if (!attr.hasLabels) { attr.BuildLabels(GetStrategy(property)); } EditorGUI.BeginProperty(position, label, property); EditorGUI.BeginDisabledGroup(attr.providers.Length == 0); position = EditorGUI.PrefixLabel(position, label); float width = position.width / 2 - 2; Rect rect = new Rect(position.x, position.y, width, EditorGUIUtility.singleLineHeight); int indentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; ParamRelativityType relativityType = (ParamRelativityType)property.FindPropertyRelative("relativityType").enumValueIndex; ParamNormalRelativity relativeTo = (ParamNormalRelativity)property.FindPropertyRelative("relativeTo").enumValueIndex; // draw the provider picker SerializedProperty prop = property.FindPropertyRelative("provider"); DrawProviderPicker(rect, prop, attr); // draw the name prop rect.x += width + 4; prop = property.FindPropertyRelative("defaultParam.name"); EditorGUI.BeginChangeCheck(); string newName = EditorGUI.DelayedTextField(rect, prop.stringValue); if (EditorGUI.EndChangeCheck()) { prop.stringValue = newName; } EditorGUI.indentLevel = indentLevel + 1; float lineHeight = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; float yOff = lineHeight; // relativity if (relativityType != ParamRelativityType.None) { rect = initialRect; rect.height = EditorGUIUtility.singleLineHeight; rect.y += yOff; DrawRelativityProps(rect, property, attr); yOff += lineHeight; } // position options bool showPositionOptions = property.FindPropertyRelative("showPositionOptions").boolValue; if (showPositionOptions && relativityType == ParamRelativityType.Normal && relativeTo != ParamNormalRelativity.World) { rect = initialRect; rect.height = EditorGUIUtility.singleLineHeight; rect.y += yOff; EditorGUI.PropertyField(rect, property.FindPropertyRelative("useTransform")); rect.y += lineHeight; EditorGUI.PropertyField(rect, property.FindPropertyRelative("useSpriteFlip")); yOff += lineHeight * 2; } // default value rect = initialRect; rect.y += yOff; rect.height = EditorGUIUtility.singleLineHeight; rect = EditorGUI.PrefixLabel(rect, new GUIContent("Default")); ParamPropertyDrawer.DrawValueProp(rect, property.FindPropertyRelative("defaultParam"), ""); EditorGUI.indentLevel = indentLevel; EditorGUI.EndDisabledGroup(); EditorGUI.EndProperty(); }
static SettingsProvider PreferenceGUI() { ReorderableList floatNameList = new ReorderableList(floatPropertyNames, typeof(string), false, true, false, false); ReorderableList vectorNameList = new ReorderableList(vectorPropertyNames, typeof(string), false, true, false, false); ReorderableList colorNameList = new ReorderableList(colorPropertyNames, typeof(string), false, true, false, false); floatNameList.drawElementCallback = EditFloatString; floatNameList.drawHeaderCallback = FloatHeaderGUI; vectorNameList.drawElementCallback = EditVectorString; vectorNameList.drawHeaderCallback = VectorHeaderGUI; colorNameList.drawElementCallback = EditColorString; colorNameList.drawHeaderCallback = ColorHeaderGUI; void EditFloatString(Rect rect, int index, bool isActive, bool isFocused) { EditorGUI.BeginDisabled(index >= floatPropertyCount); floatPropertyNames[index] = EditorGUI.DelayedTextField(rect, floatPropertyNames[index]); EditorGUI.EndDisabled(); } void EditVectorString(Rect rect, int index, bool isActive, bool isFocused) { EditorGUI.BeginDisabled(index >= vectorPropertyCount); vectorPropertyNames[index] = EditorGUI.DelayedTextField(rect, vectorPropertyNames[index]); EditorGUI.EndDisabled(); } void EditColorString(Rect rect, int index, bool isActive, bool isFocused) { EditorGUI.BeginDisabled(index >= colorPropertyCount); colorPropertyNames[index] = EditorGUI.DelayedTextField(rect, colorPropertyNames[index]); EditorGUI.EndDisabled(); } return(new SettingsProvider("Project/VFX Volume Mixer", SettingsScope.Project) { guiHandler = searchContext => OpenGUI() }); void FloatHeaderGUI(Rect r) { floatPropertyCount = EditorGUI.IntSlider(r, floatPropertyCount, 0, 8); } void VectorHeaderGUI(Rect r) { vectorPropertyCount = EditorGUI.IntSlider(r, vectorPropertyCount, 0, 8); } void ColorHeaderGUI(Rect r) { colorPropertyCount = EditorGUI.IntSlider(r, colorPropertyCount, 0, 8); } void OpenGUI() { DrawList("Float Properties", floatNameList); DrawList("Vector3 Properties", vectorNameList); DrawList("Color Properties", colorNameList); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { FindPropertiesAndRects(position, property, label); name.serializedObject.Update(); var type = System.Type.GetType(typeString.stringValue); if (type == null) { return; } if (type.Equals(typeof(System.Type))) { Rect objectRect = position; objectRect.width = 20; objectRect.x = position.width + EditorGUI.IndentedRect(position).x - 20; Rect stringRect = position; stringRect.width -= 17; objectParameter.objectReferenceValue = EditorGUI.ObjectField(objectRect, new GUIContent(), objectParameter.objectReferenceValue, typeof(object), true); if (GUI.changed) { if (objectParameter.objectReferenceValue == null) { return; } string typeName = objectParameter.objectReferenceValue.GetType().FullName; if (typeName.Contains("UnityEditor")) { typeName = objectParameter.objectReferenceValue.name + ", Assembly-CSharp"; } if (System.Type.GetType(typeName) == null) { typeName += ", UnityEngine"; } if (System.Type.GetType(typeName) == null) { typeName = ""; } stringParameter.stringValue = typeName; } stringParameter.stringValue = EditorGUI.DelayedTextField(stringRect, new GUIContent(name.stringValue), stringParameter.stringValue); return; } if (type.IsSubclassOf(typeof(Object)) | type.Equals(typeof(Object))) { if (objectParameter.objectReferenceValue != null && !(objectParameter.objectReferenceValue.GetType().Equals(type) || objectParameter.objectReferenceValue.GetType().IsSubclassOf(type))) { objectParameter.objectReferenceValue = null; } objectParameter.objectReferenceValue = EditorGUI.ObjectField(position, new GUIContent(name.stringValue), objectParameter.objectReferenceValue, type, true); return; } if (type.Equals(typeof(Vector3))) { vectorParameter.vector3Value = EditorGUI.Vector3Field(position, new GUIContent(name.stringValue), vectorParameter.vector3Value); return; } if (type.Equals(typeof(Vector2))) { vectorParameter.vector3Value = EditorGUI.Vector2Field(position, new GUIContent(name.stringValue), vectorParameter.vector3Value); return; } if (type.Equals(typeof(Color))) { colorParameter.colorValue = EditorGUI.ColorField(position, new GUIContent(name.stringValue), colorParameter.colorValue); return; } if (type.Equals(typeof(bool))) { Rect switchRect, boolRect; switchRect = position; switchRect.width = (position.xMax - position.xMin) / 2; switchRect.x += (position.xMax - position.xMin) / 2; boolRect = position; boolRect.width = (position.xMax - position.xMin) / 2; boolParameter.boolValue = EditorGUI.Toggle(boolRect, new GUIContent(name.stringValue), boolParameter.boolValue); isSwitch.boolValue = EditorGUI.Toggle(switchRect, new GUIContent("Switch"), isSwitch.boolValue); return; } if (type.Equals(typeof(string))) { stringParameter.stringValue = EditorGUI.TextField(position, new GUIContent(name.stringValue), stringParameter.stringValue); return; } if (type.Equals(typeof(float))) { floatParameter.floatValue = EditorGUI.FloatField(position, new GUIContent(name.stringValue), floatParameter.floatValue); return; } if (type.Equals(typeof(double))) { doubleParameter.doubleValue = EditorGUI.DoubleField(position, new GUIContent(name.stringValue), doubleParameter.doubleValue); return; } if (type.Equals(typeof(int))) { intParameter.intValue = EditorGUI.IntField(position, new GUIContent(name.stringValue), intParameter.intValue); return; } }
////TODO: interactive picker; if more than one control makes it through the filters, present list of //// candidates for user to choose from ////REVIEW: refactor this out of here; this should be a public API that allows anyone to have an inspector field to select a control binding internal void DrawBindingGUI(SerializedProperty pathProperty, ref bool manualPathEditMode, TreeViewState pickerTreeViewState, Action <SerializedProperty> onModified) { EditorGUILayout.BeginHorizontal(); var lineRect = GUILayoutUtility.GetRect(0, EditorGUIUtility.singleLineHeight); var labelRect = lineRect; labelRect.width = 60; EditorGUI.LabelField(labelRect, s_BindingGui); lineRect.x += 65; lineRect.width -= 65; var bindingTextRect = lineRect; var editButtonRect = lineRect; var interactivePickButtonRect = lineRect; bindingTextRect.width -= 42; editButtonRect.x += bindingTextRect.width + 21; editButtonRect.width = 21; editButtonRect.height = 15; interactivePickButtonRect.x += bindingTextRect.width; interactivePickButtonRect.width = 21; interactivePickButtonRect.height = 15; var path = pathProperty.stringValue; ////TODO: this should be cached; generates needless GC churn var displayName = InputControlPath.ToHumanReadableString(path); if (manualPathEditMode || (!string.IsNullOrEmpty(path) && string.IsNullOrEmpty(displayName))) { EditorGUI.BeginChangeCheck(); path = EditorGUI.DelayedTextField(bindingTextRect, path); if (EditorGUI.EndChangeCheck()) { pathProperty.stringValue = path; pathProperty.serializedObject.ApplyModifiedProperties(); onModified(pathProperty); } DrawInteractivePickButton(interactivePickButtonRect, pathProperty, onModified); if (GUI.Button(editButtonRect, "˅")) { bindingTextRect.x += editButtonRect.width; ShowInputControlPicker(bindingTextRect, pathProperty, pickerTreeViewState, onModified); } } else { // Dropdown that shows binding text and allows opening control picker. if (EditorGUI.DropdownButton(bindingTextRect, new GUIContent(displayName), FocusType.Keyboard)) { ////TODO: pass expectedControlLayout filter on to control picker ////TODO: for bindings that are part of composites, use the layout information from the [InputControl] attribute on the field ShowInputControlPicker(bindingTextRect, pathProperty, pickerTreeViewState, onModified); } // Button to bind interactively. DrawInteractivePickButton(interactivePickButtonRect, pathProperty, onModified); // Button that switches binding into text edit mode. if (GUI.Button(editButtonRect, "...", EditorStyles.miniButton)) { manualPathEditMode = true; } } EditorGUILayout.EndHorizontal(); }
Rect DrawResItem(int row_index, int col_index, Object res, int offY, bool isMinMode, int scrollWidth) { bool isNowSelectObj = isSelectObj(res); string resName = res.name; string controlName = GetControlName(res); GUILayout.BeginVertical(); Rect totalRect = new Rect(0, 0, 1, 1); Rect draw_rect = new Rect(col_index * (resItemSize + 10), row_index * (resItemSize + offY), resItemSize, resItemSize); totalRect.x = draw_rect.x; totalRect.y = draw_rect.y; totalRect.width = resItemSize; totalRect.height = resItemSize + RES_ITEM_LABEL_HEIGHT; var nameRect = new Rect(col_index * (resItemSize + 10), row_index * (resItemSize + offY) + resItemSize + 2, resItemSize, RES_ITEM_LABEL_HEIGHT); if (isMinMode) { nameRect.x = resItemSize + 5; nameRect.y = draw_rect.y; nameRect.width = scrollWidth; totalRect.width = scrollWidth; totalRect.height = resItemSize; } if (isNowSelectObj && isMinMode && nowFocusedControlName != controlName) { EditorGUI.DrawRect(totalRect, SelectMaskColor); } if (res is Sprite) { DrawSprit(draw_rect, res as Sprite); } else if (res is Texture2D) { DrawTexture(draw_rect, res as Texture2D); } else { GUI.Box(draw_rect, EditorGUIUtility.IconContent("PrefabNormal Icon")); //EditorGUI.DrawRect(draw_rect, Color.gray); } if (isNowSelectObj && isMinMode == false) { DrawRectOutline(draw_rect, Color.green); } EditorGUI.BeginChangeCheck(); GUI.backgroundColor = new Color(.6f, 1.0f, 1.0f, 0f); if (isNowSelectObj == false || isInEditorName == false) { EditorGUI.LabelField(nameRect, "", ServiceResSelectorUtil.GetFittableText(resName, nameRect, resNameGUIStyle), resNameGUIStyle); /* Rect btnRect = new Rect(col_index * (resItemSize + 10), row_index * (resItemSize + offY), position.width, resItemSize); * if (GUI.Button(btnRect, "")) * { * OnResItemClick(res, true); * }*/ } else { GUI.SetNextControlName(controlName); resName = EditorGUI.DelayedTextField(nameRect, "", resName, resNameGUIStyle); if (EditorGUI.EndChangeCheck() && string.IsNullOrEmpty(resName) == false) { isInEditorName = false; Debug.Log("change:" + resName); string path = AssetDatabase.GetAssetPath(res); AssetDatabase.RenameAsset(path, resName); RefreshAssets(); } } GUI.backgroundColor = Color.white; GUILayout.EndVertical(); return(totalRect); }