Inheritance: AGameState
Exemplo n.º 1
0
        public void Import(PlcBlockUserGroup Group, string path)
        {
            var filePath = Path.Combine(path, Util.RemoveInvalidFileNameChars(Name) + ".xml");
            IList <PlcBlock> importedBlocks;

            try
            {
                importedBlocks = Group.Blocks.Import(new FileInfo(filePath), ImportOptions.Override, SWImportOptions.IgnoreMissingReferencedObjects | SWImportOptions.IgnoreStructuralChanges | SWImportOptions.IgnoreUnitAttributes);
            }
            catch (Exception ex)
            {
                Trace.TraceError("Exception during import:" + Environment.NewLine + ex);
                _state = ExitState.CouldNotImport;
                return;
            }
            finally
            {
                try
                {
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                }
                catch
                {
                    // Silently ignore file operations
                }
            }
        }
Exemplo n.º 2
0
        // BreakStatement
        protected internal override bool Walk(BreakStatement node)
        {
            ExitState exit = PeekStatement(node.Statement);

            exit.And(_bits);
            return(true);
        }
Exemplo n.º 3
0
        private void SetChangeableState()
        {
            bool changeable = true;

            foreach (BlockGroup group in Groups)
            {
                changeable = changeable & group.IsChangeable;
            }
            foreach (Block block in Blocks)
            {
                changeable = changeable & block.IsChangeable;
                if (!block.IsChangeable)
                {
                    Trace.TraceInformation(block.Name + " Block Changeable: " + block.IsChangeable);
                }
            }

            if (changeable)
            {
                _state = ExitState.IsChangeable;
            }
            else
            {
                _state = ExitState.CouldNotCompile;
            }
        }
Exemplo n.º 4
0
	protected /*virtual*/ void Awake()
	{
		foreach(AGameState each in GetComponents<AGameState>())
		{
			if(states.ContainsKey(each.ID))
			{
				Debug.LogError("States ID found twice : " + each.ID.ToString());
			}
			else
			{
				states.Add(each.ID, each);
			}
			
			if(each is ExitState)
			{
				exit = each as ExitState;
			}
			
			if(each is LoadingState)
			{
				loading = each as LoadingState;
			}
			
			each.SetGameMode(this);
		}
		
		Enter();
	}
Exemplo n.º 5
0
    protected /*virtual*/ void Awake()
    {
        foreach (AGameState each in GetComponents <AGameState>())
        {
            if (states.ContainsKey(each.ID))
            {
                Debug.LogError("States ID found twice : " + each.ID.ToString());
            }
            else
            {
                states.Add(each.ID, each);
            }

            if (each is ExitState)
            {
                exit = each as ExitState;
            }

            if (each is LoadingState)
            {
                loading = each as LoadingState;
            }

            each.SetGameMode(this);
        }

        Enter();
    }
Exemplo n.º 6
0
    public virtual void Start()
    {
        RefRigidbody = GetComponent <Rigidbody>();
        RefSphere    = GetComponent <SphereCollider>();
        Neighbors    = new List <Agent>();
        FSM          = new StateMachine.StateMachine();



        InitialState initial = new InitialState(this);
        GroupState   group   = new GroupState(this);
        ExitState    exit    = new ExitState(this);

        JoinGroupTransition JG = new JoinGroupTransition();

        JG.SetTargetState(group);
        ExitTriggerTransition ET = new ExitTriggerTransition();

        ET.SetTargetState(exit);
        ExitFormationTransition EF = new ExitFormationTransition();

        EF.SetTargetState(group);

        initial.AddTransitions(JG);
        group.AddTransitions(ET);
        exit.AddTransitions(EF);

        FSM.AddState(initial);
        FSM.AddState(group);
        FSM.AddState(exit);

        FSM.Start(initial);
    }
Exemplo n.º 7
0
 public AnyState AnyState(string name, Condition switchCondition,
                          EnterState enter             = null, UpdateState update = null,
                          FixedUpdateState fixedUpdate = null, ExitState exit     = null
                          )
 {
     return(stateMachine.AnyState(name, switchCondition, enter, update, fixedUpdate, exit));
 }
Exemplo n.º 8
0
 public void SetState(ExitStateTytpes type)
 {
     if (m_States.ContainsKey(type))
     {
         m_State = m_States[type];
         m_State.UpdateParameters();
     }
 }
Exemplo n.º 9
0
    public override void _Ready()
    {
        _stateMachine = new StateMachine();
        _menuState    = new MenuState(this, _stateMachine);
        _gameState    = new GameState(this, _stateMachine);
        _exitState    = new ExitState(this, _stateMachine);

        _stateMachine.Initialize(_menuState);
    }
Exemplo n.º 10
0
 public void Add(T state, EnterState enter, UpdateState update, ExitState exit)
 {
     states.Add(state, new State
     {
         Enter  = enter,
         Update = update,
         Exit   = exit
     });
 }
Exemplo n.º 11
0
        // -- //

        public State(StateMachine stateMachine, string name, EnterState enter, UpdateState update, FixedUpdateState fixedUpdate, ExitState exit)
        {
            this.stateMachine = stateMachine;
            this.name         = name;
            this.enter        = enter;
            this.update       = update;
            this.fixedUpdate  = fixedUpdate;
            this.exit         = exit;
        }
Exemplo n.º 12
0
        public ExitState ReadExitState()
        {
            var state = new ExitState();

            PushScope();
            ReadTransitionalTarget(state);
            PopScope();
            return(state);
        }
Exemplo n.º 13
0
        public bool Export(string path)
        {
            var filePath = Path.Combine(path, Util.RemoveInvalidFileNameChars(Name) + ".xml");

            if (Util.ExportBlock(_block, filePath) != true)
            {
                _state = ExitState.CouldNotExport;
                return(false);
            }
            return(true);
        }
Exemplo n.º 14
0
        // -- //

        public State AddState(string name, EnterState enter = null,
                              UpdateState update            = null, FixedUpdateState fixedUpdate = null,
                              ExitState exit = null
                              )
        {
            State newState = new State(this, name, enter, update, fixedUpdate, exit);

            if (currentState == null)
            {
                currentState = newState;
            }

            states.Add(name, newState);

            return(newState);
        }
Exemplo n.º 15
0
        public void DoWorkAsync(IActionProvider provider)
        {
            exitState = ExitState.NORMAL;
            CancellationToken token = tokenSource.Token;

            Task mainTask = Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    if (token.IsCancellationRequested) break;
                    try
                    {
                        Action[] actions = provider.GetActions();
                        if (actions.Length == 0) break;
                        List<Task> tasks = new List<Task>();
                        foreach (Action action in actions)
                        {
                            if (token.IsCancellationRequested) break;
                            try
                            {
                                Task subtask = Task.Factory.StartNew(action, token);
                                subtask.ContinueWith(TaskFailed, TaskContinuationOptions.OnlyOnFaulted);
                                tasks.Add(subtask);
                            }
                            catch
                            {
                                exitState = ExitState.ERROR;
                                tokenSource.Cancel();
                                break;
                            }
                        }
                        try
                        {
                            Task.WaitAll(tasks.ToArray(), tokenSource.Token);
                        }
                        catch (OperationCanceledException){}
                    }
                    catch
                    {
                        exitState = ExitState.ERROR;
                        break;
                    }
                }
            }, TaskCreationOptions.LongRunning);
            mainTask.ContinueWith(Done, scheduler);
        }
    private void Awake()
    {
        wanderState = new WanderState (this); // huntStart = new HuntState (this); May replace with this
        idleState = new IdleState (this); // huntStart = new HuntState (this); May replace with this
        forageState = new ForageState (this);
        flightState = new FlightState (this);
        pursuitState = new PursuitState (this);
        exitState = new ExitState (this);
        enterState = new EnterState (this);
        navMeshAgent = GetComponent<NavMeshAgent>();

        navMeshAgent.enabled = true;
        // navMeshObstacle.enabled = false;

        navMeshRadius = navMeshAgent.radius;

        navMeshAgent.avoidancePriority = Random.Range(0, 100);  // Randomly set the avoidance priority
    }
Exemplo n.º 17
0
 protected override Validation <string, SitAction> CreateService(
     string key, string displayName, ILoggerFactory loggerFactory)
 {
     return
         (from animation in Prelude.Optional(Animation)
          .ToValidation("Animation was not specified.")
          from statesPath in StatesPath.TrimToOption()
          .ToValidation("States path was not specified.")
          from subStatesPath in SubStatesPath.TrimToOption()
          .ToValidation("Sub-states path was not specified.")
          from idleState in IdleState.TrimToOption()
          .ToValidation("Idle state value was not specified.")
          from enterState in EnterState.TrimToOption()
          .ToValidation("Enter state value was not specified.")
          from state in State.TrimToOption()
          .ToValidation("State path was not specified.")
          from exitState in ExitState.TrimToOption()
          .ToValidation("Exit state value was not specified.")
          from enterAnimatorPath in EnterAnimatorPath.TrimToOption()
          .ToValidation("Enter animator path was not specified.")
          from animatorPath in AnimatorPath.TrimToOption()
          .ToValidation("Animator path was not specified.")
          from exitAnimatorPath in ExitAnimatorPath.TrimToOption()
          .ToValidation("Exit animator path was not specified.")
          select new SitAction(
              key,
              displayName,
              animation,
              statesPath,
              subStatesPath,
              idleState,
              enterState,
              state,
              exitState,
              enterAnimatorPath,
              animatorPath,
              exitAnimatorPath,
              Active,
              loggerFactory)
     {
         SittingDownAnimation = SittingDownAnimation,
         GettingUpAnimation = GettingUpAnimation
     });
 }
Exemplo n.º 18
0
        public State To(string name, Condition switchCondition,
                        EnterState enter             = null, UpdateState update = null,
                        FixedUpdateState fixedUpdate = null, ExitState exit     = null
                        )
        {
            State stateToAdd = stateMachine.GetState(name);

            if (stateToAdd == null)
            {
                stateToAdd = stateMachine.AddState(name, enter, update, fixedUpdate, exit);
            }

            StateOutput output = new StateOutput();

            output.condition = switchCondition;
            output.toState   = stateToAdd;

            outputStates.Add(output);

            return(output.toState);
        }
Exemplo n.º 19
0
        public AnyState AnyState(string name, Condition switchCondition,
                                 EnterState enter             = null, UpdateState update = null,
                                 FixedUpdateState fixedUpdate = null, ExitState exit     = null
                                 )
        {
            AnyState stateToAdd = GetState(name) as AnyState;

            if (stateToAdd == null)
            {
                stateToAdd = new AnyState(this, name, enter, update, fixedUpdate, exit);
            }

            StateOutput output = new StateOutput();

            output.condition = switchCondition;
            output.toState   = stateToAdd;

            anyStates.Add(output);
            states.Add(name, stateToAdd);

            return(stateToAdd);
        }
Exemplo n.º 20
0
        public void Transition(ExplicitState toState)
        {
            if (CurrentState == toState)
            {
                return;
            }

            if (toState == null)
            {
                throw new ArgumentNullException("toState");
            }

            OnExitState();
            ExitState?.Invoke();
            CurrentState.OnExit();

            CurrentState = toState;

            OnEnterState();
            EnterState?.Invoke();
            CurrentState.OnEnter();
        }
Exemplo n.º 21
0
        private void SetChangeableState()
        {
            if (_block.IsKnowHowProtected)
            {
                _state = ExitState.BlockIsKnowHowProtected;
                Trace.TraceInformation(Name + " BlockIsKnowHowProtected");
                return;
            }

            if (!_block.IsConsistent)
            {
                try
                {
                    if (_block.GetService <ICompilable>().Compile().State == CompilerResultState.Error)
                    {
                        _state = ExitState.CouldNotCompile;
                        Trace.TraceInformation(Name + " CouldNotCompile");
                        return;
                    }
                }
                catch
                {
                    _state = ExitState.CouldNotCompile;
                    Trace.TraceInformation(Name + " CouldNotCompile - Catch");
                    return;
                }
            }

            if (_block.GetService <LibraryTypeInstanceInfo>() != null)
            {
                _state = ExitState.IsLibraryType;
                Trace.TraceInformation(Name + " IsLibraryType");
                return;
            }

            _state = ExitState.IsChangeable;
        }
Exemplo n.º 22
0
    private void CreateStateMachine()
    {
        _stateMachine = new StateMachine();

        var menu       = new MenuState();
        var load       = new LoadLevelState(this);
        var countDown  = new CountDownState(this);
        var play       = new PlayState(this);
        var pause      = new PauseState();
        var finishRace = new FinishRace();
        var exit       = new ExitState();

        _stateMachine.SetState(menu);

        _stateMachine.AddTransition(menu, load, () => LoadLevelState.LevelToLoad != null);
        _stateMachine.AddTransition(menu, exit, () => ExitButton.Pressed);

        _stateMachine.AddTransition(load, countDown, load.FinishLoading);

        _stateMachine.AddTransition(countDown, play, () => RaceStarted);
        _stateMachine.AddTransition(countDown, pause, () => PlayerInput.Instance.Pause);

        _stateMachine.AddTransition(play, finishRace, () => RaceFinished);
        _stateMachine.AddTransition(play, pause, () => PlayerInput.Instance.Pause);

        _stateMachine.AddTransition(finishRace, menu, () => MenuButton.Pressed);
        _stateMachine.AddTransition(finishRace, load, () => LoadLevelState.LevelToLoad != null);
        _stateMachine.AddTransition(finishRace, exit, () => ExitButton.Pressed);

        _stateMachine.AddTransition(pause, countDown, () => PauseButton.Pressed && !RaceStarted);
        _stateMachine.AddTransition(pause, countDown, () => PlayerInput.Instance.Pause && !RaceStarted);
        _stateMachine.AddTransition(pause, play, () => PauseButton.Pressed && RaceStarted);
        _stateMachine.AddTransition(pause, play, () => PlayerInput.Instance.Pause && RaceStarted);
        _stateMachine.AddTransition(pause, load, () => LoadLevelState.LevelToLoad != null);
        _stateMachine.AddTransition(pause, menu, () => MenuButton.Pressed);
        _stateMachine.AddTransition(pause, exit, () => ExitButton.Pressed);
    }
Exemplo n.º 23
0
 public void CancelAsync()
 {
     exitState = ExitState.CANCEL;
     tokenSource.Cancel();
 }
Exemplo n.º 24
0
 public static void exitLose(int newScore)
 {
     score = newScore;
     exitState = ExitState.Lost;
 }
Exemplo n.º 25
0
 private void SetStateAndExit(ExitState exitState)
 {
     this.remember  = RememberCheckbox.IsChecked.GetValueOrDefault(false);
     this.exitState = exitState;
     Close();
 }
Exemplo n.º 26
0
 public static void exitQuit()
 {
     score = 0;
     exitState = ExitState.Quit;
 }
Exemplo n.º 27
0
        // -- //

        public AnyState(StateMachine stateMachine, string name, EnterState enter, UpdateState update, FixedUpdateState fixedUpdate, ExitState exit)
            : base(stateMachine, name, enter, update, fixedUpdate, exit)
        {
        }
Exemplo n.º 28
0
 public static void NotifyExitState(GameState state)
 {
     ExitState?.Invoke(state);
 }
Exemplo n.º 29
0
 public static void exitWin(int newScore)
 {
     score = newScore;
     exitState = ExitState.Won;
 }
Exemplo n.º 30
0
 void TaskFailed(Task tast)
 {
     exitState = ExitState.ERROR;
     tokenSource.Cancel();
 }