Spin randomized, Anchored UI, remade betting board

This commit is contained in:
2023-03-01 19:27:02 +05:30
parent 2c260bdf43
commit 68b399c0e2
30 changed files with 4911 additions and 1731 deletions

View File

@@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BettingSpace : MonoBehaviour
{
public float ratio = 1;
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 2c386988596450b4ea43d1665ccb0900
guid: d7c7c2158b5c77d4ead0b20d7e008ce3
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,13 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Chip : MonoBehaviour
{
public float value;
Outline outline;
void Awake(){
outline = GetComponent<Outline>();
RouletteManager.RegisterChip(this);
RouletteManager.OnMoneyAvailablChanged.AddListener(OnMoneyChanged);
GetComponent<Button>().onClick.AddListener(OnClicked);
}
@@ -15,6 +20,14 @@ public class Chip : MonoBehaviour
gameObject.SetActive(newMoney >= value);
}
void OnClicked(){
RouletteManager.SelectedChip = value;
}
public void OnSelectedChanged(float newVal){
outline.effectColor = new Color(1,1,1, (newVal == value) ? 0.5f : 0);
}
void OnValidate(){
if(value == 0){

View File

@@ -0,0 +1,31 @@
using System.Collections;
using System.Collections.Generic;
using EasyButtons;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
public class ChipBoard : MonoBehaviour
{
public Transform numberGridParent;
public Color redColor,blackColor;
[Button]
void Config(){
for(int i= 1; i < RouletteManager.RouletteNumbers.Length-1; i++){
GameObject newItem= Instantiate(numberGridParent.GetChild(0).gameObject, numberGridParent);
newItem.GetComponent<Image>().color = RouletteManager.Reds.Contains(i+1) ? redColor : blackColor;
newItem.GetComponentInChildren<TMP_Text>().text = (i+1).ToString();
}
}
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

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

View File

@@ -1,76 +0,0 @@
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class DragChip : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
public GameObject chipPrefab;
public Image rouletteBoardImage;
private RectTransform canvasRect;
private RectTransform chipRect;
private Vector2 originalPosition;
private GameObject currentChip;
private Canvas canvas;
void Start()
{
// Get the RectTransform component of the canvas
canvasRect = GetComponentInParent<Canvas>().GetComponent<RectTransform>();
// Get the Canvas component of the parent object
canvas = GetComponentInParent<Canvas>();
}
public void OnBeginDrag(PointerEventData eventData)
{
// Create a clone of the chip image at the current position
currentChip = Instantiate(chipPrefab, transform.position, Quaternion.identity, canvas.transform);
// Get the RectTransform component of the clone
chipRect = currentChip.GetComponent<RectTransform>();
// Store the original position of the clone before dragging
originalPosition = chipRect.anchoredPosition;
// Bring the clone to the front
chipRect.SetAsLastSibling();
}
public void OnDrag(PointerEventData eventData)
{
// Move the clone with the mouse drag movement
chipRect.anchoredPosition += eventData.delta / canvas.scaleFactor;
}
public void OnEndDrag(PointerEventData eventData)
{
// If the clone exists, check if it's dropped onto the roulette board image
if (currentChip != null)
{
RectTransform boardRect = rouletteBoardImage.GetComponent<RectTransform>();
Vector2 localMousePos;
// Check if the mouse position is within the bounds of the roulette board image
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(boardRect, Input.mousePosition, canvas.worldCamera, out localMousePos))
{
if (boardRect.rect.Contains(localMousePos))
{
// If the chip is dropped onto the roulette board image, set its parent to the image and position it at the mouse cursor
chipRect.SetParent(rouletteBoardImage.transform);
chipRect.anchoredPosition = localMousePos;
}
else
{
// If the chip is dropped outside of the roulette board image, destroy it
Destroy(currentChip);
}
}
else
{
// If the mouse position is not within the bounds of the canvas, destroy the clone
Destroy(currentChip);
}
// Set the clone to null to indicate that it no longer exists
currentChip = null;
}
}
}

View File

@@ -8,6 +8,23 @@ public class RouletteManager : MonoBehaviour
private static float moneyAvailable = 1000;
public static float MoneyAvailable {get{ return moneyAvailable;} set{OnMoneyAvailablChanged.Invoke(value); moneyAvailable = value;}}
public static UnityEvent<float> OnMoneyAvailablChanged = new UnityEvent<float>();
public static Dictionary<float, Chip> chipsBoard {get; private set;}
public static void RegisterChip(Chip chip){
if(chipsBoard == null){chipsBoard = new Dictionary<float, Chip>();}
chipsBoard.Add(chip.value, chip);
selectedChipChanged.AddListener(chip.OnSelectedChanged);
chip.OnSelectedChanged(SelectedChip);
}
public static UnityEvent<float> selectedChipChanged = new UnityEvent<float>();
private static float m_selectedChip = 0.2f;
public static float SelectedChip { get{ return m_selectedChip; } set{
m_selectedChip = value;
selectedChipChanged.Invoke(value);
}}
public static int[] RouletteNumbers = {0,32,15,19,4,21,2,25,17,34,6,27,13,36,11,30,8,23,10,5,24,16,33,1,20,14,31,9,22,18,29,7,28,12,35,3,26};
public static List<int> Reds = new List<int>(){1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36};
void Start()

View File

@@ -16,6 +16,7 @@ public class Spinner : MonoBehaviour
public float SpinForce = 10;
[Tooltip("How smooth the speed goes up")]
public float SpinSmoothness = 1f;
public float SpinSmoothnessMax = 1f;
[Tooltip("How smooth the speed goes down")]
public float Friction = 0.005f;
[Tooltip("When should the wheel stop")]
@@ -27,7 +28,7 @@ public class Spinner : MonoBehaviour
void Start()
{
Debug.Log(RouletteNumbers.Length);
Debug.Log(RouletteManager.RouletteNumbers.Length);
}
bool pushing = false;
// Update is called once per frame
@@ -55,14 +56,15 @@ public class Spinner : MonoBehaviour
IEnumerator spin(){
pushing=true;
numText.text ="";
float m_spinSmoothness = Random.Range(SpinSmoothness, SpinSmoothnessMax);
while(CurrentSpeed < SpinForce){
CurrentSpeed += SpinSmoothness;
CurrentSpeed += m_spinSmoothness;
yield return new WaitForFixedUpdate();
}
pushing = false;
}
public int[] RouletteNumbers = {0,32,15,19,4,21,2,25,17,34,6,27,13,36,11,30,8,23,10,5,24,16,33,1,20,14,31,9,22,18,29,7,28,12,35,3,26};
private void m_onSpinStopped(){
@@ -76,14 +78,14 @@ public class Spinner : MonoBehaviour
}
int GetLandedNumber(){
float fraction = ((wheel.eulerAngles.z) / 360f) * (float)RouletteNumbers.Length;
float fraction = ((wheel.eulerAngles.z) / 360f) * (float)RouletteManager.RouletteNumbers.Length;
int index= Mathf.RoundToInt(fraction) + offset;
if(index < 0){
index = RouletteNumbers.Length + index - 1;
}else if(index >= RouletteNumbers.Length){
index = index - RouletteNumbers.Length;
index = RouletteManager.RouletteNumbers.Length + index - 1;
}else if(index >= RouletteManager.RouletteNumbers.Length){
index = index - RouletteManager.RouletteNumbers.Length;
}
int m_LandedNumber = RouletteNumbers[index];
int m_LandedNumber = RouletteManager.RouletteNumbers[index];
return m_LandedNumber;
}