Init
This commit is contained in:
113
Assets/Roaming/Scripts/Controller/Camera/BaseController.cs
Normal file
113
Assets/Roaming/Scripts/Controller/Camera/BaseController.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class BaseController : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// <20>Ƿ<EFBFBD><C7B7>ڼ<EFBFBD><DABC>̿<EFBFBD><CCBF><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
private static bool isKeyOnControl;
|
||||
|
||||
/// <summary>
|
||||
/// <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
public static bool IsMouseOnControl;
|
||||
|
||||
/// <summary>
|
||||
/// <20>Ƿ<EFBFBD><C7B7>Զ<EFBFBD>Ѱ·<D1B0><C2B7>
|
||||
/// </summary>
|
||||
private static bool isNavOnControl;
|
||||
|
||||
/// <summary>
|
||||
/// <20>Ƿ<EFBFBD><C7B7>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
private static bool isTouchOnControl;
|
||||
|
||||
/// <summary>
|
||||
/// <20>Ƿ<EFBFBD><C7B7>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
private static bool isJoyStickOnControl;
|
||||
|
||||
/// <summary>
|
||||
/// <20>Ƿ<EFBFBD>UI<55><49><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
public static bool IsUIClicked;
|
||||
|
||||
/// <summary>
|
||||
/// <20>ܷ<EFBFBD><DCB7><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
public static bool CanControl = false;
|
||||
|
||||
public static bool IsAnimatorOnControl;
|
||||
|
||||
public static bool IsAutoNavigating;
|
||||
|
||||
public static bool IsKeyOnControl
|
||||
{
|
||||
get => isKeyOnControl;
|
||||
set
|
||||
{
|
||||
if (isKeyOnControl != value)
|
||||
{
|
||||
isKeyOnControl = value;
|
||||
if (!isKeyOnControl) OnStatusChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static bool IsNavOnControl
|
||||
{
|
||||
get => isNavOnControl; set
|
||||
{
|
||||
if (isNavOnControl != value)
|
||||
{
|
||||
isNavOnControl = value;
|
||||
if (!isNavOnControl) OnStatusChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static bool IsTouchOnControl
|
||||
{
|
||||
get => isTouchOnControl; set
|
||||
{
|
||||
if (isTouchOnControl != value)
|
||||
{
|
||||
isTouchOnControl = value;
|
||||
if (!isTouchOnControl) OnStatusChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static bool IsJoyStickOnControl
|
||||
{
|
||||
get => isJoyStickOnControl; set
|
||||
{
|
||||
if (isJoyStickOnControl != value)
|
||||
{
|
||||
isJoyStickOnControl = value;
|
||||
if (!isJoyStickOnControl) OnStatusChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void HideView()
|
||||
{
|
||||
CanControl = true;
|
||||
if (AudioManager.Instance != null)
|
||||
{
|
||||
AudioManager.Instance.ResumeBackgroundMusic();
|
||||
}
|
||||
CommonData.ReleaseMemory();
|
||||
}
|
||||
|
||||
static void OnStatusChanged()
|
||||
{
|
||||
if(StatusChanged != null)
|
||||
{
|
||||
StatusChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public static event UnityAction StatusChanged;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02872a782e43a3c49a96f3938e84fb09
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,85 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[RequireComponent(typeof(Animator))]
|
||||
public class CameraAnimController : MonoBehaviour
|
||||
{
|
||||
public bool playAnim;
|
||||
|
||||
Animator anim;
|
||||
|
||||
public Button btnSkipAnim;
|
||||
|
||||
void Start()
|
||||
{
|
||||
anim = GetComponent<Animator>();
|
||||
|
||||
//if (Application.isEditor || playAnim)
|
||||
//{
|
||||
// AudioManager.Instance.PlayBg(0);
|
||||
// if (anim.enabled)
|
||||
// {
|
||||
// OnEnterGame();
|
||||
// }
|
||||
//}
|
||||
|
||||
btnSkipAnim.onClick.AddListener(OnSkipAnimClick);
|
||||
}
|
||||
|
||||
public void OnEnterGame()
|
||||
{
|
||||
if (anim != null && anim.enabled)
|
||||
{
|
||||
BaseController.IsAnimatorOnControl = true;
|
||||
anim.SetTrigger("EnterGame");
|
||||
}
|
||||
else
|
||||
{
|
||||
OnEnterAnimPlayEnd();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public GameObject objHelp;
|
||||
|
||||
public void OnEnterAnimPlayEnd()
|
||||
{
|
||||
DestroyBtnSkipAnim();
|
||||
anim.enabled = false;
|
||||
BaseController.CanControl = true;
|
||||
BaseController.IsAnimatorOnControl = false;
|
||||
Invoke("LoadTexture", 0.5f);
|
||||
}
|
||||
|
||||
private void LoadTexture()
|
||||
{
|
||||
TipPointCollider.Instance.ControllerStatusChanged();
|
||||
}
|
||||
|
||||
public void OnSkipAnimClick()
|
||||
{
|
||||
Skip();
|
||||
}
|
||||
|
||||
public void DestroyBtnSkipAnim()
|
||||
{
|
||||
if (btnSkipAnim != null && btnSkipAnim.gameObject != null)
|
||||
Destroy(btnSkipAnim.gameObject);
|
||||
}
|
||||
|
||||
void Skip()
|
||||
{
|
||||
if (anim.GetCurrentAnimatorClipInfo(0).Length > 0)
|
||||
{
|
||||
AnimationClip clip = anim.GetCurrentAnimatorClipInfo(0)[0].clip;
|
||||
anim.Play(clip.name, 0, 1);
|
||||
}
|
||||
|
||||
SceneLoader.Instance.SetCameraPosition(0);
|
||||
CommonData.MainCamera.fieldOfView = 60;
|
||||
|
||||
OnEnterAnimPlayEnd();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0fa7b7322456c6543959da754bc95a47
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,88 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class JoyStickController : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>Transform
|
||||
/// <20><>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>ǰ<EFBFBD>ű<EFBFBD><C5B1><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD>
|
||||
/// </summary>
|
||||
[Tooltip("<22><><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>Transform<72><6D>Ĭ<EFBFBD><C4AC>Ϊ<EFBFBD><CEAA>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>")]
|
||||
public Transform tran;
|
||||
/// <summary>
|
||||
/// <20>ƶ<EFBFBD><C6B6>ٶȣ<D9B6><C8A3><EFBFBD>/<2F>룩
|
||||
/// </summary>
|
||||
[Tooltip("<22>ƶ<EFBFBD><C6B6>ٶȣ<D9B6><C8A3><EFBFBD>/<2F>룩")]
|
||||
public float moveSpeed = 5;
|
||||
/// <summary>
|
||||
/// <20><>ת<EFBFBD>ٶȣ<D9B6><C8A3>Ƕ<EFBFBD>/<2F>룩
|
||||
/// </summary>
|
||||
[Tooltip("<22><>ת<EFBFBD>ٶȣ<D9B6><C8A3>Ƕ<EFBFBD>/<2F>룩")]
|
||||
public float rotateSpeed = 10;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (tran == null)
|
||||
tran = transform;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (CanControl)
|
||||
{
|
||||
if (JoyStickHandler.js_x != 0 || JoyStickHandler.js_y != 0)
|
||||
{
|
||||
IsJoyStickOnControl = true;
|
||||
ControllWithKey(JoyStickHandler.js_x, JoyStickHandler.js_y);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsJoyStickOnControl)
|
||||
{
|
||||
Invoke("SetJoyStick", 0.2f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetJoyStick()
|
||||
{
|
||||
IsJoyStickOnControl = false;
|
||||
}
|
||||
|
||||
Vector3 tmp;
|
||||
/// <summary>
|
||||
/// ʹ<>ü<EFBFBD><C3BC>̿<EFBFBD><CCBF>ƶ<EFBFBD><C6B6><EFBFBD>
|
||||
/// </summary>
|
||||
/// <param name="h">ˮƽƫ<C6BD><C6AB><EFBFBD><EFBFBD></param>
|
||||
/// <param name="v"><3E><>ֱƫ<D6B1><C6AB><EFBFBD><EFBFBD></param>
|
||||
void ControllWithKey(float h, float v)
|
||||
{
|
||||
switch (JoyStickHandler.CurrentMode)
|
||||
{
|
||||
case JoyStickHandler.Mode.Right:
|
||||
tran.Rotate(Vector3.up * rotateSpeed * Time.deltaTime); // <20><>ת
|
||||
break;
|
||||
case JoyStickHandler.Mode.Left:
|
||||
tran.Rotate(Vector3.up * -rotateSpeed * Time.deltaTime); // <20><>ת
|
||||
break;
|
||||
case JoyStickHandler.Mode.Up:
|
||||
tran.position += tran.forward * moveSpeed * Time.deltaTime; // <20>ƶ<EFBFBD>
|
||||
break;
|
||||
case JoyStickHandler.Mode.Down:
|
||||
tran.position += tran.forward * -moveSpeed * Time.deltaTime; // <20>ƶ<EFBFBD>
|
||||
break;
|
||||
}
|
||||
|
||||
//tran.position += tran.forward * moveSpeed * Time.deltaTime * v; // <20>ƶ<EFBFBD>
|
||||
//tran.Rotate(Vector3.up * rotateSpeed * Time.deltaTime * h); // <20><>ת
|
||||
|
||||
//Debug.Log(h + "," + v);
|
||||
|
||||
//tmp.x = h;
|
||||
//tmp.z = v;
|
||||
//tran.Translate(tmp * moveSpeed * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a69a62d89d0131948b00eb81fabf96a9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
170
Assets/Roaming/Scripts/Controller/Camera/JoyStickHandler.cs
Normal file
170
Assets/Roaming/Scripts/Controller/Camera/JoyStickHandler.cs
Normal file
@@ -0,0 +1,170 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class JoyStickHandler : MonoBehaviour, IPointerDownHandler, IDragHandler, IPointerUpHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// ҡ<><D2A1>ˮƽƫ<C6BD><C6AB><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
public static float js_x;
|
||||
/// <summary>
|
||||
/// ҡ<>˴<EFBFBD>ֱƫ<D6B1><C6AB><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
public static float js_y;
|
||||
|
||||
// <20><>ǰģʽ
|
||||
public static Mode CurrentMode;
|
||||
|
||||
/// <summary>
|
||||
/// ҡ<><D2A1>ģʽ
|
||||
/// </summary>
|
||||
public enum Mode { None, Up, Down, Left, Right };
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD>ͼƬRectTransform
|
||||
/// </summary>
|
||||
[Tooltip("<22><><EFBFBD><EFBFBD>ͼƬRectTransform")]
|
||||
public RectTransform background;
|
||||
/// <summary>
|
||||
/// Handle<6C><65>RectTransform
|
||||
/// </summary>
|
||||
[Tooltip("Handle<6C><65>RectTransform")]
|
||||
public RectTransform handle;
|
||||
/// <summary>
|
||||
/// ҡ<><D2A1><EFBFBD>ٶ<EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
[Tooltip("ҡ<><D2A1><EFBFBD>ٶ<EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>")]
|
||||
public float js_Speed = 1f;
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
[Tooltip("ҡ<><D2A1><EFBFBD><EFBFBD><EFBFBD>ڵĻ<DAB5><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")]
|
||||
private Canvas canvas;
|
||||
|
||||
// <20>뾶
|
||||
float radius;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
Vector2 up, down, left, right;
|
||||
|
||||
public bool TestOnEditor;
|
||||
|
||||
Color handleColor;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (!TestOnEditor && !H5Controller.IsMobileBroswer())
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
canvas = transform.parent.parent.GetComponent<Canvas>();
|
||||
|
||||
CurrentMode = Mode.None;
|
||||
radius = background.rect.width / 2.0f;
|
||||
up = new Vector2(0, radius);
|
||||
down = new Vector2(0, -radius);
|
||||
left = new Vector2(-radius, 0);
|
||||
right = new Vector2(radius, 0);
|
||||
|
||||
handleColor = handle.GetComponent<Image>().color;
|
||||
}
|
||||
|
||||
#region
|
||||
//void Update()
|
||||
//{
|
||||
// // MessageSend();
|
||||
//}
|
||||
void MessageSend()
|
||||
{
|
||||
switch (CurrentMode)
|
||||
{
|
||||
case Mode.None:
|
||||
break;
|
||||
case Mode.Up:
|
||||
break;
|
||||
case Mode.Left:
|
||||
break;
|
||||
case Mode.Down:
|
||||
break;
|
||||
case Mode.Right:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
// <20><><EFBFBD>갴<EFBFBD><EAB0B4>
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
if (BaseController.CanControl)
|
||||
{
|
||||
OnDrag(eventData);
|
||||
|
||||
handle.GetComponent<Image>().color = new Color(150, 150, 150, 255);
|
||||
}
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ſ<EFBFBD>
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
if (BaseController.CanControl)
|
||||
{
|
||||
js_x = 0;
|
||||
js_y = 0;
|
||||
|
||||
handle.anchoredPosition = Vector2.zero;
|
||||
handle.GetComponent<Image>().color = handleColor;
|
||||
CurrentMode = Mode.None;
|
||||
}
|
||||
}
|
||||
|
||||
// <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
||||
Vector2 to;
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
if (BaseController.CanControl)
|
||||
{
|
||||
to = (eventData.position - (Vector2)background.position) / canvas.scaleFactor;
|
||||
if (to.magnitude <= radius)
|
||||
{
|
||||
handle.anchoredPosition = to;
|
||||
}
|
||||
else
|
||||
{
|
||||
to = to / (to.magnitude / radius);
|
||||
handle.anchoredPosition = to;
|
||||
}
|
||||
|
||||
CalcDis();
|
||||
}
|
||||
}
|
||||
void CalcDis()
|
||||
{
|
||||
float dis = 0f;
|
||||
if (Vector2.Distance(up, handle.anchoredPosition) < dis || dis == 0)
|
||||
{
|
||||
dis = Vector2.Distance(up, handle.anchoredPosition);
|
||||
CurrentMode = Mode.Up;
|
||||
}
|
||||
if (Vector2.Distance(down, handle.anchoredPosition) < dis)
|
||||
{
|
||||
dis = Vector2.Distance(down, handle.anchoredPosition);
|
||||
CurrentMode = Mode.Down;
|
||||
}
|
||||
if (Vector2.Distance(left, handle.anchoredPosition) < dis)
|
||||
{
|
||||
dis = Vector2.Distance(left, handle.anchoredPosition);
|
||||
CurrentMode = Mode.Left;
|
||||
}
|
||||
if (Vector2.Distance(right, handle.anchoredPosition) < dis)
|
||||
{
|
||||
dis = Vector2.Distance(right, handle.anchoredPosition);
|
||||
CurrentMode = Mode.Right;
|
||||
}
|
||||
|
||||
js_x = (radius - Vector2.Distance(right, handle.anchoredPosition)) / radius * js_Speed;
|
||||
js_y = (radius - Vector2.Distance(up, handle.anchoredPosition)) / radius * js_Speed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10ba3f8f0d4ad744ab79ad142ba75cee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
89
Assets/Roaming/Scripts/Controller/Camera/KeyController.cs
Normal file
89
Assets/Roaming/Scripts/Controller/Camera/KeyController.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class KeyController : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>Transform
|
||||
/// <20><>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>ǰ<EFBFBD>ű<EFBFBD><C5B1><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD>
|
||||
/// </summary>
|
||||
[Tooltip("<22><><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>Transform<72><6D>Ĭ<EFBFBD><C4AC>Ϊ<EFBFBD><CEAA>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>")]
|
||||
public Transform tran;
|
||||
/// <summary>
|
||||
/// <20>ƶ<EFBFBD><C6B6>ٶȣ<D9B6><C8A3><EFBFBD>/<2F>룩
|
||||
/// </summary>
|
||||
[Tooltip("<22>ƶ<EFBFBD><C6B6>ٶȣ<D9B6><C8A3><EFBFBD>/<2F>룩")]
|
||||
public float moveSpeed = 5;
|
||||
/// <summary>
|
||||
/// <20><>ת<EFBFBD>ٶȣ<D9B6><C8A3>Ƕ<EFBFBD>/<2F>룩
|
||||
/// </summary>
|
||||
[Tooltip("<22><>ת<EFBFBD>ٶȣ<D9B6><C8A3>Ƕ<EFBFBD>/<2F>룩")]
|
||||
public float rotateSpeed = 10;
|
||||
/// <summary>
|
||||
/// <20>ƶ<EFBFBD>ʱ<EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD>
|
||||
/// </summary>
|
||||
public bool AutoResetView = true;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (tran == null)
|
||||
tran = transform;
|
||||
}
|
||||
|
||||
float h, v;
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Debug.Log(IsKeyOnControl);
|
||||
if (CanControl)
|
||||
{
|
||||
if (Input.GetKey(KeyCode.Q))
|
||||
{
|
||||
tran.Rotate(Vector3.down * rotateSpeed * Time.deltaTime); // <20><><EFBFBD><EFBFBD>ת
|
||||
}
|
||||
if (Input.GetKey(KeyCode.E))
|
||||
{
|
||||
tran.Rotate(Vector3.up * rotateSpeed * Time.deltaTime); // <20><><EFBFBD><EFBFBD>ת
|
||||
}
|
||||
|
||||
h = Input.GetAxis("Horizontal"); // <20><>ȡˮƽƫ<C6BD><C6AB><EFBFBD><EFBFBD>
|
||||
v = Input.GetAxis("Vertical"); // <20><>ȡ<EFBFBD><C8A1>ֱƫ<D6B1><C6AB><EFBFBD><EFBFBD>
|
||||
|
||||
if (h != 0 || v != 0)
|
||||
{
|
||||
ControllWithKey(h, v);
|
||||
}
|
||||
else
|
||||
{
|
||||
IsKeyOnControl = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 tmp;
|
||||
/// <summary>
|
||||
/// ʹ<>ü<EFBFBD><C3BC>̿<EFBFBD><CCBF>ƶ<EFBFBD><C6B6><EFBFBD>
|
||||
/// </summary>
|
||||
/// <param name="h">ˮƽƫ<C6BD><C6AB><EFBFBD><EFBFBD></param>
|
||||
/// <param name="v"><3E><>ֱƫ<D6B1><C6AB><EFBFBD><EFBFBD></param>
|
||||
void ControllWithKey(float h, float v)
|
||||
{
|
||||
IsKeyOnControl = true;
|
||||
|
||||
//tran.position += tran.forward * moveSpeed * Time.deltaTime * v; // <20>ƶ<EFBFBD>
|
||||
//tran.Rotate(Vector3.up * rotateSpeed * Time.deltaTime * h); // <20><>ת
|
||||
|
||||
tmp.x = h;
|
||||
tmp.z = v;
|
||||
if (Input.GetKey(KeyCode.LeftShift))
|
||||
{
|
||||
tran.Translate(tmp * moveSpeed * Time.deltaTime * 4f);
|
||||
}
|
||||
else
|
||||
{
|
||||
tran.Translate(tmp * moveSpeed * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c49e18dbe71a63049965566f8743c9d2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
271
Assets/Roaming/Scripts/Controller/Camera/MouseController.cs
Normal file
271
Assets/Roaming/Scripts/Controller/Camera/MouseController.cs
Normal file
@@ -0,0 +1,271 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class MouseController : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>Transform
|
||||
/// <20><>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>ǰ<EFBFBD>ű<EFBFBD><C5B1><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD>
|
||||
/// </summary>
|
||||
[Tooltip("<22><><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>Transform<72><6D>Ĭ<EFBFBD><C4AC>Ϊ<EFBFBD><CEAA>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>")]
|
||||
public Transform tran;
|
||||
[Tooltip("<22><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҽ<EFBFBD><D2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת")]
|
||||
public bool RotateEnabled = true;
|
||||
[Tooltip("<22><><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>")]
|
||||
public bool MoveEnabled = true;
|
||||
[Tooltip("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֿ<EFBFBD><D6BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD>")]
|
||||
public bool CameraFovEnabled = true;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (tran == null)
|
||||
tran = transform;
|
||||
|
||||
agent = GetComponent<NavMeshAgent>();
|
||||
|
||||
if (H5Controller.IsMobileBroswer())
|
||||
{
|
||||
Destroy(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (CanControl && !IsJoyStickOnControl)
|
||||
{
|
||||
if (RotateEnabled)
|
||||
RotateWithMouse();
|
||||
if (MoveEnabled)
|
||||
MoveWithMidBtn();
|
||||
if (CameraFovEnabled)
|
||||
CameraFOVWithWheel();
|
||||
}
|
||||
}
|
||||
|
||||
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת
|
||||
// <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
||||
float mouseX;
|
||||
float mouseY;
|
||||
float rotationX;
|
||||
float rotationY;
|
||||
Quaternion rotation;
|
||||
|
||||
[Header("<22><><EFBFBD><EFBFBD><EFBFBD>Ҽ<EFBFBD><D2BC><EFBFBD><EFBFBD>Ʋ<EFBFBD><C6B2><EFBFBD>")]
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶķ<C6B5><C4B7><EFBFBD>ö<EFBFBD><C3B6>
|
||||
/// </summary>
|
||||
[Tooltip("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶķ<C6B5><C4B7><EFBFBD>ö<EFBFBD><C3B6>")]
|
||||
public RotationAxes axes = RotationAxes.MouseXAndY;
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD>Ƕ<EFBFBD><C7B6><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
[Tooltip("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD>Ƕ<EFBFBD><C7B6><EFBFBD><EFBFBD><EFBFBD>")]
|
||||
public int yRotationMinLimit = -10;
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD>Ƕ<EFBFBD><C7B6><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
[Tooltip("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD>Ƕ<EFBFBD><C7B6><EFBFBD><EFBFBD><EFBFBD>")]
|
||||
public int yRotationMaxLimit = 30;
|
||||
/// <summary>
|
||||
/// ˮƽ<CBAE><C6BD>ת<EFBFBD>ٶ<EFBFBD>
|
||||
/// </summary>
|
||||
[Tooltip("ˮƽ<CBAE><C6BD>ת<EFBFBD>ٶ<EFBFBD>")]
|
||||
public float xRotationSpeed = 3;
|
||||
/// <summary>
|
||||
/// <20><>ֱ<EFBFBD><D6B1>ת<EFBFBD>ٶ<EFBFBD>
|
||||
/// </summary>
|
||||
[Tooltip("<22><>ֱ<EFBFBD><D6B1>ת<EFBFBD>ٶ<EFBFBD>")]
|
||||
public float yRotationSpeed = 3;
|
||||
|
||||
/// <summary>
|
||||
/// <20>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD><EFBFBD>Ϊˮƽ<CBAE><C6BD><EFBFBD>ٶ<EFBFBD>
|
||||
/// </summary>
|
||||
[Tooltip("<22>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD><EFBFBD>Ϊˮƽ<CBAE><C6BD><EFBFBD>ٶ<EFBFBD>")]
|
||||
public float resetAngleSpeed = 1f;
|
||||
|
||||
NavMeshAgent agent;
|
||||
Vector3 upPos;
|
||||
Vector3 vTmp;
|
||||
|
||||
void RotateWithMouse()
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if ((Input.touchCount == 0 && Input.GetMouseButton(0)) || Input.touchCount == 1)
|
||||
{
|
||||
// agent.enabled = false;
|
||||
|
||||
IsMouseOnControl = true;
|
||||
|
||||
if (axes == RotationAxes.MouseXAndY)
|
||||
{
|
||||
rotationX = CommonData.MainCamera.transform.localEulerAngles.y + Input.GetAxis("Mouse X") * xRotationSpeed;
|
||||
rotationY += Input.GetAxis("Mouse Y") * yRotationSpeed;
|
||||
rotationY = Mathf.Clamp(rotationY, yRotationMinLimit, yRotationMaxLimit);
|
||||
CommonData.MainCamera.transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
|
||||
}
|
||||
else if (axes == RotationAxes.MouseX)
|
||||
{
|
||||
CommonData.MainCamera.transform.Rotate(0, Input.GetAxis("Mouse X") * yRotationSpeed, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
rotationY += Input.GetAxis("Mouse Y") * yRotationSpeed;
|
||||
rotationY = Mathf.Clamp(rotationY, yRotationMinLimit, yRotationMaxLimit);
|
||||
CommonData.MainCamera.transform.localEulerAngles = new Vector3(-rotationY, CommonData.MainCamera.transform.localEulerAngles.y, 0);
|
||||
}
|
||||
|
||||
//GetComponent<NavMeshAgent>().enabled = false;
|
||||
}
|
||||
|
||||
if (Input.GetMouseButtonUp(0))
|
||||
{
|
||||
rotationX = 0;
|
||||
rotationY = 0;
|
||||
|
||||
// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD>תλ<D7AA><CEBB>
|
||||
upPos = tran.localRotation.eulerAngles;
|
||||
if (upPos.x > yRotationMaxLimit + 1)
|
||||
{
|
||||
upPos.x -= 360f;
|
||||
}
|
||||
|
||||
IsMouseOnControl = false;
|
||||
}
|
||||
|
||||
if (IsMouseOnControl && agent != null && !agent.enabled)
|
||||
{
|
||||
vTmp = tran.localRotation.eulerAngles;
|
||||
|
||||
if (Mathf.Abs(vTmp.x) <= 0.01f)
|
||||
{
|
||||
vTmp.x = 0;
|
||||
// agent.enabled = true;
|
||||
IsMouseOnControl = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
vTmp.x -= Time.deltaTime * upPos.x * resetAngleSpeed;
|
||||
if ((upPos.x > 0 && vTmp.x <= 0) || (upPos.x < 0 && vTmp.x >= 360f))
|
||||
{
|
||||
vTmp.x = 0;
|
||||
// agent.enabled = true;
|
||||
IsMouseOnControl = false;
|
||||
}
|
||||
}
|
||||
|
||||
tran.localRotation = Quaternion.Euler(vTmp);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD>ĽǶ<C4BD>
|
||||
/// </summary>
|
||||
/// <param name="value"><3E>Ƕ<EFBFBD>ֵ</param>
|
||||
/// <param name="min"><3E><>Сֵ</param>
|
||||
/// <param name="max"><3E><><EFBFBD><EFBFBD>ֵ</param>
|
||||
float ClampValue(float value, float min, float max)
|
||||
{
|
||||
// <20><EFBFBD><DEB6><EFBFBD>0-360֮<30><D6AE>
|
||||
if (value <= -360)
|
||||
value += 360;
|
||||
if (value >= 360)
|
||||
value -= 360;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>value<75><65>ֵ<EFBFBD><D6B5>min<69><6E>max֮<78>䣬<EFBFBD><E4A3AC><EFBFBD><EFBFBD>valueС<65><D0A1>min<69><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>min<69><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>value<75><65><EFBFBD><EFBFBD>max<61><78><EFBFBD><EFBFBD><EFBFBD><EFBFBD>max<61><78><EFBFBD><EFBFBD><EFBFBD><EFBFBD>value
|
||||
return Mathf.Clamp(value, min, max);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region <EFBFBD>м<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>
|
||||
// <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
||||
float mouseX2;
|
||||
float mouseY2;
|
||||
Vector3 moveDir;
|
||||
|
||||
/// <summary>
|
||||
/// <20>м<EFBFBD><D0BC>ƶ<EFBFBD><C6B6>ٶ<EFBFBD>
|
||||
/// </summary>
|
||||
[Header("<22><><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD>Ʋ<EFBFBD><C6B2><EFBFBD>")]
|
||||
[Tooltip("<22>м<EFBFBD><D0BC>ƶ<EFBFBD><C6B6>ٶ<EFBFBD>")]
|
||||
public float moveSpeed = 1;
|
||||
|
||||
/// <summary>
|
||||
/// <20>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>
|
||||
/// </summary>
|
||||
public void MoveWithMidBtn()
|
||||
{
|
||||
if (Input.GetMouseButton(2))
|
||||
{
|
||||
mouseX2 = Input.GetAxis("Mouse X");
|
||||
mouseY2 = Input.GetAxis("Mouse Y");
|
||||
if (mouseX2 != 0 || mouseY2 != 0)
|
||||
{
|
||||
IsMouseOnControl = true;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>λ<EFBFBD>õ<EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Vector3<72><33><EFBFBD>ͣ<EFBFBD>ʵ<EFBFBD><CAB5>ԭ<EFBFBD><D4AD><EFBFBD>ǣ<EFBFBD><C7A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļӷ<C4BC><D3B7><EFBFBD>
|
||||
moveDir = (mouseX2 * -tran.right + mouseY2 * -tran.forward);
|
||||
//<2F><><EFBFBD><EFBFBD>y<EFBFBD><79><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>
|
||||
moveDir.y = 0;
|
||||
tran.position += moveDir * 0.5f * moveSpeed;
|
||||
}
|
||||
}
|
||||
if (Input.GetMouseButtonUp(2))
|
||||
{
|
||||
IsMouseOnControl = false;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region <EFBFBD><EFBFBD><EFBFBD>ֿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
||||
float fov; // <20>Ƕ<EFBFBD>
|
||||
float wheel; // <20><><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>
|
||||
|
||||
/// <summary>
|
||||
/// fov <20><>С<EFBFBD>Ƕ<EFBFBD>
|
||||
/// </summary>
|
||||
[Tooltip("fov <20><>С<EFBFBD>Ƕ<EFBFBD>")]
|
||||
public int fovMinLimit = 25;
|
||||
/// <summary>
|
||||
/// fov <20><><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD>
|
||||
/// </summary>
|
||||
[Tooltip("fov <20><><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD>")]
|
||||
public int fovMaxLimit = 75;
|
||||
/// <summary>
|
||||
/// fov <20>仯<EFBFBD>ٶ<EFBFBD>
|
||||
/// </summary>
|
||||
[Tooltip("fov <20>仯<EFBFBD>ٶ<EFBFBD>")]
|
||||
public float fovSpeed = 50.0f;
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD>ֿ<EFBFBD><D6BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
public void CameraFOVWithWheel()
|
||||
{
|
||||
wheel = Input.GetAxis("Mouse ScrollWheel");
|
||||
if (wheel != 0)
|
||||
{
|
||||
fov = CommonData.MainCamera.fieldOfView;
|
||||
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵĻ<D6B5><C4BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
fov += wheel * Time.deltaTime * 100 * fovSpeed;
|
||||
// fov <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
fov = Mathf.Clamp(fov, fovMinLimit, fovMaxLimit);
|
||||
//<2F>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> fov
|
||||
CommonData.MainCamera.fieldOfView = fov;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <20><>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD><C3B6>
|
||||
/// </summary>
|
||||
public enum RotationAxes
|
||||
{
|
||||
MouseXAndY,
|
||||
MouseX,
|
||||
MouseY
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 135abf4e8f80c9e46b1fe197da7e0075
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
164
Assets/Roaming/Scripts/Controller/Camera/NavController.cs
Normal file
164
Assets/Roaming/Scripts/Controller/Camera/NavController.cs
Normal file
@@ -0,0 +1,164 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
[RequireComponent(typeof(NavMeshAgent))]
|
||||
public class NavController : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ʾ<EFBFBD>Ĺ<EFBFBD>Ȧ<EFBFBD><C8A6><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
[Tooltip("<22><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ʾ<EFBFBD>Ĺ<EFBFBD>Ȧ<EFBFBD><C8A6><EFBFBD><EFBFBD>")]
|
||||
public GameObject preClick;
|
||||
|
||||
/// <summary>
|
||||
/// <20>ɵ<EFBFBD><C9B5><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
[Tooltip("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵIJ㣬<C4B2><E3A3AC>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>Ϊ<EFBFBD><CEAA>")]
|
||||
public LayerMask layer;
|
||||
|
||||
/// <summary>
|
||||
/// <20><>ɫѰ·<D1B0><C2B7>ת<EFBFBD>ٶ<EFBFBD>
|
||||
/// </summary>
|
||||
[Tooltip("<22><>ɫѰ·<D1B0><C2B7>ת<EFBFBD>ٶ<EFBFBD>")]
|
||||
public float rotateSpeed = 50f;
|
||||
|
||||
/// <summary>
|
||||
/// <20><>ɫѰ·<D1B0>ƶ<EFBFBD><C6B6>ٶ<EFBFBD>
|
||||
/// </summary>
|
||||
[Tooltip("<22><>ɫѰ·<D1B0>ƶ<EFBFBD><C6B6>ٶ<EFBFBD>")]
|
||||
public float moveSpeed = 2f;
|
||||
|
||||
/// <summary>
|
||||
/// <20><>ɫѰ·<D1B0><C2B7>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
[Tooltip("<22><>ɫѰ·<D1B0><C2B7>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>")]
|
||||
public float MaxNavDistance = 10f;
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
NavMeshAgent agent;
|
||||
|
||||
GameObject objClick;
|
||||
|
||||
void Start()
|
||||
{
|
||||
agent = GetComponent<NavMeshAgent>();
|
||||
|
||||
if (agent != null)
|
||||
{
|
||||
// <20><>ʼ<EFBFBD><CABC><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD>ٶ<EFBFBD>
|
||||
agent.speed = moveSpeed;
|
||||
agent.angularSpeed = rotateSpeed;
|
||||
}
|
||||
if(transform.parent != null)
|
||||
objClick = Instantiate(preClick, transform.parent.transform);
|
||||
else
|
||||
objClick = Instantiate(preClick);
|
||||
objClick.SetActive(false);
|
||||
|
||||
layerMask = (1 << 0) | (1 << 6); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD>ϲ㣨ǽ<E3A3A8><C7BD>
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD><DFBC><EFBFBD>
|
||||
RaycastHit hit;
|
||||
Ray ray;
|
||||
int layerMask;
|
||||
NavMeshHit meshHit;
|
||||
|
||||
Vector3 mouseDownPos;
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
if (CanControl
|
||||
&& agent.enabled
|
||||
&& !IsTouchOnControl
|
||||
&& !IsJoyStickOnControl
|
||||
&& !IsUIClicked)
|
||||
{
|
||||
if (Input.GetMouseButtonUp(1) || Input.touchCount == 1)
|
||||
{
|
||||
if (!EventSystem.current.IsPointerOverGameObject())
|
||||
{
|
||||
if (!IsMouseOnControl && Input.touchCount == 1)
|
||||
{
|
||||
ray = CommonData.MainCamera.ScreenPointToRay(Input.touches[0].position);
|
||||
}
|
||||
else
|
||||
{
|
||||
ray = CommonData.MainCamera.ScreenPointToRay(Input.mousePosition);
|
||||
}
|
||||
|
||||
if (Physics.Raycast(ray, out hit, MaxNavDistance, layerMask))
|
||||
{
|
||||
// Debug.Log(hit.collider.name);
|
||||
// <20>жϵ<D0B6><CFB5><EFBFBD><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õIJ<C3B5><C4B2>Ƿ<EFBFBD>һ<EFBFBD><D2BB>
|
||||
if (Mathf.Pow(2, hit.collider.gameObject.layer) == layer.value)
|
||||
{
|
||||
if (NavMesh.SamplePosition(hit.point, out meshHit, 1.0f, NavMesh.AllAreas))
|
||||
{
|
||||
// agent.enabled = true;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>λ<EFBFBD>ò<EFBFBD><C3B2><EFBFBD>ʾ
|
||||
objClick.transform.position = hit.point;
|
||||
objClick.SetActive(true);
|
||||
|
||||
// <20>Զ<EFBFBD>Ѱ·<D1B0><C2B7>Ŀ<EFBFBD><C4BF>λ<EFBFBD><CEBB>
|
||||
agent.isStopped = false;
|
||||
agent.SetDestination(hit.point);
|
||||
|
||||
// <20><>ʶ<EFBFBD>Զ<EFBFBD>Ѱ·<D1B0><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
IsNavOnControl = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>̻<EFBFBD><CCBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹͣѰ·
|
||||
// if (IsMouseOnControl || IsKeyOnControl || IsJoyStickOnControl)
|
||||
if (IsKeyOnControl || IsJoyStickOnControl)
|
||||
{
|
||||
StopNav();
|
||||
}
|
||||
|
||||
if (IsNavOnControl && !IsMoving())
|
||||
{
|
||||
IsNavOnControl = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ֹͣѰ·
|
||||
/// </summary>
|
||||
public void StopNav()
|
||||
{
|
||||
if (agent.enabled)
|
||||
{
|
||||
agent.isStopped = true; // ֹͣ<CDA3>Զ<EFBFBD>Ѱ·
|
||||
}
|
||||
|
||||
objClick.SetActive(false); // <20><><EFBFBD>ص<EFBFBD><D8B5><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
IsNavOnControl = false;
|
||||
|
||||
// agent.enabled = false;
|
||||
}
|
||||
|
||||
// Unity<74><79><EFBFBD><EFBFBD><EFBFBD>Ƿ<C7B7>Ŀ<EFBFBD>ĵصķ<D8B5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Щ<EFBFBD><D0A9><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD>ĵأ<C4B5>
|
||||
public bool IsMoving()
|
||||
{
|
||||
if (!agent.enabled)
|
||||
return false;
|
||||
//bool r = agent.pathPending || agent.remainingDistance > agent.stoppingDistance || agent.velocity != Vector3.zero;
|
||||
//r = agent.enabled ? r : false;
|
||||
//return r;
|
||||
|
||||
return agent.enabled ?
|
||||
agent.pathPending || agent.remainingDistance > agent.stoppingDistance || agent.velocity != Vector3.zero
|
||||
:
|
||||
false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 151e2b8e130408245ba9b46b6639f9d6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
140
Assets/Roaming/Scripts/Controller/Camera/ShowController.cs
Normal file
140
Assets/Roaming/Scripts/Controller/Camera/ShowController.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
public class ShowControllerXX : MonoBehaviour
|
||||
{
|
||||
public static ShowControllerXX Instance;
|
||||
|
||||
List<BaseShow> lstShow;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
lstShow = new List<BaseShow>();
|
||||
}
|
||||
|
||||
public void AddShow(BaseShow bs)
|
||||
{
|
||||
lstShow.Add(bs);
|
||||
}
|
||||
|
||||
public void RemoveShow(BaseShow bs)
|
||||
{
|
||||
lstShow.Remove(bs);
|
||||
}
|
||||
|
||||
public string GetImageShow(Data info, int index)
|
||||
{
|
||||
var result = lstShow.FirstOrDefault(show =>
|
||||
(show.info.ObjectID == info.ObjectID || show.info.ParentID == info.ParentID)
|
||||
&& show.info.Type == DataType.MultiImage
|
||||
&& show.info.Index == index
|
||||
);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
int count = lstShow.Count(show => show.info.ParentID == info.ObjectID);
|
||||
if (result == null)
|
||||
{
|
||||
return info.Title;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImageShow isResult = (result as ImageShow);
|
||||
if (isResult == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return isResult.info.Title;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float distance;
|
||||
bool canClickNewStatus;
|
||||
ShowBoxCollider tmpSBC;
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
//if (
|
||||
// BaseController.IsJoyStickOnControl
|
||||
// || BaseController.IsKeyOnControl
|
||||
// || BaseController.IsMouseOnControl
|
||||
// || BaseController.IsNavOnControl
|
||||
// )
|
||||
if(BaseController.CanControl &&
|
||||
!BaseController.IsKeyOnControl &&
|
||||
!BaseController.IsNavOnControl &&
|
||||
!BaseController.IsJoyStickOnControl)
|
||||
{
|
||||
foreach (BaseShow show in lstShow)
|
||||
{
|
||||
if(show.transform.childCount > 0)
|
||||
{
|
||||
distance = show.GetComponentsInChildren<Transform>().Min(tran => Vector3.Distance(CommonData.MainCamera.transform.position, tran.position));
|
||||
// Debug.Log(show.name);
|
||||
}
|
||||
|
||||
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>õľ<C3B5><C4BE><EFBFBD>
|
||||
if (distance == 0)
|
||||
distance = Vector3.Distance(CommonData.MainCamera.transform.position, show.transform.position);
|
||||
else
|
||||
distance = Mathf.Min(
|
||||
distance,
|
||||
Vector3.Distance(CommonData.MainCamera.transform.position, show.transform.position)
|
||||
);
|
||||
|
||||
canClickNewStatus = (distance <= CommonData.ClickDistance);
|
||||
|
||||
// <20>ɵ<EFBFBD><C9B5><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD>ı䣨<C4B1><E4A3A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>룩
|
||||
if (show.CanClick != canClickNewStatus)
|
||||
{
|
||||
show.CanClick = canClickNewStatus;
|
||||
|
||||
if (show.info.Clickable)
|
||||
{
|
||||
if (show.CanClick)
|
||||
{
|
||||
tmpSBC = show.gameObject.AddComponent<ShowBoxCollider>();
|
||||
tmpSBC.showHotTip = show.info.ShowHotTip;
|
||||
tmpSBC.showBox = show.info.ShowBox;
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(show.gameObject.GetComponent<ShowBoxCollider>());
|
||||
}
|
||||
}
|
||||
|
||||
show.OnStatusChange();
|
||||
|
||||
// <20><><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD>п<EFBFBD><D0BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (show.sbc != null)
|
||||
{
|
||||
if (show.CanClick)
|
||||
{
|
||||
show.sbc.enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
show.sbc.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
distance = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae555112443ec7f4285f00959f43442e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
78
Assets/Roaming/Scripts/Controller/Camera/TouchController.cs
Normal file
78
Assets/Roaming/Scripts/Controller/Camera/TouchController.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class TouchController : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>Transform
|
||||
/// <20><>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>ǰ<EFBFBD>ű<EFBFBD><C5B1><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD>
|
||||
/// </summary>
|
||||
[Tooltip("<22><><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>Transform<72><6D>Ĭ<EFBFBD><C4AC>Ϊ<EFBFBD><CEAA>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>")]
|
||||
public Transform tran;
|
||||
/// <summary>
|
||||
/// <20>ƶ<EFBFBD><C6B6>ٶȣ<D9B6><C8A3><EFBFBD>/<2F>룩
|
||||
/// </summary>
|
||||
[Tooltip("<22>ƶ<EFBFBD><C6B6>ٶȣ<D9B6><C8A3><EFBFBD>/<2F>룩")]
|
||||
public float moveSpeed = 5;
|
||||
/// <summary>
|
||||
/// <20><>ת<EFBFBD>ٶȣ<D9B6><C8A3>Ƕ<EFBFBD>/<2F>룩
|
||||
/// </summary>
|
||||
[Tooltip("<22><>ת<EFBFBD>ٶȣ<D9B6><C8A3>Ƕ<EFBFBD>/<2F>룩")]
|
||||
public float rotateSpeed = 10;
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
||||
/// </summary>
|
||||
Vector2 startTouchPosition;
|
||||
void Start()
|
||||
{
|
||||
if (tran == null)
|
||||
tran = transform;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (CanControl)
|
||||
{
|
||||
if (Input.touchCount > 0)
|
||||
{
|
||||
Touch touch = Input.GetTouch(0);
|
||||
|
||||
if (touch.phase == TouchPhase.Began)
|
||||
{
|
||||
startTouchPosition = touch.position;
|
||||
}
|
||||
else if (touch.phase == TouchPhase.Moved)
|
||||
{
|
||||
Vector2 deltaTouch = touch.position - startTouchPosition;
|
||||
|
||||
tran.position += tran.forward * moveSpeed * Time.deltaTime * deltaTouch.y; // <20>ƶ<EFBFBD>
|
||||
|
||||
if (deltaTouch.x > 0)
|
||||
tran.Rotate(Vector3.up * rotateSpeed * Time.deltaTime ); // <20><>ת
|
||||
else
|
||||
tran.Rotate(Vector3.up * -rotateSpeed * Time.deltaTime); // <20><>ת
|
||||
|
||||
IsTouchOnControl = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
IsTouchOnControl = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(IsTouchOnControl)
|
||||
{
|
||||
Invoke("SetTouch", 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetTouch()
|
||||
{
|
||||
IsTouchOnControl = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d4944a79ad629b848a497939d5c64dae
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user