Пример #1
0
        void ICmpInitializable.OnInit(Component.InitContext context)
        {
            if (context == InitContext.Activate && DualityApp.ExecContext != DualityApp.ExecutionContext.Editor)
            {
                GameRes.Data.LoadAll();                 // Preload all data - loading it on-demand might result in freeze-frames for big files
                DualityApp.Keyboard.KeyDown += this.Keyboard_KeyDown;
                this.mainCamObj              = Scene.Current.AllObjects.FirstByName("MainCamera");

                // Setup highscore text
                GameObject highscoreObj = Scene.Current.AllObjects.FirstByName("HighscoreText");
                if (highscoreObj != null && highscoreObj.GetComponent <TextRenderer>() != null)
                {
                    string text          = "/ac/cBBDDBBFF/f[0]Highscore/n/f[1]";
                    var    highscore     = MetaHelper.QueryHighscore().ToArray();
                    bool   currentPassed = false;
                    if (highscore.Length > 0)
                    {
                        foreach (var entry in highscore)
                        {
                            string entryString = entry.Name + new string(' ', 20 - entry.Name.Length - entry.ScoreString.Length) + entry.ScoreString;
                            if (entry.Score == Player.Score && !currentPassed)
                            {
                                text         += "/cFFBBBBFF" + entryString + "/cBBDDBBFF/n";
                                currentPassed = true;
                            }
                            else
                            {
                                text += entryString + "/n";
                            }
                        }
                    }
                    else
                    {
                        text += "/n/n/n/n- empty -";
                    }
                    TextRenderer r = highscoreObj.GetComponent <TextRenderer>();
                    r.Text.SourceText = text;
                    r.UpdateMetrics();
                }
            }
        }