mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 12:52:07 +01:00
backbtn
This commit is contained in:
67
Assets/Scripts/HomeMenu/HomeSceneBackBtnScript.cs
Normal file
67
Assets/Scripts/HomeMenu/HomeSceneBackBtnScript.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class HomeSceneBackBtnScript : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
|
||||
{
|
||||
[SerializeField] GameObject arrow1;
|
||||
[SerializeField] GameObject arrow2;
|
||||
|
||||
[SerializeField] float hoverTransitionTime = 0.1f;
|
||||
[SerializeField] float exitTransitionTime = 0.1f;
|
||||
|
||||
float hoveringTimePassed = 0.0f;
|
||||
float exitingTimePassed = 0.0f;
|
||||
|
||||
bool isHovering = false;
|
||||
|
||||
void Update()
|
||||
{
|
||||
RectTransform arrow1RectTransform = arrow1.GetComponent<RectTransform>();
|
||||
RectTransform arrow2RectTransform = arrow2.GetComponent<RectTransform>();
|
||||
|
||||
if (isHovering)
|
||||
{
|
||||
exitingTimePassed = 0.0f;
|
||||
hoveringTimePassed += Time.deltaTime;
|
||||
|
||||
arrow1.GetComponent<Image>().color = Color.Lerp(new Color(255,255,255,0), Color.white, hoveringTimePassed / hoverTransitionTime);
|
||||
arrow2.GetComponent<Image>().color = Color.Lerp(new Color(255, 255, 255, 0), Color.white, hoveringTimePassed / hoverTransitionTime);
|
||||
|
||||
arrow1RectTransform.anchoredPosition = new Vector2(Mathf.Lerp(0, 15, hoveringTimePassed / hoverTransitionTime), arrow1RectTransform.anchoredPosition.y);
|
||||
arrow2RectTransform.anchoredPosition = new Vector2(Mathf.Lerp(10, 30, hoveringTimePassed / hoverTransitionTime), arrow2RectTransform.anchoredPosition.y);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
hoveringTimePassed = 0.0f;
|
||||
exitingTimePassed += Time.deltaTime;
|
||||
|
||||
arrow1.GetComponent<Image>().color = Color.Lerp(Color.white, new Color(255, 255, 255, 0), exitingTimePassed / exitTransitionTime);
|
||||
arrow2.GetComponent<Image>().color = Color.Lerp(Color.white, new Color(255, 255, 255, 0), exitingTimePassed / exitTransitionTime);
|
||||
|
||||
arrow1RectTransform.anchoredPosition = new Vector2(Mathf.Lerp(15, 0, exitingTimePassed / exitTransitionTime), arrow1RectTransform.anchoredPosition.y);
|
||||
arrow2RectTransform.anchoredPosition = new Vector2(Mathf.Lerp(30, 10, exitingTimePassed / exitTransitionTime), arrow2RectTransform.anchoredPosition.y);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
isHovering = true;
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
isHovering = false;
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
isHovering = false;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/HomeMenu/HomeSceneBackBtnScript.cs.meta
Normal file
11
Assets/Scripts/HomeMenu/HomeSceneBackBtnScript.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a462a75af2318e84dbd62ed7b9a53bb9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
61
Assets/Scripts/HomeMenu/HomeSceneBtnBigScript.cs
Normal file
61
Assets/Scripts/HomeMenu/HomeSceneBtnBigScript.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class HomeSceneBtnBigScript : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
|
||||
{
|
||||
[SerializeField] GameObject background;
|
||||
[SerializeField] float hoverTransitionTime = 0.1f;
|
||||
[SerializeField] float exitTransitionTime = 0.1f;
|
||||
[SerializeField] Color backgroundColor;
|
||||
|
||||
float hoveringTimePassed = 0.0f;
|
||||
float exitingTimePassed = 0.0f;
|
||||
|
||||
bool isHovering = false;
|
||||
|
||||
void Update()
|
||||
{
|
||||
RectTransform rectTransform = GetComponent<RectTransform>();
|
||||
RectTransform backgroundRectTranform = background.GetComponent<RectTransform>();
|
||||
|
||||
background.GetComponent<Image>().color = backgroundColor;
|
||||
|
||||
if (isHovering)
|
||||
{
|
||||
exitingTimePassed = 0.0f;
|
||||
hoveringTimePassed += Time.deltaTime;
|
||||
|
||||
|
||||
backgroundRectTranform.sizeDelta = new Vector2(Mathf.Lerp(0, rectTransform.rect.width, hoveringTimePassed / hoverTransitionTime), rectTransform.rect.height);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
hoveringTimePassed = 0.0f;
|
||||
exitingTimePassed += Time.deltaTime;
|
||||
|
||||
backgroundRectTranform.sizeDelta = new Vector2(Mathf.Lerp(rectTransform.rect.width, 0, exitingTimePassed / exitTransitionTime), rectTransform.rect.height);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
isHovering = true;
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
isHovering = false;
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
isHovering = false;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/HomeMenu/HomeSceneBtnBigScript.cs.meta
Normal file
11
Assets/Scripts/HomeMenu/HomeSceneBtnBigScript.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67e879cab196397419f533767bafdcd3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -35,7 +35,7 @@ public class InputValidator : MonoBehaviour
|
||||
}
|
||||
else if(InputType== TypeOfInput.IP)
|
||||
{
|
||||
inputField.contentType = TMP_InputField.ContentType.Alphanumeric;
|
||||
inputField.contentType = TMP_InputField.ContentType.Standard;
|
||||
}
|
||||
|
||||
inputField.onValueChanged.AddListener(delegate { ValueChangeCheck(); });
|
||||
|
||||
Reference in New Issue
Block a user