public static void StartSleep(PESleep peSleep, PeEntity character, float hours = 12) { if (null != character) { SleepController sc = character.GetComponent <SleepController>(); if (sc == null) { sc = character.gameObject.AddComponent <SleepController>(); sc.isMainPlayer = Pathea.PeCreature.Instance.mainPlayer == character; if (sc.isMainPlayer) { MotionMgrCmpt mmc = character.GetCmpt <MotionMgrCmpt>(); Action_Sleep actionSleep = mmc.GetAction <Action_Sleep>(); actionSleep.startSleepEvt += sc.MainPlayerStartSleep; actionSleep.startSleepEvt += (i) => FastTravelMgr.Instance.Add(sc); actionSleep.endSleepEvt += sc.MainPlayerEndSleep; actionSleep.endSleepEvt += (i) => FastTravelMgr.Instance.Remove(sc); } } sc.character = character.GetComponent <OperateCmpt>(); sc.maxSleepTime = hours * 3600f; sc.timeCount = 0; sc.peSleep = peSleep; sc.enabled = true; sc.actionTime = 2f; peSleep.StartOperate(sc.character, EOperationMask.Sleep); // peSleep.Do(sc.character); } }
// 关闭事件监听 public override void Close() { PeEntity mainPlayer = PeCreature.Instance.mainPlayer; if (mainPlayer != null) { Action_Sleep sleep = mainPlayer.motionMgr.GetAction <Action_Sleep>(); if (sleep != null) { sleep.startSleepEvt -= OnResponse; } } else { Debug.LogError("main player is null"); } }