Skip to content

Commit

Permalink
safer null check
Browse files Browse the repository at this point in the history
  • Loading branch information
Thaina committed Jun 17, 2024
1 parent 935f360 commit ccb5e99
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions Runtime/WebViewPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ public void LoadWebView(string loginToken = "")
#else
InitializeAndShowWebView(loginToken);
#endif
messagePanel.SetMessage(messageType);
messagePanel.SetVisible(true);
if(messagePanel)
{
messagePanel.SetMessage(messageType);
messagePanel.SetVisible(true);
}

SetScreenPadding();
}

Expand Down Expand Up @@ -92,8 +96,12 @@ public void ReloadWithLoginToken(string loginToken = "")
/// </summary>
public void SetVisible(bool visible)
{
messagePanel.SetVisible(visible);
if (webViewObject != null)
if (messagePanel)
{
messagePanel.SetVisible(visible);
}

if (webViewObject)
{
webViewObject.IsVisible = visible;
}
Expand All @@ -102,7 +110,7 @@ public void SetVisible(bool visible)
private void OnDrawGizmos()
{
var rectTransform = transform as RectTransform;
if (rectTransform != null)
if (rectTransform)
{
Gizmos.matrix = rectTransform.localToWorldMatrix;
Gizmos.color = Color.green;
Expand All @@ -123,7 +131,10 @@ private void SetScreenPadding()
webViewObject.SetMargins(screenPadding.left, screenPadding.top, screenPadding.right, screenPadding.bottom);
}

messagePanel.SetMargins(screenPadding.left, screenPadding.top, screenPadding.right, screenPadding.bottom);
if (messagePanel)
{
messagePanel.SetMargins(screenPadding.left, screenPadding.top, screenPadding.right, screenPadding.bottom);
}
}

// Receives message from RPM website, which contains avatar URL.
Expand All @@ -132,7 +143,8 @@ private void OnWebMessageReceived(string message)
SDKLogger.AvatarLoaderLogger.Log(TAG, $"--- WebView Message: {message}");
try
{
HandleEvents(JsonConvert.DeserializeObject<WebMessage>(message));
var jsonMessage = JsonConvert.DeserializeObject<WebMessage>(message);
HandleEvents(jsonMessage);
}
catch (Exception e)
{
Expand Down

0 comments on commit ccb5e99

Please sign in to comment.