Exemplo n.º 1
0
        /// <summary>
        /// Creates a TimeContainer and adds it to the active timers list
        /// </summary>
        /// <param name="_Trigger">Event to trigger</param>
        /// <param name="_Delay">Time until trigger</param>
        /// <param name="_Loop">Loops the timer</param>
        /// <param name="_Linked">Linked Object</param>
        /// <param name="_Tick">Event call on each tick</param>
        /// <param name="_TickTime">Time between ticks</param>
        /// <param name="_Start">Event on timer start</param>
        /// <param name="_delayedStart">Time to wait before starting timer</param>
        /// <returns></returns>
        public static TimeContainer AddDelegate(onFinishedReturn _Trigger = null, float _Delay = 1, bool _Loop = false, object _Linked = null, Tick _Tick = null, float _TickTime = 0, Start _Start = null, float _delayedStart = 0)
        {
            TimeContainer TimeDelegate = new TimeContainer(_Start, _Tick, _Trigger, _Linked, _Delay, _Loop, _TickTime, _delayedStart);

            Instance.ActiveTimecontainersList.Add(TimeDelegate);

            if (_delayedStart > 0)
            {
                TimeDelegate.isPaused = true;
                AddDelegate((object o) =>
                {
                    if (_Start != null)
                    {
                        _Start();
                    }
                    TimeDelegate.isPaused = false;
                }, _delayedStart);
            }
            else if (_Start != null)
            {
                _Start();
            }

            return(TimeDelegate);
        }
Exemplo n.º 2
0
 public void CheckEndGame(TimeContainer currentTime)
 {
     if (currentTime.Value.days >= EndDay)
     {
         LoadNextScene();
     }
 }
Exemplo n.º 3
0
    void Start()
    {
        text = GetComponent <Text>();
        TimeContainer time = DataContainer.Instance.timeContainer;

        text.text = "Time: " + time.Minutes + ":" + time.Seconds.ToString().PadLeft(2, '0');
    }
Exemplo n.º 4
0
 public void CheckEvents(TimeContainer time)
 {
     foreach (TimeEvent timeEvent in timeEvents)
     {
         CheckEvent(timeEvent);
     }
 }
Exemplo n.º 5
0
    /// <typeparam name="TOwner">보간을 값을 가지고 있는 대상</typeparam>
    /// <typeparam name="TValue">보간할 값의 타입</typeparam>
    /// <returns></returns>
    public static IEnumerator TweenRoutine <TOwner, TValue>(
        TOwner target,
        Func <TValue> end,
        Func <TOwner, TValue> startGetter,
        Action <TOwner, TValue> setter,
        Func <TValue, TValue, float, TValue> lerpFunc,
        TimeContainer tc,
        AnimationCurve curve = null)
    {
        if (curve == null)
        {
            curve = AnimationCurve.Linear(0, 0, 1, 1);
        }
        TValue start = default(TValue);

        if (startGetter != null)
        {
            start = startGetter(target);
        }
        while (tc.t < 1f)
        {
            tc.t += Time.deltaTime / tc.time;
            if (setter != null && lerpFunc != null)
            {
                setter(target, lerpFunc(start, end(), curve.Evaluate(tc.t)));
            }
            yield return(null);
        }
        if (setter != null)
        {
            setter(target, end());
        }
    }
Exemplo n.º 6
0
 public void SetTime(TimeContainer time)
 {
     totalTime =
         time.Value.days +
         (time.Value.hours / hoursPerDay) +
         (time.Value.minutes / hoursPerDay / minutesPerHours);
     CurrentTime.Value.dayName = time.Value.dayName;
 }
Exemplo n.º 7
0
    private void StartTimer(TimeContainer timeContainer)
    {
        TimerUpdate(timeContainer);
        var countdownTimer = new CountdownTimer(timeContainer);

        countdownTimer.OnTimeChange += TimerUpdate;
        countdownTimer.OnFinish     += () => SetActivePopUpButton(true);
    }
Exemplo n.º 8
0
 public void RemoveListener(TimeContainer del)
 {
     if (ActiveTimecontainersList.Contains(del))
     {
         ActiveTimecontainersList.Remove(del);
         del.LinkedObject = null;
     }
 }
Exemplo n.º 9
0
    private void TimerUpdate(TimeContainer leftTime)
    {
        var text = $"{leftTime.Minutes:00}:{leftTime.Seconds:00}";

        _text.text = text;

        _leftTime.Minutes = leftTime.Minutes;
        _leftTime.Seconds = leftTime.Seconds;
    }
Exemplo n.º 10
0
    public void RestoreObject(TimeContainer timeContainer)
    {
        float _restoreAmount = Time.deltaTime * drainRestoreSpeed;

        timeContainer.Restore(ref _restoreAmount);
        if (_restoreAmount > 0)
        {
            _doingRestorePower = true;
            _currentTime      -= _restoreAmount;
        }
    }
Exemplo n.º 11
0
    public void DrainObject(TimeContainer timeContainer)
    {
        float _drainAmount = Time.deltaTime * drainRestoreSpeed;

        timeContainer.Drain(ref _drainAmount);
        if (_drainAmount > 0)
        {
            _doingDrainPower = true;
            _currentTime    += _drainAmount;
        }
    }
Exemplo n.º 12
0
    public void SkipTime(TimeContainer time)
    {
        for (int i = CurrentTime.Value.days; i < CurrentTime.Value.days + time.Value.days - 1; i++)
        {
            CurrentTime.Value.dayName = NextDayName(CurrentTime.Value.dayName);
            OnRoutine.Invoke();
        }

        totalTime +=
            time.Value.days +
            (time.Value.hours / hoursPerDay) +
            (time.Value.minutes / hoursPerDay / minutesPerHours);
    }
Exemplo n.º 13
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        GUI.enabled = Application.isPlaying;

        TimeContainer m_Target = target as TimeContainer;

        if (GUILayout.Button("Update Changes"))
        {
            m_Target.OnValueChanged.Invoke(m_Target);
        }
    }
Exemplo n.º 14
0
    public static Coroutine AlphaTween(this Graphic runner, float start, float end, TimeContainer time, bool containChild = false, AnimationCurve curve = null)
    {
        if (containChild)
        {
            var child = runner.transform.GetComponentsInChildren <Graphic>();
            foreach (var c in child)
            {
                c.AlphaTween(start, end, time, false, curve);
            }
        }

        return(runner.StartCoroutine(TweenRoutine(runner, () => end, sp => start, UGUIUtil.SetAlpha, Mathf.Lerp, time, curve)));
    }
Exemplo n.º 15
0
        internal void Update()
        {
            TimeContainer timeContainer = new TimeContainer()
            {
                DeltaTime  = (float)PipelineTime.DeltaTime,
                TimePassed = (float)PipelineTime.TimePassed
            };

            m_timeBuffer.UpdateData(timeContainer);
            m_timeBuffer.UpdateBuffer();

            m_internalGraphics.Update();
        }
Exemplo n.º 16
0
    private void Load()
    {
        var json = PlayerPrefs.GetString(Freereward);

        if (json == String.Empty)
        {
            _isRewarded = false;
            _leftTime   = _waitTimeToOpenChest;
            return;
        }

        var data = Data.FromJson(json);

        _isRewarded = data.IsRewarded;
        _leftTime   = data.TimeContainer;
    }
Exemplo n.º 17
0
    public static void Update()
    {
        for (int i = 0; i < s_timeContainer.Count; i++)
        {
            TimeContainer timeContainer = s_timeContainer[i];
            if (0 == timeContainer.repeat || null == timeContainer.callback)
            {
                s_timeContainer.RemoveAt(i);
                continue;
            }

            if (timeContainer.currentTime <= Time.time)
            {
                timeContainer.currentTime += timeContainer.interval;
                timeContainer.repeat       = (timeContainer.repeat <= -1) ? -1 : --timeContainer.repeat;
                timeContainer.callback(timeContainer.timerID, timeContainer.args);
            }
        }
    }
Exemplo n.º 18
0
    static int Init(float delay, float interval, int repeat, Action <int, object[]> callback, params object[] args)
    {
        if (delay < 0 || interval < 0)
        {
            Debug.Log("Timer.Init ---> 参数有错,delay:" + delay + " interval: " + interval);
        }

        TimeContainer container = new TimeContainer();

        container.timerID     = ++s_timerID;
        container.interval    = interval;
        container.repeat      = repeat;
        container.currentTime = Time.time + interval + delay;
        container.callback    = callback;
        container.args        = args;
        s_timeContainer.Add(container);

        return(container.timerID);
    }
Exemplo n.º 19
0
        //called on update since update is called before OnEnabled
        public void Setup(Context context)
        {
            TimeContainer midnight     = new TimeContainer("Midnight", Resource.Drawable.AsianNight);
            TimeContainer beforeDawn   = new TimeContainer("Before Dawn", Resource.Drawable.BeforeDawn);
            TimeContainer earlyMorning = new TimeContainer("Early Morning", Resource.Drawable.CoolMorning);
            TimeContainer morning      = new TimeContainer("Morning", Resource.Drawable.MorningTown);
            TimeContainer midday       = new TimeContainer("Midday", Resource.Drawable.Afternoon);
            TimeContainer afternoon    = new TimeContainer("Afternoon", Resource.Drawable.SunriseCity);
            TimeContainer evening      = new TimeContainer("Evening", Resource.Drawable.Evening);
            TimeContainer night        = new TimeContainer("Night", Resource.Drawable.CyberpunkNight);

            timeContainers.Add(midnight);
            timeContainers.Add(beforeDawn);
            timeContainers.Add(earlyMorning);
            timeContainers.Add(morning);
            timeContainers.Add(midday);
            timeContainers.Add(afternoon);
            timeContainers.Add(evening);
            timeContainers.Add(night);
        }
Exemplo n.º 20
0
    private void SetTime()
    {
        var timeRemaining = (float)_time.Minutes * 60 + _time.Seconds;

        UpdateTimer();

        if (timeRemaining < 0)
        {
            var timeContainer = new TimeContainer();

            OnTimeChange?.Invoke(timeContainer);
            OnFinish?.Invoke();
        }

        DOVirtual.DelayedCall(1, UpdateTimer).SetLoops((int)timeRemaining + 1);

        void UpdateTimer()
        {
            // var fromMinutes = TimeSpan.FromMinutes(timeRemaining);

            int minutes = Mathf.FloorToInt(timeRemaining / 60);
            int seconds = Mathf.FloorToInt(timeRemaining % 60);

            var timeContainer = new TimeContainer
            {
                Minutes = minutes,
                Seconds = seconds
            };

            OnTimeChange?.Invoke(timeContainer);


            if (timeRemaining <= 0)
            {
                OnFinish?.Invoke();
            }

            timeRemaining -= 1;
        }
    }
Exemplo n.º 21
0
    /// <summary>
    /// 外部调用的Update,检查哪些容器符合条件.
    /// 不符合条件的删除。
    /// </summary>
    public static void Update()
    {
        //遍历所有的容器
        for (int i = 0; i < s_timeContainer.Count; i++)
        {
            TimeContainer timeContainer = s_timeContainer[i];

            //如果重复的次数为0,或者回调函数为空。那么清除此容器。
            if (0 == timeContainer.repeat || null == timeContainer.callback)
            {
                s_timeContainer.RemoveAt(i);
                continue;
            }

            //叠加的时间符合条件,执行回调函数。并让repeat减1.
            if (timeContainer.currentTime <= Time.time)
            {
                timeContainer.currentTime += timeContainer.interval;
                timeContainer.repeat       = (timeContainer.repeat <= -1) ? -1 : --timeContainer.repeat;
                timeContainer.callback(timeContainer.timerID, timeContainer.args);
            }
        }
    }
Exemplo n.º 22
0
 public static Coroutine FillTween(this Image runner, float end, TimeContainer time, AnimationCurve curve = null)
 {
     return(runner.StartCoroutine(TweenRoutine(runner, () => end, r => r.fillAmount, (p, i) => p.fillAmount = i, Mathf.Lerp, time, curve)));
 }
Exemplo n.º 23
0
 public static Coroutine MoveLocal(this MonoBehaviour runner, Vector3 start, Vector3 end, TimeContainer time, AnimationCurve curve = null)
 {
     return(runner.StartCoroutine(TweenRoutine(runner.transform, () => end, t => start, (t, e) => t.localPosition = e, Vector3.Lerp, time, curve)));
 }
Exemplo n.º 24
0
 public static Coroutine ChangeUISize(this MonoBehaviour runner, Vector2 end, TimeContainer time, AnimationCurve curve = null)
 {
     return(runner.StartCoroutine(TweenRoutine(runner.GetComponent <RectTransform>(), () => end, t => t.sizeDelta, (t, e) => t.sizeDelta = e, Vector2.Lerp, time, curve)));
 }
Exemplo n.º 25
0
 public static Coroutine MoveUI(this MonoBehaviour runner, Vector2 start, Vector2 end, TimeContainer time, AnimationCurve curve = null)
 {
     return(runner.StartCoroutine(TweenRoutine(runner.GetComponent <RectTransform>(), () => end, t => start, (t, e) => t.anchoredPosition = e, Vector2.Lerp, time, curve)));
 }
Exemplo n.º 26
0
 public static Coroutine Stay(this MonoBehaviour runner, Transform end, TimeContainer time)
 {
     return(runner.StartCoroutine(TweenRoutine(runner.transform, () => end.position, t => t.position, (t, e) => t.position = e, (a, b, t) => b, time)));
 }
Exemplo n.º 27
0
 public static Coroutine Scale(this MonoBehaviour runner, Vector3 end, TimeContainer time, AnimationCurve curve = null)
 {
     return(runner.StartCoroutine(TweenRoutine(runner.transform, () => end, t => t.localScale, (t, e) => t.localScale = e, Vector3.LerpUnclamped, time, curve)));
 }
Exemplo n.º 28
0
 public static Coroutine NumberTween(this TextMeshProUGUI runner, long end, TimeContainer time, AnimationCurve curve = null)
 {
     return(runner.StartCoroutine(TweenRoutine(runner, () => end, LongParse, (p, i) => p.text = i.ToString("N0"), LerpUtil.LongLerp, time, curve)));
 }
Exemplo n.º 29
0
 public static Coroutine ProgressTween(this UIProgressBar runner, float start, float end, TimeContainer time, AnimationCurve curve = null)
 {
     return(runner.StartCoroutine(TweenRoutine(runner, () => end, r => start, (p, i) => p.value = i, Mathf.Lerp, time, curve)));
 }
Exemplo n.º 30
0
 public static Coroutine ColorTween(this Graphic runner, Color end, TimeContainer time, bool containChild = false, AnimationCurve curve = null)
 {
     return(runner.StartCoroutine(TweenRoutine(runner, () => end, sp => sp.color, (o, c) => o.color = c, Color.Lerp, time, curve)));
 }