diff options
Diffstat (limited to 'Other/NavMeshTest/Assets/Scripts')
24 files changed, 495 insertions, 0 deletions
diff --git a/Other/NavMeshTest/Assets/Scripts/CameraController.cs b/Other/NavMeshTest/Assets/Scripts/CameraController.cs new file mode 100644 index 0000000..7315615 --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/CameraController.cs @@ -0,0 +1,66 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CameraController : MonoBehaviour +{ + public float mouseMoveSpeed; + public float aroundSpeed; + public float zoomSpeed; + + private Camera m_Camera; + + private void Awake() + { + m_Camera = GetComponent<Camera>(); + } + + private void Update() + { + if(Input.GetMouseButton(2)) + { + float mouseX = Input.GetAxis("Mouse X"); + float mouseY = Input.GetAxis("Mouse Y"); + + Vector3 position = transform.position; + + Vector3 forwardDir = Vector3.ProjectOnPlane(transform.forward, Vector3.up).normalized; + + position += forwardDir * Time.unscaledDeltaTime * mouseMoveSpeed * -mouseY; + + position += transform.right * Time.unscaledDeltaTime * mouseMoveSpeed * -mouseX; + + transform.position = position; + } + + if(Input.GetMouseButton(1)) + { + float mouseX = Input.GetAxis("Mouse X"); + float mouseY = Input.GetAxis("Mouse Y"); + + float y = transform.position.y; + + Plane ground = new Plane(Vector3.up, Vector3.zero); + Ray ray = new Ray(transform.position, transform.forward); + float enter; + if(ground.Raycast(ray, out enter)) + { + Vector3 point = transform.position + transform.forward * enter; + + float angle = mouseX * Time.unscaledDeltaTime * aroundSpeed; + transform.RotateAround(point, Vector3.up, angle); + + angle = -mouseY * Time.unscaledDeltaTime * aroundSpeed; + transform.RotateAround(point, transform.right, angle); + } + } + + float scroll = Input.mouseScrollDelta.y; + + m_Camera.orthographicSize = m_Camera.orthographicSize + -scroll * zoomSpeed * Time.unscaledDeltaTime; + m_Camera.orthographicSize = Mathf.Clamp(m_Camera.orthographicSize, 3, 15); + + } + + +} diff --git a/Other/NavMeshTest/Assets/Scripts/CameraController.cs.meta b/Other/NavMeshTest/Assets/Scripts/CameraController.cs.meta new file mode 100644 index 0000000..0d8d5aa --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/CameraController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 07ad5207819b44a428942360a8559c67 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NavMeshTest/Assets/Scripts/Comment.cs b/Other/NavMeshTest/Assets/Scripts/Comment.cs new file mode 100644 index 0000000..edcd2ab --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/Comment.cs @@ -0,0 +1,11 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Comment : MonoBehaviour +{ + [TextArea(5, 10)] + public string comment; + + +}
\ No newline at end of file diff --git a/Other/NavMeshTest/Assets/Scripts/Comment.cs.meta b/Other/NavMeshTest/Assets/Scripts/Comment.cs.meta new file mode 100644 index 0000000..eaeecf9 --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/Comment.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 08a4dac05d37dde44aeba9d930048f8b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NavMeshTest/Assets/Scripts/FaceTo.cs b/Other/NavMeshTest/Assets/Scripts/FaceTo.cs new file mode 100644 index 0000000..c809ca5 --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/FaceTo.cs @@ -0,0 +1,22 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class FaceTo : MonoBehaviour +{ + + public Transform target; + + void Update() + { + if (target == null) + return; + + Vector3 dir = target.position - transform.position; + dir = dir.normalized; + + Vector3 faceto = Vector3.ProjectOnPlane(dir, Vector3.up).normalized; + + transform.rotation = Quaternion.LookRotation(faceto, Vector3.up); + } +} diff --git a/Other/NavMeshTest/Assets/Scripts/FaceTo.cs.meta b/Other/NavMeshTest/Assets/Scripts/FaceTo.cs.meta new file mode 100644 index 0000000..c7a8987 --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/FaceTo.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 24b8c7f4739ac724088b9e5f8ac16d6e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NavMeshTest/Assets/Scripts/MoveToMouse.cs b/Other/NavMeshTest/Assets/Scripts/MoveToMouse.cs new file mode 100644 index 0000000..81a2b1b --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/MoveToMouse.cs @@ -0,0 +1,34 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.AI; + +public class MoveToMouse : MonoBehaviour +{ + public Transform flag; + + private NavMeshAgent m_Agent; + + private void Awake() + { + m_Agent = GetComponent<NavMeshAgent>(); + } + + private void Update() + { + if(Input.GetMouseButtonDown(0)) + { + Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); + RaycastHit info; + if(Physics.Raycast(ray, out info, Mathf.Infinity, Physics.DefaultRaycastLayers)) + { + if(info.collider.gameObject.layer != LayerMask.NameToLayer("Prop")) + { + m_Agent.destination = info.point; + flag.position = info.point; + } + } + } + } + +} diff --git a/Other/NavMeshTest/Assets/Scripts/MoveToMouse.cs.meta b/Other/NavMeshTest/Assets/Scripts/MoveToMouse.cs.meta new file mode 100644 index 0000000..9b636ce --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/MoveToMouse.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 20baf0e0b4c5a854e8a4a81f4b3b0bd5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NavMeshTest/Assets/Scripts/MovingPlatform.cs b/Other/NavMeshTest/Assets/Scripts/MovingPlatform.cs new file mode 100644 index 0000000..6907636 --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/MovingPlatform.cs @@ -0,0 +1,28 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class MovingPlatform : MonoBehaviour +{ + + private void OnTriggerEnter(Collider other) + { + + Debug.Log("trigger"); + + if(other.gameObject.CompareTag("Player")) + { + other.gameObject.transform.SetParent(transform); + } + + } + + private void OnTriggerExit(Collider other) + { + if (other.gameObject.CompareTag("Player")) + { + other.gameObject.transform.SetParent(null); + } + } + +}
\ No newline at end of file diff --git a/Other/NavMeshTest/Assets/Scripts/MovingPlatform.cs.meta b/Other/NavMeshTest/Assets/Scripts/MovingPlatform.cs.meta new file mode 100644 index 0000000..3decca2 --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/MovingPlatform.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f08c9ac012a073f4bbaa8b57b6dc3cf8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NavMeshTest/Assets/Scripts/NavigateToTarget.cs b/Other/NavMeshTest/Assets/Scripts/NavigateToTarget.cs new file mode 100644 index 0000000..a7ed374 --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/NavigateToTarget.cs @@ -0,0 +1,53 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.AI; + +public class NavigateToTarget : MonoBehaviour +{ + public Transform flag; + + public NavMeshAgent agent; + + private Transform m_Target; + private Vector3 m_TargetPosition; + + private void Awake() + { + agent = GetComponent<NavMeshAgent>(); + + agent.autoTraverseOffMeshLink = false; + } + + private void Update() + { + if (Input.GetMouseButtonDown(0)) + { + Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); + RaycastHit info; + if (Physics.Raycast(ray, out info, Mathf.Infinity, Physics.DefaultRaycastLayers)) + { + if (info.collider.gameObject.layer != LayerMask.NameToLayer("Prop")) + { + m_Target = info.collider.gameObject.transform; + m_TargetPosition = m_Target.InverseTransformPoint(info.point); + } + } + } + + if(m_Target != null) + { + Vector3 pos = m_Target.TransformPoint(m_TargetPosition); + + agent.destination = pos; + flag.position = pos; + } + + if(agent.isOnOffMeshLink) + { + + } + + } + +} diff --git a/Other/NavMeshTest/Assets/Scripts/NavigateToTarget.cs.meta b/Other/NavMeshTest/Assets/Scripts/NavigateToTarget.cs.meta new file mode 100644 index 0000000..141ec5a --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/NavigateToTarget.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 351de54852744e347813e384a095fbcb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NavMeshTest/Assets/Scripts/Prop.meta b/Other/NavMeshTest/Assets/Scripts/Prop.meta new file mode 100644 index 0000000..a87c688 --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/Prop.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f48dd675f2341424eb83a80a6ec71374 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NavMeshTest/Assets/Scripts/Prop/Door.cs b/Other/NavMeshTest/Assets/Scripts/Prop/Door.cs new file mode 100644 index 0000000..d222797 --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/Prop/Door.cs @@ -0,0 +1,15 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.AI; + +public class Door : Switchable +{ + public Transform plank; + + public override void OnSwitch(bool on) + { + plank.GetComponent<MeshRenderer>().enabled = !on; + plank.GetComponent<NavMeshObstacle>().enabled = !on; + } +} diff --git a/Other/NavMeshTest/Assets/Scripts/Prop/Door.cs.meta b/Other/NavMeshTest/Assets/Scripts/Prop/Door.cs.meta new file mode 100644 index 0000000..5190cf8 --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/Prop/Door.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c22c62dfca55ff144bf01ebccebb49bc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NavMeshTest/Assets/Scripts/Prop/Gate.cs b/Other/NavMeshTest/Assets/Scripts/Prop/Gate.cs new file mode 100644 index 0000000..3104b32 --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/Prop/Gate.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Gate : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Other/NavMeshTest/Assets/Scripts/Prop/Gate.cs.meta b/Other/NavMeshTest/Assets/Scripts/Prop/Gate.cs.meta new file mode 100644 index 0000000..de2ee0b --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/Prop/Gate.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: eb933ba9cfde80c4fbe1ef5a467fb99d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NavMeshTest/Assets/Scripts/Prop/Switch.cs b/Other/NavMeshTest/Assets/Scripts/Prop/Switch.cs new file mode 100644 index 0000000..1312616 --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/Prop/Switch.cs @@ -0,0 +1,63 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public abstract class Switchable : MonoBehaviour +{ + public virtual void OnSwitch(bool on) + { } +} + + +public class Switch : MonoBehaviour +{ + public Switchable target; + + public Transform bar; + + public Vector2 rotationRange; + + private bool m_IsOn; + + private void Start() + { + m_IsOn = false; + OnPressed(); + } + + private void Update() + { + if(Input.GetMouseButtonDown(0)) + { + Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); + RaycastHit info; + if (Physics.Raycast(ray, out info)) + { + if(info.collider.gameObject == gameObject) + { + m_IsOn = !m_IsOn; + + OnPressed(); + + if (target != null) + { + target.OnSwitch(m_IsOn); + } + } + } + } + } + + void OnPressed() + { + if(m_IsOn) + { + bar.localRotation = Quaternion.Euler(0, 0, rotationRange.x); + } + else + { + bar.localRotation = Quaternion.Euler(0, 0, rotationRange.y); + } + } + +}
\ No newline at end of file diff --git a/Other/NavMeshTest/Assets/Scripts/Prop/Switch.cs.meta b/Other/NavMeshTest/Assets/Scripts/Prop/Switch.cs.meta new file mode 100644 index 0000000..757a879 --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/Prop/Switch.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0e50f703823877b4c93c62af16e9e011 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NavMeshTest/Assets/Scripts/Tween.meta b/Other/NavMeshTest/Assets/Scripts/Tween.meta new file mode 100644 index 0000000..03d47a2 --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/Tween.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0f8cabd79bae7944681dd1fb0a42a052 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NavMeshTest/Assets/Scripts/Tween/SmoothMove.cs b/Other/NavMeshTest/Assets/Scripts/Tween/SmoothMove.cs new file mode 100644 index 0000000..1ead7ff --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/Tween/SmoothMove.cs @@ -0,0 +1,21 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class SmoothMove : MonoBehaviour +{ + public Vector3 from; + public Vector3 to; + + public float speed; + + float time; + + private void Update() + { + time += Time.deltaTime * speed; + + transform.position = Vector3.Lerp(from, to, Mathf.PingPong(time, 10) / 10.0f); + } + +} diff --git a/Other/NavMeshTest/Assets/Scripts/Tween/SmoothMove.cs.meta b/Other/NavMeshTest/Assets/Scripts/Tween/SmoothMove.cs.meta new file mode 100644 index 0000000..7e98d19 --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/Tween/SmoothMove.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ff71ad33a52ece64eb93ef7695ba5a8c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NavMeshTest/Assets/Scripts/UpdateNavMeshLink.cs b/Other/NavMeshTest/Assets/Scripts/UpdateNavMeshLink.cs new file mode 100644 index 0000000..d6534c9 --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/UpdateNavMeshLink.cs @@ -0,0 +1,27 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.AI; + +[RequireComponent(typeof(NavMeshLink))] +public class UpdateNavMeshLink : MonoBehaviour +{ + public Transform from; + public Transform to; + + private NavMeshLink m_Link; + + private void Awake() + { + m_Link = GetComponent<NavMeshLink>(); + } + + private void Update() + { + if (from == null || to == null) + return; + m_Link.startPoint = transform.InverseTransformPoint(from.position); + m_Link.endPoint = transform.InverseTransformPoint(to.position); + } + +} diff --git a/Other/NavMeshTest/Assets/Scripts/UpdateNavMeshLink.cs.meta b/Other/NavMeshTest/Assets/Scripts/UpdateNavMeshLink.cs.meta new file mode 100644 index 0000000..5e78ea2 --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/UpdateNavMeshLink.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 449b306fe19d22145b902df25af123a9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |