/** * <summary>Gets the PresetValue for a specific variable.</summary> * <param name = "_var">The variable to get the PresetValue of</param> */ public PresetValue GetPresetValue(GVar _var) { foreach (PresetValue presetValue in presetValues) { if (presetValue.id == _var.id) { return(presetValue); } } PresetValue newPresetValue = new PresetValue(_var); presetValues.Add(newPresetValue); return(newPresetValue); }
private void ShowVarGUI(VariableLocation location, List <VarPreset> _varPresets = null, string apiPrefix = "") { EditorGUILayout.BeginVertical(CustomStyles.thinBox); showVariablesProperties = CustomGUILayout.ToggleHeader(showVariablesProperties, location + " variable '" + selectedVar.label + "' properties"); if (showVariablesProperties) { selectedVar.label = CustomGUILayout.TextField("Label:", selectedVar.label, apiPrefix + ".label"); selectedVar.type = (VariableType)CustomGUILayout.EnumPopup("Type:", selectedVar.type, apiPrefix + ".type"); if (location == VariableLocation.Local) { //EditorGUILayout.LabelField ("Replacement token:", "[localvar:" + selectedVar.id.ToString () + "]"); CustomGUILayout.TokenLabel("[localvar:" + selectedVar.id.ToString() + "]"); } else { //EditorGUILayout.LabelField ("Replacement token:", "[var:" + selectedVar.id.ToString () + "]"); CustomGUILayout.TokenLabel("[var:" + selectedVar.id.ToString() + "]"); } if (selectedVar.type == VariableType.Boolean) { if (selectedVar.val != 1) { selectedVar.val = 0; } selectedVar.val = CustomGUILayout.Popup("Initial value:", selectedVar.val, boolType, apiPrefix + ".val"); } else if (selectedVar.type == VariableType.Integer) { selectedVar.val = CustomGUILayout.IntField("Initial value:", selectedVar.val, apiPrefix + ".val"); } else if (selectedVar.type == VariableType.PopUp) { selectedVar.popUps = PopupsGUI(selectedVar.popUps); selectedVar.val = CustomGUILayout.Popup("Initial value:", selectedVar.val, selectedVar.popUps, apiPrefix + ".val"); selectedVar.canTranslate = CustomGUILayout.Toggle("Values can be translated?", selectedVar.canTranslate, apiPrefix + ".canTranslate"); } else if (selectedVar.type == VariableType.String) { selectedVar.textVal = CustomGUILayout.TextField("Initial value:", selectedVar.textVal, apiPrefix + ".textVal"); selectedVar.canTranslate = CustomGUILayout.Toggle("Values can be translated?", selectedVar.canTranslate, apiPrefix + ".canTranslate"); } else if (selectedVar.type == VariableType.Float) { selectedVar.floatVal = CustomGUILayout.FloatField("Initial value:", selectedVar.floatVal, apiPrefix + ".floatVal"); } else if (selectedVar.type == VariableType.Vector3) { selectedVar.vector3Val = CustomGUILayout.Vector3Field("Initial value:", selectedVar.vector3Val, apiPrefix + ".vector3Val"); } if (_varPresets != null) { foreach (VarPreset _varPreset in _varPresets) { // Local string apiPrefix2 = (location == VariableLocation.Local) ? "AC.KickStarter.localVariables.GetPreset (" + _varPreset.ID + ").GetPresetValue (" + selectedVar.id + ")" : "AC.KickStarter.runtimeVariables.GetPreset (" + _varPreset.ID + ").GetPresetValue (" + selectedVar.id + ")"; _varPreset.UpdateCollection(selectedVar); string label = "'" + _varPreset.label + "' value:"; PresetValue presetValue = _varPreset.GetPresetValue(selectedVar); if (selectedVar.type == VariableType.Boolean) { presetValue.val = CustomGUILayout.Popup(label, presetValue.val, boolType, apiPrefix2 + ".val"); } else if (selectedVar.type == VariableType.Integer) { presetValue.val = CustomGUILayout.IntField(label, presetValue.val, apiPrefix2 + ".val"); } else if (selectedVar.type == VariableType.PopUp) { presetValue.val = CustomGUILayout.Popup(label, presetValue.val, selectedVar.popUps, apiPrefix2 + ".val"); } else if (selectedVar.type == VariableType.String) { presetValue.textVal = CustomGUILayout.TextField(label, presetValue.textVal, apiPrefix2 + ".textVal"); } else if (selectedVar.type == VariableType.Float) { presetValue.floatVal = CustomGUILayout.FloatField(label, presetValue.floatVal, apiPrefix2 + ".floatVal"); } else if (selectedVar.type == VariableType.Vector3) { presetValue.vector3Val = CustomGUILayout.Vector3Field(label, presetValue.vector3Val, apiPrefix2 + ".vector3Val"); } } } if (location == VariableLocation.Local) { selectedVar.link = VarLink.None; } else { EditorGUILayout.Space(); selectedVar.link = (VarLink)CustomGUILayout.EnumPopup("Link to:", selectedVar.link, apiPrefix + ".link"); if (selectedVar.link == VarLink.PlaymakerGlobalVariable) { if (PlayMakerIntegration.IsDefinePresent()) { selectedVar.pmVar = CustomGUILayout.TextField("Playmaker Global Variable:", selectedVar.pmVar, apiPrefix + ".pmVar"); selectedVar.updateLinkOnStart = CustomGUILayout.Toggle("Use PM for initial value?", selectedVar.updateLinkOnStart, apiPrefix + ".updateLinkOnStart"); } else { EditorGUILayout.HelpBox("The 'PlayMakerIsPresent' Scripting Define Symbol must be listed in the\nPlayer Settings. Please set it from Edit -> Project Settings -> Player", MessageType.Warning); } } else if (selectedVar.link == VarLink.OptionsData) { EditorGUILayout.HelpBox("This Variable will be stored in PlayerPrefs, and not in saved game files.", MessageType.Info); } } } EditorGUILayout.EndVertical(); }
/** * <summary>Gets the PresetValue for a speicific variable.</summary> * <param name = "_var">The variable to get the PresetValue of</param> */ public PresetValue GetPresetValue(GVar _var) { foreach (PresetValue presetValue in presetValues) { if (presetValue.id == _var.id) { return presetValue; } } PresetValue newPresetValue = new PresetValue (_var); presetValues.Add (newPresetValue); return newPresetValue; }
private void ShowVarGUI(VariableLocation location, List <VarPreset> _varPresets = null) { EditorGUILayout.LabelField(location + " variable '" + selectedVar.label + "' properties", EditorStyles.boldLabel); EditorGUILayout.BeginVertical("Button"); selectedVar.label = EditorGUILayout.TextField("Label:", selectedVar.label); selectedVar.type = (VariableType)EditorGUILayout.EnumPopup("Type:", selectedVar.type); if (location == VariableLocation.Local) { EditorGUILayout.LabelField("Replacement token:", "[localvar:" + selectedVar.id.ToString() + "]"); } else { EditorGUILayout.LabelField("Replacement token:", "[var:" + selectedVar.id.ToString() + "]"); } if (selectedVar.type == VariableType.Boolean) { if (selectedVar.val != 1) { selectedVar.val = 0; } selectedVar.val = EditorGUILayout.Popup("Initial value:", selectedVar.val, boolType); } else if (selectedVar.type == VariableType.Integer) { selectedVar.val = EditorGUILayout.IntField("Initial value:", selectedVar.val); } else if (selectedVar.type == VariableType.PopUp) { selectedVar.popUps = PopupsGUI(selectedVar.popUps); selectedVar.val = EditorGUILayout.Popup("Initial value:", selectedVar.val, selectedVar.popUps); } else if (selectedVar.type == VariableType.String) { selectedVar.textVal = EditorGUILayout.TextField("Initial value:", selectedVar.textVal); } else if (selectedVar.type == VariableType.Float) { selectedVar.floatVal = EditorGUILayout.FloatField("Initial value:", selectedVar.floatVal); } if (_varPresets != null) { foreach (VarPreset _varPreset in _varPresets) { _varPreset.UpdateCollection(selectedVar); string label = "'" + _varPreset.label + "' value:"; PresetValue presetValue = _varPreset.GetPresetValue(selectedVar); if (selectedVar.type == VariableType.Boolean) { presetValue.val = EditorGUILayout.Popup(label, presetValue.val, boolType); } else if (selectedVar.type == VariableType.Integer) { presetValue.val = EditorGUILayout.IntField(label, presetValue.val); } else if (selectedVar.type == VariableType.PopUp) { presetValue.val = EditorGUILayout.Popup(label, presetValue.val, selectedVar.popUps); } else if (selectedVar.type == VariableType.String) { presetValue.textVal = EditorGUILayout.TextField(label, presetValue.textVal); } else if (selectedVar.type == VariableType.Float) { presetValue.floatVal = EditorGUILayout.FloatField(label, presetValue.floatVal); } } } if (location == VariableLocation.Local) { selectedVar.link = VarLink.None; } else { EditorGUILayout.Space(); selectedVar.link = (VarLink)EditorGUILayout.EnumPopup("Link to:", selectedVar.link); if (selectedVar.link == VarLink.PlaymakerGlobalVariable) { if (PlayMakerIntegration.IsDefinePresent()) { selectedVar.pmVar = EditorGUILayout.TextField("Playmaker Global Variable:", selectedVar.pmVar); selectedVar.updateLinkOnStart = EditorGUILayout.Toggle("Use PM for initial value?", selectedVar.updateLinkOnStart); } else { EditorGUILayout.HelpBox("The 'PlayMakerIsPresent' Scripting Define Symbol must be listed in the\nPlayer Settings. Please set it from Edit -> Project Settings -> Player", MessageType.Warning); } } else if (selectedVar.link == VarLink.OptionsData) { EditorGUILayout.HelpBox("This Variable will be stored in PlayerPrefs, and not in saved game files.", MessageType.Info); } } EditorGUILayout.EndVertical(); }
public void ShowGUI(VariableLocation location, bool canEdit, List <VarPreset> _varPresets = null, string apiPrefix = "", Variables _variables = null) { string labelPrefix = (canEdit) ? "Initial value:" : "Current value:"; string helpText = (canEdit) ? "Its initial value" : "Its current value"; if (!canEdit && HasTranslations() && Options.GetLanguage() > 0) { labelPrefix = "Original language value:"; } if (canEdit) { label = CustomGUILayout.TextField("Label:", label, apiPrefix + ".label", "Its editor name"); type = (VariableType)CustomGUILayout.EnumPopup("Type:", type, apiPrefix + ".type", "Its variable type"); } else { EditorGUILayout.LabelField("Label: " + label); EditorGUILayout.LabelField("Type: " + type.ToString()); } switch (type) { case VariableType.Boolean: if (val != 1) { val = 0; } val = CustomGUILayout.Popup(labelPrefix, val, boolType, apiPrefix + ".BooleanValue", helpText); break; case VariableType.Float: floatVal = CustomGUILayout.FloatField(labelPrefix, floatVal, apiPrefix + ".FloatValue", helpText); break; case VariableType.Integer: val = CustomGUILayout.IntField(labelPrefix, val, apiPrefix + ".IntegerValue", helpText); break; case VariableType.PopUp: Object objectToRecord = null; if (location == VariableLocation.Global) { objectToRecord = KickStarter.variablesManager; } if (location == VariableLocation.Local) { objectToRecord = KickStarter.localVariables; } if (location == VariableLocation.Component) { objectToRecord = _variables; } VariablesManager.ShowPopUpLabelsGUI(this, canEdit, objectToRecord); if (GetNumPopUpValues() > 0) { string[] popUpLabels = GenerateEditorPopUpLabels(); val = CustomGUILayout.Popup(labelPrefix, val, popUpLabels, apiPrefix + ".IntegerValue", helpText); } else { val = 0; } if (popUpID > 0) { if (Application.isPlaying && canTranslate) { EditorGUILayout.LabelField("Values can be translated"); } } else { if (canEdit) { canTranslate = CustomGUILayout.Toggle("Values can be translated?", canTranslate, apiPrefix + ".canTranslate", "If True, the variable's value can be translated"); } else if (canTranslate) { EditorGUILayout.LabelField("Values can be translated"); } } break; case VariableType.String: EditorGUILayout.BeginHorizontal(); CustomGUILayout.LabelField(labelPrefix, GUILayout.Width(140f), apiPrefix + ".TextValue"); EditorStyles.textField.wordWrap = true; textVal = CustomGUILayout.TextArea(textVal, GUILayout.MaxWidth(800f), apiPrefix + ".TextValue"); EditorGUILayout.EndHorizontal(); if (canEdit) { canTranslate = CustomGUILayout.Toggle("Values can be translated?", canTranslate, apiPrefix + ".canTranslate", "If True, the variable's value can be translated"); } else if (canTranslate) { EditorGUILayout.LabelField("Values can be translated"); } break; case VariableType.Vector3: vector3Val = CustomGUILayout.Vector3Field(labelPrefix, vector3Val, apiPrefix + ".Vector3Value", helpText); break; } switch (location) { case VariableLocation.Global: CustomGUILayout.TokenLabel("[var:" + id.ToString() + "]"); break; case VariableLocation.Local: CustomGUILayout.TokenLabel("[localvar:" + id.ToString() + "]"); break; case VariableLocation.Component: if (_variables != null) { ConstantID _constantID = _variables.GetComponent <ConstantID> (); if (_constantID != null && _constantID.constantID != 0) { CustomGUILayout.TokenLabel("[compvar:" + _constantID.constantID.ToString() + ":" + id.ToString() + "]"); } } break; } if (_varPresets != null) { EditorGUILayout.Space(); foreach (VarPreset _varPreset in _varPresets) { // Local string apiPrefix2 = (location == VariableLocation.Local) ? "AC.KickStarter.localVariables.GetPreset (" + _varPreset.ID + ").GetPresetValue (" + id + ")" : "AC.KickStarter.runtimeVariables.GetPreset (" + _varPreset.ID + ").GetPresetValue (" + id + ")"; _varPreset.UpdateCollection(this); string label = "'" + (!string.IsNullOrEmpty(_varPreset.label) ? _varPreset.label : ("Preset #" + _varPreset.ID.ToString())) + "' value:"; PresetValue presetValue = _varPreset.GetPresetValue(this); switch (type) { case VariableType.Boolean: presetValue.val = CustomGUILayout.Popup(label, presetValue.val, boolType, apiPrefix2 + ".BooleanValue"); break; case VariableType.Float: presetValue.floatVal = CustomGUILayout.FloatField(label, presetValue.floatVal, apiPrefix2 + ".FloatValue"); break; case VariableType.Integer: presetValue.val = CustomGUILayout.IntField(label, presetValue.val, apiPrefix2 + ".IntegerValue"); break; case VariableType.PopUp: presetValue.val = CustomGUILayout.Popup(label, presetValue.val, popUps, apiPrefix2 + ".IntegerValue"); break; case VariableType.String: presetValue.textVal = CustomGUILayout.TextField(label, presetValue.textVal, apiPrefix2 + ".TextValue"); break; case VariableType.Vector3: presetValue.vector3Val = CustomGUILayout.Vector3Field(label, presetValue.vector3Val, apiPrefix2 + ".Vector3Value"); break; } } } EditorGUILayout.Space(); if (canEdit) { switch (location) { case VariableLocation.Local: link = VarLink.None; break; case VariableLocation.Global: case VariableLocation.Component: link = (VarLink)CustomGUILayout.EnumPopup("Link to:", link, apiPrefix + ".link", "What it links to"); if (link == VarLink.PlaymakerVariable) { if (PlayMakerIntegration.IsDefinePresent()) { if (location == VariableLocation.Global) { pmVar = CustomGUILayout.TextField("Playmaker Global Variable:", pmVar, apiPrefix + ".pmVar", "The name of the Playmaker variable to link to."); } else if (location == VariableLocation.Component) { if (_variables != null && PlayMakerIntegration.HasFSM(_variables.gameObject)) { pmVar = CustomGUILayout.TextField("Playmaker Local Variable:", pmVar, apiPrefix + ".pmVar", "The name of the Playmaker variable to link to. It is assumed to be placed on the same GameObject as this Variables component."); } else { EditorGUILayout.HelpBox("A Playmaker FSM component must be present on the Variables GameObject.", MessageType.Info); } } if (!string.IsNullOrEmpty(pmVar)) { updateLinkOnStart = CustomGUILayout.Toggle("Use PM for initial value?", updateLinkOnStart, apiPrefix + ".updateLinkOnStart", "If True, then Playmaker will be referred to for the initial value"); } } else { EditorGUILayout.HelpBox("The 'PlayMakerIsPresent' Scripting Define Symbol must be listed in the\nPlayer Settings. Please set it from Edit -> Project Settings -> Player", MessageType.Warning); } } else if (link == VarLink.OptionsData) { if (location == VariableLocation.Global) { EditorGUILayout.HelpBox("This Variable will be stored in PlayerPrefs, and not in saved game files.", MessageType.Info); } else { EditorGUILayout.HelpBox("Component variables cannot be linked to Options Data - use Global variables instead.", MessageType.Warning); } } else if (link == VarLink.CustomScript) { updateLinkOnStart = CustomGUILayout.Toggle("Script sets initial value?", updateLinkOnStart, apiPrefix + ".updateLinkOnStart", "If True, then a custom script will be referred to for the initial value"); EditorGUILayout.HelpBox("See the Manual's 'Global variable linking' chapter for details on how to synchronise values.", MessageType.Info); } break; } } else { if (link != VarLink.None) { EditorGUILayout.LabelField("Links to: " + link.ToString()); if (link == VarLink.PlaymakerVariable && !string.IsNullOrEmpty(pmVar)) { EditorGUILayout.LabelField("Linked PM variable: " + pmVar); } if (link == VarLink.PlaymakerVariable || link == VarLink.CustomScript) { if (updateLinkOnStart) { EditorGUILayout.LabelField("Script sets initial value"); } } } } if (canEdit) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent("Internal description:", "An Editor-only description to aid designers"), GUILayout.MaxWidth(146f)); description = EditorGUILayout.TextArea(description); EditorGUILayout.EndHorizontal(); } else { if (!string.IsNullOrEmpty(description)) { EditorGUILayout.LabelField("Internal description: " + description); } } }