本文整理汇总了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);
}
示例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);
}
示例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");
}
示例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);
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}