override public float Run() { if (_gameObject == null) { return(0f); } if (invAction == InvAction.Add) { // Instantiate GameObject oldOb = AssignFile(constantID, _gameObject); if (_gameObject.activeInHierarchy || (oldOb != null && oldOb.activeInHierarchy)) { RememberTransform rememberTransform = oldOb.GetComponent <RememberTransform>(); if (rememberTransform != null && rememberTransform.saveScenePresence && rememberTransform.linkedPrefabID != 0) { // Bypass this check } else { ACDebug.LogWarning(gameObject.name + " won't be instantiated, as it is already present in the scene.", gameObject); return(0f); } } Vector3 position = _gameObject.transform.position; Quaternion rotation = _gameObject.transform.rotation; if (positionRelativeTo != PositionRelativeTo.Nothing) { float forward = _gameObject.transform.position.z; float right = _gameObject.transform.position.x; float up = _gameObject.transform.position.y; if (positionRelativeTo == PositionRelativeTo.RelativeToActiveCamera) { Transform mainCam = KickStarter.mainCamera.transform; position = mainCam.position + (mainCam.forward * forward) + (mainCam.right * right) + (mainCam.up * up); rotation.eulerAngles += mainCam.transform.rotation.eulerAngles; } else if (positionRelativeTo == PositionRelativeTo.RelativeToPlayer) { if (KickStarter.player) { Transform playerTranform = KickStarter.player.transform; position = playerTranform.position + (playerTranform.forward * forward) + (playerTranform.right * right) + (playerTranform.up * up); rotation.eulerAngles += playerTranform.rotation.eulerAngles; } } else if (positionRelativeTo == PositionRelativeTo.RelativeToGameObject) { if (relativeGameObject != null) { Transform relativeTransform = relativeGameObject.transform; position = relativeTransform.position + (relativeTransform.forward * forward) + (relativeTransform.right * right) + (relativeTransform.up * up); rotation.eulerAngles += relativeTransform.rotation.eulerAngles; } } else if (positionRelativeTo == PositionRelativeTo.EnteredValue) { position += relativeVector; } else if (positionRelativeTo == PositionRelativeTo.VectorVariable) { if (variableLocation == VariableLocation.Global) { position += GlobalVariables.GetVector3Value(vectorVarID); } else if (variableLocation == VariableLocation.Local && !isAssetFile) { position += LocalVariables.GetVector3Value(vectorVarID); } } } GameObject newObject = (GameObject)Instantiate(_gameObject, position, rotation); newObject.name = _gameObject.name; if (newObject.GetComponent <RememberTransform>()) { newObject.GetComponent <RememberTransform>().OnSpawn(); } KickStarter.stateHandler.IgnoreNavMeshCollisions(); } else if (invAction == InvAction.Remove) { // Delete KickStarter.sceneChanger.ScheduleForDeletion(_gameObject); } else if (invAction == InvAction.Replace) { if (replaceGameObject == null) { ACDebug.LogWarning("Cannot perform swap because the object to remove was not found in the scene."); return(0f); } Vector3 position = replaceGameObject.transform.position; Quaternion rotation = replaceGameObject.transform.rotation; GameObject oldOb = AssignFile(constantID, _gameObject); if (gameObject.activeInHierarchy || (oldOb != null && oldOb.activeInHierarchy)) { ACDebug.Log(gameObject.name + " won't be instantiated, as it is already present in the scene.", gameObject); return(0f); } KickStarter.sceneChanger.ScheduleForDeletion(replaceGameObject); GameObject newObject = (GameObject)Instantiate(_gameObject, position, rotation); newObject.name = _gameObject.name; KickStarter.stateHandler.IgnoreNavMeshCollisions(); } return(0f); }
override public ActionEnd End(List <Action> actions) { if (numSockets <= 0) { ACDebug.LogWarning("Could not compute Random check because no values were possible!"); return(GenerateStopActionEnd()); } if (!saveToVariable) { int value = ownVarValue; ownVarValue++; if (ownVarValue >= numSockets) { if (doLoop) { ownVarValue = 0; } else { ownVarValue = numSockets - 1; } } return(ProcessResult(value, actions)); } if (variableID == -1) { return(GenerateStopActionEnd()); } GVar var = null; if (location == VariableLocation.Local && !isAssetFile) { var = LocalVariables.GetVariable(variableID); } else { var = GlobalVariables.GetVariable(variableID); } if (var != null) { if (var.type == VariableType.Integer) { var.Download(); if (var.val < 1) { var.val = 1; } int originalValue = var.val - 1; var.val++; if (var.val > numSockets) { if (doLoop) { var.val = 1; } else { var.val = numSockets; } } var.Upload(); return(ProcessResult(originalValue, actions)); } else { ACDebug.LogWarning("'Variable: Run sequence' Action is referencing a Variable that does not exist or is not an Integer!"); } } return(GenerateStopActionEnd()); }
/** * <summary>Sets the value of a local Float variable.</summary> * <param name = "_id">The ID number of the variable</param> * <param name = "_value">The new float value of the variable</param> */ public static void SetFloatValue(int _id, float _value) { LocalVariables.GetVariable(_id).floatVal = _value; }
/** * <summary>Sets the value of a local PopUp variable.</summary> * <param name = "_id">The ID number of the variable</param> * <param name = "_value">The new index value of the variable</param> */ public static void SetPopupValue(int _id, int _value) { LocalVariables.GetVariable(_id).val = _value; }
/** * <summary>Returns the value of a local Float variable.</summary> * <param name = "_id">The ID number of the variable</param> * <returns>The float value of the variable</returns> */ public static float GetFloatValue(int _id) { return(LocalVariables.GetVariable(_id).floatVal); }
/** * <summary>Returns the value of a local Popup variable.</summary> * <param name = "_id">The ID number of the variable</param> * <param name = "languageNumber">The index number of the game's current language</param> * <returns>The string value of the variable</returns> */ public static string GetPopupValue(int _id, int languageNumber = 0) { return(LocalVariables.GetVariable(_id).GetValue(languageNumber)); }
/** * <summary>Returns the value of a local String variable.</summary> * <param name = "_id">The ID number of the variable</param> * <param name = "languageNumber">The index number of the game's current language</param> * <returns>The string value of the variable</returns> */ public static string GetStringValue(int _id, int lanugageNumber = 0) { return(LocalVariables.GetVariable(_id).GetValue()); }
private void RunToTime(float _time, bool isSkipping) { if (transformType == TransformType.CopyMarker) { if (marker) { linkedProp.Move(marker, moveMethod, _time, timeCurve); } } else { Vector3 targetVector = Vector3.zero; if (setVectorMethod == SetVectorMethod.FromVector3Variable) { if (variableLocation == VariableLocation.Global) { targetVector = GlobalVariables.GetVector3Value(vectorVarID); } else if (variableLocation == VariableLocation.Local && !isAssetFile) { targetVector = LocalVariables.GetVector3Value(vectorVarID); } } else if (setVectorMethod == SetVectorMethod.EnteredHere) { targetVector = newVector; } if (transformType == TransformType.Translate) { if (toBy == ToBy.By) { targetVector = SetRelativeTarget(targetVector, isSkipping, linkedProp.transform.localPosition); } } else if (transformType == TransformType.Rotate) { if (toBy == ToBy.By) { int numZeros = 0; if (targetVector.x == 0f) { numZeros++; } if (targetVector.y == 0f) { numZeros++; } if (targetVector.z == 0f) { numZeros++; } if (numZeros == 2) { targetVector = SetRelativeTarget(targetVector, isSkipping, linkedProp.transform.eulerAngles); } else { Quaternion currentRotation = linkedProp.transform.localRotation; linkedProp.transform.Rotate(targetVector, Space.World); targetVector = linkedProp.transform.localEulerAngles; linkedProp.transform.localRotation = currentRotation; } } } else if (transformType == TransformType.Scale) { if (toBy == ToBy.By) { targetVector = SetRelativeTarget(targetVector, isSkipping, linkedProp.transform.localScale); } } if (transformType == TransformType.Rotate) { linkedProp.Move(targetVector, moveMethod, _time, transformType, doEulerRotation, timeCurve, clearExisting); } else { linkedProp.Move(targetVector, moveMethod, _time, transformType, false, timeCurve, clearExisting); } } }
public override void AssignValues(List <ActionParameter> parameters) { if (invAction == InvAction.Add || invAction == InvAction.Replace) { _gameObject = AssignFile(parameters, parameterID, 0, gameObject); if (invAction == InvAction.Replace) { replaceGameObject = AssignFile(parameters, replaceParameterID, replaceConstantID, replaceGameObject); } else if (invAction == InvAction.Add) { relativeGameObject = AssignFile(parameters, relativeGameObjectParameterID, relativeGameObjectID, relativeGameObject); } } else if (invAction == InvAction.Remove) { _gameObject = AssignFile(parameters, parameterID, constantID, gameObject); } relativeVector = AssignVector3(parameters, relativeVectorParameterID, relativeVector); if (invAction == InvAction.Add && positionRelativeTo == PositionRelativeTo.VectorVariable) { runtimeVariable = null; switch (variableLocation) { case VariableLocation.Global: vectorVarID = AssignVariableID(parameters, vectorVarParameterID, vectorVarID); runtimeVariable = GlobalVariables.GetVariable(vectorVarID, true); break; case VariableLocation.Local: if (!isAssetFile) { vectorVarID = AssignVariableID(parameters, vectorVarParameterID, vectorVarID); runtimeVariable = LocalVariables.GetVariable(vectorVarID, localVariables); } break; case VariableLocation.Component: Variables runtimeVariables = AssignFile <Variables> (variablesConstantID, variables); if (runtimeVariables != null) { runtimeVariable = runtimeVariables.GetVariable(vectorVarID); } runtimeVariable = AssignVariable(parameters, vectorVarParameterID, runtimeVariable); break; } } runtimeSpawnedObjectParameter = null; if (invAction == InvAction.Add) { runtimeSpawnedObjectParameter = GetParameterWithID(parameters, spawnedObjectParameterID); if (runtimeSpawnedObjectParameter != null && runtimeSpawnedObjectParameter.parameterType != ParameterType.GameObject) { runtimeSpawnedObjectParameter = null; } } }
override public float Run() { if (teleporter && obToMove) { Vector3 position = teleporter.transform.position; Quaternion rotation = teleporter.transform.rotation; if (positionRelativeTo == PositionRelativeTo.RelativeToActiveCamera) { Transform mainCam = KickStarter.mainCamera.transform; float right = teleporter.transform.position.x; float up = teleporter.transform.position.y; float forward = teleporter.transform.position.z; position = mainCam.position + (mainCam.forward * forward) + (mainCam.right * right) + (mainCam.up * up); rotation.eulerAngles += mainCam.transform.rotation.eulerAngles; } else if (positionRelativeTo == PositionRelativeTo.RelativeToPlayer && !isPlayer) { if (KickStarter.player) { Transform playerTranform = KickStarter.player.transform; float right = teleporter.transform.position.x; float up = teleporter.transform.position.y; float forward = teleporter.transform.position.z; position = playerTranform.position + (playerTranform.forward * forward) + (playerTranform.right * right) + (playerTranform.up * up); rotation.eulerAngles += playerTranform.rotation.eulerAngles; } } else if (positionRelativeTo == PositionRelativeTo.RelativeToGameObject) { if (relativeGameObject != null) { Transform relativeTransform = relativeGameObject.transform; float right = teleporter.transform.position.x; float up = teleporter.transform.position.y; float forward = teleporter.transform.position.z; position = relativeTransform.position + (relativeTransform.forward * forward) + (relativeTransform.right * right) + (relativeTransform.up * up); rotation.eulerAngles += relativeTransform.rotation.eulerAngles; } } else if (positionRelativeTo == PositionRelativeTo.EnteredValue) { position += relativeVector; } else if (positionRelativeTo == PositionRelativeTo.VectorVariable) { if (variableLocation == VariableLocation.Global) { position += GlobalVariables.GetVector3Value(vectorVarID); } else if (variableLocation == VariableLocation.Local && !isAssetFile) { position += LocalVariables.GetVector3Value(vectorVarID); } } if (copyRotation) { obToMove.transform.rotation = rotation; if (obToMove.GetComponent <Char>()) { // Is a character, so set the lookDirection, otherwise will revert back to old rotation obToMove.GetComponent <Char>().SetLookDirection(teleporter.transform.forward, true); obToMove.GetComponent <Char>().Halt(); } } if (obToMove.GetComponent <Char>()) { obToMove.GetComponent <Char>().Teleport(position, recalculateActivePathFind); } else { obToMove.transform.position = position; } if (isPlayer && snapCamera) { if (KickStarter.mainCamera != null && KickStarter.mainCamera.attachedCamera != null && KickStarter.mainCamera.attachedCamera.targetIsPlayer) { KickStarter.mainCamera.attachedCamera.MoveCameraInstant(); } } } return(0f); }
/** * <summary>Unsets the values of all script variables, so that they can be re-assigned to the correct scene if multiple scenes are open.</summary> */ public void ClearVariables() { playerPrefab = null; mainCameraPrefab = null; persistentEnginePrefab = null; gameEnginePrefab = null; // Managers sceneManagerPrefab = null; settingsManagerPrefab = null; actionsManagerPrefab = null; variablesManagerPrefab = null; inventoryManagerPrefab = null; speechManagerPrefab = null; cursorManagerPrefab = null; menuManagerPrefab = null; // PersistentEngine components optionsComponent = null; runtimeInventoryComponent = null; runtimeVariablesComponent = null; playerMenusComponent = null; stateHandlerComponent = null; sceneChangerComponent = null; saveSystemComponent = null; levelStorageComponent = null; runtimeLanguagesComponent = null; // GameEngine components menuSystemComponent = null; dialogComponent = null; playerInputComponent = null; playerInteractionComponent = null; playerMovementComponent = null; playerCursorComponent = null; playerQTEComponent = null; sceneSettingsComponent = null; navigationManagerComponent = null; actionListManagerComponent = null; localVariablesComponent = null; menuPreviewComponent = null; SetGameEngine (); }
override public void AssignValues(List <ActionParameter> parameters) { if (isPlayer) { if (KickStarter.player != null) { runtimeLinkedProp = KickStarter.player.GetComponent <Moveable>(); if (runtimeLinkedProp == null) { ACDebug.LogWarning("The player " + KickStarter.player + " requires a Moveable component to be moved with the 'Object: Transform' Action.", KickStarter.player); } } else { runtimeLinkedProp = null; } } else { runtimeLinkedProp = AssignFile <Moveable> (parameters, parameterID, constantID, linkedProp); } runtimeMarker = AssignFile <Marker> (parameters, markerParameterID, markerID, marker); transitionTime = AssignFloat(parameters, transitionTimeParameterID, transitionTime); newVector = AssignVector3(parameters, newVectorParameterID, newVector); if (!(transformType == TransformType.CopyMarker || (transformType == TransformType.Translate && toBy == ToBy.To) || (transformType == TransformType.Rotate && toBy == ToBy.To))) { inWorldSpace = false; } runtimeVariable = null; if (transformType != TransformType.CopyMarker && setVectorMethod == SetVectorMethod.FromVector3Variable) { switch (variableLocation) { case VariableLocation.Global: vectorVarID = AssignVariableID(parameters, vectorVarParameterID, vectorVarID); runtimeVariable = GlobalVariables.GetVariable(vectorVarID, true); break; case VariableLocation.Local: if (!isAssetFile) { vectorVarID = AssignVariableID(parameters, vectorVarParameterID, vectorVarID); runtimeVariable = LocalVariables.GetVariable(vectorVarID, localVariables); } break; case VariableLocation.Component: Variables runtimeVariables = AssignFile <Variables> (variablesConstantID, variables); if (runtimeVariables != null) { runtimeVariable = runtimeVariables.GetVariable(vectorVarID); } runtimeVariable = AssignVariable(parameters, vectorVarParameterID, runtimeVariable); break; } } }
override public void ShowGUI (List<ActionParameter> parameters) { if (isAssetFile) { location = VariableLocation.Global; } else { location = (VariableLocation) EditorGUILayout.EnumPopup ("Source:", location); } if (location == VariableLocation.Global) { if (!variablesManager) { variablesManager = AdvGame.GetReferences ().variablesManager; } if (variablesManager) { ShowVarGUI (variablesManager.vars, parameters, ParameterType.GlobalVariable); } } else if (location == VariableLocation.Local) { if (!localVariables && GameObject.FindWithTag (Tags.gameEngine) && GameObject.FindWithTag (Tags.gameEngine).GetComponent<LocalVariables>()) { localVariables = GameObject.FindWithTag (Tags.gameEngine).GetComponent <LocalVariables>(); } if (localVariables) { ShowVarGUI (localVariables.localVars, parameters, ParameterType.LocalVariable); } } }
private void SendSceneToData(SubScene subScene = null) { SceneSettings sceneSettings = (subScene == null) ? KickStarter.sceneSettings : subScene.SceneSettings; LocalVariables localVariables = (subScene == null) ? KickStarter.localVariables : subScene.LocalVariables; List <TransformData> thisLevelTransforms = PopulateTransformData(subScene); List <ScriptData> thisLevelScripts = PopulateScriptData(subScene); SingleLevelData thisLevelData = new SingleLevelData(); thisLevelData.sceneNumber = (subScene == null) ? UnityVersionHandler.GetCurrentSceneNumber() : subScene.SceneInfo.number; thisLevelData.activeLists = KickStarter.actionListManager.GetSaveData(subScene); if (sceneSettings != null) { if (sceneSettings.navMesh && sceneSettings.navMesh.GetComponent <ConstantID>()) { thisLevelData.navMesh = Serializer.GetConstantID(sceneSettings.navMesh.gameObject); } if (sceneSettings.defaultPlayerStart && sceneSettings.defaultPlayerStart.GetComponent <ConstantID>()) { thisLevelData.playerStart = Serializer.GetConstantID(sceneSettings.defaultPlayerStart.gameObject); } if (sceneSettings.sortingMap && sceneSettings.sortingMap.GetComponent <ConstantID>()) { thisLevelData.sortingMap = Serializer.GetConstantID(sceneSettings.sortingMap.gameObject); } if (sceneSettings.cutsceneOnLoad && sceneSettings.cutsceneOnLoad.GetComponent <ConstantID>()) { thisLevelData.onLoadCutscene = Serializer.GetConstantID(sceneSettings.cutsceneOnLoad.gameObject); } if (sceneSettings.cutsceneOnStart && sceneSettings.cutsceneOnStart.GetComponent <ConstantID>()) { thisLevelData.onStartCutscene = Serializer.GetConstantID(sceneSettings.cutsceneOnStart.gameObject); } if (sceneSettings.tintMap && sceneSettings.tintMap.GetComponent <ConstantID>()) { thisLevelData.tintMap = Serializer.GetConstantID(sceneSettings.tintMap.gameObject); } } thisLevelData.localVariablesData = SaveSystem.CreateVariablesData(localVariables.localVars, false, VariableLocation.Local); thisLevelData.allTransformData = thisLevelTransforms; thisLevelData.allScriptData = thisLevelScripts; bool found = false; for (int i = 0; i < allLevelData.Count; i++) { if (allLevelData[i].sceneNumber == thisLevelData.sceneNumber) { allLevelData[i] = thisLevelData; found = true; break; } } if (!found) { allLevelData.Add(thisLevelData); } }
override public void ShowGUI (List<ActionParameter> parameters) { if (isAssetFile) { location = VariableLocation.Global; } else { location = (VariableLocation) EditorGUILayout.EnumPopup ("Source:", location); } if (isAssetFile && getVarMethod == GetVarMethod.LocalVariable) { EditorGUILayout.HelpBox ("Local Variables cannot be referenced by Asset-based Actions.", MessageType.Warning); } if (location == VariableLocation.Global) { if (!variablesManager) { variablesManager = AdvGame.GetReferences ().variablesManager; } if (variablesManager) { parameterID = Action.ChooseParameterGUI ("Variable:", parameters, parameterID, ParameterType.GlobalVariable); if (parameterID >= 0) { variableID = ShowVarGUI (parameters, variablesManager.vars, variableID, false); } else { variableID = ShowVarGUI (parameters, variablesManager.vars, variableID, true); } } } else if (location == VariableLocation.Local) { if (!localVariables && GameObject.FindWithTag (Tags.gameEngine) && GameObject.FindWithTag (Tags.gameEngine).GetComponent<LocalVariables>()) { localVariables = GameObject.FindWithTag (Tags.gameEngine).GetComponent <LocalVariables>(); } if (localVariables) { parameterID = Action.ChooseParameterGUI ("Variable:", parameters, parameterID, ParameterType.LocalVariable); if (parameterID >= 0) { variableID = ShowVarGUI (parameters, localVariables.localVars, variableID, false); } else { variableID = ShowVarGUI (parameters, localVariables.localVars, variableID, true); } } } }
override public void ShowGUI (List<ActionParameter> parameters) { // OLD if (isAssetFile) { oldLocation = VariableLocation.Global; } else { oldLocation = (VariableLocation) EditorGUILayout.EnumPopup ("'From' source:", oldLocation); } if (oldLocation == VariableLocation.Global) { if (!variablesManager) { variablesManager = AdvGame.GetReferences ().variablesManager; } if (variablesManager) { oldVariableID = ShowVarGUI (variablesManager.vars, parameters, ParameterType.GlobalVariable, oldVariableID, oldParameterID, false); } } else if (oldLocation == VariableLocation.Local) { if (!localVariables && GameObject.FindWithTag (Tags.gameEngine) && GameObject.FindWithTag (Tags.gameEngine).GetComponent<LocalVariables>()) { localVariables = GameObject.FindWithTag (Tags.gameEngine).GetComponent <LocalVariables>(); } if (localVariables) { oldVariableID = ShowVarGUI (localVariables.localVars, parameters, ParameterType.LocalVariable, oldVariableID, oldParameterID, false); } } EditorGUILayout.Space (); // NEW if (isAssetFile) { newLocation = VariableLocation.Global; } else { newLocation = (VariableLocation) EditorGUILayout.EnumPopup ("'To' source:", newLocation); } if (newLocation == VariableLocation.Global) { if (!variablesManager) { variablesManager = AdvGame.GetReferences ().variablesManager; } if (variablesManager) { newVariableID = ShowVarGUI (variablesManager.vars, parameters, ParameterType.GlobalVariable, newVariableID, newParameterID, true); } } else if (newLocation == VariableLocation.Local) { if (!localVariables && GameObject.FindWithTag (Tags.gameEngine) && GameObject.FindWithTag (Tags.gameEngine).GetComponent<LocalVariables>()) { localVariables = GameObject.FindWithTag (Tags.gameEngine).GetComponent <LocalVariables>(); } if (localVariables) { newVariableID = ShowVarGUI (localVariables.localVars, parameters, ParameterType.LocalVariable, newVariableID, newParameterID, true); } } // Types match? if (oldParameterID == -1 && newParameterID == -1 && newVarType != oldVarType) { EditorGUILayout.HelpBox ("The chosen Variables do not share the same Type", MessageType.Warning); } AfterRunningOption (); }
private int ShowVarGUI (List<ActionParameter> parameters, List<GVar> vars, int ID, bool changeID) { if (vars.Count > 0) { if (changeID) { ID = ShowVarSelectorGUI (vars, ID); } variableNumber = Mathf.Min (variableNumber, vars.Count-1); getVarMethod = (GetVarMethod) EditorGUILayout.EnumPopup ("Compare with:", getVarMethod); if (parameters == null || parameters.Count == 0) { EditorGUILayout.BeginHorizontal (); } if (vars [variableNumber].type == VariableType.Boolean) { boolCondition = (BoolCondition) EditorGUILayout.EnumPopup (boolCondition); if (getVarMethod == GetVarMethod.EnteredValue) { checkParameterID = Action.ChooseParameterGUI ("Boolean:", parameters, checkParameterID, ParameterType.Boolean); if (checkParameterID < 0) { boolValue = (BoolValue) EditorGUILayout.EnumPopup ("Boolean:", boolValue); } } } else if (vars [variableNumber].type == VariableType.Integer) { intCondition = (IntCondition) EditorGUILayout.EnumPopup (intCondition); if (getVarMethod == GetVarMethod.EnteredValue) { checkParameterID = Action.ChooseParameterGUI ("Integer:", parameters, checkParameterID, ParameterType.Integer); if (checkParameterID < 0) { intValue = EditorGUILayout.IntField ("Integer:", intValue); } } } else if (vars [variableNumber].type == VariableType.PopUp) { intCondition = (IntCondition) EditorGUILayout.EnumPopup (intCondition); if (getVarMethod == GetVarMethod.EnteredValue) { checkParameterID = Action.ChooseParameterGUI ("Value:", parameters, checkParameterID, ParameterType.Integer); if (checkParameterID < 0) { intValue = EditorGUILayout.Popup ("Value:", intValue, vars [variableNumber].popUps); } } } else if (vars [variableNumber].type == VariableType.Float) { intCondition = (IntCondition) EditorGUILayout.EnumPopup (intCondition); if (getVarMethod == GetVarMethod.EnteredValue) { checkParameterID = Action.ChooseParameterGUI ("Float:", parameters, checkParameterID, ParameterType.Float); if (checkParameterID < 0) { floatValue = EditorGUILayout.FloatField ("Float:", floatValue); } } } else if (vars [variableNumber].type == VariableType.String) { boolCondition = (BoolCondition) EditorGUILayout.EnumPopup (boolCondition); if (getVarMethod == GetVarMethod.EnteredValue) { checkParameterID = Action.ChooseParameterGUI ("String:", parameters, checkParameterID, ParameterType.String); if (checkParameterID < 0) { stringValue = EditorGUILayout.TextField ("String:", stringValue); } } } if (getVarMethod == GetVarMethod.GlobalVariable) { if (!variablesManager) { variablesManager = AdvGame.GetReferences ().variablesManager; } if (variablesManager == null || variablesManager.vars == null || variablesManager.vars.Count == 0) { EditorGUILayout.HelpBox ("No Global variables exist!", MessageType.Info); } else { checkParameterID = Action.ChooseParameterGUI ("Global variable:", parameters, checkParameterID, ParameterType.GlobalVariable); if (checkParameterID < 0) { compareVariableID = ShowVarSelectorGUI (variablesManager.vars, compareVariableID); } } } else if (getVarMethod == GetVarMethod.LocalVariable) { if (!localVariables && GameObject.FindWithTag (Tags.gameEngine) && GameObject.FindWithTag (Tags.gameEngine).GetComponent<LocalVariables>()) { localVariables = GameObject.FindWithTag (Tags.gameEngine).GetComponent <LocalVariables>(); } if (localVariables == null || localVariables.localVars == null || localVariables.localVars.Count == 0) { EditorGUILayout.HelpBox ("No Local variables exist!", MessageType.Info); } else { checkParameterID = Action.ChooseParameterGUI ("Local variable:", parameters, checkParameterID, ParameterType.LocalVariable); if (checkParameterID < 0) { compareVariableID = ShowVarSelectorGUI (localVariables.localVars, compareVariableID); } } } if (parameters == null || parameters.Count == 0) { EditorGUILayout.EndHorizontal (); } } else { EditorGUILayout.HelpBox ("No variables exist!", MessageType.Info); ID = -1; variableNumber = -1; } return ID; }
private void SaveSceneData(SubScene subScene = null) { Scene scene = (subScene) ? subScene.gameObject.scene : SceneChanger.CurrentScene; SceneSettings sceneSettings = (subScene == null) ? KickStarter.sceneSettings : subScene.SceneSettings; LocalVariables localVariables = (subScene == null) ? KickStarter.localVariables : subScene.LocalVariables; List <TransformData> thisLevelTransforms = PopulateTransformData(scene); List <ScriptData> thisLevelScripts = PopulateScriptData(scene); SingleLevelData thisLevelData = new SingleLevelData(); thisLevelData.sceneNumber = (subScene == null) ? SceneChanger.CurrentSceneIndex : subScene.SceneIndex; thisLevelData.activeLists = KickStarter.actionListManager.GetSaveData(subScene); if (sceneSettings) { if (sceneSettings.navMesh) { thisLevelData.navMesh = Serializer.GetConstantID(sceneSettings.navMesh.gameObject, false); } if (sceneSettings.defaultPlayerStart) { thisLevelData.playerStart = Serializer.GetConstantID(sceneSettings.defaultPlayerStart.gameObject, false); } if (sceneSettings.sortingMap) { thisLevelData.sortingMap = Serializer.GetConstantID(sceneSettings.sortingMap.gameObject, false); } if (sceneSettings.cutsceneOnLoad) { thisLevelData.onLoadCutscene = Serializer.GetConstantID(sceneSettings.cutsceneOnLoad.gameObject, false); } if (sceneSettings.cutsceneOnStart) { thisLevelData.onStartCutscene = Serializer.GetConstantID(sceneSettings.cutsceneOnStart.gameObject, false); } if (sceneSettings.tintMap) { thisLevelData.tintMap = Serializer.GetConstantID(sceneSettings.tintMap.gameObject, false); } } if (localVariables) { thisLevelData.localVariablesData = SaveSystem.CreateVariablesData(localVariables.localVars, false, VariableLocation.Local); } thisLevelData.allTransformData = thisLevelTransforms; thisLevelData.allScriptData = thisLevelScripts; if (allLevelData == null) { allLevelData = new List <SingleLevelData>(); } for (int i = 0; i < allLevelData.Count; i++) { if (allLevelData[i].DataMatchesScene(thisLevelData)) { allLevelData[i] = thisLevelData; return; } } allLevelData.Add(thisLevelData); }
override public string SetLabel () { if (location == VariableLocation.Local && !isAssetFile) { if (!localVariables && GameObject.FindWithTag (Tags.gameEngine) && GameObject.FindWithTag (Tags.gameEngine).GetComponent<LocalVariables>()) { localVariables = GameObject.FindWithTag (Tags.gameEngine).GetComponent <LocalVariables>(); } if (localVariables) { return GetLabelString (localVariables.localVars); } } else { if (!variablesManager) { variablesManager = AdvGame.GetReferences ().variablesManager; } if (variablesManager) { return GetLabelString (variablesManager.vars); } } return ""; }
/** * <summary>Returns the value of a local Vector3 variable.</summary> * <param name = "_id">The ID number of the variable</param> * <returns>The Vector3 value of the variable</returns> */ public static Vector3 GetVector3Value(int _id) { return(LocalVariables.GetVariable(_id).vector3Val); }
private void Export() { #if UNITY_WEBPLAYER ACDebug.LogWarning("Game text cannot be exported in WebPlayer mode - please switch platform and try again."); #else if (variablesManager == null || exportColumns == null || exportColumns.Count == 0) { return; } if (variableLocation == VariableLocation.Local && allScenes) { bool canProceed = EditorUtility.DisplayDialog("Export variables", "AC will now go through your game, and collect all variables to be exported.\n\nIt is recommended to back up your project beforehand.", "OK", "Cancel"); if (!canProceed) { return; } if (!UnityVersionHandler.SaveSceneIfUserWants()) { return; } } string suggestedFilename = ""; if (AdvGame.GetReferences().settingsManager) { suggestedFilename = AdvGame.GetReferences().settingsManager.saveFileName + " - "; } if (variableLocation == VariableLocation.Local && allScenes) { suggestedFilename += " All "; } suggestedFilename += variableLocation.ToString() + " Variables.csv"; string fileName = EditorUtility.SaveFilePanel("Export variables", "Assets", suggestedFilename, "csv"); if (fileName.Length == 0) { return; } bool fail = false; List <string[]> output = new List <string[]>(); List <string> headerList = new List <string>(); headerList.Add("ID"); foreach (ExportColumn exportColumn in exportColumns) { headerList.Add(exportColumn.GetHeader()); } output.Add(headerList.ToArray()); // Global if (variableLocation == VariableLocation.Global) { List <GVar> exportVars = new List <GVar>(); foreach (GVar globalVariable in variablesManager.vars) { exportVars.Add(new GVar(globalVariable)); } foreach (GVar exportVar in exportVars) { List <string> rowList = new List <string>(); rowList.Add(exportVar.id.ToString()); foreach (ExportColumn exportColumn in exportColumns) { string cellText = exportColumn.GetCellText(exportVar, VariableLocation.Global, replaceForwardSlashes); rowList.Add(cellText); if (cellText.Contains(CSVReader.csvDelimiter)) { fail = true; ACDebug.LogError("Cannot export variables since global variable " + exportVar.id.ToString() + " (" + exportVar.label + ") contains the character '" + CSVReader.csvDelimiter + "'."); } } output.Add(rowList.ToArray()); } } // Local else if (variableLocation == VariableLocation.Local) { if (allScenes) { string originalScene = UnityVersionHandler.GetCurrentSceneFilepath(); string[] sceneFiles = AdvGame.GetSceneFiles(); foreach (string sceneFile in sceneFiles) { UnityVersionHandler.OpenScene(sceneFile); if (FindObjectOfType <LocalVariables>()) { LocalVariables localVariables = FindObjectOfType <LocalVariables>(); if (localVariables != null) { string sceneName = UnityVersionHandler.GetCurrentSceneName(); output = GatherOutput(output, localVariables.localVars, sceneName); } } } if (originalScene == "") { UnityVersionHandler.NewScene(); } else { UnityVersionHandler.OpenScene(originalScene); } } else { string sceneName = UnityVersionHandler.GetCurrentSceneName(); output = GatherOutput(output, KickStarter.localVariables.localVars, sceneName); } } // Component else if (variableLocation == VariableLocation.Component) { string sceneName = UnityVersionHandler.GetCurrentSceneName(); if (variables != null) { output = GatherOutput(output, variables.vars, sceneName); } } if (!fail) { int length = output.Count; System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int j = 0; j < length; j++) { sb.AppendLine(string.Join(CSVReader.csvDelimiter, output[j])); } if (Serializer.SaveFile(fileName, sb.ToString())) { int numExported = output.Count - 1; if (numExported == 1) { ACDebug.Log("1 " + variableLocation + " variable exported."); } else { ACDebug.Log(numExported.ToString() + " " + variableLocation + " variables exported."); } } } #endif }
/** * <summary>Sets the value of a local String variable.</summary> * <param>_id">The ID number of the variable</param> * <param>_value">The new string value of the variable</param> */ public static void SetStringValue(int _id, string _value) { LocalVariables.GetVariable(_id).textVal = _value; }
/** * <summary>Returns the value of a local String variable.</summary> * <param name = "_id">The ID number of the variable</param> * <returns>The string value of the variable</returns> */ public static string GetStringValue(int _id) { return(LocalVariables.GetVariable(_id).textVal); }
/** * <summary>Sets the value of a local Vector3 variable.</summary> * <param name = "_id">The ID number of the variable</param> * <param name = "_value">The new Vector3 value of the variable</param> */ public static void SetVector3Value(int _id, Vector3 _value) { LocalVariables.GetVariable(_id).vector3Val = _value; }
/** * <summary>Returns the value of a local Popup variable.</summary> * <param name = "_id">The ID number of the variable</param> * <returns>The string value of the variable</returns> */ public static string GetPopupValue(int _id) { return(LocalVariables.GetVariable(_id).GetValue()); }
/** * <summary>Returns the value of a local Integer variable.</summary> * <param name = "_id">The ID number of the variable</param> * <returns>The integer value of the variable</returns> */ public static int GetIntegerValue(int _id) { return(LocalVariables.GetVariable(_id).val); }
/** * <summary>Returns the value of a local Boolean variable.</summary> * <param name = "_id">The ID number of the variable</param> * <returns>The boolean value of the variable</returns> */ public static bool GetBooleanValue(int _id) { return(LocalVariables.GetVariable(_id).BooleanValue); }
public override void AssignValues(List <ActionParameter> parameters) { GameObject invPrefab = null; ActionParameter parameter = GetParameterWithID(parameters, parameterID); if (parameter != null && parameter.parameterType == ParameterType.InventoryItem) { InvItem invItem = KickStarter.inventoryManager.GetItem(parameter.intValue); if (invItem != null) { invPrefab = invItem.linkedPrefab; } } switch (invAction) { case InvAction.Add: case InvAction.Replace: if (invPrefab != null) { _gameObject = invPrefab; } else { _gameObject = AssignFile(parameters, parameterID, 0, gameObject); } if (invAction == InvAction.Replace) { replaceGameObject = AssignFile(parameters, replaceParameterID, replaceConstantID, replaceGameObject); } else if (invAction == InvAction.Add) { relativeGameObject = AssignFile(parameters, relativeGameObjectParameterID, relativeGameObjectID, relativeGameObject); } break; case InvAction.Remove: if (invPrefab != null) { ConstantID invPrefabConstantID = invPrefab.GetComponent <ConstantID> (); if (invPrefabConstantID != null && invPrefabConstantID.constantID != 0) { _gameObject = AssignFile(invPrefabConstantID.constantID, _gameObject); } else { LogWarning("Cannot locate scene instance of prefab " + invPrefab + " as it has no Constant ID number"); } } else { _gameObject = AssignFile(parameters, parameterID, constantID, gameObject); } if (_gameObject != null && !_gameObject.activeInHierarchy) { _gameObject = null; } break; default: break; } relativeVector = AssignVector3(parameters, relativeVectorParameterID, relativeVector); if (invAction == InvAction.Add && positionRelativeTo == PositionRelativeTo.VectorVariable) { runtimeVariable = null; switch (variableLocation) { case VariableLocation.Global: vectorVarID = AssignVariableID(parameters, vectorVarParameterID, vectorVarID); runtimeVariable = GlobalVariables.GetVariable(vectorVarID, true); break; case VariableLocation.Local: if (!isAssetFile) { vectorVarID = AssignVariableID(parameters, vectorVarParameterID, vectorVarID); runtimeVariable = LocalVariables.GetVariable(vectorVarID, localVariables); } break; case VariableLocation.Component: Variables runtimeVariables = AssignFile <Variables> (variablesConstantID, variables); if (runtimeVariables != null) { runtimeVariable = runtimeVariables.GetVariable(vectorVarID); } runtimeVariable = AssignVariable(parameters, vectorVarParameterID, runtimeVariable); break; } } runtimeSpawnedObjectParameter = null; if (invAction == InvAction.Add) { runtimeSpawnedObjectParameter = GetParameterWithID(parameters, spawnedObjectParameterID); if (runtimeSpawnedObjectParameter != null && runtimeSpawnedObjectParameter.parameterType != ParameterType.GameObject) { runtimeSpawnedObjectParameter = null; } } }
/** * <summary>Sets the value of a local Integer variable.</summary> * <param name = "_id">The ID number of the variable</param> * <param name = "_value">The new integer value of the variable</param> */ public static void SetIntegerValue(int _id, int _value) { LocalVariables.GetVariable(_id).IntegerValue = _value; }
private void Export() { #if UNITY_WEBPLAYER ACDebug.LogWarning("Game text cannot be exported in WebPlayer mode - please switch platform and try again."); #else if (variablesManager == null || exportColumns == null || exportColumns.Count == 0) { return; } if (variableLocation == VariableLocation.Local && allScenes) { bool canProceed = EditorUtility.DisplayDialog("Export variables", "AC will now go through your game, and collect all variables to be exported.\n\nIt is recommended to back up your project beforehand.", "OK", "Cancel"); if (!canProceed) { return; } if (!UnityEditor.SceneManagement.EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) { return; } } string suggestedFilename = ""; if (AdvGame.GetReferences().settingsManager) { suggestedFilename = AdvGame.GetReferences().settingsManager.saveFileName + " - "; } if (variableLocation == VariableLocation.Local && allScenes) { suggestedFilename += " All "; } suggestedFilename += variableLocation.ToString() + " Variables.csv"; string fileName = EditorUtility.SaveFilePanel("Export variables", "Assets", suggestedFilename, "csv"); if (fileName.Length == 0) { return; } List <string[]> output = new List <string[]>(); List <string> headerList = new List <string>(); headerList.Add("ID"); foreach (ExportColumn exportColumn in exportColumns) { headerList.Add(exportColumn.GetHeader()); } output.Add(headerList.ToArray()); // Global if (variableLocation == VariableLocation.Global) { List <GVar> exportVars = new List <GVar>(); foreach (GVar globalVariable in variablesManager.vars) { exportVars.Add(new GVar(globalVariable)); } foreach (GVar exportVar in exportVars) { List <string> rowList = new List <string>(); rowList.Add(exportVar.id.ToString()); foreach (ExportColumn exportColumn in exportColumns) { string cellText = exportColumn.GetCellText(exportVar, VariableLocation.Global, replaceForwardSlashes); rowList.Add(cellText); } output.Add(rowList.ToArray()); } } // Local else if (variableLocation == VariableLocation.Local) { if (allScenes) { string originalScene = UnityVersionHandler.GetCurrentSceneFilepath(); string[] sceneFiles = AdvGame.GetSceneFiles(); foreach (string sceneFile in sceneFiles) { UnityVersionHandler.OpenScene(sceneFile); if (FindObjectOfType <LocalVariables>()) { LocalVariables localVariables = FindObjectOfType <LocalVariables>(); if (localVariables != null) { string sceneName = UnityVersionHandler.GetCurrentSceneName(); output = GatherOutput(output, localVariables.localVars, sceneName); } } } if (string.IsNullOrEmpty(originalScene)) { UnityVersionHandler.NewScene(); } else { UnityVersionHandler.OpenScene(originalScene); } } else { string sceneName = UnityVersionHandler.GetCurrentSceneName(); output = GatherOutput(output, KickStarter.localVariables.localVars, sceneName); } } // Component else if (variableLocation == VariableLocation.Component) { string sceneName = UnityVersionHandler.GetCurrentSceneName(); if (variables != null) { output = GatherOutput(output, variables.vars, sceneName); } } string fileContents = CSVReader.CreateCSVGrid(output); if (!string.IsNullOrEmpty(fileContents) && Serializer.SaveFile(fileName, fileContents)) { int numExported = output.Count - 1; if (numExported == 1) { ACDebug.Log("1 " + variableLocation + " variable exported."); } else { ACDebug.Log(numExported.ToString() + " " + variableLocation + " variables exported."); } } #endif }
/** * <summary>Sets the value of a local Boolean variable.</summary> * <param name = "_id">The ID number of the variable</param> * <param name = "_value">The new bool value of the variable</param> */ public static void SetBooleanValue(int _id, bool _value) { LocalVariables.GetVariable(_id).BooleanValue = _value; }
private void UnloadVariablesData(string data, LocalVariables localVariables) { if (data == null) { return; } if (data.Length > 0) { string[] varsArray = data.Split(SaveSystem.pipe[0]); foreach (string chunk in varsArray) { string[] chunkData = chunk.Split(SaveSystem.colon[0]); int _id = 0; int.TryParse(chunkData[0], out _id); GVar _var = LocalVariables.GetVariable(_id, localVariables); if (_var != null) { if (_var.type == VariableType.String) { string _text = chunkData[1]; _var.SetStringValue(_text); } else if (_var.type == VariableType.Float) { float _value = 0f; float.TryParse(chunkData[1], out _value); _var.SetFloatValue(_value, SetVarMethod.SetValue); } else if (_var.type == VariableType.Vector3) { string _text = chunkData[1]; _text = AdvGame.PrepareStringForLoading(_text); Vector3 _value = Vector3.zero; string[] valuesArray = _text.Split(","[0]); if (valuesArray != null && valuesArray.Length == 3) { float xValue = 0f; float.TryParse(valuesArray[0], out xValue); float yValue = 0f; float.TryParse(valuesArray[1], out yValue); float zValue = 0f; float.TryParse(valuesArray[2], out zValue); _value = new Vector3(xValue, yValue, zValue); } _var.SetVector3Value(_value); } else { int _value = 0; int.TryParse(chunkData[1], out _value); _var.SetValue(_value, SetVarMethod.SetValue); } } } } }
override public void ShowGUI (List<ActionParameter> parameters) { if (isAssetFile) { location = VariableLocation.Global; } else { location = (VariableLocation) EditorGUILayout.EnumPopup ("Source:", location); } if (location == VariableLocation.Global) { if (!variablesManager) { variablesManager = AdvGame.GetReferences ().variablesManager; } if (variablesManager) { parameterID = Action.ChooseParameterGUI ("Integer variable:", parameters, parameterID, ParameterType.GlobalVariable); if (parameterID >= 0) { variableID = ShowVarGUI (variablesManager.vars, variableID, false); } else { variableID = ShowVarGUI (variablesManager.vars, variableID, true); } } } else if (location == VariableLocation.Local) { if (!localVariables && GameObject.FindWithTag (Tags.gameEngine) && GameObject.FindWithTag (Tags.gameEngine).GetComponent<LocalVariables>()) { localVariables = GameObject.FindWithTag (Tags.gameEngine).GetComponent <LocalVariables>(); } if (localVariables) { parameterID = Action.ChooseParameterGUI ("Integer variable:", parameters, parameterID, ParameterType.LocalVariable); if (parameterID >= 0) { variableID = ShowVarGUI (localVariables.localVars, variableID, false); } else { variableID = ShowVarGUI (localVariables.localVars, variableID, true); } } } numSockets = EditorGUILayout.IntSlider ("# of possible values:", numSockets, 1, 10); doLoop = EditorGUILayout.Toggle ("Run on a loop?", doLoop); }