diff --git a/Assets/Mirror/Examples/AdditiveScenes/Prefabs/Player.prefab b/Assets/Mirror/Examples/AdditiveScenes/Prefabs/Player.prefab index c37f346f5..3279cc9d3 100644 --- a/Assets/Mirror/Examples/AdditiveScenes/Prefabs/Player.prefab +++ b/Assets/Mirror/Examples/AdditiveScenes/Prefabs/Player.prefab @@ -1,87 +1,5 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: ---- !u!1 &2720178739875597319 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 8740139267343819840} - - component: {fileID: 1782430381883734809} - - component: {fileID: 3878212865935595091} - m_Layer: 0 - m_Name: Camera - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &8740139267343819840 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2720178739875597319} - m_LocalRotation: {x: 0.08715578, y: -0, z: -0, w: 0.9961947} - m_LocalPosition: {x: 0, y: 3, z: -8} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 5328458565928408179} - m_RootOrder: 1 - m_LocalEulerAnglesHint: {x: 10, y: 0, z: 0} ---- !u!20 &1782430381883734809 -Camera: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2720178739875597319} - m_Enabled: 0 - serializedVersion: 2 - m_ClearFlags: 1 - m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} - m_projectionMatrixMode: 1 - m_SensorSize: {x: 36, y: 24} - m_LensShift: {x: 0, y: 0} - m_GateFitMode: 2 - m_FocalLength: 50 - m_NormalizedViewPortRect: - serializedVersion: 2 - x: 0 - y: 0 - width: 1 - height: 1 - near clip plane: 0.3 - far clip plane: 1000 - field of view: 60 - orthographic: 0 - orthographic size: 5 - m_Depth: 0 - m_CullingMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_RenderingPath: -1 - m_TargetTexture: {fileID: 0} - m_TargetDisplay: 0 - m_TargetEye: 3 - m_HDR: 1 - m_AllowMSAA: 1 - m_AllowDynamicResolution: 0 - m_ForceIntoRT: 0 - m_OcclusionCulling: 1 - m_StereoConvergence: 10 - m_StereoSeparation: 0.022 ---- !u!81 &3878212865935595091 -AudioListener: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2720178739875597319} - m_Enabled: 1 --- !u!1 &5815001218983416211 GameObject: m_ObjectHideFlags: 0 @@ -94,7 +12,7 @@ GameObject: - component: {fileID: 1800893346221236401} - component: {fileID: 136369082707552984} m_Layer: 0 - m_Name: Cube + m_Name: Visor m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -194,7 +112,6 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 3254954141432383832} - - {fileID: 8740139267343819840} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -273,8 +190,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 9b91ecbcc199f4492b9a91e820070131, type: 3} m_Name: m_EditorClassIdentifier: - m_ServerOnly: 0 - m_LocalPlayerAuthority: 1 + serverOnly: 0 + localPlayerAuthority: 1 m_AssetId: a5bdca0a2315d43499be7dcef473fbc7 m_SceneId: 0 --- !u!114 &8704659178864205755 @@ -289,15 +206,20 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e8f68561248aaca4fb96847ce24742ee, type: 3} m_Name: m_EditorClassIdentifier: - syncInterval: 0.1 - moveSpeed: 350 - horiz: 0 - vert: 0 - turn: 0 - turnSpeedAccel: 30 - turnSpeedDecel: 30 - maxTurnSpeed: 100 + syncInterval: 0 playerColor: {r: 0, g: 0, b: 0, a: 1} + moveSpeed: 8 + turnSpeedAccel: 5 + turnSpeedDecel: 5 + maxTurnSpeed: 150 + jumpSpeed: 0 + maxJumpSpeed: 5 + jumpFactor: 0.05 + horizontal: 0 + vertical: 0 + turn: 0 + isGrounded: 1 + isFalling: 0 --- !u!114 &887491563423388292 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Mirror/Examples/AdditiveScenes/Scenes/MainScene.unity b/Assets/Mirror/Examples/AdditiveScenes/Scenes/MainScene.unity index c42e20f23..ef56d3701 100644 --- a/Assets/Mirror/Examples/AdditiveScenes/Scenes/MainScene.unity +++ b/Assets/Mirror/Examples/AdditiveScenes/Scenes/MainScene.unity @@ -544,11 +544,11 @@ Camera: width: 1 height: 1 near clip plane: 0.3 - far clip plane: 11 + far clip plane: 1000 field of view: 60 - orthographic: 1 - orthographic size: 25 - m_Depth: -1 + orthographic: 0 + orthographic size: 5 + m_Depth: 0 m_CullingMask: serializedVersion: 2 m_Bits: 4294967295 @@ -571,7 +571,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 534669902} m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068} - m_LocalPosition: {x: 0, y: 10, z: 0} + m_LocalPosition: {x: 0, y: 50, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -1855,7 +1855,7 @@ MonoBehaviour: OnClientDataReceived: m_PersistentCalls: m_Calls: [] - m_TypeName: Mirror.UnityEventByteArray, Mirror, Version=0.0.0.0, Culture=neutral, + m_TypeName: Mirror.UnityEventArraySegment, Mirror, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null OnClientError: m_PersistentCalls: @@ -1874,7 +1874,7 @@ MonoBehaviour: OnServerDataReceived: m_PersistentCalls: m_Calls: [] - m_TypeName: Mirror.UnityEventIntByteArray, Mirror, Version=0.0.0.0, Culture=neutral, + m_TypeName: Mirror.UnityEventIntArraySegment, Mirror, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null OnServerError: m_PersistentCalls: diff --git a/Assets/Mirror/Examples/AdditiveScenes/Scripts/AdditiveNetworkManager.cs b/Assets/Mirror/Examples/AdditiveScenes/Scripts/AdditiveNetworkManager.cs index 7f160cc01..2354834f0 100644 --- a/Assets/Mirror/Examples/AdditiveScenes/Scripts/AdditiveNetworkManager.cs +++ b/Assets/Mirror/Examples/AdditiveScenes/Scripts/AdditiveNetworkManager.cs @@ -21,7 +21,6 @@ public override void OnStartServer() SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive); Debug.LogFormat("Loaded {0}", sceneName); } - //StartCoroutine(LoadScene(sceneName)); } IEnumerator LoadScene(string sceneName) diff --git a/Assets/Mirror/Examples/AdditiveScenes/Scripts/PlayerController.cs b/Assets/Mirror/Examples/AdditiveScenes/Scripts/PlayerController.cs index 493d34191..d22730f37 100644 --- a/Assets/Mirror/Examples/AdditiveScenes/Scripts/PlayerController.cs +++ b/Assets/Mirror/Examples/AdditiveScenes/Scripts/PlayerController.cs @@ -7,11 +7,6 @@ public class PlayerController : NetworkBehaviour { CharacterController characterController; - public float moveSpeed = 300f; - public float maxTurnSpeed = 90f; - public float turnSpeedAccel = 30f; - public float turnSpeedDecel = 30f; - public override void OnStartServer() { base.OnStartServer(); @@ -21,22 +16,20 @@ public override void OnStartServer() [SyncVar(hook = nameof(SetColor))] public Color playerColor = Color.black; - // Unity makes a clone of the material when GetComponent().material is used - // Cache it here and Destroy it in OnDestroy to prevent a memory leak - Material materialClone; + // Unity makes a clone of the material when GetComponent().material is used + // Cache it here and Destroy it in OnDestroy to prevent a memory leak + Material materialClone; - void SetColor(Color color) - { - if (materialClone == null) materialClone = GetComponent().material; - materialClone.color = color; - } + void SetColor(Color color) + { + if (materialClone == null) materialClone = GetComponent().material; + materialClone.color = color; + } - private void OnDestroy() - { - Destroy(materialClone); - } - - Camera mainCam; + private void OnDestroy() + { + Destroy(materialClone); + } public override void OnStartLocalPlayer() { @@ -44,31 +37,28 @@ public override void OnStartLocalPlayer() characterController = GetComponent(); - // Grab a refernce to the main camera so we can enable it again in OnDisable - mainCam = Camera.main; - - // Turn off the main camera because the Player prefab has its own camera - mainCam.enabled = false; - - // Enable the local player's camera - GetComponentInChildren().enabled = true; + Camera.main.transform.SetParent(transform); + Camera.main.transform.localPosition = new Vector3(0f, 3f, -8f); + Camera.main.transform.localEulerAngles = new Vector3(10f, 0f, 0f); } - void OnDisable() - { - if (isLocalPlayer) - { - // Disable the local player's camera - GetComponentInChildren().enabled = false; + [Header("Movement Settings")] + public float moveSpeed = 8f; + public float turnSpeedAccel = 5f; + public float turnSpeedDecel = 5f; + public float maxTurnSpeed = 150f; - // Re-enable the main camera when Stop is pressed in the HUD - if (mainCam != null) mainCam.enabled = true; - } - } + [Header("Jump Settings")] + public float jumpSpeed = 0f; + public float maxJumpSpeed = 5F; + public float jumpFactor = .05F; - float horizontal = 0f; - float vertical = 0f; - float turn = 0f; + [Header("Diagnostics")] + public float horizontal = 0f; + public float vertical = 0f; + public float turn = 0f; + public bool isGrounded = true; + public bool isFalling = false; void Update() { @@ -81,14 +71,21 @@ void Update() turn -= turnSpeedAccel; else if (Input.GetKey(KeyCode.E) && (turn < maxTurnSpeed)) turn += turnSpeedAccel; + else if (turn > turnSpeedDecel) + turn -= turnSpeedDecel; + else if (turn < -turnSpeedDecel) + turn += turnSpeedDecel; + else + turn = 0f; + + if (!isFalling && Input.GetKey(KeyCode.Space) && (isGrounded || jumpSpeed < maxJumpSpeed)) + jumpSpeed += maxJumpSpeed * jumpFactor; + else if (isGrounded) + isFalling = false; else { - if (turn > turnSpeedDecel) - turn -= turnSpeedDecel; - else if (turn < -turnSpeedDecel) - turn += turnSpeedDecel; - else - turn = 0f; + isFalling = true; + jumpSpeed = 0; } } @@ -98,9 +95,17 @@ void FixedUpdate() transform.Rotate(0f, turn * Time.fixedDeltaTime, 0f); - Vector3 direction = Vector3.ClampMagnitude(new Vector3(horizontal, 0f, vertical), 1f) * moveSpeed; + Vector3 direction = new Vector3(horizontal, jumpSpeed, vertical); + direction = Vector3.ClampMagnitude(direction, 1f); direction = transform.TransformDirection(direction); - characterController.SimpleMove(direction * Time.fixedDeltaTime); + direction *= moveSpeed; + + if (jumpSpeed > 0) + characterController.Move(direction * Time.fixedDeltaTime); + else + characterController.SimpleMove(direction); + + isGrounded = characterController.isGrounded; } } } diff --git a/Assets/Mirror/Examples/AdditiveScenes/Scripts/SceneLoader.cs b/Assets/Mirror/Examples/AdditiveScenes/Scripts/SceneLoader.cs index 1908c8e6d..64b1920cd 100644 --- a/Assets/Mirror/Examples/AdditiveScenes/Scripts/SceneLoader.cs +++ b/Assets/Mirror/Examples/AdditiveScenes/Scripts/SceneLoader.cs @@ -16,10 +16,10 @@ public enum LoadAction // Tell the client to load a single subscene // This is called from ZoneHandler's server-only OnTrigger events [TargetRpc] - public void TargetLoadUnloadScene(NetworkConnection networkConnection, string SceneName, LoadAction loadAction) + public void TargetLoadUnloadScene(NetworkConnection networkConnection, string sceneName, LoadAction loadAction) { // Check if server here because we already pre-loaded the subscenes on the server - if (!isServer) StartCoroutine(LoadUnloadScene(SceneName, loadAction)); + if (!isServer) StartCoroutine(LoadUnloadScene(sceneName, loadAction)); } // isBusy protects us from being overwhelmed by server messages to load several subscenes at once. diff --git a/Assets/Mirror/Examples/AdditiveScenes/Scripts/ShootingTankBehaviour.cs b/Assets/Mirror/Examples/AdditiveScenes/Scripts/ShootingTankBehaviour.cs index 8bf37b29f..c547a7adb 100644 --- a/Assets/Mirror/Examples/AdditiveScenes/Scripts/ShootingTankBehaviour.cs +++ b/Assets/Mirror/Examples/AdditiveScenes/Scripts/ShootingTankBehaviour.cs @@ -8,7 +8,7 @@ namespace Mirror.Examples.Additive public class ShootingTankBehaviour : NetworkBehaviour { [SyncVar] - public Quaternion Rotation; + public Quaternion rotation; NetworkAnimator networkAnimator; @@ -27,7 +27,7 @@ void Update() ShootNearestPlayer(); if (isClient) - transform.rotation = Quaternion.Slerp(transform.rotation, Rotation, turnSpeed); + transform.rotation = Quaternion.Slerp(transform.rotation, rotation, turnSpeed); } [Server] @@ -51,7 +51,7 @@ void ShootNearestPlayer() if (target != null) { transform.LookAt(target.transform.position + Vector3.down); - Rotation = transform.rotation; + rotation = transform.rotation; networkAnimator.SetTrigger("Fire"); } }