-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Move visibility monitoring from View to UGXBehaviour. Resolve
- Loading branch information
Showing
6 changed files
with
55 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,61 @@ | ||
using UnityEngine; | ||
using NaughtyAttributes; | ||
using UnityEngine.Events; | ||
|
||
namespace Adrenak.UGX { | ||
[RequireComponent(typeof(RectTransform))] | ||
public class UGXBehaviour : MonoBehaviour { | ||
public View view => GetComponent<View>(); | ||
public Window window => GetComponent<Window>(); | ||
public PositionTransitioner positionTransitioner => GetComponent<PositionTransitioner>(); | ||
public OpacityTransitioner opacityTransitioner => GetComponent<OpacityTransitioner>(); | ||
|
||
public UnityEvent<Visibility> onVisibilityChanged; | ||
[ReadOnly] [SerializeField] Visibility currentVisibility = Visibility.None; | ||
|
||
public Visibility CurrentVisibility { | ||
get => currentVisibility; | ||
private set => currentVisibility = value; | ||
} | ||
|
||
RectTransform rt; | ||
public RectTransform RT { | ||
get { | ||
if (rt == null) | ||
rt = GetComponent<RectTransform>(); | ||
return rt; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// If you're overriding this, make sure to call base.Awake() first thing | ||
/// in the Awake method of your subclass | ||
/// By marking this method as protected, it'll warn any inheritors | ||
/// </summary> | ||
protected void Awake() => CurrentVisibility = GetVisibility(); | ||
|
||
/// <summary> | ||
/// If you're overriding this, make sure to call base.Update() first thing | ||
/// in the Update method of your subclass | ||
/// By marking this method as protected, it'll warn any inheritors | ||
/// </summary> | ||
protected void Update() { | ||
UpdateVisibility(); | ||
} | ||
|
||
void UpdateVisibility() { | ||
var visibility = GetVisibility(); | ||
if (CurrentVisibility == visibility) return; | ||
|
||
CurrentVisibility = visibility; | ||
onVisibilityChanged?.Invoke(CurrentVisibility); | ||
} | ||
|
||
Visibility GetVisibility() { | ||
if (RT.IsVisible(out bool? fully)) | ||
return fully.Value ? Visibility.None : Visibility.Partial; | ||
else | ||
return Visibility.Full; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters