public void CopyButton (Button _button) { interaction = _button.interaction; assetFile = _button.assetFile; customScriptObject = _button.customScriptObject; customScriptFunction = _button.customScriptFunction; isDisabled = _button.isDisabled; invID = _button.invID; iconID = _button.iconID; playerAction = _button.playerAction; setProximity = _button.setProximity; proximity = _button.proximity; faceAfter = _button.faceAfter; isBlocking = _button.isBlocking; }
private void ButtonGUI (Button button, string suffix, InteractionSource source) { bool isEnabled = !button.isDisabled; isEnabled = EditorGUILayout.Toggle ("Enabled:", isEnabled); button.isDisabled = !isEnabled; if (source == InteractionSource.AssetFile) { button.assetFile = (ActionListAsset) EditorGUILayout.ObjectField ("Interaction:", button.assetFile, typeof (ActionListAsset), false); } else if (source == InteractionSource.CustomScript) { button.customScriptObject = (GameObject) EditorGUILayout.ObjectField ("Object with script:", button.customScriptObject, typeof (GameObject), true); button.customScriptFunction = EditorGUILayout.TextField ("Message to send:", button.customScriptFunction); } else if (source == InteractionSource.InScene) { EditorGUILayout.BeginHorizontal (); button.interaction = (Interaction) EditorGUILayout.ObjectField ("Interaction:", button.interaction, typeof (Interaction), true); if (button.interaction == null) { if (GUILayout.Button ("Auto-create", autoWidth)) { Undo.RecordObject (_target, "Create Interaction"); Interaction newInteraction = AdvGame.GetReferences ().sceneManager.AddPrefab ("Logic", "Interaction", true, false, true).GetComponent <Interaction>(); string hotspotName = _target.gameObject.name; if (_target.hotspotName != "") { hotspotName = _target.hotspotName; } newInteraction.gameObject.name = AdvGame.UniqueName (suffix + ": " + hotspotName); button.interaction = newInteraction; } } EditorGUILayout.EndHorizontal (); } button.playerAction = (PlayerAction) EditorGUILayout.EnumPopup ("Player action:", button.playerAction); if (button.playerAction == PlayerAction.WalkTo || button.playerAction == PlayerAction.WalkToMarker) { button.isBlocking = EditorGUILayout.Toggle ("Cutscene while moving?", button.isBlocking); button.faceAfter = EditorGUILayout.Toggle ("Face after moving?", button.faceAfter); if (button.playerAction == PlayerAction.WalkTo) { button.setProximity = EditorGUILayout.Toggle ("Set minimum distance?", button.setProximity); if (button.setProximity) { button.proximity = EditorGUILayout.FloatField ("Proximity:", button.proximity); } } } }
public void StopInteraction () { button = null; StopCoroutine ("UseObject"); }
private IEnumerator UseObject (int selectedItemID) { bool doRun = false; if (playerInput.hotspotMovingTo == hotspot) { doRun = true; } if (playerInput != null && playerInput.runLock == PlayerMoveLock.AlwaysWalk) { doRun = false; } if (KickStarter.player) { if (button != null && !button.isBlocking && (button.playerAction == PlayerAction.WalkToMarker || button.playerAction == PlayerAction.WalkTo) && settingsManager.movementMethod != MovementMethod.UltimateFPS) { stateHandler.gameState = GameState.Normal; playerInput.hotspotMovingTo = hotspot; } else { stateHandler.gameState = GameState.Cutscene; playerInput.hotspotMovingTo = null; } } Hotspot _hotspot = hotspot; hotspot.Deselect (); hotspot = null; if (KickStarter.player) { if (button != null && button.playerAction != PlayerAction.DoNothing) { Vector3 lookVector = Vector3.zero; Vector3 targetPos = _hotspot.transform.position; if (settingsManager.ActInScreenSpace ()) { lookVector = AdvGame.GetScreenDirection (KickStarter.player.transform.position, _hotspot.transform.position); } else { lookVector = targetPos - KickStarter.player.transform.position; lookVector.y = 0; } KickStarter.player.SetLookDirection (lookVector, false); if (button.playerAction == PlayerAction.TurnToFace) { while (KickStarter.player.IsTurning ()) { yield return new WaitForFixedUpdate (); } } if (button.playerAction == PlayerAction.WalkToMarker && _hotspot.walkToMarker) { if (Vector3.Distance (KickStarter.player.transform.position, _hotspot.walkToMarker.transform.position) > (1.05f - settingsManager.destinationAccuracy)) { if (GetComponent <NavigationManager>()) { Vector3[] pointArray; Vector3 targetPosition = _hotspot.walkToMarker.transform.position; if (settingsManager.ActInScreenSpace ()) { targetPosition = AdvGame.GetScreenNavMesh (targetPosition); } pointArray = GetComponent <NavigationManager>().navigationEngine.GetPointsArray (KickStarter.player.transform.position, targetPosition); KickStarter.player.MoveAlongPoints (pointArray, doRun); targetPos = pointArray [pointArray.Length - 1]; } while (KickStarter.player.activePath) { yield return new WaitForFixedUpdate (); } } if (button.faceAfter) { lookVector = _hotspot.walkToMarker.transform.forward; lookVector.y = 0; KickStarter.player.Halt (); KickStarter.player.SetLookDirection (lookVector, false); while (KickStarter.player.IsTurning ()) { yield return new WaitForFixedUpdate (); } } } else if (lookVector.magnitude > 2f && button.playerAction == PlayerAction.WalkTo) { if (GetComponent <NavigationManager>()) { Vector3[] pointArray; Vector3 targetPosition = _hotspot.transform.position; if (_hotspot.walkToMarker) { targetPosition = _hotspot.walkToMarker.transform.position; } if (settingsManager.ActInScreenSpace ()) { targetPosition = AdvGame.GetScreenNavMesh (targetPosition); } pointArray = GetComponent <NavigationManager>().navigationEngine.GetPointsArray (KickStarter.player.transform.position, targetPosition); KickStarter.player.MoveAlongPoints (pointArray, doRun); targetPos = pointArray [pointArray.Length - 1]; } if (button.setProximity) { button.proximity = Mathf.Max (button.proximity, 1f); targetPos.y = KickStarter.player.transform.position.y; while (Vector3.Distance (KickStarter.player.transform.position, targetPos) > button.proximity && KickStarter.player.activePath) { yield return new WaitForFixedUpdate (); } } else { yield return new WaitForSeconds (0.6f); } if (button.faceAfter) { if (settingsManager.ActInScreenSpace ()) { lookVector = AdvGame.GetScreenDirection (KickStarter.player.transform.position, _hotspot.transform.position); } else { lookVector = _hotspot.transform.position - KickStarter.player.transform.position; lookVector.y = 0; } KickStarter.player.Halt (); KickStarter.player.SetLookDirection (lookVector, false); while (KickStarter.player.IsTurning ()) { yield return new WaitForFixedUpdate (); } } } } else { KickStarter.player.charState = CharState.Decelerate; } KickStarter.player.EndPath (); playerInput.hotspotMovingTo = null; yield return new WaitForSeconds (0.1f); KickStarter.player.EndPath (); playerInput.hotspotMovingTo = null; } _hotspot.Deselect (); hotspot = null; if (KickStarter.player) { KickStarter.player.ClearHeadTurnTarget (HeadFacing.Hotspot, false); } if (button == null) { // Unhandled event if (selectedItemID >= 0 && runtimeInventory.GetItem (selectedItemID) != null && runtimeInventory.GetItem (selectedItemID).unhandledActionList) { ActionListAsset unhandledActionList = runtimeInventory.GetItem (selectedItemID).unhandledActionList; runtimeInventory.SetNull (); AdvGame.RunActionListAsset (unhandledActionList); } else if (selectedItemID >= 0 && runtimeInventory.unhandledHotspot) { runtimeInventory.SetNull (); AdvGame.RunActionListAsset (runtimeInventory.unhandledHotspot); } else { stateHandler.gameState = GameState.Normal; if (settingsManager.inventoryDragDrop) { runtimeInventory.SetNull (); } } } else { runtimeInventory.SetNull (); if (_hotspot.interactionSource == InteractionSource.AssetFile) { AdvGame.RunActionListAsset (button.assetFile); } else if (_hotspot.interactionSource == InteractionSource.CustomScript) { if (button.customScriptObject != null && button.customScriptFunction != "") { button.customScriptObject.SendMessage (button.customScriptFunction); } } else if (_hotspot.interactionSource == InteractionSource.InScene) { if (button.interaction) { button.interaction.Interact (); } else { stateHandler.gameState = GameState.Normal; } } } button = null; }
public void ClickButton (InteractionType _interactionType, int selectedCursorID, int selectedItemID) { StopCoroutine ("UseObject"); if (KickStarter.player) { KickStarter.player.EndPath (); } if (settingsManager.interactionMethod == AC_InteractionMethod.ChooseHotspotThenInteraction && settingsManager.selectInteractions == SelectInteractions.CyclingCursorAndClickingHotspot) { if (settingsManager.autoCycleWhenInteract) { SetNextInteraction (); } else { ResetInteractionIndex (); } hotspot.lastInteractionIndex = interactionIndex; } else if (settingsManager.interactionMethod == AC_InteractionMethod.ChooseInteractionThenHotspot && settingsManager.autoCycleWhenInteract) { playerCursor.ResetSelectedCursor (); } playerInput.mouseState = MouseState.Normal; playerInput.ResetClick (); button = null; if (_interactionType == InteractionType.Use) { if (selectedCursorID == -1) { button = hotspot.GetFirstUseButton (); } else { foreach (Button _button in hotspot.useButtons) { if (_button.iconID == selectedCursorID) { button = _button; break; } } if (button == null && settingsManager.interactionMethod == AC_InteractionMethod.ChooseInteractionThenHotspot) { AdvGame.RunActionListAsset (cursorManager.GetUnhandledInteraction (selectedCursorID)); runtimeInventory.SetNull (); KickStarter.player.ClearHeadTurnTarget (HeadFacing.Hotspot, false); return; } } } else if (_interactionType == InteractionType.Examine) { button = hotspot.lookButton; } else if (_interactionType == InteractionType.Inventory && selectedItemID >= 0) { foreach (Button invButton in hotspot.invButtons) { if (invButton.invID == selectedItemID) { button = invButton; break; } } } if (button != null && button.isDisabled) { button = null; if (_interactionType != InteractionType.Inventory) { KickStarter.player.ClearHeadTurnTarget (HeadFacing.Hotspot, false); return; } } StartCoroutine ("UseObject", selectedItemID); }
/** * <summary>Handles the clicking of a Hotspot, and runs the appropriate interaction based on the current cursor and inventory.</summary> * <param name = "_interactionType">The type of interaction to run (Use, Examine, Inventory)</param> * <param name = "selectedCursorID">The ID number of the current cursor, if _interactionType = InteractionType.Use</param> * <param name = "selectedItemID">The ID number of the current inventory item (see InvItem), if _interactionType = InteractionType.Inventory</param> * <param name = "clickedHotspot">The Hotspot that was clicked on</param> */ public void ClickButton(InteractionType _interactionType, int selectedCursorID, int selectedItemID, Hotspot clickedHotspot = null) { inPreInteractionCutscene = false; StopCoroutine ("UseObject"); if (clickedHotspot != null) { hotspot = clickedHotspot; } if (KickStarter.player) { KickStarter.player.EndPath (); } if (KickStarter.settingsManager.interactionMethod == AC_InteractionMethod.ChooseHotspotThenInteraction && KickStarter.settingsManager.selectInteractions == SelectInteractions.CyclingCursorAndClickingHotspot) { if (KickStarter.settingsManager.autoCycleWhenInteract) { SetNextInteraction (); } else { ResetInteractionIndex (); } } else if (KickStarter.settingsManager.interactionMethod == AC_InteractionMethod.ChooseInteractionThenHotspot && KickStarter.settingsManager.autoCycleWhenInteract) { KickStarter.playerCursor.ResetSelectedCursor (); } KickStarter.playerInput.ResetMouseClick (); KickStarter.playerInput.ResetClick (); button = null; if (_interactionType == InteractionType.Use) { if (selectedCursorID == -1) { button = hotspot.GetFirstUseButton (); } else { foreach (Button _button in hotspot.useButtons) { if (_button.iconID == selectedCursorID && !_button.isDisabled) { button = _button; break; } } if (button == null && KickStarter.settingsManager.interactionMethod == AC_InteractionMethod.ChooseInteractionThenHotspot) { AdvGame.RunActionListAsset (KickStarter.cursorManager.GetUnhandledInteraction (selectedCursorID)); KickStarter.runtimeInventory.SetNull (); KickStarter.player.ClearHeadTurnTarget (false, HeadFacing.Hotspot); return; } } } else if (_interactionType == InteractionType.Examine) { button = hotspot.lookButton; } else if (_interactionType == InteractionType.Inventory && selectedItemID >= 0) { foreach (Button invButton in hotspot.invButtons) { if (invButton.invID == selectedItemID && !invButton.isDisabled) { if ((KickStarter.runtimeInventory.IsGivingItem () && invButton.selectItemMode == SelectItemMode.Give) || (!KickStarter.runtimeInventory.IsGivingItem () && invButton.selectItemMode == SelectItemMode.Use)) { button = invButton; break; } } } } if (button != null && button.isDisabled) { button = null; if (_interactionType != InteractionType.Inventory) { KickStarter.player.ClearHeadTurnTarget (false, HeadFacing.Hotspot); return; } } StartCoroutine ("UseObject", selectedItemID); }
private void StopInteraction() { button = null; inPreInteractionCutscene = false; StopCoroutine ("UseObject"); }
public bool UpgradeSelf() { if (useButton.IsButtonModified ()) { Button newUseButton = new Button (); newUseButton.CopyButton (useButton); useButtons.Add (newUseButton); useButton = new Button (); provideUseInteraction = true; if (Application.isPlaying) { Debug.Log ("Hotspot '" + gameObject.name + "' has been temporarily upgraded - please view it's Inspector when the game ends and save the scene."); } else { Debug.Log ("Upgraded Hotspot '" + gameObject.name + "', please save the scene."); } return true; } return false; }
private IEnumerator UseObject(int selectedItemID) { bool doRun = false; bool doSnap = false; if (hotspotMovingTo == hotspot && KickStarter.playerInput.LastClickWasDouble ()) { if (hotspotMovingTo.doubleClickingHotspot == DoubleClickingHotspot.TriggersInteractionInstantly) { doSnap = true; } else { doRun = true; } } if (KickStarter.playerInput != null && KickStarter.playerInput.runLock == PlayerMoveLock.AlwaysWalk) { doRun = false; } if (KickStarter.player) { if (button != null && !button.isBlocking && (button.playerAction == PlayerAction.WalkToMarker || button.playerAction == PlayerAction.WalkTo)) { KickStarter.stateHandler.gameState = GameState.Normal; hotspotMovingTo = hotspot; } else { if (button != null && button.playerAction != PlayerAction.DoNothing) { inPreInteractionCutscene = true; KickStarter.stateHandler.gameState = GameState.Cutscene; } else { KickStarter.stateHandler.gameState = GameState.Normal; } hotspotMovingTo = null; } } Hotspot _hotspot = hotspot; if (KickStarter.player == null || inPreInteractionCutscene || (button != null && button.playerAction == PlayerAction.DoNothing)) { DeselectHotspot (); } if (KickStarter.player) { if (button != null && button.playerAction != PlayerAction.DoNothing) { Vector3 lookVector = Vector3.zero; Vector3 targetPos = _hotspot.transform.position; if (KickStarter.settingsManager.ActInScreenSpace ()) { lookVector = AdvGame.GetScreenDirection (KickStarter.player.transform.position, _hotspot.transform.position); } else { lookVector = targetPos - KickStarter.player.transform.position; lookVector.y = 0; } KickStarter.player.SetLookDirection (lookVector, false); if (button.playerAction == PlayerAction.TurnToFace) { while (KickStarter.player.IsTurning ()) { yield return new WaitForFixedUpdate (); } } if (button.playerAction == PlayerAction.WalkToMarker && _hotspot.walkToMarker) { if (Vector3.Distance (KickStarter.player.transform.position, _hotspot.walkToMarker.transform.position) > KickStarter.settingsManager.GetDestinationThreshold ()) { if (KickStarter.navigationManager) { Vector3[] pointArray; Vector3 targetPosition = _hotspot.walkToMarker.transform.position; if (KickStarter.settingsManager.ActInScreenSpace ()) { targetPosition = AdvGame.GetScreenNavMesh (targetPosition); } pointArray = KickStarter.navigationManager.navigationEngine.GetPointsArray (KickStarter.player.transform.position, targetPosition, KickStarter.player); KickStarter.player.MoveAlongPoints (pointArray, doRun); targetPos = pointArray [pointArray.Length - 1]; } while (KickStarter.player.GetPath ()) { if (doSnap) { KickStarter.player.Teleport (targetPos); break; } yield return new WaitForFixedUpdate (); } } if (button.faceAfter) { lookVector = _hotspot.walkToMarker.transform.forward; lookVector.y = 0; KickStarter.player.EndPath (); KickStarter.player.SetLookDirection (lookVector, false); while (KickStarter.player.IsTurning ()) { if (doSnap) { KickStarter.player.SetLookDirection (lookVector, true); break; } yield return new WaitForFixedUpdate (); } } } else if (button.playerAction == PlayerAction.WalkTo) { float dist = Vector3.Distance (KickStarter.player.transform.position, targetPos); if (_hotspot.walkToMarker) { dist = Vector3.Distance (KickStarter.player.transform.position, _hotspot.walkToMarker.transform.position); } if ((button.setProximity && dist > button.proximity) || (!button.setProximity && dist > 2f)) { if (KickStarter.navigationManager) { Vector3[] pointArray; Vector3 targetPosition = _hotspot.transform.position; if (_hotspot.walkToMarker) { targetPosition = _hotspot.walkToMarker.transform.position; } if (KickStarter.settingsManager.ActInScreenSpace ()) { targetPosition = AdvGame.GetScreenNavMesh (targetPosition); } pointArray = KickStarter.navigationManager.navigationEngine.GetPointsArray (KickStarter.player.transform.position, targetPosition, KickStarter.player); KickStarter.player.MoveAlongPoints (pointArray, doRun); targetPos = pointArray [pointArray.Length - 1]; } if (button.setProximity) { button.proximity = Mathf.Max (button.proximity, 1f); targetPos.y = KickStarter.player.transform.position.y; while (Vector3.Distance (KickStarter.player.transform.position, targetPos) > button.proximity && KickStarter.player.GetPath ()) { if (doSnap) { break; } yield return new WaitForFixedUpdate (); } } else { if (!doSnap) { yield return new WaitForSeconds (0.6f); } } } if (button.faceAfter) { if (KickStarter.settingsManager.ActInScreenSpace ()) { lookVector = AdvGame.GetScreenDirection (KickStarter.player.transform.position, _hotspot.transform.position); } else { lookVector = _hotspot.transform.position - KickStarter.player.transform.position; lookVector.y = 0; } KickStarter.player.EndPath (); KickStarter.player.SetLookDirection (lookVector, false); while (KickStarter.player.IsTurning ()) { if (doSnap) { KickStarter.player.SetLookDirection (lookVector, true); } yield return new WaitForFixedUpdate (); } } } } else { KickStarter.player.charState = CharState.Decelerate; } KickStarter.player.EndPath (); hotspotMovingTo = null; // yield return new WaitForSeconds (0.1f); // KickStarter.player.EndPath (); hotspotMovingTo = null; } DeselectHotspot (); inPreInteractionCutscene = false; KickStarter.playerMenus.SetInteractionMenus (false); if (KickStarter.player) { KickStarter.player.ClearHeadTurnTarget (false, HeadFacing.Hotspot); } if (button == null) { // Unhandled event if (selectedItemID >= 0 && KickStarter.runtimeInventory.GetItem (selectedItemID) != null && KickStarter.runtimeInventory.GetItem (selectedItemID).unhandledActionList) { ActionListAsset unhandledActionList = KickStarter.runtimeInventory.GetItem (selectedItemID).unhandledActionList; KickStarter.runtimeInventory.SetNull (); AdvGame.RunActionListAsset (unhandledActionList); } else if (selectedItemID >= 0 && KickStarter.runtimeInventory.unhandledGive && KickStarter.runtimeInventory.IsGivingItem ()) { KickStarter.runtimeInventory.SetNull (); AdvGame.RunActionListAsset (KickStarter.runtimeInventory.unhandledGive); } else if (selectedItemID >= 0 && KickStarter.runtimeInventory.unhandledHotspot && !KickStarter.runtimeInventory.IsGivingItem ()) { KickStarter.runtimeInventory.SetNull (); AdvGame.RunActionListAsset (KickStarter.runtimeInventory.unhandledHotspot); } else { KickStarter.stateHandler.gameState = GameState.Normal; if (KickStarter.settingsManager.inventoryDragDrop) { KickStarter.runtimeInventory.SetNull (); } } } else { KickStarter.runtimeInventory.SetNull (); if (_hotspot.interactionSource == InteractionSource.AssetFile) { AdvGame.RunActionListAsset (button.assetFile); } else if (_hotspot.interactionSource == InteractionSource.CustomScript) { if (button.customScriptObject != null && button.customScriptFunction != "") { button.customScriptObject.SendMessage (button.customScriptFunction); } } else if (_hotspot.interactionSource == InteractionSource.InScene) { if (button.interaction) { button.interaction.Interact (); } else { KickStarter.stateHandler.gameState = GameState.Normal; } } } button = null; }
private void ButtonGUI(Button button, string suffix, InteractionSource source) { bool isEnabled = !button.isDisabled; isEnabled = EditorGUILayout.Toggle ("Enabled:", isEnabled); button.isDisabled = !isEnabled; if (source == InteractionSource.AssetFile) { button.assetFile = (ActionListAsset) EditorGUILayout.ObjectField ("Interaction:", button.assetFile, typeof (ActionListAsset), false); } else if (source == InteractionSource.CustomScript) { button.customScriptObject = (GameObject) EditorGUILayout.ObjectField ("Object with script:", button.customScriptObject, typeof (GameObject), true); button.customScriptFunction = EditorGUILayout.TextField ("Message to send:", button.customScriptFunction); } else if (source == InteractionSource.InScene) { EditorGUILayout.BeginHorizontal (); button.interaction = (Interaction) EditorGUILayout.ObjectField ("Interaction:", button.interaction, typeof (Interaction), true); if (button.interaction == null) { if (GUILayout.Button ("Create", autoWidth)) { Undo.RecordObject (_target, "Create Interaction"); Interaction newInteraction = SceneManager.AddPrefab ("Logic", "Interaction", true, false, true).GetComponent <Interaction>(); string hotspotName = _target.gameObject.name; if (_target != null && _target.hotspotName != null && _target.hotspotName.Length > 0) { hotspotName = _target.hotspotName; } newInteraction.gameObject.name = AdvGame.UniqueName (hotspotName + ": " + suffix); button.interaction = newInteraction; } } EditorGUILayout.EndHorizontal (); } button.playerAction = (PlayerAction) EditorGUILayout.EnumPopup ("Player action:", button.playerAction); if (button.playerAction == PlayerAction.WalkTo || button.playerAction == PlayerAction.WalkToMarker) { if (button.playerAction == PlayerAction.WalkToMarker && _target.walkToMarker == null) { EditorGUILayout.HelpBox ("You must assign a 'Walk-to marker' above for this option to work.", MessageType.Warning); } if (KickStarter.settingsManager == null || KickStarter.settingsManager.movementMethod != MovementMethod.UltimateFPS) { button.isBlocking = EditorGUILayout.Toggle ("Cutscene while moving?", button.isBlocking); } button.faceAfter = EditorGUILayout.Toggle ("Face after moving?", button.faceAfter); if (button.playerAction == PlayerAction.WalkTo) { button.setProximity = EditorGUILayout.Toggle ("Set minimum distance?", button.setProximity); if (button.setProximity) { button.proximity = EditorGUILayout.FloatField ("Proximity:", button.proximity); } } } }