技能主要更新,修复卡顿并加入动画,以及各种其他更新。
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,116 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class BottomBarButtonHover : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler, IPointerMoveHandler
|
||||
{
|
||||
public float hoverScale = 1.06f;
|
||||
public float pressScale = 0.92f;
|
||||
public float hoverWidthScale = 1.08f;
|
||||
public float scaleLerp = 12f;
|
||||
public float gyroAngle = 6f;
|
||||
public float gyroLerp = 12f;
|
||||
|
||||
private RectTransform rect;
|
||||
private LayoutElement layout;
|
||||
private float basePreferredWidth;
|
||||
private Vector3 baseScale;
|
||||
private bool hovering;
|
||||
private bool pressed;
|
||||
private Vector3 targetScale;
|
||||
private Quaternion targetRotation = Quaternion.identity;
|
||||
private Camera eventCamera;
|
||||
private RectTransform layoutRoot;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
rect = GetComponent<RectTransform>();
|
||||
baseScale = transform.localScale;
|
||||
targetScale = baseScale;
|
||||
|
||||
layout = GetComponent<LayoutElement>();
|
||||
if (layout == null)
|
||||
layout = gameObject.AddComponent<LayoutElement>();
|
||||
|
||||
basePreferredWidth = layout.preferredWidth;
|
||||
if (basePreferredWidth <= 0f && rect != null)
|
||||
basePreferredWidth = rect.rect.width;
|
||||
|
||||
if (basePreferredWidth <= 0f)
|
||||
basePreferredWidth = 100f;
|
||||
|
||||
layout.preferredWidth = basePreferredWidth;
|
||||
|
||||
var group = GetComponentInParent<LayoutGroup>();
|
||||
if (group != null)
|
||||
layoutRoot = group.GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
float dt = Time.unscaledDeltaTime;
|
||||
transform.localScale = Vector3.Lerp(transform.localScale, targetScale, 1f - Mathf.Exp(-scaleLerp * dt));
|
||||
|
||||
if (hovering)
|
||||
{
|
||||
Vector2 localPoint;
|
||||
if (rect != null && RectTransformUtility.ScreenPointToLocalPointInRectangle(rect, Input.mousePosition, eventCamera, out localPoint))
|
||||
{
|
||||
Vector2 size = rect.rect.size;
|
||||
float nx = size.x > 0f ? localPoint.x / size.x : 0f;
|
||||
float ny = size.y > 0f ? localPoint.y / size.y : 0f;
|
||||
float rotX = -ny * gyroAngle * 2f;
|
||||
float rotY = nx * gyroAngle * 2f;
|
||||
targetRotation = Quaternion.Euler(rotX, rotY, 0f);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
targetRotation = Quaternion.identity;
|
||||
}
|
||||
|
||||
transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRotation, 1f - Mathf.Exp(-gyroLerp * dt));
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
hovering = true;
|
||||
eventCamera = eventData.pressEventCamera;
|
||||
layout.preferredWidth = basePreferredWidth * hoverWidthScale;
|
||||
RebuildLayout();
|
||||
if (!pressed)
|
||||
targetScale = baseScale * hoverScale;
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
hovering = false;
|
||||
layout.preferredWidth = basePreferredWidth;
|
||||
RebuildLayout();
|
||||
if (!pressed)
|
||||
targetScale = baseScale;
|
||||
}
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
pressed = true;
|
||||
targetScale = baseScale * pressScale;
|
||||
}
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
pressed = false;
|
||||
targetScale = baseScale * (hovering ? hoverScale : 1f);
|
||||
}
|
||||
|
||||
public void OnPointerMove(PointerEventData eventData)
|
||||
{
|
||||
eventCamera = eventData.pressEventCamera;
|
||||
}
|
||||
|
||||
private void RebuildLayout()
|
||||
{
|
||||
if (layoutRoot != null)
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(layoutRoot);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3c858fc56d8aa84daefcd0121bcadd8
|
||||
File diff suppressed because it is too large
Load Diff
@@ -16,6 +16,13 @@ public class btmandtopController : MonoBehaviour
|
||||
public Button email_display;
|
||||
public Button notice_display;
|
||||
|
||||
public Button button_Music;
|
||||
[Header("MusicPic")]
|
||||
public RectTransform musicPicRoot;
|
||||
public bool showMusicPicInUI = false;
|
||||
public string uiSceneName = "UI_UI";
|
||||
public float musicPicFadeTime = 0.25f;
|
||||
|
||||
[Header("sig prefabs")]
|
||||
public GameObject showLevel_prefab;
|
||||
public GameObject store_prefab;
|
||||
@@ -33,15 +40,37 @@ public class btmandtopController : MonoBehaviour
|
||||
|
||||
// cached reference to the settings instance to ensure only one exists
|
||||
private GameObject settingsInstance;
|
||||
private GameObject showLevelInstance;
|
||||
private GameObject emailInstance;
|
||||
private GameObject noticeInstance;
|
||||
private CanvasGroup musicPicGroup;
|
||||
private Coroutine musicPicFade;
|
||||
private bool musicPicVisible = true;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
EnsureMusicPicRoot();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (button_Music == null)
|
||||
{
|
||||
var btn = transform.Find("Button_Music") as RectTransform;
|
||||
if (btn != null)
|
||||
button_Music = btn.GetComponent<Button>();
|
||||
if (button_Music == null)
|
||||
{
|
||||
var any = FindByName("Button_Music");
|
||||
if (any != null) button_Music = any.GetComponent<Button>();
|
||||
}
|
||||
}
|
||||
instantiateSettings = () => ToggleSettingsPrefab();
|
||||
instantiateUserInfo = () => InstantiatePrefab(userInfo_prefab);
|
||||
instantiateStore = () => InstantiatePrefab(store_prefab);
|
||||
instantiateShowLevel = () => InstantiatePrefab(showLevel_prefab);
|
||||
instantiateEmail = () => InstantiatePrefab(email_prefab);
|
||||
instantiateNotice = () => InstantiatePrefab(notice_prefab);
|
||||
instantiateShowLevel = () => ShowLevelPrefab();
|
||||
instantiateEmail = () => ShowEmailPrefab();
|
||||
instantiateNotice = () => ShowNoticePrefab();
|
||||
|
||||
if (settings_launch != null)
|
||||
settings_launch.onClick.AddListener(instantiateSettings);
|
||||
@@ -56,6 +85,17 @@ public class btmandtopController : MonoBehaviour
|
||||
if (notice_display != null)
|
||||
notice_display.onClick.AddListener(instantiateNotice);
|
||||
|
||||
EnsureMusicPicRoot();
|
||||
SetupMusicPicDefault();
|
||||
if (button_Music != null)
|
||||
button_Music.onClick.AddListener(ToggleMusicPicLocal);
|
||||
|
||||
var binder = BgmUiBinder.Instance != null ? BgmUiBinder.Instance : Object.FindAnyObjectByType<BgmUiBinder>();
|
||||
if (binder != null && musicPicRoot != null)
|
||||
{
|
||||
binder.SetMusicRoot(musicPicRoot);
|
||||
}
|
||||
|
||||
// Pre-instantiate settings prefab and keep it inactive, ensuring only one exists
|
||||
if (settings_prefab != null && putPrefabsHere != null)
|
||||
{
|
||||
@@ -80,7 +120,7 @@ public class btmandtopController : MonoBehaviour
|
||||
Canvas c = settingsInstance.GetComponentInChildren<Canvas>(true);
|
||||
if (c != null)
|
||||
{
|
||||
Camera[] cams = GameObject.FindObjectsOfType<Camera>();
|
||||
Camera[] cams = Object.FindObjectsByType<Camera>(FindObjectsInactive.Exclude, FindObjectsSortMode.None);
|
||||
if (cams != null && cams.Length > 0)
|
||||
{
|
||||
c.worldCamera = cams[0];
|
||||
@@ -100,8 +140,160 @@ public class btmandtopController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if(Input.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
//ToggleSettingsPrefab();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void ToggleMusicPic()
|
||||
{
|
||||
var binder = BgmUiBinder.Instance != null ? BgmUiBinder.Instance : Object.FindAnyObjectByType<BgmUiBinder>();
|
||||
if (binder != null)
|
||||
{
|
||||
binder.ToggleMusicPic();
|
||||
var spectrum = binder.GetSpectrumRoot();
|
||||
if (spectrum != null && binder.transform != null)
|
||||
{
|
||||
spectrum.localRotation = binder.transform.localRotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureMusicPicRoot()
|
||||
{
|
||||
if (musicPicRoot != null)
|
||||
return;
|
||||
var child = transform.Find("MusicPic");
|
||||
if (child != null)
|
||||
{
|
||||
musicPicRoot = child as RectTransform;
|
||||
return;
|
||||
}
|
||||
var sceneMusic = GameObject.Find("MusicPic");
|
||||
if (sceneMusic != null)
|
||||
{
|
||||
musicPicRoot = sceneMusic.GetComponent<RectTransform>();
|
||||
if (musicPicRoot != null)
|
||||
{
|
||||
musicPicRoot.SetParent(transform, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupMusicPicDefault()
|
||||
{
|
||||
if (musicPicRoot == null)
|
||||
return;
|
||||
EnsureMusicPicGroup();
|
||||
SetMusicPicVisible(false, true);
|
||||
}
|
||||
|
||||
private void EnsureMusicPicGroup()
|
||||
{
|
||||
if (musicPicRoot == null)
|
||||
return;
|
||||
if (musicPicGroup == null)
|
||||
musicPicGroup = musicPicRoot.GetComponent<CanvasGroup>();
|
||||
if (musicPicGroup == null)
|
||||
musicPicGroup = musicPicRoot.gameObject.AddComponent<CanvasGroup>();
|
||||
}
|
||||
|
||||
private void ToggleMusicPicLocal()
|
||||
{
|
||||
EnsureMusicPicRoot();
|
||||
var binder = BgmUiBinder.Instance != null ? BgmUiBinder.Instance : Object.FindAnyObjectByType<BgmUiBinder>();
|
||||
if (musicPicRoot == null)
|
||||
{
|
||||
if (binder != null)
|
||||
binder.ToggleMusicPic();
|
||||
return;
|
||||
}
|
||||
|
||||
SetMusicPicVisible(!musicPicVisible, false);
|
||||
}
|
||||
|
||||
private void SetMusicPicVisible(bool visible, bool instant)
|
||||
{
|
||||
if (musicPicRoot == null)
|
||||
return;
|
||||
EnsureMusicPicGroup();
|
||||
musicPicVisible = visible;
|
||||
|
||||
if (musicPicFade != null)
|
||||
{
|
||||
StopCoroutine(musicPicFade);
|
||||
musicPicFade = null;
|
||||
}
|
||||
|
||||
if (instant)
|
||||
{
|
||||
musicPicGroup.alpha = visible ? 1f : 0f;
|
||||
musicPicGroup.interactable = visible;
|
||||
musicPicGroup.blocksRaycasts = visible;
|
||||
musicPicRoot.gameObject.SetActive(visible);
|
||||
return;
|
||||
}
|
||||
|
||||
musicPicRoot.gameObject.SetActive(true);
|
||||
musicPicFade = StartCoroutine(FadeMusicPic(visible));
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator FadeMusicPic(bool visibleAtEnd)
|
||||
{
|
||||
EnsureMusicPicGroup();
|
||||
if (musicPicGroup == null)
|
||||
yield break;
|
||||
float start = musicPicGroup != null ? musicPicGroup.alpha : 0f;
|
||||
float target = visibleAtEnd ? 1f : 0f;
|
||||
float t = 0f;
|
||||
while (t < 1f)
|
||||
{
|
||||
if (musicPicGroup == null || musicPicRoot == null)
|
||||
yield break;
|
||||
t += Time.unscaledDeltaTime / Mathf.Max(0.0001f, musicPicFadeTime);
|
||||
float eased = Mathf.SmoothStep(0f, 1f, t);
|
||||
musicPicGroup.alpha = Mathf.LerpUnclamped(start, target, eased);
|
||||
yield return null;
|
||||
}
|
||||
if (musicPicGroup != null)
|
||||
{
|
||||
musicPicGroup.alpha = target;
|
||||
musicPicGroup.interactable = visibleAtEnd;
|
||||
musicPicGroup.blocksRaycasts = visibleAtEnd;
|
||||
}
|
||||
if (!visibleAtEnd && musicPicRoot != null)
|
||||
{
|
||||
musicPicRoot.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
GameObject FindByName(string name)
|
||||
{
|
||||
var all = Resources.FindObjectsOfTypeAll<Transform>();
|
||||
for (int i = 0; i < all.Length; i++)
|
||||
{
|
||||
var t = all[i];
|
||||
if (t == null) continue;
|
||||
if (!t.gameObject.scene.IsValid() || !t.gameObject.scene.isLoaded) continue;
|
||||
if (t.name == name) return t.gameObject;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if (musicPicFade != null)
|
||||
{
|
||||
StopCoroutine(musicPicFade);
|
||||
musicPicFade = null;
|
||||
}
|
||||
musicPicGroup = null;
|
||||
if (settings_launch != null)
|
||||
settings_launch.onClick.RemoveListener(instantiateSettings);
|
||||
if (userInfo_launch != null)
|
||||
@@ -114,6 +306,9 @@ public class btmandtopController : MonoBehaviour
|
||||
email_display.onClick.RemoveListener(instantiateEmail);
|
||||
if (notice_display != null)
|
||||
notice_display.onClick.RemoveListener(instantiateNotice);
|
||||
|
||||
if (button_Music != null)
|
||||
button_Music.onClick.RemoveListener(ToggleMusicPicLocal);
|
||||
}
|
||||
|
||||
private void ToggleSettingsPrefab()
|
||||
@@ -131,7 +326,7 @@ public class btmandtopController : MonoBehaviour
|
||||
Canvas c = settingsInstance.GetComponentInChildren<Canvas>(true);
|
||||
if (c != null)
|
||||
{
|
||||
Camera[] cams = GameObject.FindObjectsOfType<Camera>();
|
||||
Camera[] cams = Object.FindObjectsByType<Camera>(FindObjectsInactive.Exclude, FindObjectsSortMode.None);
|
||||
if (cams != null && cams.Length > 0)
|
||||
{
|
||||
c.worldCamera = cams[0];
|
||||
@@ -151,6 +346,97 @@ public class btmandtopController : MonoBehaviour
|
||||
settingsInstance.SetActive(!active);
|
||||
}
|
||||
|
||||
private void ShowLevelPrefab()
|
||||
{
|
||||
ShowPrefab(showLevel_prefab, ref showLevelInstance);
|
||||
CloseInfoPanels(showLevelInstance);
|
||||
}
|
||||
|
||||
private void ShowEmailPrefab()
|
||||
{
|
||||
ShowPrefab(email_prefab, ref emailInstance);
|
||||
CloseInfoPanels(emailInstance);
|
||||
}
|
||||
|
||||
private void ShowNoticePrefab()
|
||||
{
|
||||
ShowPrefab(notice_prefab, ref noticeInstance);
|
||||
CloseInfoPanels(noticeInstance);
|
||||
}
|
||||
|
||||
private void ShowPrefab(GameObject prefab, ref GameObject instance)
|
||||
{
|
||||
if (prefab == null || putPrefabsHere == null) return;
|
||||
|
||||
if (instance == null)
|
||||
{
|
||||
instance = FindExistingInstance(prefab);
|
||||
if (instance == null)
|
||||
{
|
||||
instance = Instantiate(prefab, putPrefabsHere.transform);
|
||||
TryAssignCanvasCamera(instance);
|
||||
}
|
||||
else
|
||||
{
|
||||
instance.transform.SetParent(putPrefabsHere.transform, false);
|
||||
}
|
||||
}
|
||||
|
||||
instance.SetActive(true);
|
||||
instance.transform.SetAsLastSibling();
|
||||
}
|
||||
|
||||
private void CloseInfoPanels(GameObject keep)
|
||||
{
|
||||
CloseInstance(ref showLevelInstance, keep);
|
||||
CloseInstance(ref emailInstance, keep);
|
||||
CloseInstance(ref noticeInstance, keep);
|
||||
}
|
||||
|
||||
private void CloseInstance(ref GameObject instance, GameObject keep)
|
||||
{
|
||||
if (instance == null || instance == keep) return;
|
||||
instance.SetActive(false);
|
||||
}
|
||||
|
||||
private GameObject FindExistingInstance(GameObject prefab)
|
||||
{
|
||||
if (prefab == null || putPrefabsHere == null) return null;
|
||||
|
||||
Transform parent = putPrefabsHere.transform;
|
||||
for (int i = 0; i < parent.childCount; i++)
|
||||
{
|
||||
Transform child = parent.GetChild(i);
|
||||
if (child == null) continue;
|
||||
if (child.name == prefab.name || child.name == prefab.name + "(Clone)")
|
||||
{
|
||||
return child.gameObject;
|
||||
}
|
||||
}
|
||||
|
||||
GameObject existing = GameObject.Find(prefab.name + "(Clone)");
|
||||
return existing;
|
||||
}
|
||||
|
||||
private void TryAssignCanvasCamera(GameObject instance)
|
||||
{
|
||||
if (instance == null) return;
|
||||
|
||||
try
|
||||
{
|
||||
Canvas c = instance.GetComponentInChildren<Canvas>(true);
|
||||
if (c != null)
|
||||
{
|
||||
Camera[] cams = Object.FindObjectsByType<Camera>(FindObjectsInactive.Exclude, FindObjectsSortMode.None);
|
||||
if (cams != null && cams.Length > 0)
|
||||
{
|
||||
c.worldCamera = cams[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private void InstantiatePrefab(GameObject prefab)
|
||||
{
|
||||
if (prefab != null && putPrefabsHere != null)
|
||||
|
||||
@@ -5,6 +5,7 @@ public class loadtopandbottomPrefab: MonoBehaviour
|
||||
[Header("father obj")]
|
||||
public GameObject top_and_bottom_Panel;
|
||||
public GameObject gameobject_to_Instantiate_below;
|
||||
[SerializeField] bool notify_Main_Panel = true;
|
||||
|
||||
void Start()
|
||||
{
|
||||
@@ -17,11 +18,34 @@ public class loadtopandbottomPrefab: MonoBehaviour
|
||||
Camera cam = Camera.main;
|
||||
if (cam == null)
|
||||
{
|
||||
cam = FindObjectOfType<Camera>();
|
||||
cam = Object.FindAnyObjectByType<Camera>();
|
||||
}
|
||||
canvas.worldCamera = cam;
|
||||
cam = null;
|
||||
}
|
||||
if (notify_Main_Panel)
|
||||
{
|
||||
Bind_Main_Panel(instantiated);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Bind_Main_Panel(GameObject instantiated)
|
||||
{
|
||||
if (instantiated == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
UI_Panel_Main main = Object.FindAnyObjectByType<UI_Panel_Main>();
|
||||
if (main == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
RectTransform top = instantiated.transform.Find("TOP") as RectTransform;
|
||||
RectTransform bottom = instantiated.transform.Find("BTM") as RectTransform;
|
||||
if (top != null || bottom != null)
|
||||
{
|
||||
main.Bind_Top_Bottom(top, bottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user