public static void CloneKillerInt(KillerInt targetInt, KillerInt sourceInt) { targetInt.curModMode = sourceInt.curModMode; targetInt.selfValue = sourceInt.selfValue; targetInt.worldVariableName = sourceInt.worldVariableName; targetInt.variableSource = sourceInt.variableSource; }
public static DTInspectorUtility.FunctionButtons DisplayKillerInt(ref bool isDirty, KillerInt killInt, string fieldLabel, Object srcObject, bool showDeleteButton = false, bool indent = false) { var oldBg = GUI.backgroundColor; EditorGUILayout.BeginHorizontal(); var allStatNames = AllStatNamesOfType(WorldVariableTracker.VariableType._integer); if (indent) { GUILayout.Space(12); } GUILayout.Label(fieldLabel, GUILayout.MinWidth(50)); GUILayout.FlexibleSpace(); var newVarIndex = -1; var unfoundVariableName = string.Empty; if (showDeleteButton) { var newModMode = (KillerVariable.ModMode)EditorGUILayout.EnumPopup("", killInt.curModMode, GUILayout.Width(ModModeFieldWidth)); if (newModMode != killInt.curModMode) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, srcObject, "change Mod Mode for " + fieldLabel); killInt.curModMode = newModMode; } } var fieldWidth = showDeleteButton ? ShortFieldWidth : FieldWidth; var oldLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = TinyLabelWidth; switch (killInt.variableSource) { case LevelSettings.VariableSource.Self: var newVal = EditorGUILayout.IntField("I", killInt.selfValue, GUILayout.MinWidth(fieldWidth)); if (newVal != killInt.selfValue) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, srcObject, "change " + fieldLabel); killInt.Value = newVal; } break; case LevelSettings.VariableSource.Variable: var oldIndex = allStatNames.IndexOf(killInt.worldVariableName); if (oldIndex < 0) { unfoundVariableName = killInt.worldVariableName; oldIndex = 0; } newVarIndex = EditorGUILayout.Popup("I", oldIndex, allStatNames.ToArray(), GUILayout.MinWidth(fieldWidth)); if (oldIndex != newVarIndex) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, srcObject, "change Variable for " + fieldLabel); killInt.worldVariableName = allStatNames[newVarIndex]; } break; } EditorGUIUtility.labelWidth = oldLabelWidth; GUI.backgroundColor = DTInspectorUtility.BrightButtonColor; var newSource = (LevelSettings.VariableSource)EditorGUILayout.EnumPopup(killInt.variableSource, GUILayout.Width(70)); if (newSource != killInt.variableSource) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, srcObject, "change source of " + fieldLabel); killInt.variableSource = newSource; } GUI.backgroundColor = oldBg; var deletePressed = false; if (showDeleteButton) { GUI.backgroundColor = DTInspectorUtility.DeleteButtonColor; if (GUILayout.Button(new GUIContent("Delete", "Remove this mod"), EditorStyles.miniButton, GUILayout.Width(50))) { deletePressed = true; } GUI.backgroundColor = oldBg; } EditorGUILayout.EndHorizontal(); if (killInt.variableSource != LevelSettings.VariableSource.Variable || (killInt.worldVariableName != LevelSettings.DropDownNoneOption && newVarIndex > 0)) { return(deletePressed ? DTInspectorUtility.FunctionButtons.Remove : DTInspectorUtility.FunctionButtons.None); } if (string.IsNullOrEmpty(unfoundVariableName)) { DTInspectorUtility.ShowRedErrorBox("No variable has been selected. " + fieldLabel + " will get a value of " + KillerInt.DefaultValue + "."); } else { DTInspectorUtility.ShowRedErrorBox("Could not find variable '" + unfoundVariableName + "' to assign to " + fieldLabel + ". Please select another."); } return(deletePressed ? DTInspectorUtility.FunctionButtons.Remove : DTInspectorUtility.FunctionButtons.None); }