Example #1
0
        protected virtual GlobalClock FindParent()
        {
            GlobalClock oldParent = _parent as GlobalClock;

            if (oldParent != null)
            {
                oldParent.Unregister(this);
            }

            if (string.IsNullOrEmpty(parentKey))
            {
                return(null);
            }

            if (!Timekeeper.instance.HasClock(parentKey))
            {
                throw new ChronosException(string.Format("Missing parent clock: '{0}'.", parentKey));
            }

            GlobalClock parent = Timekeeper.instance.Clock(parentKey);

            parent.Register(this);

            return(parent);
        }
Example #2
0
        /// <summary>
        /// Adds a global clock with the specified key and returns it.
        /// </summary>
        public virtual GlobalClock AddClock(string key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            if (HasClock(key))
            {
                throw new ChronosException(string.Format("Global clock '{0}' already exists.", key));
            }

            GlobalClock clock = gameObject.AddComponent <GlobalClock>();

            clock.key = key;
            return(clock);
        }
Example #3
0
        protected virtual Clock FindClock()
        {
            if (mode == TimelineMode.Local)
            {
                LocalClock localClock = GetComponent <LocalClock>();

                if (localClock == null)
                {
                    throw new ChronosException(string.Format("Missing local clock."));
                }

                return(localClock);
            }
            else if (mode == TimelineMode.Global)
            {
                GlobalClock oldGlobalClock = _clock as GlobalClock;

                if (oldGlobalClock != null)
                {
                    oldGlobalClock.Unregister(this);
                }

                if (!Timekeeper.instance.HasClock(globalClockKey))
                {
                    throw new ChronosException(string.Format("Missing global clock: '{0}'.", globalClockKey));
                }

                GlobalClock globalClock = Timekeeper.instance.Clock(globalClockKey);

                globalClock.Register(this);

                return(globalClock);
            }
            else
            {
                throw new ChronosException(string.Format("Unknown timeline mode: '{0}'.", mode));
            }
        }