diff --git a/.icon.png b/.icon.png new file mode 100644 index 0000000..88f2743 Binary files /dev/null and b/.icon.png differ diff --git a/GameWorkstore.ProtocolUI.asmdef b/GameWorkstore.ProtocolUI.asmdef new file mode 100644 index 0000000..1c7db32 --- /dev/null +++ b/GameWorkstore.ProtocolUI.asmdef @@ -0,0 +1,15 @@ +{ + "name": "GameWorkstore.ProtocolUI", + "references": [ + "GUID:c32d36751e998d74999be5c29b033d6e" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/GameWorkstore.ProtocolUI.asmdef.meta b/GameWorkstore.ProtocolUI.asmdef.meta new file mode 100644 index 0000000..5d8fcf4 --- /dev/null +++ b/GameWorkstore.ProtocolUI.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 08dbee498d7574248954d8f542a6d2a4 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..7eebb27 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,23 @@ +MIT License + +Copyright (c) 2015, Unity Technologies + +Copyright (c) 2020 Game Workstore + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/LICENSE.md.meta b/LICENSE.md.meta new file mode 100644 index 0000000..931d4ed --- /dev/null +++ b/LICENSE.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: d32ba5ded8ab1184982bf9915cd85fe1 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/README.md b/README.md new file mode 100644 index 0000000..6b59517 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# Game Workstore Protocol UI + +Protocol UI is a small framework to work with multiple screens on a easy and organized way and manage layered panels on Unity. +Use it your own risk! + +# How to install + +At package.json, add these lines of code: +```json +"com.gameworkstore.protocolui": "https://github.com/GameWorkstore/protocolui.git#1.2.4" +"com.gameworkstore.patterns": "https://github.com/GameWorkstore/patterns.git#1.3.2" +``` + +And wait for unity to download and compile the package. + +you can upgrade your version by including the release version at end of the link: +```json +"com.gameworkstore.protocolui": "https://github.com/GameWorkstore/protocolui.git#1.2.4" +``` + +# Contributions + +If you are using this library and want to submit a change, go ahead! Overall, this project accepts contributions if: +- Is a bug fix; +- Or, is a generalization of a well-known issue; +- Or is performance improvement; +- Or is an improvement to already supported feature. + +Also, you can donate to allow us to drink coffee while we improve it for you! diff --git a/README.md.meta b/README.md.meta new file mode 100644 index 0000000..c28617a --- /dev/null +++ b/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 4961490634aa0d34890a7beb0a72932e +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime.meta b/Runtime.meta new file mode 100644 index 0000000..e1279c9 --- /dev/null +++ b/Runtime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 30f625eb7707e474da5377d92cbaf48b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AspectRatio.meta b/Runtime/AspectRatio.meta new file mode 100644 index 0000000..f4cb79b --- /dev/null +++ b/Runtime/AspectRatio.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bc95c30433c680f469e997d55895f4b2 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AspectRatio/AspectRatioConfig.cs b/Runtime/AspectRatio/AspectRatioConfig.cs new file mode 100644 index 0000000..b5bf797 --- /dev/null +++ b/Runtime/AspectRatio/AspectRatioConfig.cs @@ -0,0 +1,42 @@ +using System; +using UnityEngine; + +namespace GameWorkstore.ProtocolUI +{ + public enum AspectRatioTarget + { + A4X3, + A16X9 + } + + [Serializable] + public struct AspectRatioGroup + { + public AspectRatioTarget Target; + public float Min; + public float Max; + + public bool IsInRange(float value) => value >= Min && value < Max; + } + + [CreateAssetMenu(fileName=nameof(AspectRatioConfig),menuName="ProtocolUI/"+nameof(AspectRatioConfig))] + public class AspectRatioConfig : ScriptableObject + { + public AspectRatioGroup[] AspectRatioGroup = new AspectRatioGroup[] + { + new AspectRatioGroup() + { + Min = 1, + Max = 1.45f, + Target = AspectRatioTarget.A4X3 + }, + new AspectRatioGroup() + { + Min = 1.45f, + Max = 100000, + Target = AspectRatioTarget.A16X9 + } + }; + public AspectRatioTarget Default = AspectRatioTarget.A16X9; + } +} diff --git a/Runtime/AspectRatio/AspectRatioConfig.cs.meta b/Runtime/AspectRatio/AspectRatioConfig.cs.meta new file mode 100644 index 0000000..07d4d18 --- /dev/null +++ b/Runtime/AspectRatio/AspectRatioConfig.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3bdcd3d8dee9fba4f864f9918d661e11 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AspectRatio/UIAspectRatioInitializer.cs b/Runtime/AspectRatio/UIAspectRatioInitializer.cs new file mode 100644 index 0000000..4190d88 --- /dev/null +++ b/Runtime/AspectRatio/UIAspectRatioInitializer.cs @@ -0,0 +1,15 @@ +using GameWorkstore.Patterns; +using UnityEngine; + +namespace GameWorkstore.ProtocolUI +{ + public class UIAspectRatioInitializer : MonoBehaviour + { + public AspectRatioConfig Config; + + private void Awake() + { + ServiceProvider.GetService().Initialize(Config); + } + } +} diff --git a/Runtime/AspectRatio/UIAspectRatioInitializer.cs.meta b/Runtime/AspectRatio/UIAspectRatioInitializer.cs.meta new file mode 100644 index 0000000..20a016a --- /dev/null +++ b/Runtime/AspectRatio/UIAspectRatioInitializer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 81a87584308d70f4693085f8e0e7afcd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AspectRatio/UIAspectRatioSelector.cs b/Runtime/AspectRatio/UIAspectRatioSelector.cs new file mode 100644 index 0000000..5535df3 --- /dev/null +++ b/Runtime/AspectRatio/UIAspectRatioSelector.cs @@ -0,0 +1,24 @@ +using GameWorkstore.Patterns; +using UnityEngine; + +namespace GameWorkstore.ProtocolUI +{ + public class UIAspectRatioSelector : MonoBehaviour + { + public GameObject A16x9; + public GameObject A4x3; + + public void OnEnable() + { + var aspectRatio = ServiceProvider.GetService(); + aspectRatio.OnAspectRatioChanged.Register(OnAspectRatioChanged); + OnAspectRatioChanged(aspectRatio.CurrentAspectRatioTarget); + } + + private void OnAspectRatioChanged(AspectRatioTarget current) + { + A16x9.SetActive(current == AspectRatioTarget.A16X9); + A4x3.SetActive(current == AspectRatioTarget.A4X3); + } + } +} diff --git a/Runtime/AspectRatio/UIAspectRatioSelector.cs.meta b/Runtime/AspectRatio/UIAspectRatioSelector.cs.meta new file mode 100644 index 0000000..4ed3fad --- /dev/null +++ b/Runtime/AspectRatio/UIAspectRatioSelector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ac325bf44323a304aac1483d38ef6119 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AspectRatio/UIAspectRatioService.cs b/Runtime/AspectRatio/UIAspectRatioService.cs new file mode 100644 index 0000000..fc10fab --- /dev/null +++ b/Runtime/AspectRatio/UIAspectRatioService.cs @@ -0,0 +1,57 @@ +using GameWorkstore.Patterns; +using UnityEngine; + +namespace GameWorkstore.ProtocolUI +{ + public class UIAspectRatioService : IService + { + private int LastScreenWidth = -1; + private int LastScreenHeight = -1; + private AspectRatioConfig _config = null; + + public AspectRatioTarget CurrentAspectRatioTarget = AspectRatioTarget.A16X9; + public Signal OnAspectRatioChanged = new Signal(); + + public override void Preprocess() + { + ServiceProvider.GetService().LateUpdate.Register(Update); + } + + public override void Postprocess() + { + ServiceProvider.GetService().LateUpdate.Unregister(Update); + } + + public void Initialize(AspectRatioConfig config) + { + _config = config; + } + + private void Update() + { + if (_config == null) return; + if (LastScreenWidth == Screen.width && LastScreenHeight == Screen.height) return; + LastScreenWidth = Screen.width; + LastScreenHeight = Screen.height; + + bool isPortrait = Screen.height > Screen.width; + var ratio = isPortrait ? + Screen.height / (float)Screen.width : + Screen.width / (float)Screen.height; + + foreach (var group in _config.AspectRatioGroup) + { + if (group.IsInRange(ratio)) + { + CurrentAspectRatioTarget = group.Target; + OnAspectRatioChanged.Invoke(group.Target); + return; + } + } + + //default + CurrentAspectRatioTarget = _config.Default; + OnAspectRatioChanged.Invoke(_config.Default); + } + } +} diff --git a/Runtime/AspectRatio/UIAspectRatioService.cs.meta b/Runtime/AspectRatio/UIAspectRatioService.cs.meta new file mode 100644 index 0000000..a269e4d --- /dev/null +++ b/Runtime/AspectRatio/UIAspectRatioService.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 96cb525e206050d47a6b02034e142c91 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Listeners.meta b/Runtime/Listeners.meta new file mode 100644 index 0000000..7b952e5 --- /dev/null +++ b/Runtime/Listeners.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 73682d3da85cc57439966e804f674071 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Listeners/UIActiveStateButtonListener.cs b/Runtime/Listeners/UIActiveStateButtonListener.cs new file mode 100644 index 0000000..b0a0e04 --- /dev/null +++ b/Runtime/Listeners/UIActiveStateButtonListener.cs @@ -0,0 +1,24 @@ +using GameWorkstore.Patterns; +using UnityEngine; +using UnityEngine.UI; + +namespace GameWorkstore.ProtocolUI +{ + public class UIActiveStateButtonListener : MonoBehaviour + { + public UIStateScriptable State; + private UIStateService _uistateservice; + + // Start is called before the first frame update + private void Awake() + { + _uistateservice = ServiceProvider.GetService(); + GetComponent