Bets placement WIP
This commit is contained in:
parent
68b399c0e2
commit
c71850c9c1
File diff suppressed because it is too large
Load Diff
|
|
@ -1,18 +1,54 @@
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
public class BettingSpace : MonoBehaviour
|
public class BettingSpace : MonoBehaviour
|
||||||
{
|
{
|
||||||
public float ratio = 1;
|
public float ratio = 1;
|
||||||
|
EventTrigger eventTrigger;
|
||||||
|
Image image;
|
||||||
|
Color defaultColor;
|
||||||
|
RectTransform rect;
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
|
rect = GetComponent<RectTransform>();
|
||||||
|
image = GetComponent<Image>();
|
||||||
|
defaultColor = image.color;
|
||||||
|
eventTrigger = GetComponent<EventTrigger>();
|
||||||
|
|
||||||
|
EventTrigger.Entry OnEnter = new EventTrigger.Entry();
|
||||||
|
OnEnter.eventID = EventTriggerType.PointerEnter;
|
||||||
|
OnEnter.callback.AddListener(onEnter);
|
||||||
|
|
||||||
|
EventTrigger.Entry OnExit = new EventTrigger.Entry();
|
||||||
|
OnExit.eventID = EventTriggerType.PointerExit;
|
||||||
|
OnExit.callback.AddListener(onExit);
|
||||||
|
|
||||||
|
EventTrigger.Entry OnClick = new EventTrigger.Entry();
|
||||||
|
OnClick.eventID = EventTriggerType.PointerClick;
|
||||||
|
OnClick.callback.AddListener(onClick);
|
||||||
|
|
||||||
|
eventTrigger.triggers.Add(OnEnter);
|
||||||
|
eventTrigger.triggers.Add(OnExit);
|
||||||
|
eventTrigger.triggers.Add(OnClick);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
void onEnter(BaseEventData e){
|
||||||
void Update()
|
image.color = new Color(defaultColor.r,defaultColor.g,defaultColor.b,defaultColor.a*0.5f);
|
||||||
{
|
}
|
||||||
|
|
||||||
|
void onExit(BaseEventData e){
|
||||||
|
image.color = defaultColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void onClick(BaseEventData e){
|
||||||
|
GameObject newChip = Instantiate(RouletteManager.SelectedChipItem.gameObject, transform);
|
||||||
|
newChip.GetComponent<RectTransform>().localPosition = Vector3.zero;
|
||||||
|
newChip.GetComponent<RectTransform>().sizeDelta = new Vector2(50,50);
|
||||||
|
|
||||||
|
RouletteManager.AddBet(RouletteManager.SelectedChip);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,22 @@
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
public class Chip : MonoBehaviour
|
public class Chip : MonoBehaviour
|
||||||
{
|
{
|
||||||
public float value;
|
public float value;
|
||||||
Outline outline;
|
public Vector3 defScale{get; private set;}
|
||||||
|
|
||||||
|
|
||||||
void Awake(){
|
void Awake(){
|
||||||
outline = GetComponent<Outline>();
|
defScale = transform.localScale;
|
||||||
RouletteManager.RegisterChip(this);
|
if(RouletteManager.RegisterChip(this)){
|
||||||
RouletteManager.OnMoneyAvailablChanged.AddListener(OnMoneyChanged);
|
RouletteManager.OnMoneyAvailablChanged.AddListener(OnMoneyChanged);
|
||||||
GetComponent<Button>().onClick.AddListener(OnClicked);
|
GetComponent<Button>().onClick.AddListener(OnClicked);
|
||||||
|
}else{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -25,7 +29,8 @@ public class Chip : MonoBehaviour
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnSelectedChanged(float newVal){
|
public void OnSelectedChanged(float newVal){
|
||||||
outline.effectColor = new Color(1,1,1, (newVal == value) ? 0.5f : 0);
|
// outline.effectColor = new Color(1,1,1, (newVal == value) ? 0.5f : 0);
|
||||||
|
transform.localScale = defScale *( (newVal == value) ? 1.3f : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,26 @@
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
|
|
||||||
public class RouletteManager : MonoBehaviour
|
public class RouletteManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
public static RouletteManager instance { get; private set;}
|
||||||
private static float moneyAvailable = 1000;
|
private static float moneyAvailable = 1000;
|
||||||
public static float MoneyAvailable {get{ return moneyAvailable;} set{OnMoneyAvailablChanged.Invoke(value); moneyAvailable = value;}}
|
public static float MoneyAvailable {get{ return moneyAvailable;} set{OnMoneyAvailablChanged.Invoke(value); moneyAvailable = value;}}
|
||||||
public static UnityEvent<float> OnMoneyAvailablChanged = new UnityEvent<float>();
|
public static UnityEvent<float> OnMoneyAvailablChanged = new UnityEvent<float>();
|
||||||
|
|
||||||
public static Dictionary<float, Chip> chipsBoard {get; private set;}
|
public static Dictionary<float, Chip> chipsBoard {get; private set;}
|
||||||
public static void RegisterChip(Chip chip){
|
public static bool RegisterChip(Chip chip){
|
||||||
if(chipsBoard == null){chipsBoard = new Dictionary<float, Chip>();}
|
if(chipsBoard == null){chipsBoard = new Dictionary<float, Chip>();}
|
||||||
|
|
||||||
|
if(chipsBoard.ContainsKey(chip.value)){return false;}
|
||||||
|
|
||||||
chipsBoard.Add(chip.value, chip);
|
chipsBoard.Add(chip.value, chip);
|
||||||
selectedChipChanged.AddListener(chip.OnSelectedChanged);
|
selectedChipChanged.AddListener(chip.OnSelectedChanged);
|
||||||
chip.OnSelectedChanged(SelectedChip);
|
chip.OnSelectedChanged(SelectedChip);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
public static UnityEvent<float> selectedChipChanged = new UnityEvent<float>();
|
public static UnityEvent<float> selectedChipChanged = new UnityEvent<float>();
|
||||||
private static float m_selectedChip = 0.2f;
|
private static float m_selectedChip = 0.2f;
|
||||||
|
|
@ -23,10 +28,23 @@ public class RouletteManager : MonoBehaviour
|
||||||
m_selectedChip = value;
|
m_selectedChip = value;
|
||||||
selectedChipChanged.Invoke(value);
|
selectedChipChanged.Invoke(value);
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
public static Chip SelectedChipItem{get{return chipsBoard[SelectedChip];}}
|
||||||
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 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};
|
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};
|
||||||
|
|
||||||
|
public static float bets;
|
||||||
|
public TMP_Text betsvalue;
|
||||||
|
|
||||||
|
public static void AddBet(float value){
|
||||||
|
bets += value;
|
||||||
|
MoneyAvailable-=value;
|
||||||
|
instance.BetsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Awake(){
|
||||||
|
instance =this;
|
||||||
|
}
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
Spinner.OnSpinStopped.AddListener(OnSpinStopped);
|
Spinner.OnSpinStopped.AddListener(OnSpinStopped);
|
||||||
|
|
@ -36,4 +54,8 @@ public class RouletteManager : MonoBehaviour
|
||||||
MoneyAvailable -= 100;
|
MoneyAvailable -= 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BetsChanged(){
|
||||||
|
betsvalue.text = "$"+bets.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user