/** * <summary>Creates a new instance of the 'Variable: Pop Up switch' Action, set to switch a Local PopUp variable</summary> * <param name = "localVariableID">The ID number of the Local PopUp variable</param> * <returns>The generated Action</returns> */ public static ActionVarPopup CreateNew_Local(int localVariableID) { ActionVarPopup newAction = (ActionVarPopup)CreateInstance <ActionVarPopup>(); newAction.location = VariableLocation.Local; newAction.variableID = localVariableID; GVar variable = newAction.GetVariable(); if (variable != null) { newAction.numSockets = variable.GetNumPopUpValues(); } return(newAction); }
private int GetNumOptions() { if (!Application.isPlaying && cycleType == AC_CycleType.Variable && (linkedVariable == null || linkedVariable.id != varID)) { if (AdvGame.GetReferences().variablesManager != null) { linkedVariable = AdvGame.GetReferences().variablesManager.GetVariable(varID); } } if (cycleType == AC_CycleType.Variable && linkedVariable != null && linkedVariable.type == VariableType.PopUp) { return(linkedVariable.GetNumPopUpValues()); } return(optionsArray.Count); }
/** * <summary>Creates a new instance of the 'Variable: Pop Up switch' Action, set to switch a Component PopUp variable</summary> * <param name = "variables">The variable's associated Variables component</param> * <param name = "componentVariableID">The ID number of the Component PopUp variable</param> * <returns>The generated Action</returns> */ public static ActionVarPopup CreateNew_Component(Variables variables, int componentVariableID) { ActionVarPopup newAction = (ActionVarPopup)CreateInstance <ActionVarPopup>(); newAction.location = VariableLocation.Component; newAction.variables = variables; newAction.variableID = componentVariableID; GVar variable = newAction.GetVariable(); if (variable != null) { newAction.numSockets = variable.GetNumPopUpValues(); } return(newAction); }
override public void ShowGUI(List <ActionParameter> parameters) { location = (VariableLocation)EditorGUILayout.EnumPopup("Source:", location); switch (location) { case VariableLocation.Global: if (AdvGame.GetReferences().variablesManager != null) { parameterID = Action.ChooseParameterGUI("Variable:", parameters, parameterID, ParameterType.GlobalVariable); if (parameterID >= 0) { placeholderPopUpLabelDataID = AdvGame.GetReferences().variablesManager.ShowPlaceholderPresetData(placeholderPopUpLabelDataID); if (placeholderPopUpLabelDataID <= 0) { placeholderNumValues = EditorGUILayout.DelayedIntField("Placeholder # of values:", placeholderNumValues); if (placeholderNumValues < 1) { placeholderNumValues = 1; } } } else { variableID = AdvGame.GlobalVariableGUI("PopUp variable:", variableID, VariableType.PopUp); } } break; case VariableLocation.Local: if (isAssetFile) { EditorGUILayout.HelpBox("Local variables cannot be accessed in ActionList assets.", MessageType.Info); } else if (localVariables == null) { EditorGUILayout.HelpBox("No 'Local Variables' component found in the scene. Please add an AC GameEngine object from the Scene Manager.", MessageType.Info); } else { parameterID = Action.ChooseParameterGUI("Variable:", parameters, parameterID, ParameterType.LocalVariable); if (parameterID >= 0) { placeholderPopUpLabelDataID = AdvGame.GetReferences().variablesManager.ShowPlaceholderPresetData(placeholderPopUpLabelDataID); if (placeholderPopUpLabelDataID <= 0) { placeholderNumValues = EditorGUILayout.DelayedIntField("Placeholder # of values:", placeholderNumValues); if (placeholderNumValues < 1) { placeholderNumValues = 1; } } } else { variableID = AdvGame.LocalVariableGUI("PopUp variable:", variableID, VariableType.PopUp); } } break; case VariableLocation.Component: parameterID = Action.ChooseParameterGUI("Variable:", parameters, parameterID, ParameterType.ComponentVariable); if (parameterID >= 0) { placeholderPopUpLabelDataID = AdvGame.GetReferences().variablesManager.ShowPlaceholderPresetData(placeholderPopUpLabelDataID); if (placeholderPopUpLabelDataID <= 0) { placeholderNumValues = EditorGUILayout.DelayedIntField("Placeholder # of values:", placeholderNumValues); if (placeholderNumValues < 1) { placeholderNumValues = 1; } } } else { variables = (Variables)EditorGUILayout.ObjectField("Component:", variables, typeof(Variables), true); variablesConstantID = FieldToID <Variables> (variables, variablesConstantID); variables = IDToField <Variables> (variables, variablesConstantID, false); if (variables != null) { variableID = AdvGame.ComponentVariableGUI("PopUp variable:", variableID, VariableType.PopUp, variables); } } break; } if (parameterID >= 0) { numSockets = placeholderNumValues; PopUpLabelData popUpLabelData = AdvGame.GetReferences().variablesManager.GetPopUpLabelData(placeholderPopUpLabelDataID); if (popUpLabelData != null) { numSockets = popUpLabelData.Length; placeholderNumValues = numSockets; } } else { GVar _var = GetVariable(); if (_var != null) { numSockets = _var.GetNumPopUpValues(); placeholderNumValues = numSockets; placeholderPopUpLabelDataID = _var.popUpID; } } if (numSockets == 0) { EditorGUILayout.HelpBox("The selected variable has no values!", MessageType.Warning); } }
protected void SetVariable(GVar var, VariableLocation location, bool doSkip) { if (var == null) { return; } switch (var.type) { case VariableType.Integer: { int _value = 0; if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere) { if (setVarMethod == SetVarMethod.Formula) { _value = (int)AdvGame.CalculateFormula(AdvGame.ConvertTokens(formula, Options.GetLanguage(), localVariables)); } else { _value = intValue; } } else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter) { if (animator && !string.IsNullOrEmpty(parameterName)) { _value = animator.GetInteger(parameterName); setVarMethod = SetVarMethod.SetValue; } } if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip) { var.RestoreBackupValue(); } var.SetValue(_value, setVarMethod); if (doSkip) { var.BackupValue(); } break; } case VariableType.Float: { float _value = 0; if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere) { if (setVarMethod == SetVarMethod.Formula) { _value = (float)AdvGame.CalculateFormula(AdvGame.ConvertTokens(formula, Options.GetLanguage(), localVariables)); } else { _value = floatValue; } } else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter) { if (animator && !string.IsNullOrEmpty(parameterName)) { _value = animator.GetFloat(parameterName); setVarMethod = SetVarMethod.SetValue; } } if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip) { var.RestoreBackupValue(); } var.SetFloatValue(_value, setVarMethod); if (doSkip) { var.BackupValue(); } break; } case VariableType.Boolean: { int _value = 0; if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere) { _value = (int)boolValue; } else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter) { if (animator && !string.IsNullOrEmpty(parameterName)) { if (animator.GetBool(parameterName)) { _value = 1; } } } var.SetValue(_value, SetVarMethod.SetValue); break; } case VariableType.Vector3: { Vector3 newValue = vector3Value; if (setVarMethodVector == SetVarMethodVector.IncreaseByValue) { newValue += var.vector3Val; } var.SetVector3Value(newValue); break; } case VariableType.PopUp: { int _value = 0; if (setVarMethod == SetVarMethod.Formula) { _value = (int)AdvGame.CalculateFormula(AdvGame.ConvertTokens(formula, Options.GetLanguage(), localVariables)); } else if (setVarMethod == SetVarMethod.SetAsRandom) { _value = var.GetNumPopUpValues(); } else { _value = Mathf.Clamp(intValue, 0, var.GetNumPopUpValues() - 1); } if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip) { var.RestoreBackupValue(); } var.SetValue(_value, setVarMethod); if (doSkip) { var.BackupValue(); } break; } case VariableType.String: { string _value = string.Empty; if (setVarMethodString == SetVarMethodString.EnteredHere) { _value = AdvGame.ConvertTokens(stringValue, Options.GetLanguage(), localVariables); } else if (setVarMethodString == SetVarMethodString.SetAsMenuElementText) { MenuElement menuElement = PlayerMenus.GetElementWithName(menuName, elementName); if (menuElement != null) { if (menuElement is MenuInput) { MenuInput menuInput = (MenuInput)menuElement; _value = menuInput.GetContents(); if (KickStarter.runtimeLanguages.LanguageReadsRightToLeft(Options.GetLanguage()) && _value.Length > 0) { // Invert char[] charArray = _value.ToCharArray(); _value = ""; for (int i = charArray.Length - 1; i >= 0; i--) { _value += charArray[i]; } } } else { PlayerMenus.GetMenuWithName(menuName).Recalculate(); menuElement.PreDisplay(slotNumber, Options.GetLanguage(), false); _value = menuElement.GetLabel(slotNumber, Options.GetLanguage()); } } else { LogWarning("Could not find MenuInput '" + elementName + "' in Menu '" + menuName + "'"); } } var.SetStringValue(_value, lineID); break; } default: break; } var.Upload(location, runtimeVariables); KickStarter.actionListManager.VariableChanged(); }