private void CheckCurrentPhase(SavedTime time) { if (!Info.Availability.Phases.HasFlag(time.DayPhase)) { LifetimeFactor++; LifespanSpeedUpEvent?.UnsubscribeFromClockEvents(); Debug.Log(name + " is out of its dayphase!\nDecreasing lifetime."); } }
/// <summary> /// Force execute all events at a given time /// </summary> /// <param name="timeToExecuteOn">Time to execute on</param> public void ForceExecuteAllEvents(SavedTime timeToExecuteOn) { OnSecondChange?.Invoke(timeToExecuteOn); OnMinuteChange?.Invoke(timeToExecuteOn); OnDayPhaseChange?.Invoke(timeToExecuteOn); OnHourChange?.Invoke(timeToExecuteOn); OnDayChange?.Invoke(timeToExecuteOn); OnMonthChange?.Invoke(timeToExecuteOn); OnYearChange?.Invoke(timeToExecuteOn); }
/// <summary> /// Create a new clock event /// </summary> /// <param name="activationTime">Time it should activate</param> /// <param name="repetitionType">When will the event try to activate</param> /// <param name="onlyOnce">Will it only activate only once</param> /// <param name="actions">Callbacks</param> public ClockEvent(SavedTime activationTime, EventRepetitionType repetitionType, bool onlyOnce, params Action <SavedTime>[] actions) { TimeOfCreation = MainClock.NowTime; ActivationTime = activationTime; RepetitionType = repetitionType; OnlyOnce = onlyOnce; IsInjected = false; AddNewListeners(actions); }
/// <summary> /// Try to call the event /// </summary> /// <param name="currentTime">time to try to activate</param> public void TryActivation(SavedTime currentTime) { if (currentTime.MatchesWithShallow(ActivationTime)) { if (OnlyOnce) { Unsubscribe(); } OnEventTrigger(currentTime); } }
// Use this for initialization void Start() { long ticks = Timespan.Instance.GetCurrentTicks(); Debug.Log(ticks); SavedTime time = new SavedTime(); time.ticks = ticks; string json = JsonUtility.ToJson(time); Debug.Log(json); SavedTime oldTime = Timespan.Instance.GetCurrentTicksFromJson(json); Debug.Log(oldTime.ticks); }
private void DoTimeEventsUpdate() { SavedTime thisUpdateTime = MainClock.NowTime; if (thisUpdateTime.Seconds != lastUpdateTime.Seconds) { OnSecondChange?.Invoke(thisUpdateTime); if (thisUpdateTime.Minutes != lastUpdateTime.Minutes) { OnMinuteChange?.Invoke(thisUpdateTime); if (thisUpdateTime.Hours24 != lastUpdateTime.Hours24) { if (thisUpdateTime.DayPhase != lastUpdateTime.DayPhase) { OnDayPhaseChange?.Invoke(thisUpdateTime); } OnHourChange?.Invoke(thisUpdateTime); if (thisUpdateTime.Day != lastUpdateTime.Day) { OnDayChange?.Invoke(thisUpdateTime); if (thisUpdateTime.Month != lastUpdateTime.Month) { OnMonthChange?.Invoke(thisUpdateTime); if (thisUpdateTime.Year != lastUpdateTime.Year) { OnYearChange?.Invoke(thisUpdateTime); } } } } } } lastUpdateTime = thisUpdateTime; }
public bool Write(DAIIO io, bool skiplength = false) { try { io.xbaseStream.Write(DataMagic, 0, 8); io.Position = 0x41; io.WriteInt64(SavedTime.ToUnixSecondsWithAdd()); io.WriteInt16((short)SID.Length); io.WriteString(SID); io.WriteUInt16(GameVersion); io.WriteUInt16(SaveVersion); io.WriteUInt16(ProjectVersion); io.WriteUInt16(BitstreamFeatures); io.WriteUInt32(ChangeList); io.WriteUInt16((ushort)Level.Length); io.WriteString(Level); io.WriteUInt32(Difficulty); if (BundleList == null) { BundleList = new string[BundleCount]; for (int xb = 0; xb < BundleCount; xb++) { BundleList[xb] = ""; } } BundleCount = (ushort)BundleList.Length; io.WriteUInt16(BundleCount); for (int i = 0; i < BundleCount; i++) { io.WriteInt16((short)BundleList[i].Length); io.WriteString(BundleList[i]); } if (Inclusions == null) { Inclusions = new Inclusion[InclusionCount]; for (int xb = 0; xb < InclusionCount; xb++) { Inclusions[xb] = new Inclusion(); } } InclusionCount = (ushort)Inclusions.Length; io.WriteInt16((short)InclusionCount); for (int i = 0; i < InclusionCount; i++) { Inclusions[i].Write(io); } if (SubLevelInfoCount <= 0x40 && SubLevelInfoCount > 0) { if (SubLevelEntries == null) { SubLevelEntries = new SubLevelInfo[SubLevelInfoCount]; for (int xb = 0; xb < SubLevelInfoCount; xb++) { SubLevelEntries[xb] = new SubLevelInfo(); } } SubLevelInfoCount = SubLevelEntries.Length; io.WriteBits(SubLevelInfoCount, 0xc); for (int i = 0; i < SubLevelInfoCount; i++) { SubLevelEntries[i].Write(io); } } if (LevelChecksum == null) { LevelChecksum = new byte[0x10]; } for (int i = 0; i < 0x10; i++) { io.WriteBits(LevelChecksum[i], 0x8); } io.WriteBits(DLC, 0x14); io.WriteBits(EntityVersion, 0x10); io.WriteBits(ProjectVersionContext, 0x10); io.WriteBoolean(HasDebugInfo); /////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////CALCULATE SECTION BOOKMARKS///////////////////////////////////////// var pos = io.Position; /////////////////////////////////////////////////////////////////////////// pos += 0x54; //////////////////////////////////////////////////////////////////////////////////// pos += (EntityContentLength + ////////////////////////////////////////////////////////////////// (((SaveEntityComplexLength + 0x38) + SaveEntity.Length) + EntityMetaData.Length)); //// AgentTocBookmark = (int)pos; //////////////////////////////////////////////////////////////// pos += (AgentToc.Length + 0x18); //////////////////////////////////////////////////////////// ClientDataBookmark = (int)pos; //////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// io.WriteBits(AgentTocBookmark, 0x1A); io.WriteBits(ClientDataBookmark, 0x1A); io.WriteBits(EntityContentLength, 0x20); /////////////////////////////////////////////////////////////////////////////// ////////////////////////WRITE UNFINISHED SECTION////////////////////////////// EntityContent.Write(io); ///////////////////////////////////////////////////// //MUST WRITE UNFINISHED RAW DATA, REMOVE IF CONTENT HAS BEEN MAPPED OUT///// if (tmpdata.Length > 0) //////////////////////////////////////////////////// { io.WriteData(tmpdata, (EntityContentLength - EntityContent.Length)); //// } ///////////////////////////////////////////////////////////////////////// //Start writing SaveEntity SaveEntityBookmark = (int)io.Position; io.WriteBits(SaveEntityComplexLength, 6); io.WriteData(SaveEntityComplex, SaveEntityComplexLength); io.WriteBits(SaveEntityBookmark, 0x1A); SaveEntity.Write(io); EntityMetaData.Write(io); AgentToc.Write(io); ClientData.Write(io); // io.FinishWriter(); if (LastPartSeedLength > 0) { io.WriteBits((uint)LastPartSeed, (uint)LastPartSeedLength, true); } io.Flush(); return(true); } catch (Exception) { return(false); } }
private void Awake() { lastUpdateTime = MainClock.NowTime; UpdateAction = DoTimeEventsUpdate; }
/// <summary> /// Force use the event with the given time /// </summary> public void ForceUse(SavedTime time) { OnTriggered?.Invoke(time); }
/// <summary> /// When the event is triggered /// </summary> /// <param name="timeOfTrigger">Time of the trigger</param> protected void OnEventTrigger(SavedTime timeOfTrigger) { OnTriggered?.Invoke(timeOfTrigger); }