rev 0.4, dev panel

This commit is contained in:
2026-02-05 06:32:52 +05:30
parent 803e186bcc
commit df77848ca5
19 changed files with 3635 additions and 93 deletions

View File

@@ -0,0 +1,57 @@
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
public class DevOptionItem : MonoBehaviour
{
public TMP_Text txtTitle;
public TMP_InputField inputMin, inputMax, inputValue;
public Slider slider;
public UnityAction<float> OnChanged;
void Awake()
{
inputMin.onEndEdit.AddListener(OnEndEditMin);
inputMax.onEndEdit.AddListener(OnEndEditMax);
inputValue.onEndEdit.AddListener(OnEndEditValue);
slider.onValueChanged.AddListener(OnValueChanged);
}
public void Setup(string title, float min, float max, float value){
txtTitle.text = title;
inputMin.text = min.ToString();
inputMax.text = max.ToString();
inputValue.text = value.ToString();
slider.minValue = min;
slider.maxValue = max;
slider.value = value;
}
void OnEndEditMin(string value){
float.TryParse(value, out float min);
slider.minValue = min;
}
void OnEndEditMax(string value){
float.TryParse(value, out float max);
slider.maxValue = max;
}
void OnEndEditValue(string value){
float parsedValue;
if (float.TryParse(value, out parsedValue)) {
slider.value = parsedValue;
}
}
void OnValueChanged(float value){
inputValue.text = value.ToString();
if (OnChanged != null) {
OnChanged.Invoke(value);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: fc8c3535b2249f247abdb4f3964eca7e

View File

@@ -0,0 +1,93 @@
using System;
using System.Collections;
using UnityEngine;
public class DevSettingsPanel : MonoBehaviour
{
public static Action OnChanged;
public static DevSettingsPanel instance;
public Transform contentParent;
public DevOptionItem devOptionItemPrefab;
void Awake()
{
instance = this;
}
void Start()
{
StartCoroutine(CoroutinePopulate());
}
IEnumerator CoroutinePopulate()
{
yield return new WaitForSeconds(1f); //Wait for the game manager to be initialized
Populate();
}
void Populate()
{
DevOptionItem puckForce = Instantiate(devOptionItemPrefab, contentParent);
puckForce.Setup("Puck Force", 2500, 6000, GameManager.instance.puckForce);
puckForce.OnChanged += OnPuckForceChanged;
DevOptionItem puckDragClampMax = Instantiate(devOptionItemPrefab, contentParent);
puckDragClampMax.Setup("Puck Launch Max Length", 1, 10, GameManager.instance.puckDragClampMax);
puckDragClampMax.OnChanged += OnPuckDragClampMaxChanged;
DevOptionItem puckDragClampMin = Instantiate(devOptionItemPrefab, contentParent);
puckDragClampMin.Setup("Puck Launch Min Length", 0, 2, GameManager.instance.puckDragMinClamp);
puckDragClampMin.OnChanged += OnPuckDragClampMinChanged;
DevOptionItem ballMoveTime = Instantiate(devOptionItemPrefab, contentParent);
ballMoveTime.Setup("Ball Drag", 0f, 10, GameManager.instance.ballMoveTime);
ballMoveTime.OnChanged += OnBallMoveTimeChanged;
DevOptionItem puckMass = Instantiate(devOptionItemPrefab, contentParent);
puckMass.Setup("Puck Mass", 1f, 50, GameManager.instance.puckMass);
puckMass.OnChanged += OnPuckMassChanged;
DevOptionItem puckDrag = Instantiate(devOptionItemPrefab, contentParent);
puckDrag.Setup("Puck Drag", 0f, 10, GameManager.instance.puckDrag);
puckDrag.OnChanged += OnPuckDragChanged;
}
void OnPuckForceChanged(float value)
{
GameManager.instance.puckForce = value;
OnChanged?.Invoke();
}
void OnPuckDragClampMaxChanged(float value)
{
GameManager.instance.puckDragClampMax = value;
OnChanged?.Invoke();
}
void OnPuckDragClampMinChanged(float value)
{
GameManager.instance.puckDragMinClamp = value;
OnChanged?.Invoke();
}
void OnBallMoveTimeChanged(float value)
{
GameManager.instance.ballMoveTime = value;
OnChanged?.Invoke();
}
void OnPuckMassChanged(float value)
{
GameManager.instance.puckMass = value;
OnChanged?.Invoke();
}
void OnPuckDragChanged(float value)
{
GameManager.instance.puckDrag = value;
OnChanged?.Invoke();
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 42df6f977bdfdf54092d0442ed988ef0

View File

@@ -44,6 +44,26 @@ public class GameManager : MonoBehaviour
public int hitCounter = 0;
public static GameManager instance;
public float puckMass{
get{
if(pucks.Count > 0){return pucks[0].rb.mass;}else{return 1f;}
}set{
foreach(Puck puck in pucks){
puck.rb.mass = value;
}
}
}
public float puckDrag{
get{
if(pucks.Count > 0){return pucks[0].rb.linearDamping;}else{return 0f;}
}set{
foreach(Puck puck in pucks){
puck.rb.linearDamping = value;
}
}
}
void Awake()
{
instance = this;
@@ -193,6 +213,8 @@ public class GameManager : MonoBehaviour
//kickoff goal
Debug.Log("Kickoff goal");
StartCoroutine(CoroutineOnGoal(team,true));//true = Kickoff goal, reset only the ball
hitCounter = 0;
return;
}
if(team == Team.Blue){
@@ -253,7 +275,7 @@ public class GameManager : MonoBehaviour
float resetDuration = 0.5f;
if(!kickoff){
foreach(Puck puck in pucks){
puck.Reset(resetDuration);
puck.Reset(null, resetDuration);
}
}

View File

@@ -14,7 +14,7 @@ public class Goal : MonoBehaviour
Debug.Log("Puck goal", gameObject);
Puck puck = collision.gameObject.GetComponent<Puck>();
Debug.Log(puck.name);
puck.ScheduleReset();
puck.ScheduleReset(collision.transform.position);
}
}

View File

@@ -101,13 +101,14 @@ public class Puck : MonoBehaviour
}
public void Reset(float duration)
public void Reset(Vector3? position = null, float duration = 0.5f)
{
StartCoroutine(CoroutineReset(duration));
Vector3 pos = position ?? startPosition;
StartCoroutine(CoroutineReset(pos, duration));
}
Coroutine coroutineScheduleReset;
public void ScheduleReset(float duration = 0.5f){
coroutineScheduleReset = StartCoroutine(CoroutineScheduleReset(duration));
public void ScheduleReset(Vector3 position, float duration = 0.5f){
coroutineScheduleReset = StartCoroutine(CoroutineScheduleReset(position, duration));
}
public void UnscheduleReset(){
@@ -116,20 +117,25 @@ public class Puck : MonoBehaviour
}
}
IEnumerator CoroutineScheduleReset(float duration){
IEnumerator CoroutineScheduleReset(Vector3 position, float duration){
while(GameManager.isMoving){
yield return null;
}
Reset(duration);
Debug.Log("Resetting puck", gameObject);
Vector3 dir = position - transform.position;
dir = dir.normalized;
position += dir * 1.25f;
Reset(position, duration);
}
IEnumerator CoroutineReset(float duration){
IEnumerator CoroutineReset(Vector3 pos, float duration){
float t=0;
Vector3 pos1 = transform.position;
Quaternion rot1 = transform.rotation;
while(t<duration){
t+=Time.deltaTime;
transform.position = Vector3.Lerp(pos1, startPosition, t/duration);
transform.position = Vector3.Lerp(pos1, pos, t/duration);
transform.rotation = Quaternion.Lerp(rot1, Quaternion.identity, t/duration);
yield return null;
}