This commit is contained in:
2025-01-17 13:10:42 +01:00
commit 4536213c91
15115 changed files with 1442174 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
{
"displayName": "In-Game Hints",
"description": "Demonstrates how to create in-game hints in the UI which reflect current bindings and active control schemes."
}

View File

@@ -0,0 +1,440 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator
// version 1.11.2
// from Assets/Samples/InGameHints/InGameHintsActions.inputactions
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
namespace UnityEngine.InputSystem.Samples.InGameHints
{
public partial class @InGameHintsActions: IInputActionCollection2, IDisposable
{
public InputActionAsset asset { get; }
public @InGameHintsActions()
{
asset = InputActionAsset.FromJson(@"{
""name"": ""InGameHintsActions"",
""maps"": [
{
""name"": ""Gameplay"",
""id"": ""9af2d1b0-cc47-4300-854c-838acb4b168b"",
""actions"": [
{
""name"": ""Move"",
""type"": ""Value"",
""id"": ""7e7492e7-1329-48bb-9fdc-279fd15473b4"",
""expectedControlType"": ""Vector2"",
""processors"": """",
""interactions"": """",
""initialStateCheck"": true
},
{
""name"": ""Look"",
""type"": ""Value"",
""id"": ""981fecc2-2e7a-4d6a-b041-00b47626e0a1"",
""expectedControlType"": ""Vector2"",
""processors"": """",
""interactions"": """",
""initialStateCheck"": true
},
{
""name"": ""PickUp"",
""type"": ""Button"",
""id"": ""5a59bbc2-a3d4-4cbd-88bb-01120d97dc69"",
""expectedControlType"": """",
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
},
{
""name"": ""Drop"",
""type"": ""Button"",
""id"": ""f37bbe7e-e241-443f-b868-c784e1219f25"",
""expectedControlType"": """",
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
},
{
""name"": ""Throw"",
""type"": ""Button"",
""id"": ""e450d71c-7cc5-4879-afb5-f3ed682d9824"",
""expectedControlType"": """",
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
}
],
""bindings"": [
{
""name"": """",
""id"": ""5abc4d20-74bd-4f14-902f-2bd2cf59cc28"",
""path"": ""<Gamepad>/leftStick"",
""interactions"": """",
""processors"": """",
""groups"": ""Gamepad"",
""action"": ""Move"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": ""WASD"",
""id"": ""b16141b1-1611-44db-9576-5a004eb451f2"",
""path"": ""2DVector"",
""interactions"": """",
""processors"": """",
""groups"": ""Keyboard&Mouse"",
""action"": ""Move"",
""isComposite"": true,
""isPartOfComposite"": false
},
{
""name"": ""up"",
""id"": ""2b20de3f-1ad8-4b42-b591-595edf60dced"",
""path"": ""<Keyboard>/w"",
""interactions"": """",
""processors"": """",
""groups"": ""Keyboard&Mouse"",
""action"": ""Move"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""down"",
""id"": ""2f92eaa9-7f1f-4f42-9682-d105f7c2fc22"",
""path"": ""<Keyboard>/s"",
""interactions"": """",
""processors"": """",
""groups"": ""Keyboard&Mouse"",
""action"": ""Move"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""left"",
""id"": ""3ba79a56-c5f8-4999-8203-bef8471f4bd8"",
""path"": ""<Keyboard>/a"",
""interactions"": """",
""processors"": """",
""groups"": ""Keyboard&Mouse"",
""action"": ""Move"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""right"",
""id"": ""8d9acfe6-d844-4860-a151-01d6eb0dfb48"",
""path"": ""<Keyboard>/d"",
""interactions"": """",
""processors"": """",
""groups"": ""Keyboard&Mouse"",
""action"": ""Move"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": """",
""id"": ""b69cbeb7-a5bf-4df1-8965-17d944634cef"",
""path"": ""<Gamepad>/rightStick"",
""interactions"": """",
""processors"": """",
""groups"": ""Gamepad"",
""action"": ""Look"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""b2ddefc9-49da-485d-be28-58e3ec3f8080"",
""path"": ""<Mouse>/delta"",
""interactions"": """",
""processors"": """",
""groups"": ""Keyboard&Mouse"",
""action"": ""Look"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""92182492-7b62-47e0-94ad-53d9937d9905"",
""path"": ""<Gamepad>/buttonSouth"",
""interactions"": """",
""processors"": """",
""groups"": ""Gamepad"",
""action"": ""PickUp"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""e20635aa-ffe7-4ed9-8802-96c039d26a8f"",
""path"": ""<Keyboard>/q"",
""interactions"": """",
""processors"": """",
""groups"": ""Keyboard&Mouse"",
""action"": ""PickUp"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""f5571cd9-1166-4ddc-9071-37dc597b1d4e"",
""path"": ""<Gamepad>/buttonEast"",
""interactions"": """",
""processors"": """",
""groups"": ""Gamepad"",
""action"": ""Drop"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""950f549e-ec9c-4d03-aeff-f09ec4031d01"",
""path"": ""<Keyboard>/e"",
""interactions"": """",
""processors"": """",
""groups"": ""Keyboard&Mouse"",
""action"": ""Drop"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""47d1952d-797b-4f5b-986c-654b8e479deb"",
""path"": ""<Gamepad>/buttonSouth"",
""interactions"": """",
""processors"": """",
""groups"": ""Gamepad"",
""action"": ""Throw"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""02e2493d-1eb3-4334-9d25-92f2b5e21399"",
""path"": ""<Keyboard>/space"",
""interactions"": """",
""processors"": """",
""groups"": ""Keyboard&Mouse"",
""action"": ""Throw"",
""isComposite"": false,
""isPartOfComposite"": false
}
]
}
],
""controlSchemes"": [
{
""name"": ""Gamepad"",
""bindingGroup"": ""Gamepad"",
""devices"": [
{
""devicePath"": ""<Gamepad>"",
""isOptional"": false,
""isOR"": false
}
]
},
{
""name"": ""Keyboard&Mouse"",
""bindingGroup"": ""Keyboard&Mouse"",
""devices"": [
{
""devicePath"": ""<Keyboard>"",
""isOptional"": false,
""isOR"": false
},
{
""devicePath"": ""<Mouse>"",
""isOptional"": false,
""isOR"": false
}
]
}
]
}");
// Gameplay
m_Gameplay = asset.FindActionMap("Gameplay", throwIfNotFound: true);
m_Gameplay_Move = m_Gameplay.FindAction("Move", throwIfNotFound: true);
m_Gameplay_Look = m_Gameplay.FindAction("Look", throwIfNotFound: true);
m_Gameplay_PickUp = m_Gameplay.FindAction("PickUp", throwIfNotFound: true);
m_Gameplay_Drop = m_Gameplay.FindAction("Drop", throwIfNotFound: true);
m_Gameplay_Throw = m_Gameplay.FindAction("Throw", throwIfNotFound: true);
}
~@InGameHintsActions()
{
UnityEngine.Debug.Assert(!m_Gameplay.enabled, "This will cause a leak and performance issues, InGameHintsActions.Gameplay.Disable() has not been called.");
}
public void Dispose()
{
UnityEngine.Object.Destroy(asset);
}
public InputBinding? bindingMask
{
get => asset.bindingMask;
set => asset.bindingMask = value;
}
public ReadOnlyArray<InputDevice>? devices
{
get => asset.devices;
set => asset.devices = value;
}
public ReadOnlyArray<InputControlScheme> controlSchemes => asset.controlSchemes;
public bool Contains(InputAction action)
{
return asset.Contains(action);
}
public IEnumerator<InputAction> GetEnumerator()
{
return asset.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void Enable()
{
asset.Enable();
}
public void Disable()
{
asset.Disable();
}
public IEnumerable<InputBinding> bindings => asset.bindings;
public InputAction FindAction(string actionNameOrId, bool throwIfNotFound = false)
{
return asset.FindAction(actionNameOrId, throwIfNotFound);
}
public int FindBinding(InputBinding bindingMask, out InputAction action)
{
return asset.FindBinding(bindingMask, out action);
}
// Gameplay
private readonly InputActionMap m_Gameplay;
private List<IGameplayActions> m_GameplayActionsCallbackInterfaces = new List<IGameplayActions>();
private readonly InputAction m_Gameplay_Move;
private readonly InputAction m_Gameplay_Look;
private readonly InputAction m_Gameplay_PickUp;
private readonly InputAction m_Gameplay_Drop;
private readonly InputAction m_Gameplay_Throw;
public struct GameplayActions
{
private @InGameHintsActions m_Wrapper;
public GameplayActions(@InGameHintsActions wrapper) { m_Wrapper = wrapper; }
public InputAction @Move => m_Wrapper.m_Gameplay_Move;
public InputAction @Look => m_Wrapper.m_Gameplay_Look;
public InputAction @PickUp => m_Wrapper.m_Gameplay_PickUp;
public InputAction @Drop => m_Wrapper.m_Gameplay_Drop;
public InputAction @Throw => m_Wrapper.m_Gameplay_Throw;
public InputActionMap Get() { return m_Wrapper.m_Gameplay; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
public bool enabled => Get().enabled;
public static implicit operator InputActionMap(GameplayActions set) { return set.Get(); }
public void AddCallbacks(IGameplayActions instance)
{
if (instance == null || m_Wrapper.m_GameplayActionsCallbackInterfaces.Contains(instance)) return;
m_Wrapper.m_GameplayActionsCallbackInterfaces.Add(instance);
@Move.started += instance.OnMove;
@Move.performed += instance.OnMove;
@Move.canceled += instance.OnMove;
@Look.started += instance.OnLook;
@Look.performed += instance.OnLook;
@Look.canceled += instance.OnLook;
@PickUp.started += instance.OnPickUp;
@PickUp.performed += instance.OnPickUp;
@PickUp.canceled += instance.OnPickUp;
@Drop.started += instance.OnDrop;
@Drop.performed += instance.OnDrop;
@Drop.canceled += instance.OnDrop;
@Throw.started += instance.OnThrow;
@Throw.performed += instance.OnThrow;
@Throw.canceled += instance.OnThrow;
}
private void UnregisterCallbacks(IGameplayActions instance)
{
@Move.started -= instance.OnMove;
@Move.performed -= instance.OnMove;
@Move.canceled -= instance.OnMove;
@Look.started -= instance.OnLook;
@Look.performed -= instance.OnLook;
@Look.canceled -= instance.OnLook;
@PickUp.started -= instance.OnPickUp;
@PickUp.performed -= instance.OnPickUp;
@PickUp.canceled -= instance.OnPickUp;
@Drop.started -= instance.OnDrop;
@Drop.performed -= instance.OnDrop;
@Drop.canceled -= instance.OnDrop;
@Throw.started -= instance.OnThrow;
@Throw.performed -= instance.OnThrow;
@Throw.canceled -= instance.OnThrow;
}
public void RemoveCallbacks(IGameplayActions instance)
{
if (m_Wrapper.m_GameplayActionsCallbackInterfaces.Remove(instance))
UnregisterCallbacks(instance);
}
public void SetCallbacks(IGameplayActions instance)
{
foreach (var item in m_Wrapper.m_GameplayActionsCallbackInterfaces)
UnregisterCallbacks(item);
m_Wrapper.m_GameplayActionsCallbackInterfaces.Clear();
AddCallbacks(instance);
}
}
public GameplayActions @Gameplay => new GameplayActions(this);
private int m_GamepadSchemeIndex = -1;
public InputControlScheme GamepadScheme
{
get
{
if (m_GamepadSchemeIndex == -1) m_GamepadSchemeIndex = asset.FindControlSchemeIndex("Gamepad");
return asset.controlSchemes[m_GamepadSchemeIndex];
}
}
private int m_KeyboardMouseSchemeIndex = -1;
public InputControlScheme KeyboardMouseScheme
{
get
{
if (m_KeyboardMouseSchemeIndex == -1) m_KeyboardMouseSchemeIndex = asset.FindControlSchemeIndex("Keyboard&Mouse");
return asset.controlSchemes[m_KeyboardMouseSchemeIndex];
}
}
public interface IGameplayActions
{
void OnMove(InputAction.CallbackContext context);
void OnLook(InputAction.CallbackContext context);
void OnPickUp(InputAction.CallbackContext context);
void OnDrop(InputAction.CallbackContext context);
void OnThrow(InputAction.CallbackContext context);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 30718f5974310d148a77ab1e420b1b83
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,241 @@
{
"name": "InGameHintsActions",
"maps": [
{
"name": "Gameplay",
"id": "9af2d1b0-cc47-4300-854c-838acb4b168b",
"actions": [
{
"name": "Move",
"type": "Value",
"id": "7e7492e7-1329-48bb-9fdc-279fd15473b4",
"expectedControlType": "Vector2",
"processors": "",
"interactions": "",
"initialStateCheck": true
},
{
"name": "Look",
"type": "Value",
"id": "981fecc2-2e7a-4d6a-b041-00b47626e0a1",
"expectedControlType": "Vector2",
"processors": "",
"interactions": "",
"initialStateCheck": true
},
{
"name": "PickUp",
"type": "Button",
"id": "5a59bbc2-a3d4-4cbd-88bb-01120d97dc69",
"expectedControlType": "",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Drop",
"type": "Button",
"id": "f37bbe7e-e241-443f-b868-c784e1219f25",
"expectedControlType": "",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Throw",
"type": "Button",
"id": "e450d71c-7cc5-4879-afb5-f3ed682d9824",
"expectedControlType": "",
"processors": "",
"interactions": "",
"initialStateCheck": false
}
],
"bindings": [
{
"name": "",
"id": "5abc4d20-74bd-4f14-902f-2bd2cf59cc28",
"path": "<Gamepad>/leftStick",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Move",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "WASD",
"id": "b16141b1-1611-44db-9576-5a004eb451f2",
"path": "2DVector",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "Move",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "up",
"id": "2b20de3f-1ad8-4b42-b591-595edf60dced",
"path": "<Keyboard>/w",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "Move",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "2f92eaa9-7f1f-4f42-9682-d105f7c2fc22",
"path": "<Keyboard>/s",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "Move",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "left",
"id": "3ba79a56-c5f8-4999-8203-bef8471f4bd8",
"path": "<Keyboard>/a",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "Move",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "right",
"id": "8d9acfe6-d844-4860-a151-01d6eb0dfb48",
"path": "<Keyboard>/d",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "Move",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "",
"id": "b69cbeb7-a5bf-4df1-8965-17d944634cef",
"path": "<Gamepad>/rightStick",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Look",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "b2ddefc9-49da-485d-be28-58e3ec3f8080",
"path": "<Mouse>/delta",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "Look",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "92182492-7b62-47e0-94ad-53d9937d9905",
"path": "<Gamepad>/buttonSouth",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "PickUp",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "e20635aa-ffe7-4ed9-8802-96c039d26a8f",
"path": "<Keyboard>/q",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "PickUp",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "f5571cd9-1166-4ddc-9071-37dc597b1d4e",
"path": "<Gamepad>/buttonEast",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Drop",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "950f549e-ec9c-4d03-aeff-f09ec4031d01",
"path": "<Keyboard>/e",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "Drop",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "47d1952d-797b-4f5b-986c-654b8e479deb",
"path": "<Gamepad>/buttonSouth",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Throw",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "02e2493d-1eb3-4334-9d25-92f2b5e21399",
"path": "<Keyboard>/space",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "Throw",
"isComposite": false,
"isPartOfComposite": false
}
]
}
],
"controlSchemes": [
{
"name": "Gamepad",
"bindingGroup": "Gamepad",
"devices": [
{
"devicePath": "<Gamepad>",
"isOptional": false,
"isOR": false
}
]
},
{
"name": "Keyboard&Mouse",
"bindingGroup": "Keyboard&Mouse",
"devices": [
{
"devicePath": "<Keyboard>",
"isOptional": false,
"isOR": false
},
{
"devicePath": "<Mouse>",
"isOptional": false,
"isOR": false
}
]
}
]
}

View File

@@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: 6bb4ca8e0c27ed041910c04f94cf6c7e
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
generateWrapperCode: 1
wrapperCodePath:
wrapperClassName:
wrapperCodeNamespace: UnityEngine.InputSystem.Samples.InGameHints

View File

@@ -0,0 +1,235 @@
// This example demonstrates how to display text in the UI that involves action bindings.
// When the player switches control schemes or customizes controls (the latter is not set up
// in this example but if supported, would work with the existing code as is), text that
// is shown to the user may be affected.
//
// In the example, the player is able to move around the world and look at objects (simple
// cubes). When an object is in sight, the player can pick the object with a button. While
// having an object picked up, the player can then either throw the object or drop it back
// on the ground.
//
// Depending on the current context, we display hints in the UI that reflect the currently
// active bindings.
using UnityEngine.UI;
namespace UnityEngine.InputSystem.Samples.InGameHints
{
public class InGameHintsExample : MonoBehaviour
{
public Text helpText;
public float moveSpeed;
public float rotateSpeed;
public float throwForce;
public float pickupDistance;
public float holdDistance;
private Vector2 m_Rotation;
private enum State
{
Wandering,
ObjectInSights,
ObjectPickedUp
}
private PlayerInput m_PlayerInput;
private State m_CurrentState;
private Transform m_CurrentObject;
private MaterialPropertyBlock m_PropertyBlock;
// Cached help texts so that we don't generate garbage all the time. Could even cache them by control
// scheme to not create garbage during control scheme switching but we consider control scheme switches
// rare so not worth the extra cost in complexity and memory.
private string m_LookAtObjectHelpText;
private string m_ThrowObjectHelpText;
private const string kDefaultHelpTextFormat = "Move close to one of the cubes and look at it to pick up";
private const string kLookAtObjectHelpTextFormat = "Press {pickup} to pick object up";
private const string kThrowObjectHelpTextFormat = "Press {throw} to throw object; press {drop} to drop object";
public void Awake()
{
m_PlayerInput = GetComponent<PlayerInput>();
}
public void OnEnable()
{
ChangeState(State.Wandering);
}
// This is invoked by PlayerInput when the controls on the player change. If the player switches control
// schemes or keyboard layouts, we end up here and re-generate our hints.
public void OnControlsChanged()
{
UpdateUIHints(regenerate: true); // Force re-generation of our cached text strings to pick up new bindings.
}
private int m_UpdateCount;
public void Update()
{
var move = m_PlayerInput.actions["move"].ReadValue<Vector2>();
var look = m_PlayerInput.actions["look"].ReadValue<Vector2>();
Move(move);
Look(look);
switch (m_CurrentState)
{
case State.Wandering:
case State.ObjectInSights:
// While looking around for an object to pick up, we constantly raycast into the world.
if (Physics.Raycast(transform.position, transform.forward, out var hitInfo,
pickupDistance) && !hitInfo.collider.gameObject.isStatic)
{
if (m_CurrentState != State.ObjectInSights)
ChangeState(State.ObjectInSights);
m_CurrentObject = hitInfo.transform;
// Set a custom color override on the object by installing our property block.
if (m_PropertyBlock == null)
{
m_PropertyBlock = new MaterialPropertyBlock();
m_PropertyBlock.SetColor("_Color", new Color(0.75f, 0, 0));
}
m_CurrentObject.GetComponent<MeshRenderer>().SetPropertyBlock(m_PropertyBlock);
}
else if (m_CurrentState != State.Wandering)
{
// No longer have object in sight.
ChangeState(State.Wandering);
if (m_CurrentObject != null)
{
// Clear property block on renderer to get rid of our custom color override.
m_CurrentObject.GetComponent<Renderer>().SetPropertyBlock(null);
m_CurrentObject = null;
}
}
if (m_PlayerInput.actions["pickup"].triggered && m_CurrentObject != null)
{
PickUp();
ChangeState(State.ObjectPickedUp);
}
break;
case State.ObjectPickedUp:
// If the player hits the throw button, throw the currently carried object.
// For this example, let's call this good enough. In a real game, we'd want to avoid the raycast
if (m_PlayerInput.actions["throw"].triggered)
{
Throw();
ChangeState(State.Wandering);
}
else if (m_PlayerInput.actions["drop"].triggered)
{
Throw(drop: true);
ChangeState(State.Wandering);
}
break;
}
}
private void ChangeState(State newState)
{
switch (newState)
{
case State.Wandering:
break;
case State.ObjectInSights:
break;
case State.ObjectPickedUp:
break;
}
m_CurrentState = newState;
UpdateUIHints();
}
private void UpdateUIHints(bool regenerate = false)
{
if (regenerate)
{
m_ThrowObjectHelpText = default;
m_LookAtObjectHelpText = default;
}
switch (m_CurrentState)
{
case State.ObjectInSights:
if (m_LookAtObjectHelpText == null)
m_LookAtObjectHelpText = kLookAtObjectHelpTextFormat.Replace("{pickup}",
m_PlayerInput.actions["pickup"].GetBindingDisplayString());
helpText.text = m_LookAtObjectHelpText;
break;
case State.ObjectPickedUp:
if (m_ThrowObjectHelpText == null)
m_ThrowObjectHelpText = kThrowObjectHelpTextFormat
.Replace("{throw}", m_PlayerInput.actions["throw"].GetBindingDisplayString())
.Replace("{drop}", m_PlayerInput.actions["drop"].GetBindingDisplayString());
helpText.text = m_ThrowObjectHelpText;
break;
default:
helpText.text = kDefaultHelpTextFormat;
break;
}
}
// Throw or drop currently picked up object.
private void Throw(bool drop = false)
{
// Unmount it.
m_CurrentObject.parent = null;
// Turn physics back on.
var rigidBody = m_CurrentObject.GetComponent<Rigidbody>();
rigidBody.isKinematic = false;
// Apply force.
if (!drop)
rigidBody.AddForce(transform.forward * throwForce, ForceMode.Impulse);
m_CurrentObject = null;
}
private void PickUp()
{
// Mount to our transform.
m_CurrentObject.position = default;
m_CurrentObject.SetParent(transform, worldPositionStays: false);
m_CurrentObject.localPosition += new Vector3(0, 0, holdDistance);
// Remove color override.
m_CurrentObject.GetComponent<Renderer>().SetPropertyBlock(null);
// We don't want the object to be governed by physics while we hold it so turn it into a
// kinematics body.
m_CurrentObject.GetComponent<Rigidbody>().isKinematic = true;
}
private void Move(Vector2 direction)
{
if (direction.sqrMagnitude < 0.01)
return;
var scaledMoveSpeed = moveSpeed * Time.deltaTime;
// For simplicity's sake, we just keep movement in a single plane here. Rotate
// direction according to world Y rotation of player.
var move = Quaternion.Euler(0, transform.eulerAngles.y, 0) * new Vector3(direction.x, 0, direction.y);
transform.position += move * scaledMoveSpeed;
}
private void Look(Vector2 rotate)
{
if (rotate.sqrMagnitude < 0.01)
return;
var scaledRotateSpeed = rotateSpeed * Time.deltaTime;
m_Rotation.y += rotate.x * scaledRotateSpeed;
m_Rotation.x = Mathf.Clamp(m_Rotation.x - rotate.y * scaledRotateSpeed, -89, 89);
transform.localEulerAngles = m_Rotation;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f7157678e0953b24eb3ce108d2e34e37
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: be0c3658cdfdbf84f8cd833d30749454
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
{
"name": "Unity.InputSystem.InGameHints",
"references": [
"GUID:75469ad4d38634e559750d17036d5f7c",
"GUID:2bafac87e7f4b9b418d9448d219b01ab"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 043547d79c83ab74e9bcfef914059964
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: