Editor stuff

This commit is contained in:
Starpelly
2022-01-05 19:11:33 -05:00
parent 775fd7e580
commit 576b0d8482
458 changed files with 37611 additions and 15 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ff6158f1872894fd18d8b73aa8b3727e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9ab9da748840643a3bd4794f6f138979
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a41308ab5f4aa489c9cf797b9152351a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3c0edb9a3f5da4e129739a8f92a115af
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2e00d759ad79242bc80e41df440cc3df
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,222 @@
/// <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
{
[ExecuteInEditMode]
public class CardExpanding3D : MonoBehaviour
{
[SerializeField]
private float lerpSpeed = 12;
[SerializeField]
private float cornerSize = 64;
[Header("Parts")]
public RectTransform[] cardCorners;
public RectTransform[] cardEdges;
public RectTransform cardCenter;
[Header("Card Info")]
[Tooltip("Positions and sizes card to its current transform.")]
public bool cardAutoSize = true;
public Vector2 cardSize;
public Vector2 cardPosition;
[Range(1, 96)]
public int cardSuperness = 4;
[Header("Page Info")]
[Tooltip("Positions and sizes the page to the top third of the screen.")]
public bool pageAutoSize = true;
public Vector2 pageSize;
public Vector2 pagePosition;
[Range(1, 96)]
public int pageSuperness = 96;
///Just like with the 2D version of this script, I don't recommend touching this.
private int animationActive = 0;
private Vector2[] nextCornerPos = new Vector2[4];
private Vector2[] nextEdgePos = new Vector2[4];
private Vector2[] nextEdgeScale = new Vector2[4];
private Vector2 nextCenterScale;
private Vector2 nextPos;
private int nextSuperness;
private RectTransform rect;
private Vector2 nextMin;
private Vector2 nextMax;
void Start()
{
if (cardAutoSize)
{
cardSize = new Vector2(cardCorners[0].localScale.x * 2 + cardEdges[0].localScale.x, cardCorners[0].localScale.y * 2 + cardEdges[0].localScale.y);
cardPosition = cardCenter.localPosition;
}
if (pageAutoSize)
{
pageSize = new Vector2(Screen.width, Screen.height / 3);
pagePosition = new Vector2(0, Screen.height / 2 - pageSize.y / 2);
}
rect = GetComponent<RectTransform>();
}
void Update()
{
if (animationActive == 1 || animationActive == -1)
{
///Lerps the corners to new positions and supernesses.
for (int i = 0; i < cardCorners.Length; i++)
{
cardCorners[i].localPosition = Vector3.Lerp(cardCorners[i].localPosition, nextCornerPos[i], Time.deltaTime * lerpSpeed);
cardCorners[i].GetComponent<SuperellipsePoints>().superness = Mathf.Lerp(cardCorners[i].GetComponent<SuperellipsePoints>().superness, nextSuperness, Time.deltaTime * lerpSpeed);
///Forces everything to either the card layout or the page layout once the superness is similar enough.
if (Mathf.Abs(cardCorners[i].GetComponent<SuperellipsePoints>().superness - nextSuperness) <= 1)
{
cardCorners[i].localPosition = nextCornerPos[i];
cardEdges[i].localPosition = nextEdgePos[i];
cardEdges[i].localScale = new Vector3(nextEdgeScale[i].x, nextEdgeScale[i].y, 1);
transform.localPosition = nextPos;
cardCenter.localScale = new Vector3(nextCenterScale.x, nextCenterScale.y, 1);
cardCorners[i].GetComponent<SuperellipsePoints>().superness = nextSuperness;
rect.offsetMin = nextMin;
rect.offsetMax = nextMax;
}
}
///Lerps the edges to new positions and sizes.
for (int i = 0; i < cardEdges.Length; i++)
{
cardEdges[i].localPosition = Vector3.Lerp(cardEdges[i].localPosition, nextEdgePos[i], Time.deltaTime * lerpSpeed);
cardEdges[i].localScale = Vector3.Lerp(cardEdges[i].localScale, new Vector3(nextEdgeScale[i].x, nextEdgeScale[i].y, 1), Time.deltaTime * lerpSpeed);
}
///Lerps the center to new position and size.
transform.localPosition = Vector3.Lerp(transform.localPosition, nextPos, Time.deltaTime * lerpSpeed);
cardCenter.localScale = Vector3.Lerp(cardCenter.localScale, new Vector3(nextCenterScale.x, nextCenterScale.y, 1), Time.deltaTime * lerpSpeed);
///Lerps the RectTransform.
rect.offsetMin = Vector3.Lerp(rect.offsetMin, nextMin, Time.deltaTime * lerpSpeed);
rect.offsetMax = Vector3.Lerp(rect.offsetMax, nextMax, Time.deltaTime * lerpSpeed);
}
}
public void ToggleCard()
{
if (animationActive != 1 || animationActive == 0)
{
animationActive = 1;
///Gets new corner positions.
for (int i = 0; i < cardCorners.Length; i++)
{
float posX = pageSize.x / 2 * Mathf.Sign(cardCorners[i].localScale.x) - cardCorners[i].localScale.x;
float posY = pageSize.y / 2 * Mathf.Sign(cardCorners[i].localScale.y) - cardCorners[i].localScale.y;
nextCornerPos[i] = new Vector2(posX, posY);
}
///Same concept as the last loop.
for (int i = 0; i < cardEdges.Length; i++)
{
float posX = 0;
float posY = 0;
float scaleX = 0;
float scaleY = 0;
if (cardEdges[i].localPosition.x != 0)
{
posX = Mathf.Sign(cardEdges[i].localPosition.x) * ((pageSize.x / 2) - (cardEdges[i].localScale.x / 2));
posY = 0;
scaleX = cornerSize;
scaleY = pageSize.y - cornerSize * 2;
}
else if (cardEdges[i].localPosition.y != 0)
{
posX = 0;
posY = Mathf.Sign(cardEdges[i].localPosition.y) * ((pageSize.y / 2) - (cardEdges[i].localScale.y / 2));
scaleX = pageSize.x - cornerSize * 2;
scaleY = cornerSize;
}
nextEdgePos[i] = new Vector2(posX, posY);
nextEdgeScale[i] = new Vector2(scaleX, scaleY);
}
nextCenterScale = pageSize - new Vector2(cornerSize * 2, cornerSize * 2);
nextPos = pagePosition;
nextSuperness = pageSuperness;
nextMin = new Vector2(-pageSize.x / 2, -pageSize.y / 2) + nextPos;
nextMax = new Vector2(pageSize.x / 2, pageSize.y / 2) + nextPos;
}
else if (animationActive != -1)
{
animationActive = -1;
///Gets new corner positions.
for (int i = 0; i < cardCorners.Length; i++)
{
float posX = Mathf.Sign(cardCorners[i].localScale.x) * (cardSize.x / 2) - cardCorners[i].localScale.x;
float posY = Mathf.Sign(cardCorners[i].localScale.y) * (cardSize.y / 2) - cardCorners[i].localScale.y;
nextCornerPos[i] = new Vector2(posX, posY);
}
///Same concept as the last loop.
for (int i = 0; i < cardEdges.Length; i++)
{
float posX = 0;
float posY = 0;
float scaleX = 0;
float scaleY = 0;
if (cardEdges[i].localPosition.x != 0)
{
posX = Mathf.Sign(cardEdges[i].localPosition.x) * (cardSize.x / 2) - Mathf.Sign(cardEdges[i].localPosition.x) * (cardEdges[i].localScale.x / 2);
posY = 0;
scaleX = cornerSize;
scaleY = cardSize.y - cornerSize * 2;
}
else if (cardEdges[i].localPosition.y != 0)
{
posX = 0;
posY = Mathf.Sign(cardEdges[i].localPosition.y) * (cardSize.y / 2) - Mathf.Sign(cardEdges[i].localPosition.y) * (cardEdges[i].localScale.y / 2);
scaleX = cardSize.x - cornerSize * 2;
scaleY = cornerSize;
}
nextEdgePos[i] = new Vector2(posX, posY);
nextEdgeScale[i] = new Vector2(scaleX, scaleY);
}
nextCenterScale = cardSize - new Vector2(cornerSize * 2, cornerSize * 2);
nextPos = cardPosition;
nextSuperness = cardSuperness;
nextMin = new Vector2(-cardSize.x / 2, -cardSize.y / 2) + nextPos;
nextMax = new Vector2(cardSize.x / 2, cardSize.y / 2) + nextPos;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 113e4a3911e6c4f3e8427bd79605739c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 85c7285af214d46818136659e00053bd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,44 @@
/// <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
{
///Credit where credit is due
///https://wiki.unity3d.com/index.php?title=Triangulator
[ExecuteInEditMode]
public class MeshCreator : MonoBehaviour
{
public void CreateMesh(List<Vector2> points)
{
// Create Vector2 vertices
Vector2[] vertices2D = points.ToArray();
// Use the triangulator to get indices for creating triangles
Triangulator tr = new Triangulator(vertices2D);
int[] indices = tr.Triangulate();
// Create the Vector3 vertices
Vector3[] vertices = new Vector3[vertices2D.Length];
for (int i = 0; i < vertices.Length; i++)
{
vertices[i] = new Vector3(vertices2D[i].x, vertices2D[i].y, 0);
}
// Create the mesh
Mesh msh = new Mesh();
msh.vertices = vertices;
msh.triangles = indices;
msh.RecalculateNormals();
msh.RecalculateBounds();
// Set up game object with mesh;
GetComponent<MeshFilter>().mesh = msh;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c87d7e3a53e4c4bf9ae3657f0dff98b6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,91 @@
/// <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
{
///The formula for a basic superellipse is
///Mathf.Pow(Mathf.Abs(x / a), n) + Mathf.Pow(Mathf.Abs(y / b), n) = 1
[ExecuteInEditMode]
public class SuperellipsePoints : MonoBehaviour
{
public float xLimits = 1f;
public float yLimits = 1f;
[Range(1f, 96f)]
public float superness = 4f;
private float lastXLim;
private float lastYLim;
private float lastSuper;
[Space]
[Range(1, 32)]
public int levelOfDetail = 4;
private int lastLoD;
[Space]
public Material material;
private List<Vector2> pointList = new List<Vector2>();
void Start()
{
RecalculateSuperellipse();
GetComponent<MeshRenderer>().material = material;
lastXLim = xLimits;
lastYLim = yLimits;
lastSuper = superness;
lastLoD = levelOfDetail;
}
void Update()
{
if (lastXLim != xLimits || lastYLim != yLimits || lastSuper != superness || lastLoD != levelOfDetail)
{
RecalculateSuperellipse();
}
lastXLim = xLimits;
lastYLim = yLimits;
lastSuper = superness;
lastLoD = levelOfDetail;
}
void RecalculateSuperellipse()
{
pointList.Clear();
float realLoD = levelOfDetail * 4;
for (float i = 0; i < xLimits; i += 1 / realLoD)
{
float y = Superellipse(xLimits, yLimits, i, superness);
Vector2 tempVecTwo = new Vector2(i, y);
pointList.Add(tempVecTwo);
}
pointList.Add(new Vector2(xLimits, 0));
pointList.Add(Vector2.zero);
GetComponent<MeshCreator>().CreateMesh(pointList);
}
float Superellipse(float a, float b, float x, float n)
{
float alpha = Mathf.Pow((x / a), n);
float beta = 1 - alpha;
float y = Mathf.Pow(beta, 1 / n) * b;
return y;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: df6beaa1c87204b919c209b770d44bc9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,132 @@
/// <summary>
/// Credit - ryanslikesocool
/// Sourced from - https://github.com/ryanslikesocool/Unity-Card-UI
/// </summary>
using UnityEngine;
using System.Collections.Generic;
namespace UnityEngine.UI.Extensions
{
///Credit where credit is due
///https://wiki.unity3d.com/index.php?title=Triangulator
[ExecuteInEditMode]
public class Triangulator
{
private List<Vector2> m_points = new List<Vector2>();
public Triangulator(Vector2[] points)
{
m_points = new List<Vector2>(points);
}
public int[] Triangulate()
{
List<int> indices = new List<int>();
int n = m_points.Count;
if (n < 3)
return indices.ToArray();
int[] V = new int[n];
if (Area() > 0)
{
for (int v = 0; v < n; v++)
V[v] = v;
}
else
{
for (int v = 0; v < n; v++)
V[v] = (n - 1) - v;
}
int nv = n;
int count = 2 * nv;
for (int m = 0, v = nv - 1; nv > 2;)
{
if ((count--) <= 0)
return indices.ToArray();
int u = v;
if (nv <= u)
u = 0;
v = u + 1;
if (nv <= v)
v = 0;
int w = v + 1;
if (nv <= w)
w = 0;
if (Snip(u, v, w, nv, V))
{
int a, b, c, s, t;
a = V[u];
b = V[v];
c = V[w];
indices.Add(a);
indices.Add(b);
indices.Add(c);
m++;
for (s = v, t = v + 1; t < nv; s++, t++)
V[s] = V[t];
nv--;
count = 2 * nv;
}
}
indices.Reverse();
return indices.ToArray();
}
private float Area()
{
int n = m_points.Count;
float A = 0.0f;
for (int p = n - 1, q = 0; q < n; p = q++)
{
Vector2 pval = m_points[p];
Vector2 qval = m_points[q];
A += pval.x * qval.y - qval.x * pval.y;
}
return (A * 0.5f);
}
private bool Snip(int u, int v, int w, int n, int[] V)
{
int p;
Vector2 A = m_points[V[u]];
Vector2 B = m_points[V[v]];
Vector2 C = m_points[V[w]];
if (Mathf.Epsilon > (((B.x - A.x) * (C.y - A.y)) - ((B.y - A.y) * (C.x - A.x))))
return false;
for (p = 0; p < n; p++)
{
if ((p == u) || (p == v) || (p == w))
continue;
Vector2 P = m_points[V[p]];
if (InsideTriangle(A, B, C, P))
return false;
}
return true;
}
private bool InsideTriangle(Vector2 A, Vector2 B, Vector2 C, Vector2 P)
{
float ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy;
float cCROSSap, bCROSScp, aCROSSbp;
ax = C.x - B.x; ay = C.y - B.y;
bx = A.x - C.x; by = A.y - C.y;
cx = B.x - A.x; cy = B.y - A.y;
apx = P.x - A.x; apy = P.y - A.y;
bpx = P.x - B.x; bpy = P.y - B.y;
cpx = P.x - C.x; cpy = P.y - C.y;
aCROSSbp = ax * bpy - ay * bpx;
cCROSSap = cx * apy - cy * apx;
bCROSScp = bx * cpy - by * cpx;
return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f));
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ac33bc8ebf2744ad6ae91f80f8542546
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: