TO SQUASH: Shark notifications.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public abstract class YummyBase : MonoBehaviour
|
||||
public abstract class YummyBase : NotifierBase
|
||||
{
|
||||
public AudioClip bounceSound;
|
||||
|
||||
@@ -9,12 +9,6 @@ public abstract class YummyBase : MonoBehaviour
|
||||
|
||||
public AudioClip missedSound;
|
||||
|
||||
public Canvas canvas;
|
||||
|
||||
public GameObject notificationPrefab;
|
||||
|
||||
protected GameObject notificationInstance;
|
||||
|
||||
private AudioSource audioSource;
|
||||
|
||||
private Animator animator;
|
||||
@@ -119,53 +113,4 @@ public abstract class YummyBase : MonoBehaviour
|
||||
}
|
||||
|
||||
protected abstract void ObtainedCallback(Player player);
|
||||
|
||||
protected void ShowNotification(string text)
|
||||
{
|
||||
if (notificationPrefab == null || canvas == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
notificationInstance = Instantiate(notificationPrefab);
|
||||
notificationInstance.transform.SetParent(canvas.transform, false);
|
||||
notificationInstance.transform.localScale = Vector3.one;
|
||||
|
||||
var notificationRect = notificationInstance.GetComponent<RectTransform>();
|
||||
var canvasRect = canvas.GetComponent<RectTransform>();
|
||||
var label = notificationInstance.GetComponent<UnityEngine.UI.Text>();
|
||||
|
||||
if (label != null)
|
||||
{
|
||||
label.text = text;
|
||||
}
|
||||
|
||||
if (notificationRect != null && canvasRect != null)
|
||||
{
|
||||
Camera worldCamera = canvas.worldCamera != null ? canvas.worldCamera : Camera.main;
|
||||
Camera uiCamera = canvas.renderMode == RenderMode.ScreenSpaceOverlay ? null : worldCamera;
|
||||
|
||||
if (worldCamera != null)
|
||||
{
|
||||
Vector2 screenPoint = worldCamera.WorldToScreenPoint(transform.position);
|
||||
|
||||
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, screenPoint, uiCamera, out Vector2 localPoint))
|
||||
{
|
||||
notificationRect.anchoredPosition = localPoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StartCoroutine(HideNotification());
|
||||
}
|
||||
|
||||
protected IEnumerator HideNotification()
|
||||
{
|
||||
yield return new WaitForSeconds(1.5f);
|
||||
|
||||
if (notificationInstance != null)
|
||||
{
|
||||
Destroy(notificationInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user