-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscoreCalculator.cs
115 lines (90 loc) · 3.17 KB
/
scoreCalculator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class scoreCalculator : MonoBehaviour {
[System.Serializable] public class mEvent : UnityEvent { }
public float score;
public static scoreCalculator instance;
[System.Serializable]
public class scoreRelevantPair{
public valueDefinitions.values valueType;
public float multiplier;
}
public scoreRelevantPair[] scoreValues;
public scoreCounter[] extraScores;
public scoreCounter highScore;
public scoreCounter maxHighScore;
[System.Serializable]
public class C_ScoreSave {
public bool saveScoreToValue = false;
public valueDefinitions.values saveToValue;
}
KingsLevelUp levelUp;
public void calculateScore(){
score = 0f;
ValueScript vs;
foreach (scoreRelevantPair srp in scoreValues) {
vs = valueManager.instance.getFirstFittingValue (srp.valueType);
score += vs.value * srp.multiplier;
if(srp.valueType == valueDefinitions.values.stockPrice)
{
string result = "";
result += "{";
result += "\"subject\":\"Algebra 1\",";
result += "\"stockPrice\": " + vs.value + "";
result += "}";
string POST_field = "/api/set";
string Json = "";
Json += result;
SenderData.instance.SendData(POST_field, Json);
}
}
foreach (scoreCounter sc in extraScores) {
score += sc.getScore ();
}
if (highScore != null) {
highScore.setScore(Mathf.RoundToInt(score));
}
if (maxHighScore != null) {
maxHighScore.setMaxScore(Mathf.RoundToInt(score));
}
addLevelUpXp(score);
}
void Awake() {
instance = this;
levelUp = gameObject.GetComponent<KingsLevelUp>();
}
void addLevelUpXp(float xp) {
if (levelUp != null) {
levelUp.AddXp(xp);
}
}
}
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(scoreCalculator.scoreRelevantPair))]
public class scoreRelevantPairDrawer : PropertyDrawer
{
// Draw the property inside the given rect
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
//don't alter
EditorGUI.BeginProperty(position, label, property);
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
var indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
// Calculate rects
var modRect = new Rect(position.x, position.y, position.width * 0.50f, position.height);
var valRect = new Rect(position.x + position.width * 0.52f , position.y, position.width * 0.48f , position.height);
// Draw fields - passs GUIContent.none to each so they are drawn without labels
EditorGUI.PropertyField(modRect, property.FindPropertyRelative("valueType"), GUIContent.none);
EditorGUI.PropertyField(valRect, property.FindPropertyRelative("multiplier"), GUIContent.none);
//don't alter
EditorGUI.indentLevel = indent;
EditorGUI.EndProperty();
}
}
#endif