Init
This commit is contained in:
24
Assets/Scripts/HotUpdate/GameStart.cs
Normal file
24
Assets/Scripts/HotUpdate/GameStart.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
public class GameStart : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
Debug.Log("Game Start");
|
||||
Addressables.LoadSceneAsync("Assets/GameRes/Scene/Test.unity").Completed+=(handle)=>
|
||||
{
|
||||
Debug.Log("Load Scene\"Test\"");
|
||||
};
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/HotUpdate/GameStart.cs.meta
Normal file
11
Assets/Scripts/HotUpdate/GameStart.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 91a52e294219f0242be13de2ba0471f2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
180
Assets/Scripts/HotUpdate/MyActions.inputactions
Normal file
180
Assets/Scripts/HotUpdate/MyActions.inputactions
Normal file
@@ -0,0 +1,180 @@
|
||||
{
|
||||
"name": "MyActions",
|
||||
"maps": [
|
||||
{
|
||||
"name": "Map",
|
||||
"id": "9b2dac95-d312-427d-8a31-ce291063a847",
|
||||
"actions": [
|
||||
{
|
||||
"name": "Move",
|
||||
"type": "Value",
|
||||
"id": "c600010c-741d-4ca9-aa4c-530804b962cd",
|
||||
"expectedControlType": "",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": true
|
||||
},
|
||||
{
|
||||
"name": "Jump",
|
||||
"type": "Button",
|
||||
"id": "d80c1257-09a3-4e8e-b96f-bc85555fbf9e",
|
||||
"expectedControlType": "",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "Zoom",
|
||||
"type": "Value",
|
||||
"id": "d42a56f1-abed-47ce-8eba-da4bb48e2303",
|
||||
"expectedControlType": "",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": true
|
||||
},
|
||||
{
|
||||
"name": "Esc",
|
||||
"type": "Button",
|
||||
"id": "2cc7fb6d-38ed-46cd-8733-8da61480105a",
|
||||
"expectedControlType": "",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "Alt",
|
||||
"type": "Button",
|
||||
"id": "469ee5e2-ba9d-485e-b0c5-764d70e16a2d",
|
||||
"expectedControlType": "",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
}
|
||||
],
|
||||
"bindings": [
|
||||
{
|
||||
"name": "Move",
|
||||
"id": "7fe7158f-cccd-4fdd-913e-a274c55e0fcd",
|
||||
"path": "2DVector",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Move",
|
||||
"isComposite": true,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "up",
|
||||
"id": "d49bf5a2-1859-4517-b4a7-b4f4a8abfd2d",
|
||||
"path": "<Keyboard>/w",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "down",
|
||||
"id": "0a084e7e-94f2-4bb5-80aa-58d3f1f63f45",
|
||||
"path": "<Keyboard>/s",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "left",
|
||||
"id": "4a6fe744-a732-4176-a41d-d72cbc9c173a",
|
||||
"path": "<Keyboard>/a",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "right",
|
||||
"id": "f9a32fde-1141-48d4-a638-50962544314e",
|
||||
"path": "<Keyboard>/d",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "cd94b74d-2756-4fce-9067-8b7dd9b18c45",
|
||||
"path": "<Keyboard>/space",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Jump",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "1D Axis",
|
||||
"id": "7ee6a4b1-c1a1-4b1b-92cc-cc05c3ccb1f6",
|
||||
"path": "1DAxis",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Zoom",
|
||||
"isComposite": true,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "negative",
|
||||
"id": "7a62b1f0-5da3-4eb6-8252-233fea59b5cd",
|
||||
"path": "<Mouse>/scroll/up",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Zoom",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "positive",
|
||||
"id": "7b9d0a02-0a80-4f55-a9bb-60e0687621d9",
|
||||
"path": "<Mouse>/scroll/down",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Zoom",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "dac47152-10fb-4236-b70e-b0e17e9f51b4",
|
||||
"path": "<Keyboard>/escape",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Esc",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "89df66f5-0bf3-496f-83fa-7bb55f960ea3",
|
||||
"path": "<Keyboard>/leftAlt",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Alt",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"controlSchemes": []
|
||||
}
|
||||
14
Assets/Scripts/HotUpdate/MyActions.inputactions.meta
Normal file
14
Assets/Scripts/HotUpdate/MyActions.inputactions.meta
Normal file
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c599bdae20876e4a819e335af6dd11b
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
|
||||
generateWrapperCode: 0
|
||||
wrapperCodePath:
|
||||
wrapperClassName:
|
||||
wrapperCodeNamespace:
|
||||
122
Assets/Scripts/HotUpdate/ThirdCharacterController.cs
Normal file
122
Assets/Scripts/HotUpdate/ThirdCharacterController.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using Cinemachine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class ThirdCharacterController : MonoBehaviour
|
||||
{
|
||||
[Header("Settings")]
|
||||
public float moveSpeed = 5f;
|
||||
public float turnSpeed = 10f;
|
||||
public float jumpSpeed = 8f;
|
||||
public float gravity = 20f;
|
||||
public float minCameraDistance = 2f;
|
||||
public float maxCameraDistance = 10f;
|
||||
public float cameraZoomSpeed = 0.1f;
|
||||
[Header("Components")]
|
||||
public CharacterController controller;
|
||||
public Animator animator;
|
||||
public CinemachineVirtualCamera vCam;
|
||||
public Transform forwardReference;
|
||||
public Transform model;
|
||||
|
||||
private CinemachineFramingTransposer framingTransposer;
|
||||
private CinemachinePOV pov;
|
||||
private Vector3 moveDirection;
|
||||
private Vector3 verticalVelocity;
|
||||
private Vector2 moveInput;
|
||||
private bool isGrounded;
|
||||
private bool isCursorLocked = true;
|
||||
void Awake()
|
||||
{
|
||||
framingTransposer = vCam.GetCinemachineComponent<CinemachineFramingTransposer>();
|
||||
pov = vCam.GetCinemachineComponent<CinemachinePOV>();
|
||||
UpdateCursorState();
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
ApplyGravity();
|
||||
Move();
|
||||
RotateModel();
|
||||
UpdateAnimator();
|
||||
}
|
||||
private void UpdateCursorState()
|
||||
{
|
||||
Cursor.lockState = isCursorLocked ? CursorLockMode.Locked : CursorLockMode.None;
|
||||
Cursor.visible = !isCursorLocked;
|
||||
if (pov == null) return;
|
||||
pov.m_HorizontalAxis.m_InputAxisName = isCursorLocked ? "Mouse X" : "";
|
||||
pov.m_VerticalAxis.m_InputAxisName = isCursorLocked ? "Mouse Y" : "";
|
||||
pov.m_HorizontalAxis.m_MaxSpeed = isCursorLocked ? 300 : 0;
|
||||
pov.m_VerticalAxis.m_MaxSpeed = isCursorLocked ? 300 : 0;
|
||||
}
|
||||
private void ApplyGravity()
|
||||
{
|
||||
isGrounded = controller.isGrounded;
|
||||
if (isGrounded && verticalVelocity.y < 0)
|
||||
{
|
||||
verticalVelocity.y = -2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
verticalVelocity.y -= gravity * Time.deltaTime;
|
||||
}
|
||||
}
|
||||
private void Move()
|
||||
{
|
||||
forwardReference.rotation = Quaternion.AngleAxis(pov.m_HorizontalAxis.Value, Vector3.up);
|
||||
Vector3 horizontalMovement = forwardReference.TransformDirection(
|
||||
new Vector3(moveInput.x, 0, moveInput.y)) * moveSpeed;
|
||||
moveDirection = horizontalMovement + verticalVelocity;
|
||||
controller.Move(moveDirection * Time.deltaTime);
|
||||
}
|
||||
private void RotateModel()
|
||||
{
|
||||
if (moveInput == Vector2.zero) return;
|
||||
float targetAngle = Mathf.Atan2(moveInput.x, moveInput.y) * Mathf.Rad2Deg;
|
||||
Quaternion targetRotation = forwardReference.rotation * Quaternion.AngleAxis(targetAngle, Vector3.up);
|
||||
model.rotation = Quaternion.Slerp(model.rotation, targetRotation, turnSpeed * Time.deltaTime);
|
||||
}
|
||||
private void UpdateAnimator()
|
||||
{
|
||||
animator.SetBool("Move", moveInput != Vector2.zero);
|
||||
}
|
||||
public void OnMove(InputAction.CallbackContext context)
|
||||
{
|
||||
moveInput = context.ReadValue<Vector2>();
|
||||
}
|
||||
public void OnJump(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed && isGrounded)
|
||||
{
|
||||
verticalVelocity.y = jumpSpeed;
|
||||
}
|
||||
}
|
||||
public void OnEsc(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed)
|
||||
{
|
||||
isCursorLocked = !isCursorLocked;
|
||||
UpdateCursorState();
|
||||
}
|
||||
}
|
||||
public void OnAlt(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed)
|
||||
{
|
||||
isCursorLocked = false;
|
||||
UpdateCursorState();
|
||||
}
|
||||
else if (context.canceled)
|
||||
{
|
||||
isCursorLocked = true;
|
||||
UpdateCursorState();
|
||||
}
|
||||
}
|
||||
public void OnZoom(InputAction.CallbackContext context)
|
||||
{
|
||||
if (framingTransposer == null) return;
|
||||
float scrollValue = context.ReadValue<float>();
|
||||
float newDistance = framingTransposer.m_CameraDistance + (scrollValue * cameraZoomSpeed * 0.01f);
|
||||
framingTransposer.m_CameraDistance = Mathf.Clamp(newDistance, minCameraDistance, maxCameraDistance);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/HotUpdate/ThirdCharacterController.cs.meta
Normal file
11
Assets/Scripts/HotUpdate/ThirdCharacterController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de36ff070be69284da71fd9b44a5aea6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Assets/Scripts/HotUpdate/UnityScripts.HotUpdate.asmdef
Normal file
19
Assets/Scripts/HotUpdate/UnityScripts.HotUpdate.asmdef
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "UnityScripts.HotUpdate",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:75469ad4d38634e559750d17036d5f7c",
|
||||
"GUID:9e24947de15b9834991c9d8411ea37cf",
|
||||
"GUID:84651a3751eca9349aac36a66bba901b",
|
||||
"GUID:4307f53044263cf4b835bd812fc161a4"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1bbba614ff545384c97bd498ddb816ce
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user