V3.0 追加控制模式,改进代码
追加控制模式,实现鼠标在地图中的坐标映射 追加控制UI Todo: 游戏流程修改 游戏State对应修改
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MouseSelector : MonoBehaviour
|
||||
{
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
// shoot raycast from mainCamera center to mousepositon
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3460b8ea83509ed41b69b84ba0c86b87
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,104 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerCamera : MonoBehaviour
|
||||
{
|
||||
public float normalSpeed = 0.035f;
|
||||
public float shiftSpeed = 0.06f;
|
||||
public float zoomSpeed = -10.0f;
|
||||
public float rotateSpeed = 0.1f;
|
||||
|
||||
public float maxHeight = 40f;
|
||||
public float minHeight = 6f;
|
||||
|
||||
public Vector2 startMouseP;
|
||||
public Vector2 dragMouseP;
|
||||
|
||||
private float speed;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
// shift to speed UP
|
||||
if (Input.GetKey(KeyCode.LeftShift))
|
||||
{
|
||||
speed = shiftSpeed;
|
||||
zoomSpeed = 20.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
speed = normalSpeed;
|
||||
zoomSpeed = 10.0f;
|
||||
}
|
||||
|
||||
float hsp = transform.position.y * speed * Input.GetAxis("Horizontal"); // horizontal movement speed
|
||||
float vsp = transform.position.y * speed * Input.GetAxis("Vertical"); // vertical movement speed
|
||||
float scrollSp = Mathf.Log(transform.position.y) * -zoomSpeed * Input.GetAxis("Mouse ScrollWheel"); // scroll speed
|
||||
|
||||
// camera height limit
|
||||
if (transform.position.y + scrollSp > maxHeight)
|
||||
{
|
||||
scrollSp = maxHeight - transform.position.y;
|
||||
}
|
||||
else if (transform.position.y + scrollSp < minHeight)
|
||||
{
|
||||
scrollSp = minHeight - transform.position.y;
|
||||
}
|
||||
/* if((transform.position.y <= maxHeight) && (scrollSp > 0))
|
||||
{
|
||||
scrollSp = 0;
|
||||
}else if((transform.position.y >= minHeight)&& (scrollSp < 0))
|
||||
{
|
||||
scrollSp = 0;
|
||||
}
|
||||
if((transform.position.y + scrollSp) > maxHeight)
|
||||
{
|
||||
scrollSp = maxHeight - transform.position.y;
|
||||
}else if((transform.position.y + scrollSp) < minHeight)
|
||||
{
|
||||
scrollSp = minHeight - transform.position.y;
|
||||
}*/
|
||||
|
||||
Vector3 verticalMove = new Vector3(0,scrollSp,0); // vertical movement
|
||||
Vector3 lateralMove = hsp * transform.right; // lateral movement in global world ignore camera facing
|
||||
Vector3 fowardMove = transform.forward; // forward movement in global world ignore camera facing
|
||||
fowardMove.y = 0; // ignore y axis
|
||||
fowardMove = vsp * fowardMove.normalized; // normalize the vector
|
||||
|
||||
Vector3 move = verticalMove + lateralMove + fowardMove; // total movement
|
||||
|
||||
transform.position += move; // move the camera
|
||||
|
||||
cameraRotation();
|
||||
|
||||
}
|
||||
|
||||
void cameraRotation()
|
||||
{
|
||||
// camera rotation while press middle mousebutton
|
||||
if(Input.GetMouseButtonDown(2))
|
||||
{
|
||||
startMouseP = Input.mousePosition;
|
||||
}
|
||||
|
||||
if (Input.GetMouseButton(2))
|
||||
{
|
||||
dragMouseP = Input.mousePosition;
|
||||
|
||||
float dx = (dragMouseP - startMouseP).x * rotateSpeed;
|
||||
float dy = (dragMouseP - startMouseP).y * rotateSpeed;
|
||||
|
||||
transform.rotation *= Quaternion.Euler(new Vector3(0, dx, 0));
|
||||
transform.GetChild(0).rotation *= Quaternion.Euler(new Vector3(-dy, 0, 0));
|
||||
|
||||
startMouseP = dragMouseP;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2afdd3e39c405184380c3ffead15ea80
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user