Mirror intergrated, WIP on Client Prediction v1
This commit is contained in:
@@ -1,61 +1,61 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraControl : MonoBehaviour
|
||||
{
|
||||
public Camera[] cameras;
|
||||
private int currentCameraIndex;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
currentCameraIndex = 0;
|
||||
|
||||
|
||||
for (int i=1; i<cameras.Length; i++)
|
||||
{
|
||||
cameras[i].gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (cameras.Length>0)
|
||||
{
|
||||
cameras [0].gameObject.SetActive (true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Update ()
|
||||
{
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.C))
|
||||
{
|
||||
Transition();
|
||||
}
|
||||
}
|
||||
|
||||
public void Transition()
|
||||
{
|
||||
//Play transition
|
||||
ChangeCam();
|
||||
}
|
||||
|
||||
|
||||
public void ChangeCam()
|
||||
{
|
||||
currentCameraIndex ++;
|
||||
|
||||
if (currentCameraIndex < cameras.Length)
|
||||
{
|
||||
cameras[currentCameraIndex-1].gameObject.SetActive(false);
|
||||
cameras[currentCameraIndex].gameObject.SetActive(true);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
cameras[currentCameraIndex-1].gameObject.SetActive(false);
|
||||
currentCameraIndex = 0;
|
||||
cameras[currentCameraIndex].gameObject.SetActive(true);
|
||||
|
||||
}
|
||||
}
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraControl : MonoBehaviour
|
||||
{
|
||||
public Camera[] cameras;
|
||||
private int currentCameraIndex;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
currentCameraIndex = 0;
|
||||
|
||||
|
||||
for (int i=1; i<cameras.Length; i++)
|
||||
{
|
||||
cameras[i].gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (cameras.Length>0)
|
||||
{
|
||||
cameras [0].gameObject.SetActive (true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Update ()
|
||||
{
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.C))
|
||||
{
|
||||
Transition();
|
||||
}
|
||||
}
|
||||
|
||||
public void Transition()
|
||||
{
|
||||
//Play transition
|
||||
ChangeCam();
|
||||
}
|
||||
|
||||
|
||||
public void ChangeCam()
|
||||
{
|
||||
currentCameraIndex ++;
|
||||
|
||||
if (currentCameraIndex < cameras.Length)
|
||||
{
|
||||
cameras[currentCameraIndex-1].gameObject.SetActive(false);
|
||||
cameras[currentCameraIndex].gameObject.SetActive(true);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
cameras[currentCameraIndex-1].gameObject.SetActive(false);
|
||||
currentCameraIndex = 0;
|
||||
cameras[currentCameraIndex].gameObject.SetActive(true);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a10b68a6e1360c1428677384d2539cf0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
fileFormatVersion: 2
|
||||
guid: a10b68a6e1360c1428677384d2539cf0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DragAndDrop : MonoBehaviour
|
||||
{
|
||||
private float zCoord;
|
||||
private Vector3 mouseOffset;
|
||||
|
||||
private void onMouseDown()
|
||||
{
|
||||
zCoord = Camera.main.WorldToScreenPoint(transform.position).z;
|
||||
mouseOffset = transform.position - mouseWorldPos();
|
||||
}
|
||||
|
||||
|
||||
private void onMouseDrag()
|
||||
{
|
||||
transform.position = mouseWorldPos() + mouseOffset;
|
||||
}
|
||||
|
||||
|
||||
private Vector3 mouseWorldPos()
|
||||
{
|
||||
Vector3 mPos = Input.mousePosition;
|
||||
mPos.z = zCoord;
|
||||
return Camera.main.ScreenToWorldPoint(mPos);
|
||||
}
|
||||
}
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DragAndDrop : MonoBehaviour
|
||||
{
|
||||
private float zCoord;
|
||||
private Vector3 mouseOffset;
|
||||
|
||||
private void onMouseDown()
|
||||
{
|
||||
zCoord = Camera.main.WorldToScreenPoint(transform.position).z;
|
||||
mouseOffset = transform.position - mouseWorldPos();
|
||||
}
|
||||
|
||||
|
||||
private void onMouseDrag()
|
||||
{
|
||||
transform.position = mouseWorldPos() + mouseOffset;
|
||||
}
|
||||
|
||||
|
||||
private Vector3 mouseWorldPos()
|
||||
{
|
||||
Vector3 mPos = Input.mousePosition;
|
||||
mPos.z = zCoord;
|
||||
return Camera.main.ScreenToWorldPoint(mPos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6da85d893d238744aa17c170581ebc7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
fileFormatVersion: 2
|
||||
guid: e6da85d893d238744aa17c170581ebc7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
||||
@@ -1,60 +1,60 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Grabber : MonoBehaviour {
|
||||
|
||||
private GameObject selectedObject;
|
||||
|
||||
private void Update() {
|
||||
if (Input.GetMouseButtonDown(0)) {
|
||||
if(selectedObject == null) {
|
||||
RaycastHit hit = CastRay();
|
||||
|
||||
if(hit.collider != null) {
|
||||
if (!hit.collider.CompareTag("Drag")) {
|
||||
return;
|
||||
}
|
||||
|
||||
selectedObject = hit.collider.gameObject;
|
||||
Cursor.visible = false;
|
||||
}
|
||||
} else {
|
||||
Vector3 position = new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.WorldToScreenPoint(selectedObject.transform.position).z);
|
||||
Vector3 worldPosition = Camera.main.ScreenToWorldPoint(position);
|
||||
selectedObject.transform.position = new Vector3(worldPosition.x, 0f, worldPosition.z);
|
||||
|
||||
selectedObject = null;
|
||||
Cursor.visible = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(selectedObject != null) {
|
||||
Vector3 position = new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.WorldToScreenPoint(selectedObject.transform.position).z);
|
||||
Vector3 worldPosition = Camera.main.ScreenToWorldPoint(position);
|
||||
selectedObject.transform.position = new Vector3(worldPosition.x, .25f, worldPosition.z);
|
||||
|
||||
if (Input.GetMouseButtonDown(1)) {
|
||||
selectedObject.transform.rotation = Quaternion.Euler(new Vector3(
|
||||
selectedObject.transform.rotation.eulerAngles.x,
|
||||
selectedObject.transform.rotation.eulerAngles.y + 90f,
|
||||
selectedObject.transform.rotation.eulerAngles.z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private RaycastHit CastRay() {
|
||||
Vector3 screenMousePosFar = new Vector3(
|
||||
Input.mousePosition.x,
|
||||
Input.mousePosition.y,
|
||||
Camera.main.farClipPlane);
|
||||
Vector3 screenMousePosNear = new Vector3(
|
||||
Input.mousePosition.x,
|
||||
Input.mousePosition.y,
|
||||
Camera.main.nearClipPlane);
|
||||
Vector3 worldMousePosFar = Camera.main.ScreenToWorldPoint(screenMousePosFar);
|
||||
Vector3 worldMousePosNear = Camera.main.ScreenToWorldPoint(screenMousePosNear);
|
||||
RaycastHit hit;
|
||||
Physics.Raycast(worldMousePosNear, worldMousePosFar - worldMousePosNear, out hit);
|
||||
|
||||
return hit;
|
||||
}
|
||||
}
|
||||
using UnityEngine;
|
||||
|
||||
public class Grabber : MonoBehaviour {
|
||||
|
||||
private GameObject selectedObject;
|
||||
|
||||
private void Update() {
|
||||
if (Input.GetMouseButtonDown(0)) {
|
||||
if(selectedObject == null) {
|
||||
RaycastHit hit = CastRay();
|
||||
|
||||
if(hit.collider != null) {
|
||||
if (!hit.collider.CompareTag("Drag")) {
|
||||
return;
|
||||
}
|
||||
|
||||
selectedObject = hit.collider.gameObject;
|
||||
Cursor.visible = false;
|
||||
}
|
||||
} else {
|
||||
Vector3 position = new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.WorldToScreenPoint(selectedObject.transform.position).z);
|
||||
Vector3 worldPosition = Camera.main.ScreenToWorldPoint(position);
|
||||
selectedObject.transform.position = new Vector3(worldPosition.x, 0f, worldPosition.z);
|
||||
|
||||
selectedObject = null;
|
||||
Cursor.visible = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(selectedObject != null) {
|
||||
Vector3 position = new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.WorldToScreenPoint(selectedObject.transform.position).z);
|
||||
Vector3 worldPosition = Camera.main.ScreenToWorldPoint(position);
|
||||
selectedObject.transform.position = new Vector3(worldPosition.x, .25f, worldPosition.z);
|
||||
|
||||
if (Input.GetMouseButtonDown(1)) {
|
||||
selectedObject.transform.rotation = Quaternion.Euler(new Vector3(
|
||||
selectedObject.transform.rotation.eulerAngles.x,
|
||||
selectedObject.transform.rotation.eulerAngles.y + 90f,
|
||||
selectedObject.transform.rotation.eulerAngles.z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private RaycastHit CastRay() {
|
||||
Vector3 screenMousePosFar = new Vector3(
|
||||
Input.mousePosition.x,
|
||||
Input.mousePosition.y,
|
||||
Camera.main.farClipPlane);
|
||||
Vector3 screenMousePosNear = new Vector3(
|
||||
Input.mousePosition.x,
|
||||
Input.mousePosition.y,
|
||||
Camera.main.nearClipPlane);
|
||||
Vector3 worldMousePosFar = Camera.main.ScreenToWorldPoint(screenMousePosFar);
|
||||
Vector3 worldMousePosNear = Camera.main.ScreenToWorldPoint(screenMousePosNear);
|
||||
RaycastHit hit;
|
||||
Physics.Raycast(worldMousePosNear, worldMousePosFar - worldMousePosNear, out hit);
|
||||
|
||||
return hit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a68a2fd4e7e3d3f4bab9e38d25966c16
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
fileFormatVersion: 2
|
||||
guid: a68a2fd4e7e3d3f4bab9e38d25966c16
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
public class MineScript : MonoBehaviour
|
||||
{
|
||||
[HideInInspector] public TMP_Text txt;
|
||||
[HideInInspector] public TMP_Text gold;
|
||||
|
||||
private int goldAmount = 0;
|
||||
private int totalAmount = 0;
|
||||
public float refreshTime = 0.2f;
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
StartCoroutine(GetGoldTimer());
|
||||
}
|
||||
|
||||
private IEnumerator GetGoldTimer()
|
||||
{
|
||||
while (true) {
|
||||
yield return new WaitForSeconds(refreshTime);
|
||||
goldAmount++;
|
||||
UpdateGold();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateGold()
|
||||
{
|
||||
gold.text = goldAmount.ToString();
|
||||
}
|
||||
|
||||
public void CollectGold()
|
||||
{
|
||||
totalAmount = goldAmount + totalAmount;
|
||||
txt.text = totalAmount.ToString();
|
||||
goldAmount = 0;
|
||||
}
|
||||
|
||||
}
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
public class MineScript : MonoBehaviour
|
||||
{
|
||||
[HideInInspector] public TMP_Text txt;
|
||||
[HideInInspector] public TMP_Text gold;
|
||||
|
||||
private int goldAmount = 0;
|
||||
private int totalAmount = 0;
|
||||
public float refreshTime = 0.2f;
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
StartCoroutine(GetGoldTimer());
|
||||
}
|
||||
|
||||
private IEnumerator GetGoldTimer()
|
||||
{
|
||||
while (true) {
|
||||
yield return new WaitForSeconds(refreshTime);
|
||||
goldAmount++;
|
||||
UpdateGold();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateGold()
|
||||
{
|
||||
gold.text = goldAmount.ToString();
|
||||
}
|
||||
|
||||
public void CollectGold()
|
||||
{
|
||||
totalAmount = goldAmount + totalAmount;
|
||||
txt.text = totalAmount.ToString();
|
||||
goldAmount = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5dba27881224bcc41b9ee7727935bdca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
fileFormatVersion: 2
|
||||
guid: 5dba27881224bcc41b9ee7727935bdca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
||||
@@ -1,60 +1,60 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class MoveCamera : MonoBehaviour
|
||||
{
|
||||
public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
|
||||
public RotationAxes axes = RotationAxes.MouseXAndY;
|
||||
public float sensitivityX = 2F;
|
||||
public float sensitivityY = 2F;
|
||||
public float minimumY = -90F;
|
||||
public float maximumY = 90F;
|
||||
float rotationY = -60F;
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
MouseInput();
|
||||
}
|
||||
|
||||
void MouseInput()
|
||||
{
|
||||
if (EventSystem.current.IsPointerOverGameObject())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Input.GetMouseButton(0))
|
||||
{
|
||||
MouseRightClick();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MouseRightClick()
|
||||
{
|
||||
if (axes == RotationAxes.MouseXAndY)
|
||||
{
|
||||
float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
|
||||
|
||||
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
|
||||
rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
|
||||
|
||||
transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
|
||||
}
|
||||
else if (axes == RotationAxes.MouseX)
|
||||
{
|
||||
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
|
||||
rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
|
||||
|
||||
transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class MoveCamera : MonoBehaviour
|
||||
{
|
||||
public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
|
||||
public RotationAxes axes = RotationAxes.MouseXAndY;
|
||||
public float sensitivityX = 2F;
|
||||
public float sensitivityY = 2F;
|
||||
public float minimumY = -90F;
|
||||
public float maximumY = 90F;
|
||||
float rotationY = -60F;
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
MouseInput();
|
||||
}
|
||||
|
||||
void MouseInput()
|
||||
{
|
||||
if (EventSystem.current.IsPointerOverGameObject())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Input.GetMouseButton(0))
|
||||
{
|
||||
MouseRightClick();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MouseRightClick()
|
||||
{
|
||||
if (axes == RotationAxes.MouseXAndY)
|
||||
{
|
||||
float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
|
||||
|
||||
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
|
||||
rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
|
||||
|
||||
transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
|
||||
}
|
||||
else if (axes == RotationAxes.MouseX)
|
||||
{
|
||||
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
|
||||
rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
|
||||
|
||||
transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 109504a96ffb810449df1c179378f55e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
fileFormatVersion: 2
|
||||
guid: 109504a96ffb810449df1c179378f55e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
||||
Reference in New Issue
Block a user