public void OnProgressionPointAddElement(ReorderableList reorderableList) { Undo.RegisterCompleteObjectUndo(serializedObject.targetObject, "Add ProgressionItem"); ReorderableList.defaultBehaviours.DoAddButton(reorderableList); serializedObject.ApplyModifiedProperties(); ProgressionPointAsset p = CreateAsset <ProgressionPointAsset>(); p.name = GetUniqueProgressionPointName("ProgressionPointAsset"); progressionPointNames.Add(p.name); reorderableList.serializedProperty.GetArrayElementAtIndex(reorderableList.serializedProperty.arraySize - 1).objectReferenceValue = p; serializedObject.ApplyModifiedProperties(); }
private void PrefixNames() { QuestAsset quest = ((QuestAsset)serializedObject.targetObject); if (quest == null) { return; } ProgressionPointAsset[] progressionPointArray = quest.GetProgressionPoints(); for (int i = 0; i < progressionPointArray.Length; i++) { ProgressionPointAsset p = progressionPointArray[i]; string intFormat = new string('0', (progressionPointArray.Length / 10) + 1); p.name = quest.name + "_" + i.ToString(intFormat) + "|" + p.name; } EditorUtility.SetDirty(serializedObject.targetObject); }
public void OnProgressionPointElementGUI(Rect rect, int index, bool isActive, bool isFocused) { Rect topRect = rect; topRect.y -= EditorGUIUtility.singleLineHeight / 2; EditorGUI.LabelField(topRect, index.ToString()); rect.x += 20; SerializedProperty serializedProperty = progressionPointsProperty.GetArrayElementAtIndex(index); ProgressionPointAsset progressionPoint = (ProgressionPointAsset)serializedProperty.objectReferenceValue; serializedProperty.isExpanded = true; if (isActive) { int original = GUI.skin.textField.fontSize; GUI.skin.textField.fontSize = original * 2; EditorGUI.BeginChangeCheck(); GUIStyle style = new GUIStyle(GUI.skin.textField); style.fontSize = original * 2; GUI.SetNextControlName(progressionPoint.GetInstanceID().ToString()); string newName = EditorGUI.DelayedTextField(rect, "", progressionPoint.name, style); if (GUI.GetNameOfFocusedControl() == progressionPoint.GetInstanceID().ToString()) { Rect helpRect = new Rect(rect.x, rect.y - EditorGUIUtility.singleLineHeight, rect.width, rect.height / 2); EditorGUI.HelpBox(helpRect, "Press Enter To Submit", MessageType.Warning); } if (EditorGUI.EndChangeCheck()) { progressionPointNames.Remove(progressionPoint.name); newName = GetUniqueProgressionPointName(newName); progressionPointNames.Add(newName); Undo.RecordObject(progressionPoint, "Change name from " + progressionPoint.name + " to " + newName); progressionPoint.name = newName; EditorUtility.SetDirty(progressionPoint); serializedObject.ApplyModifiedProperties(); progressionPointsReorderableList.onSelectCallback(progressionPointsReorderableList); } GUI.skin.textField.fontSize = original; } else { EditorGUI.LabelField(rect, progressionPoint?progressionPoint.name:""); } }
public void OnProgressionPointRemoveElement(ReorderableList reorderableList) { Undo.RegisterCompleteObjectUndo(serializedObject.targetObject, "Delete ProgressionItem"); ProgressionPointAsset p = ((QuestAsset)serializedObject.targetObject).GetProgressionPoints()[reorderableList.index]; reorderableList.serializedProperty.DeleteArrayElementAtIndex(reorderableList.index); reorderableList.serializedProperty.MoveArrayElement(reorderableList.index, reorderableList.count - 1); reorderableList.serializedProperty.arraySize--; progressionPointNames.Remove(p.name); if (p != null) { DestroyAsset(p); } serializedObject.ApplyModifiedProperties(); if (progressionEditor != null) { DestroyImmediate(progressionEditor); } }
private void DropAreaGUI() { if (progressionPointsProperty == null) { return; } Event evt = Event.current; Rect drop_area = GUILayoutUtility.GetRect(0.0f, EditorGUIUtility.singleLineHeight, GUILayout.ExpandWidth(true)); drop_area.height += (progressionPointsProperty.arraySize + 1) * (EditorGUIUtility.singleLineHeight * 2 + 2); GUI.Box(drop_area, "Drag and Drop Progression Points"); switch (evt.type) { case EventType.DragUpdated: case EventType.DragPerform: if (!drop_area.Contains(evt.mousePosition)) { return; } DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (evt.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); foreach (Object dragged_object in DragAndDrop.objectReferences) { // Do On Drag Stuff here ProgressionPointAsset dependency = (ProgressionPointAsset)dragged_object; if (dependency != null) { Undo.RegisterCompleteObjectUndo(target, "Add dependency to progression point"); progressionPointsProperty.InsertArrayElementAtIndex(Mathf.Max(0, progressionPointsProperty.arraySize - 1)); progressionPointsProperty.GetArrayElementAtIndex(progressionPointsProperty.arraySize - 1).objectReferenceValue = dragged_object; serializedObject.ApplyModifiedProperties(); } } return; } break; } }