Exemple #1
0
 public static PostScore GetInstance()
 {
     if (!instance)
     {
         instance = new GameObject().AddComponent <PostScore>();
     }
     return(instance);
 }
Exemple #2
0
 void Awake()
 {
     if (Singleton == null)
     {
         DontDestroyOnLoad(gameObject);
         Singleton = this;
     }
     else if (Singleton != this)
     {
         Destroy(gameObject);
     }
 }
        public async Task <IActionResult> PutScore(int id, PostScore scoreDTO)
        {
            if (id != scoreDTO.ID)
            {
                return(BadRequest());
            }

            var score = await _context.Score.FirstOrDefaultAsync(s => s.ID == scoreDTO.ID);

            score.ScoreAmount = scoreDTO.ScoreAmount;
            score.Timestamp   = scoreDTO.Timestamp;
            score.User        = await _context.User.FirstOrDefaultAsync(u => u.id == scoreDTO.UserID);

            score.ScoredOn = await _context.Level.FirstOrDefaultAsync(l => l.ID == scoreDTO.ScoredOnID);

            if (score.User == null || score.ScoredOn == null)
            {
                // User of ScoredOn bestaan niet, bad request.
                return(BadRequest());
            }

            _context.Entry(score).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ScoreExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <Score> > PostScore(PostScore scoreDTO)
        {
            var score = new Score()
            {
                Timestamp   = scoreDTO.Timestamp,
                ScoreAmount = scoreDTO.ScoreAmount,
                User        = await _context.User.FirstOrDefaultAsync(u => u.id == scoreDTO.UserID),
                ScoredOn    = await _context.Level.FirstOrDefaultAsync(s => s.ID == scoreDTO.ScoredOnID)
            };

            if (score.User == null || score.ScoredOn == null)
            {
                // User of ScoredOn bestaan niet, bad request.
                return(BadRequest());
            }

            _context.Score.Add(score);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetScore", new { id = score.ID }, ConvertGetScoreDTO(score)));
        }
Exemple #5
0
 private void OnEnable()
 {
     Singleton = this;
 }
 // Post HighScore
 public void Post()
 {
     PostScore.GetInstance().Post();
 }
Exemple #7
0
 public static void CallPostScore(int score, string leaderboardID)
 {
     PostScore?.Invoke(score, leaderboardID);
 }
Exemple #8
0
 private void Start()
 {
     instance = this;
     DontDestroyOnLoad(gameObject);
 }