protected override void Awake()
    {
        base.Awake();

        CytoidApplication.SetAutoRotation(true);
        CytoidApplication.ResetResolution();

        var ringColorDef    = "#FFFFFF";
        var ringColorAltDef = "#FFFFFF";
        var fillColorDef    = "#6699CC";
        var fillColorAltDef = "#FF3C38";

        SetDefaultPref("main offset", Application.platform == RuntimePlatform.Android ? 0f : 0.1f);
        SetDefaultPref("headset offset", -0.05f);
        SetDefaultPref("show_scanner", true);
        SetDefaultPref("inverse", false);
        SetDefaultPref("ring_color", ringColorDef);
        SetDefaultPref("ring_color_alt", ringColorAltDef);
        SetDefaultPref("fill_color", fillColorDef);
        SetDefaultPref("fill_color_alt", fillColorAltDef);
        SetDefaultPref("hit_sound", "None");

        var list = HitSounds.ToList();

        list.Insert(0, new HitSound {
            Name = "None"
        });
        HitSounds = list.ToArray();
        UpdateHitSound(HitSounds[1], save: false);

        var userHitSound = PlayerPrefs.GetString("hit_sound");

        for (var index = 0; index < HitSounds.Length; index++)
        {
            if (HitSounds[index].Name == userHitSound)
            {
                UpdateHitSound(HitSounds[index]);
                HitSoundIndex = index;
            }
        }

        mainOffsetInput.text          = PlayerPrefs.GetFloat("main offset").ToString();
        headsetOffsetInput.text       = PlayerPrefs.GetFloat("headset offset").ToString();
        earlyLateIndicatorToggle.isOn = PlayerPrefsExt.GetBool("early_late_indicator");
        largerHitboxesToggle.isOn     = PlayerPrefsExt.GetBool("larger_hitboxes");

        mainOffsetInput.onEndEdit.AddListener(text =>
        {
            float offset;
            if (!float.TryParse(text, out offset))
            {
                mainOffsetInput.text = PlayerPrefs.GetFloat("main offset").ToString();
            }
            else
            {
                PlayerPrefs.SetFloat("main offset", offset);
            }
        });
        chartRelativeOffsetInput.onEndEdit.AddListener(text =>
        {
            float offset;
            if (!float.TryParse(text, out offset))
            {
                chartRelativeOffsetInput.text = ZPlayerPrefs.GetFloat(PreferenceKeys.ChartRelativeOffset(CytoidApplication.CurrentLevel.id)).ToString();
            }
            else
            {
                ZPlayerPrefs.SetFloat(PreferenceKeys.ChartRelativeOffset(CytoidApplication.CurrentLevel.id), offset);
            }
        });
        headsetOffsetInput.onEndEdit.AddListener(text =>
        {
            float offset;
            if (!float.TryParse(text, out offset))
            {
                headsetOffsetInput.text = PlayerPrefs.GetFloat("headset offset").ToString();
            }
            else
            {
                PlayerPrefs.SetFloat("headset offset", offset);
            }
        });

        usernameInput.text = PlayerPrefs.GetString(PreferenceKeys.LastUsername());
        passwordInput.text = PlayerPrefs.GetString(PreferenceKeys.LastPassword());

        if (!PlayerPrefs.HasKey("ranked"))
        {
            PlayerPrefsExt.SetBool("ranked", false);
        }

        rankStatusText.text = OnlinePlayer.Authenticated && PlayerPrefsExt.GetBool("ranked") ? "On" : "Off";

        // Initialize background
        blackout.SetActive(false);

        var backgrounds = GameObject.FindGameObjectsWithTag("Background");

        if (backgrounds.Length > 1) // Already have persisted background? (i.e. returning from Game/GameResult scene)
        {
            var localBackground = backgrounds.ToList().Find(it => it.scene == gameObject.scene);
            // Destroy local background
            Destroy(localBackground);
            // Setup the persisted background
            BackgroundCanvasHelper.SetupBackgroundCanvas(gameObject.scene);
        }
        else // Setup the local background
        {
            BackgroundCanvasHelper.SetupBackgroundCanvas(gameObject.scene);
        }

        if (OnlinePlayer.Authenticated && OnlinePlayer.AvatarTexture != null)
        {
            LoadedAvatar = true;
        }

        if (Application.platform == RuntimePlatform.Android)
        {
            headsetOffsetInput.gameObject.SetActive(false);
            LayoutRebuilder.ForceRebuildLayoutImmediate(headsetOffsetInput.transform.parent.GetComponent <RectTransform>());
        }

        EventKit.Subscribe <string>("meta reloaded", OnLevelMetaReloaded);
    }
    protected override void Awake()
    {
        base.Awake();

        CytoidApplication.SetAutoRotation(true);

        var userOffsetDef   = Application.platform == RuntimePlatform.Android ? 0.12f : 0.2f;
        var ringColorDef    = "#FFFFFF";
        var ringColorAltDef = "#FFFFFF";
        var fillColorDef    = "#6699CC";
        var fillColorAltDef = "#FF3C38";

        SetDefaultPref("user_offset", userOffsetDef);
        SetDefaultPref("show_scanner", true);
        SetDefaultPref("inverse", false);
        SetDefaultPref("ring_color", ringColorDef);
        SetDefaultPref("ring_color_alt", ringColorAltDef);
        SetDefaultPref("fill_color", fillColorDef);
        SetDefaultPref("fill_color_alt", fillColorAltDef);
        SetDefaultPref("hit_sound", "None");

        var list = HitSounds.ToList();

        list.Insert(0, new HitSound {
            Name = "None", Clip = null
        });
        HitSounds = list.ToArray();
        UpdateHitSound(HitSounds[1], save: false);

        var userHitSound = PlayerPrefs.GetString("hit_sound");

        for (var index = 0; index < HitSounds.Length; index++)
        {
            if (HitSounds[index].Name == userHitSound)
            {
                UpdateHitSound(HitSounds[index]);
                HitSoundIndex = index;
            }
        }

        userOffsetInput.text          = PlayerPrefs.GetFloat("user_offset").ToString();
        showScannerToggle.isOn        = PlayerPrefsExt.GetBool("show_scanner");
        earlyLateIndicatorToggle.isOn = PlayerPrefsExt.GetBool("early_late_indicator");
        largerHitboxesToggle.isOn     = PlayerPrefsExt.GetBool("larger_hitboxes");
        isInversedToggle.isOn         = PlayerPrefsExt.GetBool("inverse");
        ringColorInput.text           = PlayerPrefs.GetString("ring_color");
        ringColorAltInput.text        = PlayerPrefs.GetString("ring_color_alt");
        fillColorInput.text           = PlayerPrefs.GetString("fill_color");
        fillColorAltInput.text        = PlayerPrefs.GetString("fill_color_alt");

        userOffsetInput.onEndEdit.AddListener(text =>
        {
            float offset;
            if (!float.TryParse(text, out offset))
            {
                userOffsetInput.text = userOffsetDef.ToString();
            }
        });
        overrideOptionsToggle.onValueChanged.AddListener(selected =>
        {
            ZPlayerPrefs.SetBool(PreferenceKeys.WillOverrideOptions(CytoidApplication.CurrentLevel), selected);
        });
        localIsInversedToggle.onValueChanged.AddListener(selected =>
        {
            ZPlayerPrefs.SetBool(PreferenceKeys.WillInverse(CytoidApplication.CurrentLevel), selected);
        });
        localUserOffsetInput.onEndEdit.AddListener(text =>
        {
            float offset;
            if (!float.TryParse(text, out offset))
            {
                localUserOffsetInput.text = userOffsetInput.text;
            }
            else
            {
                ZPlayerPrefs.SetFloat(PreferenceKeys.NoteDelay(CytoidApplication.CurrentLevel), offset);
            }
        });
        ringColorInput.onEndEdit.AddListener(text =>
        {
            try
            {
                Convert.HexToColor(text);
            }
            catch (Exception)
            {
                ringColorInput.text = ringColorDef;
            }
        });
        ringColorAltInput.onEndEdit.AddListener(text =>
        {
            try
            {
                Convert.HexToColor(text);
            }
            catch (Exception)
            {
                ringColorAltInput.text = ringColorAltDef;
            }
        });
        fillColorInput.onEndEdit.AddListener(text =>
        {
            try
            {
                Convert.HexToColor(text);
            }
            catch (Exception)
            {
                fillColorInput.text = fillColorDef;
            }
        });
        fillColorAltInput.onEndEdit.AddListener(text =>
        {
            try
            {
                Convert.HexToColor(text);
            }
            catch (Exception)
            {
                fillColorAltInput.text = fillColorAltDef;
            }
        });
        usernameInput.text = PlayerPrefs.GetString(PreferenceKeys.LastUsername());
        passwordInput.text = PlayerPrefs.GetString(PreferenceKeys.LastPassword());

        if (!PlayerPrefs.HasKey(PreferenceKeys.RankedMode()))
        {
            PlayerPrefsExt.SetBool(PreferenceKeys.RankedMode(), false);
        }

        rankStatusText.text = "Off";

        // Initialize background
        blackout.SetActive(false);

        var backgrounds = GameObject.FindGameObjectsWithTag("Background");

        if (backgrounds.Length > 1) // Already have persisted background? (i.e. returning from Game/GameResult scene)
        {
            var localBackground = backgrounds.ToList().Find(it => it.scene == gameObject.scene);
            // Destroy local background
            Destroy(localBackground);
            // Setup the persisted background
            BackgroundCanvasHelper.SetupBackgroundCanvas(gameObject.scene);
        }
        else // Setup the local background
        {
            BackgroundCanvasHelper.SetupBackgroundCanvas(gameObject.scene);
        }
    }