diff --git a/Assets/_Game/Assignment.meta b/Assets/_Game/Assignment.meta new file mode 100644 index 00000000..7e7f5b19 --- /dev/null +++ b/Assets/_Game/Assignment.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9031aa4b757f2db4c99fc835c72305b6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Game/Assignment/ScreenBounds.cs b/Assets/_Game/Assignment/ScreenBounds.cs new file mode 100644 index 00000000..e613f953 --- /dev/null +++ b/Assets/_Game/Assignment/ScreenBounds.cs @@ -0,0 +1,64 @@ + +using UnityEngine; + +namespace Assignment +{ + public class ScreenBounds : MonoBehaviour + { + public VoidEventChannelSO screenWrapChannelX; + public VoidEventChannelSO screenWrapChannelY; + public Camera mainCamera; + [SerializeField] private Renderer[] _renderers; + + private bool IsWrappingX = false; + private bool IsWrappingY = false; + + bool CheckRenderers() + { + foreach (var renderer in _renderers) + { + if (renderer.isVisible) + { + return true; + } + } + + return false; + } + + private void Update() + { + Wrapping(); + } + + private void Wrapping() + { + bool isVisible = CheckRenderers(); + + if (isVisible) + { + IsWrappingY = false; + IsWrappingX = false; + return; + } + + if (IsWrappingX && IsWrappingY) + { + return; + } + + var viewportPosition = mainCamera.WorldToViewportPoint(transform.position); + if (viewportPosition.x > 1 || viewportPosition.x < 0) + { + screenWrapChannelX.RaiseEvent(); + } + + if ( viewportPosition.y > 1 || viewportPosition.y < 0) + { + screenWrapChannelY.RaiseEvent(); + } + + + } + } +} diff --git a/Assets/_Game/Assignment/ScreenBounds.cs.meta b/Assets/_Game/Assignment/ScreenBounds.cs.meta new file mode 100644 index 00000000..f5e6ac9e --- /dev/null +++ b/Assets/_Game/Assignment/ScreenBounds.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: af500ba305a00e947a1cc6a063a6cbd9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Game/Assignment/ScreenWrapX.asset b/Assets/_Game/Assignment/ScreenWrapX.asset new file mode 100644 index 00000000..220e954e --- /dev/null +++ b/Assets/_Game/Assignment/ScreenWrapX.asset @@ -0,0 +1,14 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0151c758e338e894a991c76757896644, type: 3} + m_Name: ScreenWrapX + m_EditorClassIdentifier: diff --git a/Assets/_Game/Assignment/ScreenWrapX.asset.meta b/Assets/_Game/Assignment/ScreenWrapX.asset.meta new file mode 100644 index 00000000..f83d23f6 --- /dev/null +++ b/Assets/_Game/Assignment/ScreenWrapX.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1d0aaa938b3929b4287accc6bc75f9cc +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Game/Assignment/ScreenWrapY.asset b/Assets/_Game/Assignment/ScreenWrapY.asset new file mode 100644 index 00000000..a597e4e0 --- /dev/null +++ b/Assets/_Game/Assignment/ScreenWrapY.asset @@ -0,0 +1,14 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0151c758e338e894a991c76757896644, type: 3} + m_Name: ScreenWrapY + m_EditorClassIdentifier: diff --git a/Assets/_Game/Assignment/ScreenWrapY.asset.meta b/Assets/_Game/Assignment/ScreenWrapY.asset.meta new file mode 100644 index 00000000..c0396e41 --- /dev/null +++ b/Assets/_Game/Assignment/ScreenWrapY.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 469315dcd57957841a79f6c527e86742 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Game/Assignment/ShipListener.cs b/Assets/_Game/Assignment/ShipListener.cs new file mode 100644 index 00000000..611e6371 --- /dev/null +++ b/Assets/_Game/Assignment/ShipListener.cs @@ -0,0 +1,41 @@ + +using UnityEngine; + +namespace Assignment +{ + public class ShipListener : MonoBehaviour + { + public VoidEventChannelSO screenWrapChannelX; + public VoidEventChannelSO screenWrapChannelY; + void OnEnable() + { + screenWrapChannelX.OnEventRaised += ScreenWrapX; + screenWrapChannelY.OnEventRaised += ScreenWrapY; + } + + private void OnDisable() + { + screenWrapChannelX.OnEventRaised -= ScreenWrapX; + screenWrapChannelY.OnEventRaised -= ScreenWrapY; + } + + + //the screenwrapping is a little bit buggy if you slowly approach the ends of the camera but i ran out of time + //and i dont really know how to fix it beyond adding that tiny offset + private void ScreenWrapX() + { + Vector3 newPositionX = transform.position; + newPositionX.x = -newPositionX.x + 0.2f; + + transform.position = newPositionX; + } + + private void ScreenWrapY() + { + Vector3 newPositionY = transform.position; + newPositionY.y = -newPositionY.y + 0.2f; + + transform.position = newPositionY; + } + } +} diff --git a/Assets/_Game/Assignment/ShipListener.cs.meta b/Assets/_Game/Assignment/ShipListener.cs.meta new file mode 100644 index 00000000..32b04f75 --- /dev/null +++ b/Assets/_Game/Assignment/ShipListener.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 25e3a44715433c747ba98423ae04e6ec +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Game/Assignment/VoidEventChannelSO.cs b/Assets/_Game/Assignment/VoidEventChannelSO.cs new file mode 100644 index 00000000..367020ec --- /dev/null +++ b/Assets/_Game/Assignment/VoidEventChannelSO.cs @@ -0,0 +1,17 @@ +using UnityEngine; +using UnityEngine.Events; + +namespace Assignment +{ + [CreateAssetMenu(menuName = "Events/Void Event Channel")] + public class VoidEventChannelSO : ScriptableObject + { + public UnityAction OnEventRaised; + + public void RaiseEvent() + { + OnEventRaised?.Invoke(); + } + } +} + diff --git a/Assets/_Game/Assignment/VoidEventChannelSO.cs.meta b/Assets/_Game/Assignment/VoidEventChannelSO.cs.meta new file mode 100644 index 00000000..c916f702 --- /dev/null +++ b/Assets/_Game/Assignment/VoidEventChannelSO.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0151c758e338e894a991c76757896644 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: