public class CScoreBoardRow {
private int m_score;
private int m_rank;
private string m_username;
}
public class CGameVersion {
public string GetVersion() {
return BackendServer.GetInstance().GetVersion();
}
}
public class CScoreBoard{
private string m_scoreBoardName;
public CScoreBoard(string _scoreBoardName) {
m_scoreBoardName = _scoreBoardName;
}
public int GetMyRank(string _userId) {
int myRank= BackendServer.GetInstance().GetUserRank(_userId, m_scoreBoardName);
return myRank;
}
public CScoreBoardRow[] GetScoreBoard(int _numRow) {
CScoreBoardRow[] scoreBoardRows=new CScoreBoardRow[_numRow];
scoreBoardRows = BackendServer.GetInstance().GetScoreBoard(0, _numRow,m_scoreBoardName);
return scoreBoardRows;
}
}
public class CServerTime {
private uint m_currServerTime;
public uint GetServerTime() {
m_currServerTime= BackendServer.GetInstance().GetServerTime();
return m_currServerTime;
}
public void UpdateCurrServerTime(uint _currServerTime) {
m_currServerTime = _currServerTime;
}
}
public class CServerController : MonoBehaviour {
private static CServerController m_instance;
private CScoreBoard m_scoreBoard;
private CServerTime m_serverTime;
public static CServerController GetInstance() {
return m_instance;
}
void Awake() {
if (m_instance == null) {
m_instance = this;
}
m_scoreBoard = new CScoreBoard("UserRanking");
m_serverTime = new CServerTime();
}
public CScoreBoardRow[] GetScoreBoard(int _numRow) {
return m_scoreBoard.GetScoreBoard(_numRow);
}
public int GetMyRank(string _userId) {
return m_scoreBoard.GetMyRank(_userId);
}
public uint GetServerTime() {
return m_serverTime.GetServerTime();
}
}
I have several questions.
If you want to implement servercontroller class that controls sent and received data,how do you do?
question1: you split it to several classes like scoreboard,servertime,version and etc classes and then create objects of these classes into servercontroller class?
or prefer to implement only one class servercontroller.
question2: you prefer to call scoreboard and other classes directly from another script like CScoreboardUI monobehaviour (create scoreboard object class and then call its functions)
or call servercontroller.GetInstance() functions.
question3:
you prefer to define numRow (GetScoreBoard(int _numRow)) as a parameter or field of the class.
and please refer one pro book to learn design pattern in game programming (reduce duplicate codes and coupling)
thanks in advance