当前位置: 首页>>代码示例>>C#>>正文


C# State.Add方法代码示例

本文整理汇总了C#中State.Add方法的典型用法代码示例。如果您正苦于以下问题:C# State.Add方法的具体用法?C# State.Add怎么用?C# State.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在State的用法示例。


在下文中一共展示了State.Add方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InitStateMachine

    ///////////////////////////////////////////////////////////////////////////////
    // Function
    ///////////////////////////////////////////////////////////////////////////////

    protected override void InitStateMachine() {
        base.InitStateMachine();

        State start = new State("start", stateMachine);
        start.onEnter += (_from, _to, _event) => { EnterStartState(); };

        State running = new State("running", stateMachine);
        running.onEnter += (_from, _to, _event) => { EnterRuningState(); };
        running.onExit += (_from, _to, _event) => { ExitRuningState(); };
        running.onAction += (_cur) => { UpdateRunningState(); };

        State pause = new State("pause", stateMachine);
        pause.onEnter += (_from, _to, _event) => { };
        pause.onExit += (_from, _to, _event) => { };

        State over = new State("over", stateMachine);
        over.onEnter += (_from, _to, _event) => { EnterOverState(); };
        over.onExit += (_from, _to, _event) => { };

        start.Add<EventTransition>(running, (int)EventType.Run);
        start.Add<EventTransition>(over, (int)EventType.Over);

        running.Add<EventTransition>(over, (int)EventType.Over);
        running.Add<EventTransition>(pause, (int)EventType.Pause);

        pause.Add<EventTransition>(running, (int)EventType.Resume);
        pause.Add<EventTransition>(over, (int)EventType.Over);

        over.Add<EventTransition>(start, (int)EventType.Restart);
    }
开发者ID:GavenZhou,项目名称:ProjectDemo,代码行数:34,代码来源:Level.cs

示例2: InitStateMachine

    protected override void InitStateMachine() {

        base.InitStateMachine();

        State start = new State("start", stateMachine);
        start.onEnter += (_from, _to, _event) => EnterStartState(_from, _to, _event);
        start.onExit += (_from, _to, _event) => { };

        State loading = new State("loading", stateMachine);
        loading.onEnter += (_from, _to, _event) => { EnterLoadingState(_from, _to, _event); };
        loading.onExit += (_from, _to, _event) => { };

        State running = new State("running", stateMachine);
        running.onEnter += (_from, _to, _event) => { curState = GameState.Running; };
        running.onExit += (_from, _to, _event) => { };
        running.onAction += UpdateRunningState;

        State quit = new State("quit", stateMachine);
        quit.onEnter += (_from, _to, _event) => { curState = GameState.Quit; };

        start.Add<EventTransition>(loading, (int)EventType.GameLoading);
        loading.Add<EventTransition>(running, (int)EventType.GameRunning);
    }
开发者ID:GavenZhou,项目名称:ProjectDemo,代码行数:23,代码来源:Game.cs

示例3: AddTest

        public void AddTest()
        {
            State state = new State();

            state.Add("url1", "label1", 1);
            Assert.AreEqual(state.Count(), 1);
            Assert.AreEqual(state.ElementAt(0).Key, 1);
            Assert.AreEqual(state.ElementAt(0).Value.Label, "label1");
            Assert.AreEqual(state.ElementAt(0).Value.Url, "url1");

            state.Add("url2", "label2", 2);
            Assert.AreEqual(state.Count(), 2);
            Assert.AreEqual(state.ElementAt(1).Key, 2);
            Assert.AreEqual(state.ElementAt(1).Value.Label, "label2");
            Assert.AreEqual(state.ElementAt(1).Value.Url, "url2");

            state.Add("url3", "label3", 3);
            Assert.AreEqual(state.Count(), 3);
            Assert.AreEqual(state.ElementAt(2).Key, 3);
            Assert.AreEqual(state.ElementAt(2).Value.Label, "label3");
            Assert.AreEqual(state.ElementAt(2).Value.Url, "url3");

            state.Add("url2", "label2_new", 4); //back to url2
            Assert.AreEqual(state.Count(), 2);
            Assert.AreEqual(state.ElementAt(1).Key, 4);
            Assert.AreEqual(state.ElementAt(1).Value.Label, "label2_new");
            Assert.AreEqual(state.ElementAt(1).Value.Url, "url2");

            state.Add("url6", "label6", 6);
            Assert.AreEqual(state.Count(), 3);
            Assert.AreEqual(state.ElementAt(2).Key, 6);
            Assert.AreEqual(state.ElementAt(2).Value.Label, "label6");
            Assert.AreEqual(state.ElementAt(2).Value.Url, "url6");

            state.Add("url5", "label5", 5); //insert url5 before url6
            Assert.AreEqual(state.Count(), 4);
            Assert.AreEqual(state.ElementAt(2).Key, 5);
            Assert.AreEqual(state.ElementAt(2).Value.Label, "label5");
            Assert.AreEqual(state.ElementAt(2).Value.Url, "url5");
            Assert.AreEqual(state.ElementAt(3).Key, 6);
            Assert.AreEqual(state.ElementAt(3).Value.Label, "label6");
            Assert.AreEqual(state.ElementAt(3).Value.Url, "url6");

            state.Add("url5", "label5_new", 5, true);
            Assert.AreEqual(state.Count(), 4);
            Assert.AreEqual(state.ElementAt(2).Key, 5);
            Assert.AreEqual(state.ElementAt(2).Value.Label, "label5");
            Assert.AreEqual(state.ElementAt(2).Value.Url, "url5");

            state.Add("url5", "label5_new", 5);
            Assert.AreEqual(state.Count(), 3);
            Assert.AreEqual(state.ElementAt(2).Key, 5);
            Assert.AreEqual(state.ElementAt(2).Value.Label, "label5_new");
            Assert.AreEqual(state.ElementAt(2).Value.Url, "url5");

            state.Add("url2_new", "label2_new", 2);
            Assert.AreEqual(state.Count(), 4);
            Assert.AreEqual(state.ElementAt(1).Key, 2);
            Assert.AreEqual(state.ElementAt(1).Value.Label, "label2_new");
            Assert.AreEqual(state.ElementAt(1).Value.Url, "url2_new");
        }
开发者ID:jbzorg,项目名称:MvcBreadCrumbs,代码行数:61,代码来源:StateTest.cs

示例4: Move

        private static void Move(State state, string srcName, string dstName)
        {
            var srcPosition = state
                .Where(_ => _.Key.StartsWith(srcName))
                .Select(_ => _.Key.Remove(0, 1))
                .Select(int.Parse)
                .Min();

            var dstPosition = state
                .Where(_ => _.Key.StartsWith(dstName))
                .Select(_ => _.Key.Remove(0, 1))
                .Select(int.Parse)
                .ToList();

            var a = srcName + srcPosition;
            var dstNormalized = dstPosition.Count == 0 ? 7 : dstPosition.Min() - 1;
            var b = dstNormalized == 0 ? "" : dstName + dstNormalized;

            state.Add(b, state[a]);
            state.Remove(a);
        }
开发者ID:Bmackenzie,项目名称:GOAP-1,代码行数:21,代码来源:hanoi_tower_solver_test.cs

示例5: GetStates

 private List<State> GetStates(string statesFilename, string projectName)
 {
     var result = new List<State>();
     string statesFile = FileReader.ReadFile(Path.Combine(GetRulesDirectory(projectName), statesFilename + rulesExtension));
     if (statesFile == null) {
         return result;
     }
     var lines = Regex.Split(statesFile, "\r\n|\r|\n");
     if (lines.Length < 2) {
         return result; // we need first line as a header and second line as an at least one state
     }
     var literals = lines[0].Split(new char[] { StatesSeparator }, StringSplitOptions.RemoveEmptyEntries);
     for (int lineNo = 1; lineNo < lines.Length; lineNo++) {
         if(lines[lineNo].Length == 0) {
             continue;
         }
         var newState = new State();
         var values = lines[lineNo].Split(StatesSeparator);
         for (int i = 0; i < values.Length; i++) {
             int val;
             var parsed = int.TryParse(values[i], out val);
             if (parsed) {
                 newState.Add(literals[i], val);
             }
         }
         result.Add(newState);
     }
     return result;
 }
开发者ID:Harriet92,项目名称:TemporalRPGSystem,代码行数:29,代码来源:LogicEngine.cs

示例6: SetToStates

 private State[] SetToStates(Set set)
 {
     var statesStrings = set.ToString().Split(new string[] { "Set", "(" }, StringSplitOptions.RemoveEmptyEntries);
     var result = new List<State>();
     for (var i = 0; i < statesStrings.Length; i++)
     {
         var stStr = statesStrings[i];
         var literals = stStr.Replace("(", "").Replace(")", "").Replace(",", "").Split(' ');
         var newState = new State();
         foreach (var literal in literals)
         {
             bool isTrue = !literal.Contains("!");
             var prop = literal.Replace("!", "");
             if (!string.IsNullOrEmpty(prop)) {
                 newState.Add(prop, isTrue.NumVal());
             }
         }
         if (newState.Keys.Count > 0) {
             result.Add(newState);
         }
     }
     return result.ToArray();
 }
开发者ID:Harriet92,项目名称:TemporalRPGSystem,代码行数:23,代码来源:LogicEngine.cs

示例7: SaveStates

 private List<State> SaveStates(Transform container)
 {
     var savedStates = new List<State>();
     foreach (Transform state in container)
     {
         var currentState = new State();
         foreach (Transform literal in state)
         {
             var script = literal.GetComponent<StateElementComponent>();
             if (script != null)
                 currentState.Add(script.LiteralName, script.IsNegated ? 0 : 1);
         }
         if (currentState.Count != 0)
         {
             savedStates.Add(currentState);
         }
     }
     return savedStates;
 }
开发者ID:Harriet92,项目名称:TemporalRPGSystem,代码行数:19,代码来源:ProjectManager.cs

示例8: GetDefaultState

 public State GetDefaultState()
 {
     var state = new State();
     foreach (Transform entity in EntitiesContainer.transform)
     {
         var entityElement = entity.GetComponent<EntityElement>();
         if (entityElement != null)
         {
             foreach (var attrName in entityElement.EntityDefinition.Attributes)
             {
                 state.Add(Literal.GenerateLiteralName(entityElement.Name, attrName), 0);
             }
         }
     }
     return state;
 }
开发者ID:Harriet92,项目名称:TemporalRPGSystem,代码行数:16,代码来源:ProjectManager.cs


注:本文中的State.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。