change: input dialogue on player spawn
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
|
||||
<ui:VisualElement name="StretchBG" style="width: 100%; height: 100%;">
|
||||
<ui:VisualElement name="StretchBG" picking-mode="Ignore" style="width: 100%; height: 100%;">
|
||||
<ui:VisualElement name="LockOnGroup" style="align-items: center; align-self: flex-start;">
|
||||
<ui:Label text="Unit Name" name="LockOnName" style="color: rgb(255, 255, 255); font-size: 29px; -unity-font-style: bold; -unity-font-definition: resource('FlatSkin/Font/Roboto-Bold');" />
|
||||
<ui:VisualElement name="LockOnIcon" style="flex-grow: 1; height: 40px; width: 40px; background-image: url("project://database/Assets/Core/UI/In-Game/Graphics/Icon-LockOnTarget.png?fileID=2800000&guid=fca1c462b5714044698de6793787093a&type=3#Icon-LockOnTarget"); -unity-background-image-tint-color: rgb(238, 66, 66);" />
|
||||
|
||||
8
Assets/Core/UI/In-Game/Layouts/InputSelectorScreen.uxml
Normal file
8
Assets/Core/UI/In-Game/Layouts/InputSelectorScreen.uxml
Normal file
@@ -0,0 +1,8 @@
|
||||
<ui:UXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
|
||||
<ui:VisualElement style="flex-grow: 1; justify-content: center; padding-top: 60px; padding-right: 60px; padding-bottom: 60px; padding-left: 60px;">
|
||||
<ui:VisualElement style="flex-grow: 0; padding-top: 15px; padding-right: 150px; padding-bottom: 15px; padding-left: 15px; background-color: rgba(34, 43, 46, 0.54); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; align-items: flex-start; align-self: flex-start;">
|
||||
<ui:Label text="Waiting for a controller input..." style="color: rgb(255, 255, 255); font-size: 24px; -unity-font-style: bold;" />
|
||||
<ui:Label text="Press any button on a controller" style="color: rgb(255, 255, 255);" />
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
</ui:UXML>
|
||||
10
Assets/Core/UI/In-Game/Layouts/InputSelectorScreen.uxml.meta
Normal file
10
Assets/Core/UI/In-Game/Layouts/InputSelectorScreen.uxml.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0cd3ec0aaa8910b4ba34a1cf93dc7932
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
|
||||
@@ -13,4 +13,9 @@ MonoBehaviour:
|
||||
m_Name: DefaultNetworkPrefabs
|
||||
m_EditorClassIdentifier:
|
||||
IsDefault: 1
|
||||
List: []
|
||||
List:
|
||||
- Override: 0
|
||||
Prefab: {fileID: 2757828562731694833, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3}
|
||||
SourcePrefabToOverride: {fileID: 0}
|
||||
SourceHashToOverride: 0
|
||||
OverridingTargetPrefab: {fileID: 0}
|
||||
|
||||
@@ -62,6 +62,8 @@ MeshRenderer:
|
||||
m_RayTracingAccelStructBuildFlagsOverride: 0
|
||||
m_RayTracingAccelStructBuildFlags: 1
|
||||
m_SmallMeshCulling: 1
|
||||
m_ForceMeshLod: -1
|
||||
m_MeshLodSelectionBias: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
@@ -83,6 +85,7 @@ MeshRenderer:
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_GlobalIlluminationMeshLod: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
@@ -126,6 +129,8 @@ GameObject:
|
||||
- component: {fileID: 2129000951396423518}
|
||||
- component: {fileID: 2842793574603981349}
|
||||
- component: {fileID: 43868462096200776}
|
||||
- component: {fileID: 2538182172493791937}
|
||||
- component: {fileID: 6067609290387865387}
|
||||
m_Layer: 0
|
||||
m_Name: Player
|
||||
m_TagString: Untagged
|
||||
@@ -428,7 +433,7 @@ MonoBehaviour:
|
||||
m_ActionEvents: []
|
||||
m_NeverAutoSwitchControlSchemes: 1
|
||||
m_DefaultControlScheme: Controller
|
||||
m_DefaultActionMap: In-Game
|
||||
m_DefaultActionMap: b2eefcc8-f0a6-4007-854d-f0b59159e624
|
||||
m_SplitScreenIndex: -1
|
||||
m_Camera: {fileID: 0}
|
||||
--- !u!143 &2106585328495276993
|
||||
@@ -551,6 +556,77 @@ MonoBehaviour:
|
||||
Radius: 0.5
|
||||
targetGroup: {fileID: 0}
|
||||
lockOnDocument: {fileID: 0}
|
||||
--- !u!114 &2538182172493791937
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2757828562731694833}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Unity.Netcode.Runtime::Unity.Netcode.NetworkObject
|
||||
GlobalObjectIdHash: 3816484910
|
||||
InScenePlacedSourceGlobalObjectIdHash: 0
|
||||
DeferredDespawnTick: 0
|
||||
Ownership: 1
|
||||
AlwaysReplicateAsRoot: 0
|
||||
SynchronizeTransform: 1
|
||||
ActiveSceneSynchronization: 0
|
||||
SceneMigrationSynchronization: 1
|
||||
SpawnWithObservers: 1
|
||||
DontDestroyWithOwner: 0
|
||||
AutoObjectParentSync: 1
|
||||
SyncOwnerTransformWhenParented: 1
|
||||
AllowOwnerToParent: 0
|
||||
--- !u!114 &6067609290387865387
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2757828562731694833}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: e96cb6065543e43c4a752faaa1468eb1, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Unity.Netcode.Runtime::Unity.Netcode.Components.NetworkTransform
|
||||
ShowTopMostFoldoutHeaderGroup: 1
|
||||
NetworkTransformExpanded: 0
|
||||
AutoOwnerAuthorityTickOffset: 1
|
||||
PositionInterpolationType: 0
|
||||
RotationInterpolationType: 0
|
||||
ScaleInterpolationType: 0
|
||||
PositionLerpSmoothing: 1
|
||||
PositionMaxInterpolationTime: 0.1
|
||||
RotationLerpSmoothing: 1
|
||||
RotationMaxInterpolationTime: 0.1
|
||||
ScaleLerpSmoothing: 1
|
||||
ScaleMaxInterpolationTime: 0.1
|
||||
AuthorityMode: 0
|
||||
TickSyncChildren: 0
|
||||
UseUnreliableDeltas: 0
|
||||
SyncPositionX: 1
|
||||
SyncPositionY: 1
|
||||
SyncPositionZ: 1
|
||||
SyncRotAngleX: 1
|
||||
SyncRotAngleY: 1
|
||||
SyncRotAngleZ: 1
|
||||
SyncScaleX: 1
|
||||
SyncScaleY: 1
|
||||
SyncScaleZ: 1
|
||||
PositionThreshold: 0.001
|
||||
RotAngleThreshold: 0.01
|
||||
ScaleThreshold: 0.01
|
||||
UseQuaternionSynchronization: 0
|
||||
UseQuaternionCompression: 0
|
||||
UseHalfFloatPrecision: 0
|
||||
InLocalSpace: 0
|
||||
SwitchTransformSpaceWhenParented: 0
|
||||
Interpolate: 1
|
||||
SlerpPosition: 0
|
||||
--- !u!1 &9138484595871696647
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -613,6 +689,8 @@ MeshRenderer:
|
||||
m_RayTracingAccelStructBuildFlagsOverride: 0
|
||||
m_RayTracingAccelStructBuildFlags: 1
|
||||
m_SmallMeshCulling: 1
|
||||
m_ForceMeshLod: -1
|
||||
m_MeshLodSelectionBias: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
@@ -634,6 +712,7 @@ MeshRenderer:
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_GlobalIlluminationMeshLod: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,14 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Reset.Core.Tools;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.Users;
|
||||
|
||||
namespace Reset{
|
||||
public static class GameManager{
|
||||
public static GameObject UI;
|
||||
public static GameObject Camera;
|
||||
public static GameObject Input;
|
||||
|
||||
[RuntimeInitializeOnLoadMethodAttribute]
|
||||
public static SessionManager Session;
|
||||
|
||||
public static GameObject Player;
|
||||
|
||||
[RuntimeInitializeOnLoadMethod]
|
||||
static void PopulateSceneReferences(){
|
||||
try {
|
||||
UI = GameObject.Find("UICanvas");
|
||||
@@ -18,8 +24,29 @@ namespace Reset{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void AttachControllerToPlayer(InputDevice device){
|
||||
if (!Player) {
|
||||
throw new Exception(message: "There is no player to attach this new input device to.");
|
||||
}
|
||||
|
||||
InputUser playerUser = Player.GetComponent<PlayerInput>().user;
|
||||
playerUser = InputUser.PerformPairingWithDevice(device, playerUser, InputUserPairingOptions.UnpairCurrentDevicesFromUser);
|
||||
}
|
||||
|
||||
public static void RequestNewController(){
|
||||
try {
|
||||
GameObject.Find("Input Selector").GetComponent<InputFinder>().AwaitNewInput();
|
||||
} catch (Exception e) {
|
||||
Debug.LogError($"Can't request a new controller: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public static void ClearCurrentController(){
|
||||
InputUser playerUser = Player.GetComponent<PlayerInput>().user;
|
||||
playerUser.UnpairDevices();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
35
Assets/Scripts/Core/InputFinder.cs
Normal file
35
Assets/Scripts/Core/InputFinder.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using Reset;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
public class InputFinder : MonoBehaviour{
|
||||
public InputActionMap actionMap;
|
||||
|
||||
void Start(){
|
||||
actionMap.actions[0].performed += ctx => { InputPressed(ctx); };
|
||||
|
||||
GetComponent<UIDocument>().enabled = false;
|
||||
}
|
||||
|
||||
public void AwaitNewInput(){
|
||||
GameManager.ClearCurrentController();
|
||||
|
||||
GetComponent<UIDocument>().enabled = true;
|
||||
actionMap.Enable();
|
||||
}
|
||||
|
||||
void InputPressed(InputAction.CallbackContext context){
|
||||
try {
|
||||
GameManager.AttachControllerToPlayer(context.control.device);
|
||||
Debug.Log(context.control.device);
|
||||
} catch (Exception e) {
|
||||
Debug.LogError($"Failed to set the new device to the player: {e.Message}");
|
||||
return;
|
||||
}
|
||||
|
||||
GetComponent<UIDocument>().enabled = false;
|
||||
actionMap.Disable();
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Core/InputFinder.cs.meta
Normal file
2
Assets/Scripts/Core/InputFinder.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8fc1a1d631088814c846ef223c98f932
|
||||
@@ -31,7 +31,9 @@ public class SessionManager : MonoBehaviour{
|
||||
var allocation = await RelayService.Instance.CreateAllocationAsync(maxConnections);
|
||||
NetworkManager.Singleton.GetComponent<UnityTransport>().SetRelayServerData(AllocationUtils.ToRelayServerData(allocation, connectionType));
|
||||
var joinCode = await RelayService.Instance.GetJoinCodeAsync(allocation.AllocationId);
|
||||
return NetworkManager.Singleton.StartHost() ? joinCode : null;
|
||||
|
||||
Debug.Log(joinCode);
|
||||
return NetworkManager.Singleton.StartClient() ? joinCode : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using Reset;
|
||||
using Reset.Core.Tools;
|
||||
using UnityEngine;
|
||||
using Sirenix.OdinInspector;
|
||||
|
||||
@@ -8,12 +10,15 @@ public class Player : MonoBehaviour{
|
||||
[HideInInspector] public new PlayerCamera camera;
|
||||
|
||||
void Awake(){
|
||||
GameManager.Player = gameObject;
|
||||
controls = GetComponent<PlayerControls>();
|
||||
GameManager.RequestNewController();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
Debug.Log(GameManager.Player);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
||||
@@ -27,6 +27,9 @@ public class PlayerControls : MonoBehaviour{
|
||||
graph = GetComponent<GraphOwner>();
|
||||
input = GetComponent<PlayerInput>();
|
||||
|
||||
// Remove all devices from this user
|
||||
input.user.UnpairDevices();
|
||||
|
||||
// Add the delegates for each method
|
||||
foreach (InputAction action in input.actions) {
|
||||
action.started += SendToGraph;
|
||||
|
||||
Reference in New Issue
Block a user