Skip to content

Commit

Permalink
Version 1.2.7
Browse files Browse the repository at this point in the history
+Small fix on UIPanel to not invoke OnEnable if the panel don't start active
  • Loading branch information
HanzaRu committed Mar 8, 2023
0 parents commit 6e8998b
Show file tree
Hide file tree
Showing 32 changed files with 733 additions and 0 deletions.
Binary file added .icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions GameWorkstore.ProtocolUI.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "GameWorkstore.ProtocolUI",
"references": [
"GUID:c32d36751e998d74999be5c29b033d6e"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions GameWorkstore.ProtocolUI.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions LICENSE.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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!
7 changes: 7 additions & 0 deletions README.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Runtime.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Runtime/AspectRatio.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions Runtime/AspectRatio/AspectRatioConfig.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
11 changes: 11 additions & 0 deletions Runtime/AspectRatio/AspectRatioConfig.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Runtime/AspectRatio/UIAspectRatioInitializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using GameWorkstore.Patterns;
using UnityEngine;

namespace GameWorkstore.ProtocolUI
{
public class UIAspectRatioInitializer : MonoBehaviour
{
public AspectRatioConfig Config;

private void Awake()
{
ServiceProvider.GetService<UIAspectRatioService>().Initialize(Config);
}
}
}
11 changes: 11 additions & 0 deletions Runtime/AspectRatio/UIAspectRatioInitializer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Runtime/AspectRatio/UIAspectRatioSelector.cs
Original file line number Diff line number Diff line change
@@ -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<UIAspectRatioService>();
aspectRatio.OnAspectRatioChanged.Register(OnAspectRatioChanged);
OnAspectRatioChanged(aspectRatio.CurrentAspectRatioTarget);
}

private void OnAspectRatioChanged(AspectRatioTarget current)
{
A16x9.SetActive(current == AspectRatioTarget.A16X9);
A4x3.SetActive(current == AspectRatioTarget.A4X3);
}
}
}
11 changes: 11 additions & 0 deletions Runtime/AspectRatio/UIAspectRatioSelector.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions Runtime/AspectRatio/UIAspectRatioService.cs
Original file line number Diff line number Diff line change
@@ -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<AspectRatioTarget> OnAspectRatioChanged = new Signal<AspectRatioTarget>();

public override void Preprocess()
{
ServiceProvider.GetService<EventService>().LateUpdate.Register(Update);
}

public override void Postprocess()
{
ServiceProvider.GetService<EventService>().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);
}
}
}
11 changes: 11 additions & 0 deletions Runtime/AspectRatio/UIAspectRatioService.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Runtime/Listeners.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Runtime/Listeners/UIActiveStateButtonListener.cs
Original file line number Diff line number Diff line change
@@ -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<UIStateService>();
GetComponent<Button>().onClick.AddListener(OnClick);
}

private void OnClick()
{
_uistateservice.SetState(State, true);
}
}
}
11 changes: 11 additions & 0 deletions Runtime/Listeners/UIActiveStateButtonListener.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Runtime/Listeners/UIDisableStateButtonListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using GameWorkstore.Patterns;
using UnityEngine;
using UnityEngine.UI;

namespace GameWorkstore.ProtocolUI
{
public class UIDisableStateButtonListener : MonoBehaviour
{
public UIStateScriptable State;
private UIStateService _uistateservice;

// Start is called before the first frame update
private void Awake()
{
_uistateservice = ServiceProvider.GetService<UIStateService>();
GetComponent<Button>().onClick.AddListener(OnClick);
}

private void OnClick()
{
_uistateservice.SetState(State, false);
}
}
}
11 changes: 11 additions & 0 deletions Runtime/Listeners/UIDisableStateButtonListener.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6e8998b

Please sign in to comment.