예제 #1
0
 public static PostScore GetInstance()
 {
     if (!instance)
     {
         instance = new GameObject().AddComponent <PostScore>();
     }
     return(instance);
 }
예제 #2
0
 void Awake()
 {
     if (Singleton == null)
     {
         DontDestroyOnLoad(gameObject);
         Singleton = this;
     }
     else if (Singleton != this)
     {
         Destroy(gameObject);
     }
 }
예제 #3
0
        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());
        }
예제 #4
0
        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)));
        }
예제 #5
0
 private void OnEnable()
 {
     Singleton = this;
 }
예제 #6
0
 // Post HighScore
 public void Post()
 {
     PostScore.GetInstance().Post();
 }
예제 #7
0
 public static void CallPostScore(int score, string leaderboardID)
 {
     PostScore?.Invoke(score, leaderboardID);
 }
예제 #8
0
 private void Start()
 {
     instance = this;
     DontDestroyOnLoad(gameObject);
 }