mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-13 13:57:43 +02:00
Editor stuff
This commit is contained in:
@ -0,0 +1,125 @@
|
||||
/// <summary>
|
||||
/// Credit - ryanslikesocool
|
||||
/// Sourced from - https://github.com/ryanslikesocool/Unity-Card-UI
|
||||
/// </summary>
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
public class CardExpanding2D : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField]
|
||||
private float lerpSpeed = 8f;
|
||||
|
||||
[SerializeField]
|
||||
private RectTransform buttonRect = null;
|
||||
private Vector2 closeButtonMin = Vector2.zero;
|
||||
private Vector2 closeButtonMax = Vector2.zero;
|
||||
|
||||
[SerializeField]
|
||||
private Vector2 cardSize = Vector2.zero;
|
||||
[SerializeField]
|
||||
private Vector2 pageSize = Vector2.zero;
|
||||
|
||||
private Vector2 cardCenter = Vector2.zero;
|
||||
private Vector2 pageCenter = Vector2.zero;
|
||||
|
||||
private Vector2 cardMin = Vector2.zero;
|
||||
private Vector2 cardMax = Vector2.zero;
|
||||
private Vector2 pageMin = Vector2.zero;
|
||||
private Vector2 pageMax = Vector2.zero;
|
||||
|
||||
private RectTransform rectTrans;
|
||||
///I wouldn't recommend changing animationActive's value here unless you want the card to start as a page.
|
||||
private int animationActive = -1;
|
||||
|
||||
void Start()
|
||||
{
|
||||
rectTrans = GetComponent<RectTransform>();
|
||||
|
||||
///Setting up the button's starting color and page position.
|
||||
buttonRect.GetComponent<Image>().color = new Color32(228, 0, 0, 0);
|
||||
|
||||
closeButtonMin = new Vector2(pageMin.x + pageSize.x - 64, pageMin.y + pageSize.y - 64);
|
||||
closeButtonMax = new Vector2(pageMax.x - 16, pageMax.y - 16);
|
||||
|
||||
///Setting up the card and page offsets.
|
||||
cardMin = new Vector2(cardCenter.x - cardSize.x * 0.5f, cardCenter.y - cardSize.y * 0.5f);
|
||||
cardMax = new Vector2(cardCenter.x + cardSize.x * 0.5f, cardCenter.y + cardSize.y * 0.5f);
|
||||
|
||||
pageMin = new Vector2(pageCenter.x - pageSize.x * 0.5f, pageCenter.y - pageSize.y * 0.5f);
|
||||
pageMax = new Vector2(pageCenter.x + pageSize.x * 0.5f, pageCenter.y + pageSize.y * 0.5f);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
///When animationActive == 1, the card is expanding into a page.
|
||||
if (animationActive == 1)
|
||||
{
|
||||
rectTrans.offsetMin = Vector2.Lerp(rectTrans.offsetMin, pageMin, Time.deltaTime * lerpSpeed);
|
||||
rectTrans.offsetMax = Vector2.Lerp(rectTrans.offsetMax, pageMax, Time.deltaTime * lerpSpeed);
|
||||
|
||||
if (rectTrans.offsetMin.x < pageMin.x * 0.995f && rectTrans.offsetMin.y < pageMin.y * 0.995f && rectTrans.offsetMax.x > pageMax.x * 0.995f && rectTrans.offsetMax.y > pageMax.y * 0.995f)
|
||||
{
|
||||
rectTrans.offsetMin = pageMin;
|
||||
rectTrans.offsetMax = pageMax;
|
||||
|
||||
///Changes the button color so it's visible in the page view.
|
||||
buttonRect.GetComponent<Image>().color = Color32.Lerp(buttonRect.GetComponent<Image>().color, new Color32(228, 0, 0, 191), Time.deltaTime * lerpSpeed);
|
||||
|
||||
if (Mathf.Abs(buttonRect.GetComponent<Image>().color.a - 191) < 2)
|
||||
{
|
||||
buttonRect.GetComponent<Image>().color = new Color32(228, 0, 0, 191);
|
||||
|
||||
animationActive = 0;
|
||||
CardStack2D.canUseHorizontalAxis = true;
|
||||
}
|
||||
}
|
||||
///When animationActive == -1, the page is shrinking into a card.
|
||||
}
|
||||
else if (animationActive == -1)
|
||||
{
|
||||
buttonRect.GetComponent<Image>().color = Color32.Lerp(buttonRect.GetComponent<Image>().color, new Color32(228, 0, 0, 0), Time.deltaTime * lerpSpeed * 1.25f);
|
||||
|
||||
rectTrans.offsetMin = Vector2.Lerp(rectTrans.offsetMin, cardMin, Time.deltaTime * lerpSpeed);
|
||||
rectTrans.offsetMax = Vector2.Lerp(rectTrans.offsetMax, cardMax, Time.deltaTime * lerpSpeed);
|
||||
|
||||
if (rectTrans.offsetMin.x > cardMin.x * 1.005f && rectTrans.offsetMin.y > cardMin.y * 1.005f && rectTrans.offsetMax.x < cardMax.x * 1.005f && rectTrans.offsetMax.y < cardMax.y * 1.005f)
|
||||
{
|
||||
rectTrans.offsetMin = cardMin;
|
||||
rectTrans.offsetMax = cardMax;
|
||||
|
||||
///Makes the button take up the whole card.
|
||||
buttonRect.offsetMin = Vector2.zero;
|
||||
buttonRect.offsetMax = Vector2.zero;
|
||||
|
||||
animationActive = 0;
|
||||
CardStack2D.canUseHorizontalAxis = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ToggleCard()
|
||||
{
|
||||
CardStack2D.canUseHorizontalAxis = false;
|
||||
if (animationActive != 1)
|
||||
{
|
||||
animationActive = 1;
|
||||
cardCenter = transform.localPosition;
|
||||
|
||||
///Makes the button the right size in page view.
|
||||
buttonRect.offsetMin = closeButtonMin;
|
||||
buttonRect.offsetMax = closeButtonMax;
|
||||
}
|
||||
else if (animationActive != -1)
|
||||
{
|
||||
animationActive = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ab9da748840643a3bd4794f6f138979
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,82 @@
|
||||
/// <summary>
|
||||
/// Credit - ryanslikesocool
|
||||
/// Sourced from - https://github.com/ryanslikesocool/Unity-Card-UI
|
||||
/// </summary>
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public class CardPopup2D : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private float rotationSpeed = 1f;
|
||||
[SerializeField]
|
||||
private float centeringSpeed = 4f;
|
||||
[SerializeField]
|
||||
private bool singleScene = false;
|
||||
|
||||
private Rigidbody rbody;
|
||||
private bool isFalling;
|
||||
private Vector3 cardFallRotation;
|
||||
private bool fallToZero;
|
||||
private float startZPos;
|
||||
|
||||
void Start()
|
||||
{
|
||||
rbody = GetComponent<Rigidbody>();
|
||||
rbody.useGravity = false;
|
||||
startZPos = transform.position.z;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (isFalling)
|
||||
{
|
||||
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(cardFallRotation), Time.deltaTime * rotationSpeed);
|
||||
}
|
||||
|
||||
///This conditional makes the popup fall nicely into place.
|
||||
if (fallToZero)
|
||||
{
|
||||
transform.position = Vector3.Lerp(transform.position, new Vector3(0, 0, startZPos), Time.deltaTime * centeringSpeed);
|
||||
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(Vector3.zero), Time.deltaTime * centeringSpeed);
|
||||
if (Vector3.Distance(transform.position, new Vector3(0, 0, startZPos)) < 0.0025f)
|
||||
{
|
||||
transform.position = new Vector3(0, 0, startZPos);
|
||||
fallToZero = false;
|
||||
}
|
||||
}
|
||||
|
||||
///This is totally unnecessary.
|
||||
if (transform.position.y < -4)
|
||||
{
|
||||
isFalling = false;
|
||||
rbody.useGravity = false;
|
||||
rbody.velocity = Vector3.zero;
|
||||
transform.position = new Vector3(0, 8, startZPos);
|
||||
if (singleScene)
|
||||
{
|
||||
CardEnter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void CardEnter()
|
||||
{
|
||||
fallToZero = true;
|
||||
}
|
||||
|
||||
///A negative fallRotation will result in the card turning clockwise, while a positive fallRotation makes the card turn counterclockwise.
|
||||
public void CardFallAway(float fallRotation)
|
||||
{
|
||||
rbody.useGravity = true;
|
||||
isFalling = true;
|
||||
cardFallRotation = new Vector3(0, 0, fallRotation);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a41308ab5f4aa489c9cf797b9152351a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,123 @@
|
||||
/// <summary>
|
||||
/// Credit - ryanslikesocool
|
||||
/// Sourced from - https://github.com/ryanslikesocool/Unity-Card-UI
|
||||
/// </summary>
|
||||
|
||||
using System.Collections;
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
|
||||
public class CardStack2D : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField]
|
||||
private float cardMoveSpeed = 8f;
|
||||
[SerializeField]
|
||||
private float buttonCooldownTime = 0.125f;
|
||||
[SerializeField]
|
||||
private int cardZMultiplier = 32;
|
||||
[SerializeField]
|
||||
private bool useDefaultUsedXPos = true;
|
||||
[SerializeField]
|
||||
private int usedCardXPos = 1280;
|
||||
[SerializeField]
|
||||
private KeyCode leftButton = KeyCode.LeftArrow;
|
||||
[SerializeField]
|
||||
private KeyCode rightButton = KeyCode.RightArrow;
|
||||
[SerializeField]
|
||||
private Transform[] cards = null;
|
||||
|
||||
|
||||
|
||||
private int cardArrayOffset;
|
||||
private Vector3[] cardPositions;
|
||||
private int xPowerDifference;
|
||||
|
||||
///Static variables can be used across the scene if this script is in it.
|
||||
///Thankfully it doesn't matter if another script attempts to use the variable and this script isn't in the scene.
|
||||
public static bool canUseHorizontalAxis = true;
|
||||
|
||||
void Start()
|
||||
{
|
||||
///I've found that 9 is a good number for this.
|
||||
///I wouldn't really recommend changing it, but go ahead if you want to.
|
||||
xPowerDifference = 9 - cards.Length;
|
||||
|
||||
///This is optional, but makes it super easy to figure out the off screen position for cards.
|
||||
///Unfortunately, it's only really useful if the cards are the same width.
|
||||
if (useDefaultUsedXPos)
|
||||
{
|
||||
int cardWidth = (int)(cards[0].GetComponent<RectTransform>().rect.width);
|
||||
usedCardXPos = (int)(Screen.width * 0.5f + cardWidth);
|
||||
}
|
||||
|
||||
cardPositions = new Vector3[cards.Length * 2 - 1];
|
||||
|
||||
///This loop is for cards still in the stack.
|
||||
for (int i = cards.Length; i > -1; i--)
|
||||
{
|
||||
if (i < cards.Length - 1)
|
||||
{
|
||||
cardPositions[i] = new Vector3(-Mathf.Pow(2, i + xPowerDifference) + cardPositions[i + 1].x, 0, cardZMultiplier * Mathf.Abs(i + 1 - cards.Length));
|
||||
}
|
||||
else
|
||||
{
|
||||
cardPositions[i] = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
///This loop is for cards outside of the stack.
|
||||
for (int i = cards.Length; i < cardPositions.Length; i++)
|
||||
{
|
||||
cardPositions[i] = new Vector3(usedCardXPos + 4 * (i - cards.Length), 0, -2 + -2 * (i - cards.Length));
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (canUseHorizontalAxis)
|
||||
{
|
||||
///Controls for the cards.
|
||||
if ((UIExtensionsInputManager.GetAxisRaw("Horizontal") < 0 || UIExtensionsInputManager.GetKey(leftButton)) && cardArrayOffset > 0)
|
||||
{
|
||||
cardArrayOffset--;
|
||||
StartCoroutine(ButtonCooldown());
|
||||
}
|
||||
else if ((UIExtensionsInputManager.GetAxisRaw("Horizontal") > 0 || UIExtensionsInputManager.GetKey(rightButton)) && cardArrayOffset < cards.Length - 1)
|
||||
{
|
||||
cardArrayOffset++;
|
||||
StartCoroutine(ButtonCooldown());
|
||||
}
|
||||
}
|
||||
|
||||
///This loop moves the cards. I know that none of my lerps are the "right way," but it looks much nicer.
|
||||
for (int i = 0; i < cards.Length; i++)
|
||||
{
|
||||
cards[i].localPosition = Vector3.Lerp(cards[i].localPosition, cardPositions[i + cardArrayOffset], Time.deltaTime * cardMoveSpeed);
|
||||
if (Mathf.Abs(cards[i].localPosition.x - cardPositions[i + cardArrayOffset].x) < 0.01f)
|
||||
{
|
||||
cards[i].localPosition = cardPositions[i + cardArrayOffset];
|
||||
|
||||
///This disables interaction with cards that are not on top of the stack.
|
||||
if (cards[i].localPosition.x == 0)
|
||||
{
|
||||
cards[i].gameObject.GetComponent<CanvasGroup>().interactable = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
cards[i].gameObject.GetComponent<CanvasGroup>().interactable = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///Stops the cards from scrolling super quickly if a button on the horizontal axis is held down.
|
||||
IEnumerator ButtonCooldown()
|
||||
{
|
||||
canUseHorizontalAxis = false;
|
||||
yield return new WaitForSeconds(buttonCooldownTime);
|
||||
canUseHorizontalAxis = true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c0edb9a3f5da4e129739a8f92a115af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user