Skip to content

Commit cff5a43

Browse files
committed
feat(core): add tutorial 27 code
1 parent a928c07 commit cff5a43

8 files changed

Lines changed: 351 additions & 28 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!1 &297393645580100840
4+
GameObject:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
serializedVersion: 6
10+
m_Component:
11+
- component: {fileID: 297393645580100841}
12+
- component: {fileID: 297393645580100843}
13+
- component: {fileID: 2512990974655891355}
14+
m_Layer: 5
15+
m_Name: UILabel
16+
m_TagString: Untagged
17+
m_Icon: {fileID: 0}
18+
m_NavMeshLayer: 0
19+
m_StaticEditorFlags: 0
20+
m_IsActive: 1
21+
--- !u!224 &297393645580100841
22+
RectTransform:
23+
m_ObjectHideFlags: 0
24+
m_CorrespondingSourceObject: {fileID: 0}
25+
m_PrefabInstance: {fileID: 0}
26+
m_PrefabAsset: {fileID: 0}
27+
m_GameObject: {fileID: 297393645580100840}
28+
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
29+
m_LocalPosition: {x: 0, y: 0, z: 0}
30+
m_LocalScale: {x: 1, y: 1, z: 1}
31+
m_Children: []
32+
m_Father: {fileID: 0}
33+
m_RootOrder: 0
34+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
35+
m_AnchorMin: {x: 0, y: 0}
36+
m_AnchorMax: {x: 0, y: 0}
37+
m_AnchoredPosition: {x: 0, y: 0}
38+
m_SizeDelta: {x: 0, y: 32}
39+
m_Pivot: {x: 0, y: 0.5}
40+
--- !u!222 &297393645580100843
41+
CanvasRenderer:
42+
m_ObjectHideFlags: 0
43+
m_CorrespondingSourceObject: {fileID: 0}
44+
m_PrefabInstance: {fileID: 0}
45+
m_PrefabAsset: {fileID: 0}
46+
m_GameObject: {fileID: 297393645580100840}
47+
m_CullTransparentMesh: 0
48+
--- !u!114 &2512990974655891355
49+
MonoBehaviour:
50+
m_ObjectHideFlags: 0
51+
m_CorrespondingSourceObject: {fileID: 0}
52+
m_PrefabInstance: {fileID: 0}
53+
m_PrefabAsset: {fileID: 0}
54+
m_GameObject: {fileID: 297393645580100840}
55+
m_Enabled: 1
56+
m_EditorHideFlags: 0
57+
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
58+
m_Name:
59+
m_EditorClassIdentifier:
60+
m_Material: {fileID: 0}
61+
m_Color: {r: 0.9056604, g: 0.9009572, b: 0.7732289, a: 1}
62+
m_RaycastTarget: 1
63+
m_Maskable: 1
64+
m_OnCullStateChanged:
65+
m_PersistentCalls:
66+
m_Calls: []
67+
m_FontData:
68+
m_Font: {fileID: 12800000, guid: fa27db405805f4adfb4b57c49cc04d47, type: 3}
69+
m_FontSize: 11
70+
m_FontStyle: 0
71+
m_BestFit: 0
72+
m_MinSize: 1
73+
m_MaxSize: 11
74+
m_Alignment: 3
75+
m_AlignByGeometry: 0
76+
m_RichText: 1
77+
m_HorizontalOverflow: 0
78+
m_VerticalOverflow: 0
79+
m_LineSpacing: 1
80+
m_Text: 0

Assets/Resources/Prefabs/UI/UILabel.prefab.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Resources/ScriptableObjects/Parameters/Global Parameters.asset

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,103 @@ MonoBehaviour:
1919
dayLengthInSeconds: 20
2020
dayInitialRatio: 0.2
2121
initialBuilding: {fileID: 11400000, guid: 5c2ccb27116004dc1acffa053dc93179, type: 2}
22+
experienceEvolutionCurve:
23+
serializedVersion: 2
24+
m_Curve:
25+
- serializedVersion: 3
26+
time: 0
27+
value: 2.9955945
28+
inSlope: 0
29+
outSlope: 0
30+
tangentMode: 0
31+
weightedMode: 0
32+
inWeight: 0
33+
outWeight: 0
34+
- serializedVersion: 3
35+
time: 4
36+
value: 10
37+
inSlope: 0
38+
outSlope: 0
39+
tangentMode: 0
40+
weightedMode: 0
41+
inWeight: 0
42+
outWeight: 0
43+
m_PreInfinity: 2
44+
m_PostInfinity: 2
45+
m_RotationOrder: 4
46+
productionMultiplierCurve:
47+
serializedVersion: 2
48+
m_Curve:
49+
- serializedVersion: 3
50+
time: 0
51+
value: 1
52+
inSlope: 0.10713435
53+
outSlope: 0.10713435
54+
tangentMode: 0
55+
weightedMode: 0
56+
inWeight: 0
57+
outWeight: 0.10338563
58+
- serializedVersion: 3
59+
time: 4
60+
value: 2
61+
inSlope: 0.015243469
62+
outSlope: 0.015243469
63+
tangentMode: 0
64+
weightedMode: 0
65+
inWeight: 0.13959914
66+
outWeight: 0
67+
m_PreInfinity: 2
68+
m_PostInfinity: 2
69+
m_RotationOrder: 4
70+
attackDamageMultiplierCurve:
71+
serializedVersion: 2
72+
m_Curve:
73+
- serializedVersion: 3
74+
time: 0
75+
value: 0
76+
inSlope: 0.5
77+
outSlope: 0.5
78+
tangentMode: 34
79+
weightedMode: 0
80+
inWeight: 0
81+
outWeight: 0.33333334
82+
- serializedVersion: 3
83+
time: 4
84+
value: 2
85+
inSlope: 0.5
86+
outSlope: 0.5
87+
tangentMode: 34
88+
weightedMode: 0
89+
inWeight: 0.33333334
90+
outWeight: 0
91+
m_PreInfinity: 2
92+
m_PostInfinity: 2
93+
m_RotationOrder: 4
94+
attackRangeMultiplierCurve:
95+
serializedVersion: 2
96+
m_Curve:
97+
- serializedVersion: 3
98+
time: 0
99+
value: 0
100+
inSlope: 0.5
101+
outSlope: 0.5
102+
tangentMode: 34
103+
weightedMode: 0
104+
inWeight: 0
105+
outWeight: 0.33333334
106+
- serializedVersion: 3
107+
time: 4
108+
value: 2
109+
inSlope: 0.5
110+
outSlope: 0.5
111+
tangentMode: 34
112+
weightedMode: 0
113+
inWeight: 0.33333334
114+
outWeight: 0
115+
m_PreInfinity: 2
116+
m_PostInfinity: 2
117+
m_RotationOrder: 4
118+
onLevelUpSound: {fileID: 8300000, guid: f12b420e471f24f419e8e84613e0cad0, type: 3}
22119
baseGoldProduction: 5
23120
bonusGoldProductionPerBuilding: 2
24121
goldBonusRange: 10

Assets/Scripts/ScriptableObjects/Parameters/GameGlobalParameters.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Linq;
12
using UnityEngine;
23

34
[CreateAssetMenu(fileName = "Global Parameters", menuName = "Scriptable Objects/Game Global Parameters", order = 10)]
@@ -14,6 +15,11 @@ public class GameGlobalParameters : GameParameters
1415

1516
[Header("Units")]
1617
public BuildingData initialBuilding;
18+
public AnimationCurve experienceEvolutionCurve;
19+
public AnimationCurve productionMultiplierCurve;
20+
public AnimationCurve attackDamageMultiplierCurve;
21+
public AnimationCurve attackRangeMultiplierCurve;
22+
public AudioClip onLevelUpSound;
1723

1824
[Header("Units production")]
1925
public int baseGoldProduction;
@@ -37,6 +43,7 @@ public class GameGlobalParameters : GameParameters
3743

3844
public int UnitMaxLevel()
3945
{
40-
return 4;
46+
Keyframe[] keys = experienceEvolutionCurve.keys;
47+
return (int)keys.Select(k => k.time).Max();
4148
}
4249
}

Assets/Scripts/UI/UIManager.cs

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections;
1+
using System.Collections;
22
using System.Collections.Generic;
33
using System.Reflection;
44
using UnityEngine;
@@ -33,9 +33,10 @@ public class UIManager : MonoBehaviour
3333
private Text _selectedUnitTitleText;
3434
private Text _selectedUnitLevelText;
3535
private Transform _selectedUnitResourcesProductionParent;
36+
private Transform _selectedUnitAttackParametersParent;
3637
private Transform _selectedUnitActionButtonsParent;
3738
private Unit _selectedUnit;
38-
private List<ResourceValue> _selectedUnitNextLevelCost;
39+
public GameObject uiLabelPrefab;
3940
public GameObject unitSkillButtonPrefab;
4041

4142
public Transform selectionGroupsParent;
@@ -76,9 +77,9 @@ private void Awake()
7677
_selectedUnitTitleText = selectedUnitMenuTransform.Find("UnitSpecific/Content/GeneralInfo/Title").GetComponent<Text>();
7778
_selectedUnitLevelText = selectedUnitMenuTransform.Find("UnitSpecific/Content/GeneralInfo/Level").GetComponent<Text>();
7879
_selectedUnitResourcesProductionParent = selectedUnitMenuTransform.Find("UnitSpecific/Content/ResourcesProduction");
80+
_selectedUnitAttackParametersParent = selectedUnitMenuTransform.Find("UnitSpecific/Content/AttackParameters");
7981
_selectedUnitActionButtonsParent = selectedUnitMenuTransform.Find("UnitSpecific/SpecificActions");
8082

81-
8283
placedBuildingProductionRectTransform.gameObject.SetActive(false);
8384

8485
gameSettingsPanel.SetActive(false);
@@ -189,17 +190,20 @@ public void HoverLevelUpButton()
189190
if (_selectedUnit.LevelMaxedOut) return;
190191
_UpdateSelectedUnitLevelUpInfoPanel();
191192
ShowInfoPanel(true);
193+
_SetSelectedUnitMenu(_selectedUnit, true);
192194
}
193195

194196
public void UnhoverLevelUpButton()
195197
{
198+
if (_selectedUnit.LevelMaxedOut) return;
196199
ShowInfoPanel(false);
200+
_SetSelectedUnitMenu(_selectedUnit);
197201
}
198202

199203
public void ClickLevelUpButton()
200204
{
201205
_selectedUnit.LevelUp();
202-
_SetSelectedUnitMenu(_selectedUnit);
206+
_SetSelectedUnitMenu(_selectedUnit, !_selectedUnit.LevelMaxedOut);
203207
if (_selectedUnit.LevelMaxedOut)
204208
{
205209
selectedUnitMenuUpgradeButton.transform.Find("Text").GetComponent<Text>().text = "Maxed out";
@@ -251,7 +255,7 @@ private void _CheckBuyLimits()
251255
_selectedUnit != null &&
252256
_selectedUnit.Owner == GameManager.instance.gamePlayersParameters.myPlayerId &&
253257
!_selectedUnit.LevelMaxedOut &&
254-
Globals.CanBuy(_selectedUnitNextLevelCost)
258+
Globals.CanBuy(_selectedUnit.LevelUpData.cost)
255259
)
256260
selectedUnitMenuUpgradeButton.GetComponent<Button>().interactable = true;
257261

@@ -280,7 +284,11 @@ private void _CheckBuyLimits()
280284
private void _UpdateSelectedUnitLevelUpInfoPanel()
281285
{
282286
int nextLevel = _selectedUnit.Level + 1;
283-
SetInfoPanel("Level up", $"Upgrade unit to level {nextLevel}", _selectedUnitNextLevelCost);
287+
SetInfoPanel(
288+
"Level up",
289+
$"Upgrade unit to level {nextLevel}",
290+
_selectedUnit.LevelUpData.cost
291+
);
284292
}
285293

286294
private void _SetResourceText(InGameResource resource, int value)
@@ -446,16 +454,17 @@ public void RemoveSelectedUnitFromUIList(string code)
446454
t.text = count.ToString();
447455
}
448456

449-
private void _SetSelectedUnitMenu(Unit unit)
457+
private void _SetSelectedUnitMenu(Unit unit, bool showUpgrade = false)
450458
{
451459
_selectedUnit = unit;
452-
_selectedUnitNextLevelCost = _selectedUnit.GetLevelUpCost();
453460

454461
bool unitIsMine = unit.Owner == GameManager.instance.gamePlayersParameters.myPlayerId;
455462

456463
// update texts
457464
_selectedUnitTitleText.text = unit.Data.unitName;
458465
_selectedUnitLevelText.text = $"Level {unit.Level}";
466+
467+
// RESOURCE PRODUCTION --------------------------------------------
459468
// clear resource production
460469
foreach (Transform child in _selectedUnitResourcesProductionParent)
461470
Destroy(child.gameObject);
@@ -467,11 +476,36 @@ private void _SetSelectedUnitMenu(Unit unit)
467476
{
468477
g = Instantiate(gameResourceCostPrefab);
469478
t = g.transform;
470-
t.Find("Text").GetComponent<Text>().text = $"+{resource.Value}";
479+
t.Find("Text").GetComponent<Text>().text = showUpgrade
480+
? $"<color=#00ff00>+{_selectedUnit.LevelUpData.newProduction[resource.Key]}</color>"
481+
: $"+{resource.Value}";
471482
t.Find("Icon").GetComponent<Image>().sprite = Resources.Load<Sprite>($"Textures/GameResources/{resource.Key}");
472-
t.SetParent(_selectedUnitResourcesProductionParent);
483+
t.SetParent(_selectedUnitResourcesProductionParent, false);
473484
}
474485
}
486+
487+
// ATTACK PARAMETERS ----------------------------------------------
488+
// clear attack parameters
489+
foreach (Transform child in _selectedUnitAttackParametersParent)
490+
Destroy(child.gameObject);
491+
// reinstantiate new ones (if I own the unit)
492+
if (unitIsMine)
493+
{
494+
GameObject g;
495+
g = Instantiate(uiLabelPrefab);
496+
g.GetComponent<Text>().text = showUpgrade
497+
? $"Damage: <color=#00ff00>{_selectedUnit.LevelUpData.newAttackDamage}</color>"
498+
: $"Damage: {unit.AttackDamage}";
499+
g.transform.SetParent(_selectedUnitAttackParametersParent, false);
500+
501+
g = Instantiate(uiLabelPrefab);
502+
g.GetComponent<Text>().text = showUpgrade
503+
? $"Range: <color=#00ff00>{(int) _selectedUnit.LevelUpData.newAttackRange}</color>"
504+
: $"Range: {(int) unit.AttackRange}";
505+
g.transform.SetParent(_selectedUnitAttackParametersParent, false);
506+
}
507+
508+
// SKILLS ---------------------------------------------------------
475509
// clear skills
476510
foreach (Transform child in _selectedUnitActionButtonsParent)
477511
Destroy(child.gameObject);
@@ -486,14 +520,14 @@ private void _SetSelectedUnitMenu(Unit unit)
486520
b = g.GetComponent<Button>();
487521
unit.SkillManagers[i].SetButton(b);
488522
t.Find("Text").GetComponent<Text>().text = unit.SkillManagers[i].skill.skillName;
489-
t.SetParent(_selectedUnitActionButtonsParent);
523+
t.SetParent(_selectedUnitActionButtonsParent, false);
490524
_AddUnitSkillButtonListener(b, i);
491525
}
492526
}
493527

494528
// if unit is mine, check if it can level up
495529
if (unitIsMine)
496-
selectedUnitMenuUpgradeButton.GetComponent<Button>().interactable = Globals.CanBuy(_selectedUnitNextLevelCost);
530+
selectedUnitMenuUpgradeButton.GetComponent<Button>().interactable = Globals.CanBuy(_selectedUnit.LevelUpData.cost);
497531

498532
// hide upgrade/destroy buttons if I don't own the building
499533
selectedUnitMenuUpgradeButton.SetActive(unitIsMine);

Assets/Scripts/Units/Buildings/BuildingPlacer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ private void Start()
1818
GameManager.instance.gamePlayersParameters.myPlayerId,
1919
GameManager.instance.startPosition
2020
);
21+
//// instantiate our headquarters
22+
//SpawnBuilding(
23+
// GameManager.instance.gameGlobalParameters.initialBuilding,
24+
// 1 - GameManager.instance.gamePlayersParameters.myPlayerId,
25+
// GameManager.instance.startPosition - Vector3.right * 32f
26+
//);
2127
}
2228

2329
void Update()

0 commit comments

Comments
 (0)