/** * <summary>A Constructor that duplicates another ActionParameter.</summary> */ public ActionParameter(ActionParameter _actionParameter, bool alsoCopyValues = false) { label = _actionParameter.label; ID = _actionParameter.ID; parameterType = _actionParameter.parameterType; if (alsoCopyValues) { intValue = _actionParameter.intValue; floatValue = _actionParameter.floatValue; stringValue = _actionParameter.stringValue; gameObject = _actionParameter.gameObject; objectValue = _actionParameter.objectValue; vector3Value = _actionParameter.vector3Value; gameObjectParameterReferences = _actionParameter.gameObjectParameterReferences; } else { intValue = -1; floatValue = 0f; stringValue = ""; gameObject = null; objectValue = null; vector3Value = Vector3.zero; gameObjectParameterReferences = GameObjectParameterReferences.ReferencePrefab; } }
/** * <summary>A Constructor that generates a unique ID number.</summary> * <param name = "idArray">An array of previously-used ID numbers, to ensure its own ID is unique.</param> */ public ActionParameter(int[] idArray) { label = string.Empty; ID = 0; intValue = -1; floatValue = 0f; stringValue = string.Empty; gameObject = null; objectValue = null; parameterType = ParameterType.GameObject; vector3Value = Vector3.zero; gameObjectParameterReferences = GameObjectParameterReferences.ReferencePrefab; variables = null; // Update id based on array foreach (int _id in idArray) { if (ID == _id) { ID++; } } label = "Parameter " + (ID + 1).ToString(); }
/** * Resets the value that the parameter assigns. */ public void Reset() { intValue = -1; floatValue = 0f; stringValue = ""; gameObject = null; objectValue = null; vector3Value = Vector3.zero; gameObjectParameterReferences = GameObjectParameterReferences.ReferencePrefab; }
/** * <summary>Copies the "value" variables from another ActionParameter, without changing the type, ID, or label.</summary> * <parameter name = "otherParameter">The ActionParameter to copy from</param> */ public void CopyValues(ActionParameter otherParameter) { intValue = otherParameter.intValue; floatValue = otherParameter.floatValue; stringValue = otherParameter.stringValue; gameObject = otherParameter.gameObject; objectValue = otherParameter.objectValue; vector3Value = otherParameter.vector3Value; gameObjectParameterReferences = otherParameter.gameObjectParameterReferences; }
/** * <summary>A Constructor that sets the ID number explicitly.</summary> * <param name = "id">The unique identifier to assign</param> */ public ActionParameter(int id) { label = ""; ID = id; intValue = -1; floatValue = 0f; stringValue = ""; gameObject = null; objectValue = null; parameterType = ParameterType.GameObject; vector3Value = Vector3.zero; gameObjectParameterReferences = GameObjectParameterReferences.ReferencePrefab; label = "Parameter " + (ID + 1).ToString(); }
public void ShowGUI(bool isAssetFile, bool onlyEditValues = false, bool readOnly = false) { if (Application.isPlaying || readOnly) { EditorGUILayout.LabelField("Type:", parameterType.ToString()); EditorGUILayout.LabelField("Current value:", "'" + GetLabel() + "'"); CustomGUILayout.TokenLabel("[param:" + ID.ToString() + "]"); } else { if (onlyEditValues) { EditorGUILayout.LabelField("Type:", parameterType.ToString()); } else { parameterType = (ParameterType)EditorGUILayout.EnumPopup("Type:", parameterType); } switch (parameterType) { case ParameterType.Boolean: BoolValue boolValue = (intValue == 1) ? BoolValue.True : BoolValue.False; boolValue = (BoolValue)EditorGUILayout.EnumPopup("Default value:", boolValue); intValue = (boolValue == BoolValue.True) ? 1 : 0; break; case ParameterType.Integer: intValue = EditorGUILayout.IntField("Default value:", intValue); break; case ParameterType.Float: floatValue = EditorGUILayout.FloatField("Default value:", floatValue); break; case ParameterType.String: EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Default value:", GUILayout.Width(145f)); EditorStyles.textField.wordWrap = true; stringValue = EditorGUILayout.TextArea(stringValue, GUILayout.MaxWidth(400f)); EditorGUILayout.EndHorizontal(); break; case ParameterType.Vector3: vector3Value = EditorGUILayout.Vector3Field("Default value:", vector3Value); break; case ParameterType.UnityObject: objectValue = (Object)EditorGUILayout.ObjectField("Default value:", objectValue, typeof(Object), true); break; case ParameterType.Document: if (AdvGame.GetReferences() && AdvGame.GetReferences().inventoryManager) { InventoryManager inventoryManager = AdvGame.GetReferences().inventoryManager; intValue = ActionRunActionList.ShowDocumentSelectorGUI("Default value:", inventoryManager.documents, intValue); } else { EditorGUILayout.HelpBox("An Inventory Manager is required.", MessageType.Warning); } break; case ParameterType.InventoryItem: if (AdvGame.GetReferences() && AdvGame.GetReferences().inventoryManager) { InventoryManager inventoryManager = AdvGame.GetReferences().inventoryManager; intValue = ActionRunActionList.ShowInvItemSelectorGUI("Default value:", inventoryManager.items, intValue); } else { EditorGUILayout.HelpBox("An Inventory Manager is required to pass Inventory items.", MessageType.Warning); } break; case ParameterType.GlobalVariable: if (AdvGame.GetReferences() && AdvGame.GetReferences().variablesManager) { VariablesManager variablesManager = AdvGame.GetReferences().variablesManager; intValue = ActionRunActionList.ShowVarSelectorGUI("Default value:", variablesManager.vars, intValue); } else { EditorGUILayout.HelpBox("A Variables Manager is required to pass Global Variables.", MessageType.Warning); } break; case ParameterType.LocalVariable: if (isAssetFile) { intValue = 0; EditorGUILayout.HelpBox("Local Variable parameters cannot have default values in ActionList Assets.", MessageType.Info); } else { if (KickStarter.localVariables) { intValue = ActionRunActionList.ShowVarSelectorGUI("Default value:", KickStarter.localVariables.localVars, intValue); } else { EditorGUILayout.HelpBox("A GameEngine prefab is required to pass Local Variables.", MessageType.Warning); } } break; case ParameterType.ComponentVariable: if (isAssetFile) { variables = null; intValue = 0; EditorGUILayout.HelpBox("Component Variable parameters cannot have default values in ActionList Assets.", MessageType.Info); } else { variables = (Variables)EditorGUILayout.ObjectField("Variables component:", variables, typeof(Variables), true); if (variables != null) { intValue = ActionRunActionList.ShowVarSelectorGUI("Default value:", variables.vars, intValue); } } break; case ParameterType.GameObject: if (isAssetFile) { gameObject = (GameObject)EditorGUILayout.ObjectField("Default value:", gameObject, typeof(GameObject), true); if (gameObject != null) { if (!UnityVersionHandler.IsPrefabFile(gameObject)) { intValue = Action.FieldToID(gameObject, intValue, false, isAssetFile); gameObject = Action.IDToField(gameObject, intValue, true, false, isAssetFile); } else { // A prefab, ask if we want to affect the prefab or the scene-based instance? gameObjectParameterReferences = (GameObjectParameterReferences)EditorGUILayout.EnumPopup("GameObject parameter:", gameObjectParameterReferences); } } else { intValue = EditorGUILayout.IntField("Default value (ID #):", intValue); } } else { // Gameobject gameObject = (GameObject)EditorGUILayout.ObjectField("Default value:", gameObject, typeof(GameObject), true); intValue = 0; if (gameObject != null && gameObject.GetComponent <ConstantID> () == null) { UnityVersionHandler.AddConstantIDToGameObject <ConstantID> (gameObject); } } break; default: break; } CustomGUILayout.TokenLabel("[param:" + ID.ToString() + "]"); } }