added game.settings.cs acting as interface for gamemanager containing game specific settings to read from once

main
Benjamin Kraft 1 year ago
parent 8962a0988b
commit f109ffbd34
  1. 69
      Assets/Scenes/Game.unity
  2. 21
      Assets/Scripts/Game/AIPlayer.cs
  3. 35
      Assets/Scripts/Game/GameManager.cs
  4. 9
      Assets/Scripts/Game/Settings.cs
  5. 3
      Assets/Scripts/Game/Settings.cs.meta
  6. 28
      Assets/Scripts/MenuUI.cs
  7. 3
      Assets/UI Toolkit/Menu.uxml
  8. 2
      Assets/UI Toolkit/PanelSettings.asset
  9. 2
      Assets/UI Toolkit/UnityDefaultRuntimeTheme.tss
  10. 11
      Assets/UI Toolkit/UnityDefaultRuntimeTheme.tss.meta
  11. 8
      Assets/UI Toolkit/UnityThemes.meta

@ -259,7 +259,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 5
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &338338487
GameObject:
@ -343,7 +343,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &948416250
GameObject:
@ -379,7 +379,7 @@ Transform:
- {fileID: 132613873}
- {fileID: 1462314554}
m_Father: {fileID: 0}
m_RootOrder: 3
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &948416252
MonoBehaviour:
@ -506,67 +506,6 @@ EdgeCollider2D:
m_AdjacentEndPoint: {x: 0, y: 0}
m_UseAdjacentStartPoint: 0
m_UseAdjacentEndPoint: 0
--- !u!1001 &1497269263
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7041796185663956338, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7041796185663956339, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3}
propertyPath: GlobalObjectIdHash
value: 290977249
objectReference: {fileID: 0}
- target: {fileID: 7041796185663956342, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3}
propertyPath: m_Name
value: Ball
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3}
--- !u!1 &1698696474
GameObject:
m_ObjectHideFlags: 0
@ -762,7 +701,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &2109945869
MonoBehaviour:

@ -3,21 +3,20 @@ using System.Linq;
using UnityEngine;
namespace Game {
public class AIPlayer : Player {
/*
* Possible optimizations:
*
* - Move to center when idle
* - Ignore impossible balls
* - Try to hit ball with edge
*/
public enum EDifficulty {
VeryEasy, Easy, Medium, Hard, VeryHard
}
* Possible optimizations:
*
* - Move to center when idle
* - Ignore impossible balls
* - Try to hit ball with edge
*/
public EDifficulty Difficulty { get; set; }
public Difficulty Difficulty { get; set; }
// True if ball y velocity points towards player
private bool BallApproaches(Ball ball) {

@ -49,20 +49,37 @@ namespace Game {
}
private void Start() {
//var ball = Instantiate(ballPrefab, Vector2.zero, Quaternion.identity).GetComponent<Ball>();
var ball = FindObjectOfType(typeof(Ball)).GetComponent<Ball>();
var ball = Instantiate(ballPrefab).GetComponent<Ball>();
Balls.Add(ball);
ball.Radius = 0.5f;
var p1Obj = Instantiate(playerPrefab);
var p2Obj = Instantiate(playerPrefab);
var p1 = p1Obj.AddComponent<AIPlayer>();
var p2 = p2Obj.AddComponent<AIPlayer>();
p1.Side = Player.ESide.Top;
p2.Side = Player.ESide.Bottom;
p1.Difficulty = AIPlayer.EDifficulty.VeryHard;
p2.Difficulty = AIPlayer.EDifficulty.VeryHard;
// p2.isThisClient = true;
Player p1, p2;
switch (Settings.Type) {
case Type.AI:
p1 = p1Obj.AddComponent<AIPlayer>();
p2 = p2Obj.AddComponent<AIPlayer>();
((AIPlayer) p1).Difficulty = Settings.AIDifficulty;
((AIPlayer) p2).Difficulty = Settings.AIDifficulty;
break;
case Type.Real:
p1 = p1Obj.AddComponent<RealPlayer>();
p2 = p2Obj.AddComponent<RealPlayer>();
((RealPlayer) p1).isThisClient = true;
break;
case Type.Hybrid:
p1 = p1Obj.AddComponent<RealPlayer>();
p2 = p2Obj.AddComponent<AIPlayer>();
((RealPlayer) p1).isThisClient = true;
((AIPlayer)p2).Difficulty = Settings.AIDifficulty;
break;
default:
throw new ArgumentOutOfRangeException();
}
p1.Side = Player.ESide.Bottom;
p2.Side = Player.ESide.Top;
Tests();
}

@ -0,0 +1,9 @@
namespace Game {
public enum Type { Real, Hybrid, AI }
public enum Difficulty { VeryEasy, Easy, Medium, Hard, VeryHard }
public struct Settings {
public static Type Type;
public static Difficulty AIDifficulty;
};
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ba3433b349f4485cb01c605e8abdd151
timeCreated: 1680961305

@ -1,3 +1,4 @@
using Game;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UIElements;
@ -19,10 +20,13 @@ public class MenuUI : MonoBehaviour {
mainMenu.Q("btn_settings").RegisterCallback<ClickEvent>(SettingsPressed);
playMenu.Q("btn_find").RegisterCallback<ClickEvent>(FindPressed);
playMenu.Q("btn_host").RegisterCallback<ClickEvent>(HostPressed);
playMenu.Q("btn_join").RegisterCallback<ClickEvent>(JoinPressed);
playMenu.Q("btn_bot").RegisterCallback<ClickEvent>(BotPressed);
playMenu.Q("btn_bots").RegisterCallback<ClickEvent>(BotsPressed);
PlayPressed(null);
BotPressed(null);
// PlayPressed(null);
// BotPressed(null);
}
private void PlayPressed(ClickEvent evt) {
@ -36,10 +40,28 @@ public class MenuUI : MonoBehaviour {
}
private void FindPressed(ClickEvent evt) {
Debug.Log("Start finding online opponent");
}
private void HostPressed(ClickEvent evt) {
}
private void JoinPressed(ClickEvent evt) {
}
private void BotPressed(ClickEvent evt) {
Settings.Type = Type.Hybrid;
Settings.AIDifficulty = Difficulty.VeryHard;
SceneManager.LoadScene("Game");
}
private void BotsPressed(ClickEvent evt) {
Settings.Type = Type.AI;
Settings.AIDifficulty = Difficulty.VeryHard;
SceneManager.LoadScene("Game");
}
}

@ -7,9 +7,10 @@
</ui:VisualElement>
<ui:VisualElement name="play_menu" class="menu" style="display: none;">
<ui:Button text="Find opponent" display-tooltip-when-elided="true" name="btn_find" />
<ui:Button text="Bot opponent" display-tooltip-when-elided="true" name="btn_bot" />
<ui:Button text="Host game" display-tooltip-when-elided="true" name="btn_host" />
<ui:Button text="Join game" display-tooltip-when-elided="true" name="btn_join" />
<ui:Button text="AI opponent" display-tooltip-when-elided="true" name="btn_bot" />
<ui:Button text="AI vs AI" display-tooltip-when-elided="true" name="btn_bots" />
</ui:VisualElement>
<ui:VisualElement name="settings_menu" class="menu" style="display: none;" />
</ui:UXML>

@ -12,7 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 19101, guid: 0000000000000000e000000000000000, type: 0}
m_Name: PanelSettings
m_EditorClassIdentifier:
themeUss: {fileID: -4733365628477956816, guid: 265dd7776008c18abae44e0779f59f95, type: 3}
themeUss: {fileID: -4733365628477956816, guid: 87c5f501dc6f5fb448eef0f9f3bffa1c, type: 3}
m_TargetTexture: {fileID: 0}
m_ScaleMode: 1
m_Scale: 1

@ -0,0 +1,2 @@
@import url("unity-theme://default");
VisualElement {}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 87c5f501dc6f5fb448eef0f9f3bffa1c
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12388, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: f7bb7308e65951375935aba0b037caa4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save