/*
     * public void Awake()
     * {
     *      if(s_instance == null)
     *              s_instance = this;
     * }*/
    /// <summary>
    /// 请求系统减速.
    /// </summary>
    /// <returns><c>true</c>, if time scale was reqed, <c>false</c> otherwise.</returns>
    /// <param name="scale">Scale.</param>
    /// <param name="duration">Duration.</param>
    /// <param name="context">Context.</param>
    public bool ReqTimeScale(float scale, float duration, GameTimeScaleContext context, System.Action <TimeScaleContextData> OnUpdate = null)
    {
        if (duration <= 0)
        {
            CancelTimeScale(context);
            return(false);
        }

        ReqTimeScaleResult policy = CheckTimeScalePolicy(context);

//		if(_currentScaleData != null)
//			Log.info(this, "[Check Time scale] currentContexgt " + _currentScaleData.context +" context "  + context + " result " + policy);
//		else
//			Log.info(this, "[Check Time scale] currentContexgt null  context "  + context + " result " + policy);
        switch (policy)
        {
        case ReqTimeScaleResult.Override:
            OverrideCurScale(scale, duration, context, OnUpdate);
            break;

        case ReqTimeScaleResult.Refused:
            RefuseScale(scale, duration, context, OnUpdate);
            return(false);

        case ReqTimeScaleResult.Break:
            BreakCurScale(scale, duration, context, OnUpdate);
            break;

        case ReqTimeScaleResult.Queued:
            break;

        default:
            break;
        }
        return(true);
    }
    /// <summary>
    /// Checks the time scale policy.
    /// </summary>
    /// <returns>The time scale policy.</returns>
    /// <param name="context">Context.</param>
    public ReqTimeScaleResult CheckTimeScalePolicy(GameTimeScaleContext context)
    {
        if (_currentScaleData == null)
        {
            return(ReqTimeScaleResult.Override);
        }
        ReqTimeScaleResult ret = ReqTimeScaleResult.None;

        switch (_currentScaleData.context)
        {
        case GameTimeScaleContext.BossKilled:
            switch (context)
            {
            case GameTimeScaleContext.BossKilled:
                ret = ReqTimeScaleResult.Override;
                break;

            case GameTimeScaleContext.GamePause:
                ret = ReqTimeScaleResult.Break;
                break;

            case GameTimeScaleContext.PlayerSkill:
                ret = ReqTimeScaleResult.Refused;
                break;

            case GameTimeScaleContext.BreakArmor:
                ret = ReqTimeScaleResult.Refused;
                break;

            case GameTimeScaleContext.PlayerVisible:
                ret = ReqTimeScaleResult.Refused;
                break;

            default:
                ret = ReqTimeScaleResult.Override;
                break;
            }
            break;

        case GameTimeScaleContext.GamePause:
            switch (context)
            {
            case GameTimeScaleContext.BossKilled:
                ret = ReqTimeScaleResult.Refused;
                break;

            case GameTimeScaleContext.GamePause:
                ret = ReqTimeScaleResult.Override;
                break;

            case GameTimeScaleContext.PlayerSkill:
                ret = ReqTimeScaleResult.Refused;
                break;

            case GameTimeScaleContext.BreakArmor:
                ret = ReqTimeScaleResult.Refused;
                break;

            case GameTimeScaleContext.PlayerVisible:
                ret = ReqTimeScaleResult.Refused;
                break;

            default:
                ret = ReqTimeScaleResult.Override;
                break;
            }
            break;

        case GameTimeScaleContext.PlayerSkill:
            switch (context)
            {
            case GameTimeScaleContext.BossKilled:
                ret = ReqTimeScaleResult.Override;
                break;

            case GameTimeScaleContext.GamePause:
                ret = ReqTimeScaleResult.Break;
                break;

            case GameTimeScaleContext.PlayerSkill:
                ret = ReqTimeScaleResult.Override;
                break;

            case GameTimeScaleContext.BreakArmor:
                ret = ReqTimeScaleResult.Override;
                break;

            case GameTimeScaleContext.PlayerVisible:
                ret = ReqTimeScaleResult.Override;
                break;

            default:
                ret = ReqTimeScaleResult.Override;
                break;
            }
            break;

        case GameTimeScaleContext.BreakArmor:
            switch (context)
            {
            case GameTimeScaleContext.BossKilled:
                ret = ReqTimeScaleResult.Override;
                break;

            case GameTimeScaleContext.GamePause:
                ret = ReqTimeScaleResult.Break;
                break;

            case GameTimeScaleContext.PlayerSkill:
                ret = ReqTimeScaleResult.Refused;
                break;

            case GameTimeScaleContext.BreakArmor:
                ret = ReqTimeScaleResult.Override;
                break;

            case GameTimeScaleContext.PlayerVisible:
                ret = ReqTimeScaleResult.Refused;
                break;

            default:
                ret = ReqTimeScaleResult.Override;
                break;
            }
            break;

        case GameTimeScaleContext.PlayerVisible:
            switch (context)
            {
            case GameTimeScaleContext.BossKilled:
                ret = ReqTimeScaleResult.Override;
                break;

            case GameTimeScaleContext.GamePause:
                ret = ReqTimeScaleResult.Break;
                break;

            case GameTimeScaleContext.PlayerSkill:
                ret = ReqTimeScaleResult.Refused;
                break;

            case GameTimeScaleContext.BreakArmor:
                ret = ReqTimeScaleResult.Refused;
                break;

            case GameTimeScaleContext.PlayerVisible:
                ret = ReqTimeScaleResult.Override;
                break;

            default:
                ret = ReqTimeScaleResult.Override;
                break;
            }
            break;

        default:
            ret = ReqTimeScaleResult.Override;
            break;
        }
        return(ret);
    }