public virtual void Print(Stack<Printer> printers, List<KeyValuePair<string, int>>.Enumerator occurenceStepper)
        {
            occurenceStepper.MoveNext();
            Console.WriteLine(occurenceStepper.Current.Key + " => " + occurenceStepper.Current.Value);

            printers.Pop().Print(printers, occurenceStepper);
        }
Example #2
0
    // Use this for initialization
    public override void Awake()
    {
        base.Awake();
        TimeScaleList.Add(Game.GameTimeScale);

        NextTimeScale = TimeScaleList.GetEnumerator();
        NextTimeScale.MoveNext();
    }
Example #3
0
 public AnimatedTexture Add(Texture tex, double time)
 {
     Textures.Add(new Tuple<Texture, double>(tex, time));
     CurrentTexture = Textures.GetEnumerator();
     CurrentTexture.MoveNext();
     TotalTime += time;
     return this;
 }
Example #4
0
        //------------------------------------------------------------------
        public override void Reset()
        {
            AddNewActions ();

            enumerator = Actions.GetEnumerator ();
            enumerator.MoveNext ();

            Actions.ForEach (action => action.Reset());
        }
Example #5
0
 public override void OnEventFunc(EventData data)
 {
     Game.GameTimeScale = NextTimeScale.Current;
     if (!NextTimeScale.MoveNext())
     {
         NextTimeScale = TimeScaleList.GetEnumerator();
         NextTimeScale.MoveNext();
     }
 }
Example #6
0
 // Use this for initialization
 public override void Awake()
 {
     base.Awake();
     Renderer = GetComponent<SpriteRenderer>();
     SpriteList.Add(Renderer.sprite);
     NextSprite = SpriteList.GetEnumerator();
     NextSprite.MoveNext();
     this.DelayedDispatch = true;
 }
 static ScriptCompilers()
 {
   using (List<System.Type>.Enumerator enumerator = new List<System.Type>() { typeof (CSharpLanguage), typeof (BooLanguage), typeof (UnityScriptLanguage) }.GetEnumerator())
   {
     while (enumerator.MoveNext())
     {
       System.Type current = enumerator.Current;
       ScriptCompilers._supportedLanguages.Add((SupportedLanguage) Activator.CreateInstance(current));
     }
   }
 }
Example #8
0
        public StatusBarPage()
        {
            InitializeComponent();

            UpdateControlsForCurrentPane();

            _imagesCollection.AddRange(
                new Image[]
                    {
                        Resources.RecordMacro,
                        Resources.reject_small,
                        Resources.research_small,
                        Resources.resetpicture_small,
                        Resources.reviewingpane_small,
                        Resources.reviewingpanevertical_small,
                        Resources.rotateleft_small,
                        Resources.setlanguage_small,
                        Resources.themes_small,
                        Resources.tight_small,
                        Resources.translationscreentip_small,
                        Resources.wordoptions_small
                    }
                );

            _imagesEnumerator = _imagesCollection.GetEnumerator();
            _imagesEnumerator.MoveNext();

            _highlightTimer = new Timer();
            _highlightTimer.Interval = 300;
            _highlightTimer.Tick += HighlightTimer_Tick;

            _progressBarTimer = new Timer();
            _progressBarTimer.Interval = 40;
            _progressBarTimer.Tick += ProgressBarTimer_Tick;
            _progressBarTimer.Start();

            CurrentPaneComboBox.SelectedIndexChanged += CurrentPaneComboBox_SelectedIndexChanged;

            AddButtonSplitButton.Command = AddButtonCommand;
            AddButtonButton.Command = AddButtonCommand;
            AddButtonWithTextButton.Command = AddButtonWithTextCommand;
            AddToggleButtonSplitButton.Command = AddToggleButtonCommand;
            AddToggleButtonButton.Command = AddToggleButtonCommand;
            AddToggleButtonWithTextButton.Command = AddToggleButtonWithTextCommand;
            AddSliderButton.Command = AddSliderCommand;

            AddButtonCommand.Executed += AddButtonCommand_Executed;
            AddButtonWithTextCommand.Executed += AddButtonWithTextCommand_Executed;
            AddToggleButtonCommand.Executed += AddToggleButtonCommand_Executed;
            AddToggleButtonWithTextCommand.Executed += AddToggleButtonWithTextCommand_Executed;
            AddSliderCommand.Executed += AddSliderCommand_Executed;
        }
        public void LoggableEntity_CreatesPropertiesForModifiedEntity()
        {
            String title = model.Title;
            entry.State = EntityState.Modified;
            entry.CurrentValues["Title"] = "Role";
            entry.OriginalValues["Title"] = "Role";

            IEnumerator<LoggableProperty> expected = new List<LoggableProperty> { new LoggableProperty(entry.Property("Title"), title) }.GetEnumerator();
            IEnumerator<LoggableProperty> actual = new LoggableEntity(entry).Properties.GetEnumerator();

            while (expected.MoveNext() | actual.MoveNext())
            {
                Assert.Equal(expected.Current.IsModified, actual.Current.IsModified);
                Assert.Equal(expected.Current.ToString(), actual.Current.ToString());
            }
        }
    //VRPNAnalogRecording Constructor
    public VRPNAnalogRecording(string nName, float nTime, VRPNAnalog.AnalogReports nData)
    {
        name = nName;
        reportTime = nTime;
        data = nData;
        e = data.list.GetEnumerator();

        while (e.MoveNext())
        {
            VRPNAnalog.AnalogReportNew report = e.Current;
            channels = report.num_channel;
            lastTime = report.msg_time.tv_sec + (report.msg_time.tv_usec / 1000000f);
        }

        e = data.list.GetEnumerator();
    }
Example #11
0
    public override void OnEventFunc(EventData data)
    {
        Renderer.sprite = NextSprite.Current;
        if(!NextSprite.MoveNext())
        {
            NextSprite = SpriteList.GetEnumerator();
            NextSprite.MoveNext();
        }

        if(DispatchOnFinish)
        {
            Dispatch = true;
        }
        else
        {
            DispatchEvent();
        }
    }
        private void textBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Tab)
            {
                TextBox textBox = (TextBox)sender;
                string text = textBox.Text;
                int caretIndex = textBox.CaretIndex;

                if (_enumerator.Current == null)
                {
                    string possibleNick = Utilities.TextUtil.GetWordFromBack(text, caretIndex);

                    _before = text.Substring(0, textBox.CaretIndex - possibleNick.Length);
                    _after = text.Substring(textBox.CaretIndex, text.Length - textBox.CaretIndex);

                    _possibleNicks = GetPossibleNicks(possibleNick);

                    _enumerator = _possibleNicks.GetEnumerator();
                }

                if (!_enumerator.MoveNext())
                {
                    _enumerator = _possibleNicks.GetEnumerator();
                    _enumerator.MoveNext();
                }

                if (_enumerator.Current != null)
                {
                    string delimiter = (_before == String.Empty) ? ": " : " ";

                    textBox.Text = string.Format("{0}{1}{2}{3}", _before, _enumerator.Current, delimiter, _after);
                    textBox.CaretIndex = _before.Length + _enumerator.Current.Length + delimiter.Length;
                }

                e.Handled = true;
            }
            else
            {
                _enumerator = new List<string>.Enumerator();
            }
        }
        public void LoggableEntity_CreatesPropertiesForAttachedEntity()
        {
            context.Dispose();
            String title = model.Title;
            context = new TestingContext();
            context.Set<Role>().Attach(model);

            entry = context.Entry<BaseModel>(model);
            entry.OriginalValues["Title"] = "Role";
            entry.CurrentValues["Title"] = "Role";
            entry.State = EntityState.Modified;

            IEnumerator<LoggableProperty> expected = new List<LoggableProperty> { new LoggableProperty(entry.Property("Title"), title) }.GetEnumerator();
            IEnumerator<LoggableProperty> actual = new LoggableEntity(entry).Properties.GetEnumerator();

            while (expected.MoveNext() | actual.MoveNext())
            {
                Assert.Equal(expected.Current.IsModified, actual.Current.IsModified);
                Assert.Equal(expected.Current.ToString(), actual.Current.ToString());
            }
        }
        protected static Token? SkipToNext(ref List<Token>.Enumerator enumerator)
        {
            Token? token;

            do {
                if (!enumerator.MoveNext())
                    return null;

                token = enumerator.Current;

                switch (token.Value.Type) {
                        // regardless where we are, skip over whitespace, etc.
                    case TokenType.WhiteSpace:
                    case TokenType.LineComment:
                    case TokenType.MultilineComment:
                        continue;
                }
                break;
            } while (true);
            return token;
        }
    //VRPNTrackerRecording Constructor
    public VRPNTrackerRecording(string nName, float nTime, VRPNTracker.TrackerReports nData)
    {
        name = nName;
        reportTime = nTime;
        data = nData;

        e = data.list.GetEnumerator();

        while (e.MoveNext())
        {
            VRPNTracker.TrackerReportNew report = e.Current;
            int test;
            if (!sensors.TryGetValue(report.sensor, out test))
            {
                sensors.Add(report.sensor, report.sensor);
            }
            lastTime = report.msg_time.tv_sec + (report.msg_time.tv_usec / 1000000f);
        }

        e = data.list.GetEnumerator();
    }
        protected override void LocalParse(ref List<Match>.Enumerator tokens, string sNum)
        {
            if (!tokens.MoveNext())
                return;

            string name, value;
            if (!string.IsNullOrEmpty(tokens.Current.Groups["lparen"].Value))
            {
                tokens.MoveNext();

                while (tokens.Current != null &&
                       string.IsNullOrEmpty(tokens.Current.Groups["rparen"].Value))
                {
                    if (
                        string.IsNullOrEmpty(
                            name = tokens.Current.Groups["name"].Value.Split(new[] { ':' })[0]))
                    {
                        tokens.MoveNext();
                        continue;
                    }

                    if (!tokens.MoveNext())
                        continue;

                    if (string.IsNullOrEmpty(value = tokens.Current.Groups["word"].Value) &&
                        string.IsNullOrEmpty(sNum = tokens.Current.Groups["float"].Value))
                    {
                        tokens.MoveNext();
                        continue;
                    }

                    _dimensions[name] = new Dimension { Name = name, Value = string.IsNullOrEmpty(sNum) ? value : sNum };
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(tokens.Current.Groups["lparen"].Value))
                    tokens.MoveNext();

                if (
                    string.IsNullOrEmpty(
                        name = tokens.Current.Groups["name"].Value.Split(new[] { ':' })[0]))
                {
                    tokens.MoveNext();
                    return;
                }

                if (!tokens.MoveNext())
                    return;

                if (string.IsNullOrEmpty(value = tokens.Current.Groups["word"].Value))
                {
                    tokens.MoveNext();
                    return;
                }

                _dimensions[name] = new Dimension { Name = name, Value = string.IsNullOrEmpty(sNum) ? value : sNum };
            }
        }
Example #17
0
 public AnimatedTexture Reset()
 {
     Timer = 0;
     CurrentTime = 0;
     CurrentTexture = Textures.GetEnumerator();
     CurrentTexture.MoveNext();
     return this;
 }
Example #18
0
 public AnimatedTexture(Texture tex)
 {
     Textures.Add(new Tuple<Texture, double>(tex, 0));
     CurrentTexture = Textures.GetEnumerator();
     CurrentTexture.MoveNext();
 }
Example #19
0
 void Turn()
 {
     direction = currentRotation.Current;
     if (!currentRotation.MoveNext())
     {
         currentRotation = currentPOI.Current.directionPattern.GetEnumerator();
         currentRotation.MoveNext();
     }
     turnTimer = 0f;
 }
Example #20
0
        /// <summary>
        /// 確認excel表格內定義的Type是否和給予的基本資料結構有對應
        /// </summary>
        /// <param name="checkType">給予的type定義</param>
        /// <param name="checkObject">對應的物件</param>
        /// <param name="tableTypeEnumerator">table內文</param>
        /// <returns>是否有對應</returns>
        bool CheckBaseTypeCorrect(Type checkType, object checkObject, ref List<string>.Enumerator tableTypeEnumerator)
        {
            if (!tableTypeEnumerator.MoveNext()) { return false; } // 沒有下一個,表示沒有對應
            // 由於可能有nullable型態,取得對應的非nullable型態再比較
            bool isNullabelType = checkType.IsGenericType && checkType.GetGenericTypeDefinition() == typeof(Nullable<>);
            Type realType = (isNullabelType) ? Nullable.GetUnderlyingType(checkType) : checkType;

            string compareStr;
            if (_baseTypeString.TryGetValue(realType, out compareStr)) // 是基本四型態之一
            {
                if (tableTypeEnumerator.Current.ToUpper().Equals(compareStr.ToUpper()))
                {
                    return true;
                }
                else  // 沒對應到正確的基本型態
                {
                    CommonFunction.DebugMsgFormat("base error : Type = {1} excelType = {2}", _debugMessage, realType, tableTypeEnumerator.Current);
                    _debugMessage = string.Format("{0} base error : Type = {1} excelType = {2}", _debugMessage, realType, tableTypeEnumerator.Current);
                    return false;
                }
            }
            else  // 不是基本四型態之一的話直接跳沒對應
            {
                CommonFunction.DebugMsgFormat("not base error : Type = {1}", _debugMessage, realType);
                _debugMessage = string.Format("{0} not base error : Type = {1}", _debugMessage, realType);
                return false;
            }
        }
Example #21
0
        public IEnumerable<DictionaryEntry> GetAutoCompleteSuggestions(string root)
        {
            Log.DebugFormat("GetAutoCompleteSuggestions called with root '{0}'", root);

            if (entriesForAutoComplete != null)
            {
                var simplifiedRoot = root.CreateAutoCompleteDictionaryEntryHash();

                if (!string.IsNullOrWhiteSpace(simplifiedRoot))
                {
                    var enumerator =
                        new List<DictionaryEntry> { new DictionaryEntry { Entry = root } } //Include the typed root as first result
                        .Union(entriesForAutoComplete
                                .Where(kvp => kvp.Key.StartsWith(simplifiedRoot))
                                .SelectMany(kvp => kvp.Value)
                                .Where(de => de.Entry.Length > root.Length)
                                .Distinct() //Phrases are stored in entriesForAutoComplete with multiple hashes (one the full version of the phrase and one the first letter of each word so you can look them up by either)
                                .OrderByDescending(de => de.UsageCount)
                                .ThenBy(de => de.Entry.Length))
                        .GetEnumerator();

                    while (enumerator.MoveNext())
                    {
                        yield return enumerator.Current;
                    }
                }

                yield break; //Not strictly necessary
            }
        }
		public void GetEnumeratorWorks() {
			var e = new List<string> { "x", "y" }.GetEnumerator();
			Assert.IsTrue(e.MoveNext());
			Assert.AreEqual(e.Current, "x");
			Assert.IsTrue(e.MoveNext());
			Assert.AreEqual(e.Current, "y");
			Assert.IsFalse(e.MoveNext());
		}
        private void RefreshNodeListAndTokenMap()
        {
            _logger.Info("Refreshing NodeList and TokenMap..");
            // Make sure we're up to date on nodes and tokens
            var tokenMap = new Dictionary<IPAddress, DictSet<string>>();
            string partitioner = null;

            var foundHosts = new List<IPAddress>();
            var dcs = new List<string>();
            var racks = new List<string>();
            var allTokens = new List<DictSet<string>>();
            IPAddress queriedHost;

            using (var rowset = _session.Query(SelectPeers, ConsistencyLevel.Quorum))
            {
                queriedHost = rowset.Info.QueriedHost;
                foreach (var row in rowset.GetRows())
                {
                    IPAddress hstip = null;
                    if(!row.IsNull("rpc_address"))
                         hstip = row.GetValue<IPEndPoint>("rpc_address").Address;
                    if (hstip == null)
                    {
                        if (!row.IsNull("peer"))
                            hstip = row.GetValue<IPEndPoint>("peer").Address;
                        _logger.Error("No rpc_address found for host in peers system table. ");
                    }
                    else if (hstip.Equals(bindAllAddress))
                    {
                        if (!row.IsNull("peer"))
                            hstip = row.GetValue<IPEndPoint>("peer").Address;
                    }

                    if (hstip != null)
                    {
                        foundHosts.Add(hstip);
                        dcs.Add(row.GetValue<string>("data_center"));
                        racks.Add(row.GetValue<string>("rack"));
                        var col = row.GetValue<IEnumerable<string>>("tokens");
                        if (col == null)
                            allTokens.Add(new DictSet<string>());
                        else
                            allTokens.Add(new DictSet<string>(col));
                    }
                }
            }

            var localhost = _cluster.Metadata.GetHost(queriedHost);
            var iterLiof = new List<Host>() { localhost }.GetEnumerator();
            iterLiof.MoveNext();
            List<IPAddress> tr = new List<IPAddress>();
            Dictionary<IPAddress, List<Exception>> exx = new Dictionary<IPAddress, List<Exception>>();
            var cn = _session.Connect(null, iterLiof, tr, exx);

            using (var outp = cn.Query(SelectLocal, ConsistencyLevel.Default,false))
            {
                if (outp is OutputRows)
                {
                    var rowset = new RowSet((outp as OutputRows), null, false);
                    // Update cluster name, DC and rack for the one node we are connected to
                    foreach (var localRow in rowset.GetRows())
                    {
                        var clusterName = localRow.GetValue<string>("cluster_name");
                        if (clusterName != null)
                            _cluster.Metadata.ClusterName = clusterName;

                        // In theory host can't be null. However there is no point in risking a NPE in case we
                        // have a race between a node removal and this.
                        if (localhost != null)
                        {
                            localhost.SetLocationInfo(localRow.GetValue<string>("data_center"), localRow.GetValue<string>("rack"));

                            partitioner = localRow.GetValue<string>("partitioner");
                            var tokens = localRow.GetValue<IList<string>>("tokens");
                            if (partitioner != null && tokens.Count > 0)
                            {
                                if (!tokenMap.ContainsKey(localhost.Address))
                                    tokenMap.Add(localhost.Address, new DictSet<string>());
                                tokenMap[localhost.Address].AddRange(tokens);
                            }
                        }

                        break; //fetch only one row
                    }
                }
            }

            for (int i = 0; i < foundHosts.Count; i++)
            {
                var host = _cluster.Metadata.GetHost(foundHosts[i]);
                if (host == null)
                {
                    // We don't know that node, add it.
                    host = _cluster.Metadata.AddHost(foundHosts[i]);
                }
                host.SetLocationInfo(dcs[i], racks[i]);

                if (partitioner != null && !allTokens[i].IsEmpty)
                    tokenMap.Add(host.Address, allTokens[i]);
            }

            // Removes all those that seems to have been removed (since we lost the control connection)
            var foundHostsSet = new DictSet<IPAddress>(foundHosts);
            foreach (var host in _cluster.Metadata.AllReplicas())
                if (!host.Equals(queriedHost) && !foundHostsSet.Contains(host))
                    _cluster.Metadata.RemoveHost(host);

            if (partitioner != null)
                _cluster.Metadata.RebuildTokenMap(partitioner, tokenMap);

            _logger.Info("NodeList and TokenMap have been successfully refreshed!");
        }
Example #24
0
 public Parser(List<Token> theList)
 {
     tokenList = theList;
     tokenEnumerator = tokenList.GetEnumerator();
     tokenEnumerator.MoveNext();
 }
Example #25
0
 public CardPresenter(List<ICardable> cardObjects)
 {
     _cardObjects = cardObjects;
     _cardEnumerator = _cardObjects.GetEnumerator();
     _cardEnumerator.MoveNext();
 }
        internal bool WaitForSchemaAgreement(IPAddress forHost = null)
        {
            var start = DateTimeOffset.Now;
            long elapsed = 0;
            while (elapsed < MaxSchemaAgreementWaitMs)
            {
                var versions = new DictSet<Guid>();

                IPAddress queriedHost;

                if (forHost == null)
                {
                    using (var rowset = _session.Query(SelectSchemaPeers, ConsistencyLevel.Default))
                    {
                        queriedHost = rowset.Info.QueriedHost;
                        foreach (var row in rowset.GetRows())
                        {
                            if (row.IsNull("rpc_address") || row.IsNull("schema_version"))
                                continue;

                            var rpc = row.GetValue<IPEndPoint>("rpc_address").Address;
                            if (rpc.Equals(bindAllAddress))
                                if (!row.IsNull("peer"))
                                    rpc = row.GetValue<IPEndPoint>("peer").Address;

                            Host peer = _cluster.Metadata.GetHost(rpc);
                            if (peer != null && peer.IsConsiderablyUp)
                                versions.Add(row.GetValue<Guid>("schema_version"));
                        }
                    }
                }
                else
                {
                    queriedHost = forHost;
                    var localhost = _cluster.Metadata.GetHost(queriedHost);
                    var iterLiof = new List<Host>() { localhost }.GetEnumerator();
                    iterLiof.MoveNext();
                    List<IPAddress> tr = new List<IPAddress>();
                    Dictionary<IPAddress, List<Exception>> exx = new Dictionary<IPAddress, List<Exception>>();
                    var cn = _session.Connect(null, iterLiof, tr, exx);

                    using (var outp = cn.Query(SelectSchemaPeers, ConsistencyLevel.Default, false))
                    {
                        if (outp is OutputRows)
                        {
                            var rowset = new RowSet((outp as OutputRows), null, false);
                            foreach (var row in rowset.GetRows())
                            {
                                if (row.IsNull("rpc_address") || row.IsNull("schema_version"))
                                    continue;

                                var rpc = row.GetValue<IPEndPoint>("rpc_address").Address;
                                if (rpc.Equals(bindAllAddress))
                                {
                                    if (!row.IsNull("peer"))
                                        rpc = row.GetValue<IPEndPoint>("peer").Address;
                                }

                                Host peer = _cluster.Metadata.GetHost(rpc);
                                if (peer != null && peer.IsConsiderablyUp)
                                    versions.Add(row.GetValue<Guid>("schema_version"));
                            }
                        }
                    }
                }

                {
                    var localhost = _cluster.Metadata.GetHost(queriedHost);
                    var iterLiof = new List<Host>() { localhost }.GetEnumerator();
                    iterLiof.MoveNext();
                    List<IPAddress> tr = new List<IPAddress>();
                    Dictionary<IPAddress, List<Exception>> exx = new Dictionary<IPAddress, List<Exception>>();
                    var cn = _session.Connect(null, iterLiof, tr, exx);

                    using (var outp = cn.Query(SelectSchemaLocal, ConsistencyLevel.Default, false))
                    {
                        if (outp is OutputRows)
                        {
                            var rowset = new RowSet((outp as OutputRows), null, false);
                            // Update cluster name, DC and rack for the one node we are connected to
                            foreach (var localRow in rowset.GetRows())
                                if (!localRow.IsNull("schema_version"))
                                {
                                    versions.Add(localRow.GetValue<Guid>("schema_version"));
                                    break;
                                }
                        }
                    }
                }

                if (versions.Count <= 1)
                    return true;

                // let's not flood the node too much
                Thread.Sleep(200);
                elapsed = (long)(DateTimeOffset.Now - start).TotalMilliseconds;
            }

            return false;
        }
Example #27
0
 protected void ResetEnumerator()
 {
     _cardEnumerator = _cardObjects.GetEnumerator();
     _cardEnumerator.MoveNext();
 }
Example #28
0
 public void Update(double dt)
 {
     Timer += dt;
     if (Textures.Count < 2)
         return;
     CurrentTime += dt;
     if (CurrentTime > CurrentTexture.Current.Item2)
     {
         CurrentTime = 0;
         if (!CurrentTexture.MoveNext())
         {
             CurrentTexture.Dispose();
             CurrentTexture = Textures.GetEnumerator();
             CurrentTexture.MoveNext();
         }
     }
 }
Example #29
0
        /// <summary>
        /// 從excel檔案中取得基本型別的資料
        /// </summary>
        /// <param name="type">基本型別的type</param>
        /// <param name="retObj">存放取得的資料</param>
        /// <param name="rowDataEnumerator">由excel來的row Data</param>
        /// <returns>可能的錯誤</returns>
        ReadExcelToJsonStringError GetBaseTypeDataFromExcel(Type type, ref object retObj, ref List<string>.Enumerator rowDataEnumerator)
        {
            if (!rowDataEnumerator.MoveNext())
            {
                retObj = null;
                return ReadExcelToJsonStringError.DATA_COL_NUM_IS_NOT_ENOUGH;
            }

            bool isNull = string.IsNullOrEmpty(rowDataEnumerator.Current);
            if (type == typeof(string))
            {
                retObj = (isNull) ? null : rowDataEnumerator.Current;
                return ReadExcelToJsonStringError.NONE;
            }
            else
            {
                bool isNullableType = type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>);
                if (isNull) // 資料是空的
                {
                    retObj = null;
                    return (isNullableType) ? ReadExcelToJsonStringError.NONE : ReadExcelToJsonStringError.DATA_CANT_BE_NULL; // type可為null,則資料為空沒問題
                }
                else // 資料非空
                {
                    string[] para = new string[1] { rowDataEnumerator.Current };
                    Type[] transferType = new Type[1] { typeof(string) };
                    Type realType = (isNullableType) ? Nullable.GetUnderlyingType(type) : type;
                    try
                    {
                        retObj = realType.GetMethod("Parse", transferType).Invoke(null, para);
                        return ReadExcelToJsonStringError.NONE;
                    }
                    catch (Exception e)
                    {
                        CommonFunction.DebugMsgFormat("取得基本型別時出錯\n{0}\n{1}", e.Message, e.StackTrace);
                        retObj = null;
                        return ReadExcelToJsonStringError.GET_BASE_TYPE_ERROR;
                    }
                }
            }
        }
Example #30
0
    void FixedUpdate()
    {
        // if we haven't set up the enumerator, do so
        if (currentPOI.Current == null)
        {
            currentPOI = points.GetEnumerator();
            currentPOI.MoveNext(); //set the enumerator to the first element (Why microsoft?)
            currentRotation = currentPOI.Current.directionPattern.GetEnumerator();
            currentRotation.MoveNext(); //why
        }

        // get the player's direction relative to the enemy if they're within range
        if (alerted)
        {
            Vector3 playerVector = player.transform.position - transform.position;
            playerVector.z = 0f;
            if (Mathf.Abs(playerVector.y) >= Mathf.Abs(playerVector.x))
            {
                if (playerVector.y <= 0)
                    playerDirection = FacingDirection.Front;
                else playerDirection = FacingDirection.Back;
            }
            else
            {
                if (playerVector.x <= 0)
                    playerDirection = FacingDirection.Left;
                else playerDirection = FacingDirection.Right;
            }
        }

        attackTimer += Time.deltaTime;

        //attack update
        if (playerScript.currentHealth <= 0)
        {
            alerted = false;
            playerInRange = false;
        }

        if (attackTimer >= timeBetweenAttacks && playerInRange && alerted && playerDirection == direction && currentHealth > 0)
        {
            attackTimer = 0f;
            attackScript.Attack(player);
        }

        //movement update
        if (!alerted)
        {
            if (destinationReached)
            { //if you are waiting at a POI
                poiTimer += Time.deltaTime;
                turnTimer += Time.deltaTime;
                if (turnTimer >= currentPOI.Current.rotationSpeed)
                    Turn();
                if (poiTimer >= currentPOI.Current.restTime)
                {
                    if (!currentPOI.MoveNext())
                    { //if you reached the end of the list, restart.
                        currentPOI = points.GetEnumerator();
                        currentPOI.MoveNext(); // y
                        currentRotation = currentPOI.Current.directionPattern.GetEnumerator();
                        currentRotation.MoveNext(); // whyyy
                    }
                    Patrol();
                }
            }
            else // or travelling to a new POI
                Patrol();
        }
        else
        {
            if (!ranged && direction == playerDirection) // chase player
                Move(player.transform.position.x - transform.position.x, player.transform.position.y - transform.position.y);

            Vector3 facing = player.transform.position - transform.position;
            facing.z = 0f;
            if (Mathf.Abs(facing.y) >= Mathf.Abs(facing.x))
            {
                if (facing.y <= 0)
                    direction = FacingDirection.Front;
                else direction = FacingDirection.Back;
            }
            else
            {
                if (facing.x <= 0)
                    direction = FacingDirection.Left;
                else direction = FacingDirection.Right;
            }
        }
        Animating();
    }