コード例 #1
0
    //饱食度变化协程
    IEnumerator BellyPointChangeCoroutine()
    {
        float currentBellyState;//当前饱食度状态

        // float currentBellyPoint = playerDataUtils.getBellyPoint();

        //第一次启动游戏,将会在一小时后,数值变化。

        while (true)
        {
            // Debug.Log(timePerBellyCoroutinesChange + " 秒后开始更新。。。");

            yield return(new WaitForSeconds(timePerBellyCoroutinesChange));//间隔多长时间,调用一次

            //this.OnBellySub();

            //判断当前睡眠状态,自动睡眠状态下,饱食不会降低.
            //如果为睡眠状态不调用
            //如果为清醒状态则调用

            //睡眠状态
            bool sleepState = playerDataUtils.isAutoSleep();

            if (sleepState)//当前状态为睡眠
            {
                Debug.Log("当前女主为睡眠状态,饱食管理器退出此次循环逻辑,等待下次再进行判断");
                continue; //退出此次循环,进行下一次循环
            }

            #region //数据变化逻辑


            #endregion

            //降低10点饱食度
            //根据返回的饱食度状态进行判断
            currentBellyState = playerDataUtils.ReduceBellyPoint(10f); //降低10点饱食度,返回当前饱食度数值
            //对currentBellyState进行判断
            if (currentBellyState == 0)                                /***为0,降到底,停止此次循环逻辑判断***/
            {
                // Debug.Log("饱食降到0,停止饱食管理器");

                //通知UI更新
                if (OnReduceBellyPointEvent != null)
                {
                    OnReduceBellyPointEvent.Invoke(0);
                }

                //饱食为0,考虑下次循环时饱食依旧为0时,会多调用UI更新.
                //玩家操作,可增加饱食度,
                isMoodEventNoticed = false;//重置
                //停止此次循环
                continue;
            }
            else
            {                              //饱食为0后,再次增加饱食度,后的变换情况---判断??心情协成又调用了一次.
                //可用bool值判断,是否进行.
                if (currentBellyState < 0) //当前的饱食度低于33, 心情开始降低
                {
                    //toDO
                    //通知UI更新
                    //更新饱食度进度条。。。。。subBellyPointPerHour = 5f

                    if (OnReduceBellyPointEvent != null)
                    {
                        OnReduceBellyPointEvent.Invoke(-currentBellyState);
                    }

                    // _UIManager.UpdateBellyPmgressbar(curBellyPoint);

                    //当前饱食度小于33
                    //开始降低心情值
                    //这里是用C#的事件机制来实现
                    //定义委托类型,让心情管理器模块订阅该事件,以便在饱食度低于33时通知心情管理模块

                    //注意:在下一次生命周期内,本通知只执行一次
                    if (OnReduceMoodPointEvent != null) //说明心情管理模块已经订阅该事件,
                    {
                        if (!isMoodEventNoticed)        //心情变化事件未触发
                        {
                            Debug.Log("饱食度低于33,进入饥饿状态,心情开始降低...");
                            // Debug.Log("当前饱食度:" + -currentBellyState);

                            OnReduceMoodPointEvent.Invoke(); //触发通知
                            isMoodEventNoticed = true;       //心情变换事件已经触发,在心情值高于33时,其值为false.需要在心情管理模块判断
                        }
                    }
                    else
                    {
                        //心情管理模块未订阅心情变化事件
                        Debug.Log("心情管理模块未订阅心情变化事件,请查看心情管理模块订阅");
                    }
                }
                else
                {
                    //正常变化

                    //修改心情变换事件状态为未触发.
                    isMoodEventNoticed = false;

                    //UI变化
                    //通知UI更新

                    //更新饱食度进度条。。。。。subBellyPointPerHour = 5f
                    // _UIManager.UpdateBellyPmgressbar(curBellyPoint);

                    //  Debug.Log("当前饱食度:" + currentBellyState);
                    if (OnReduceBellyPointEvent != null)
                    {
                        OnReduceBellyPointEvent.Invoke(currentBellyState);
                    }
                }
            }
        }
    }
コード例 #2
0
ファイル: MoodPointManager.cs プロジェクト: Ruxer/CatGirl2019
    /// <summary>
    /// 心情变换协程
    /// </summary>
    /// <returns></returns>
    IEnumerator MoodPointChangeCoroutine()
    {
        float curentChangedValue;//当前变换的值

        while (true)
        {
            //1.心情:饱食度低于33,心情每小时依次变化:1,2,3,4,5,5,5等,最多到5.
            //注意心情降低为0的情况。登录间隔时间太常,在登录时的逻辑判断后.
            //当前心情值
            currentMoodPoint = playerDataUtils.getMoodPoint();
            //当前心情状态
            //MoodState[0]:变换的值, MoodState[1]:状态值
            curentChangedValue = playerDataUtils.ReduceMoodPoint();
            //心情值
            currentMoodPoint = playerDataUtils.getMoodPoint();

            if (currentMoodPoint <= 0)
            {
                //通知UI更新
                if (OnReduceMoodPointEvent != null)
                {
                    OnReduceMoodPointEvent.Invoke(0);
                }
                //停止协程.直到接到再次启动的通知.

                PlayerDataUtils.tempPoint = 1f;
                StopCoroutine("MoodPointChangeCoroutine");
            }

            if (curentChangedValue != 0)
            {
                // Debug.Log("当前心情值:" + currentMoodState);

                //更新UI
                if (OnReduceMoodPointEvent != null)
                {
                    OnReduceMoodPointEvent.Invoke(curentChangedValue);
                }
            }
            else
            {
                Debug.Log("当前心情值:" + curentChangedValue);//心情值为0
                //更新UI
                if (OnReduceMoodPointEvent != null)
                {
                    OnReduceMoodPointEvent.Invoke(curentChangedValue);
                }

                //停止协程
                Debug.Log("停止协程");
                //重置工具类中的心情值累加器.
                PlayerDataUtils.tempPoint = 1f;
                StopCoroutine("MoodPointChangeCoroutine");
            }



            yield return(new WaitForSeconds(timePerMoodCoroutineChange));


            /*
             *
             * //subMoodPointPerHour = 1f:每小时降低的心情值
             * //maxSubMoodPoint = 5f:最大降低心情值
             * if (reduceMoodPointPerHour <= maxReduceMoodPoint)
             * {
             *
             *
             *  curMoodPoint = playerDataUtils.getMoodPoint(); //当前的心情值
             *
             *  if (curMoodPoint != 0) // 如果变化前的值不为0,
             *  {
             *      Debug.Log("当前心情值:" + curMoodPoint);
             *
             *      playerDataUtils.ReduceMoodPoint(reduceMoodPointPerHour);//降低1点到5点的心情值
             *
             *      curMoodPoint = playerDataUtils.getMoodPoint(); //变化后的心情值
             *
             *     // _UIManager.UpdateMoodPmgressbar(curMoodPoint); //进度条更新
             *  }
             *  else //如果变化前的 心情值已经变为0了
             *  {
             *
             *      Debug.Log("心情值已经降低为0, 停止心情管理器");
             *
             *      StopCoroutine("MoodPointChangeIE");
             *
             *
             *  }
             *
             *  reduceMoodPointPerHour++; //
             *
             *  if (reduceMoodPointPerHour > 5)// 降低的心情值最大为5点
             *  {
             *      reduceMoodPointPerHour = 5;
             *
             *  }
             *
             *
             *
             *
             *
             * }
             *
             *
             *
             *
             *
             *
             * yield return new WaitForSeconds(5f);
             *
             */
        }
    }