Ejemplo n.º 1
0
 private void ResetActiveState()
 {
     activeState = InitialState();
     if (activeState != null)
     {
         activeState.Active = true;
     }
     timeInState = 0;
 }
Ejemplo n.º 2
0
        private void Start()
        {
            StateChip chip = (StateChip)GetComponent <ChipUi>().Node;

            chip.StateNameChanged += Chip_StateNameChanged;
            Chip_StateNameChanged(chip, chip.StateName);
            chip.StateActiveChanged += Chip_StateActiveChanged;
            Chip_StateActiveChanged(chip, chip.Active);
        }
Ejemplo n.º 3
0
        override protected void EvaluateOutputs()
        {
            StateChip lastActiveState = activeState;

            activeState = FindActiveState();

            if (IsResetSet)
            {
                if (activeState != null)
                {
                    activeState.Active = false;
                }
                ResetActiveState();
            }
            else
            {
                timeInState++;
                if (activeState == null)
                {
                    ResetActiveState();
                }
            }

            if (activeState != null && timeInState > 0 && timeInState >= activeState.MinTimeInState)
            {
                StateChip nextState = NextStateAfterValidTransition();
                if (nextState != null)
                {
                    activeState.Active = false;
                    nextState.Active   = true;
                    activeState        = nextState;
                    timeInState        = 0;
                }
            }

            if (activeState != null)
            {
                outputPorts[0].Value = activeState.Value0;
                outputPorts[1].Value = activeState.Value1;
                outputPorts[2].Value = activeState.Value2;
                outputPorts[3].Value = timeInState * 100;
            }
            else
            {
                for (int i = 0; i < 4; ++i)
                {
                    outputPorts[i].Value = DefaultOutputValue(i);
                }
            }
            outputPorts[4].Value = !object.ReferenceEquals(lastActiveState, activeState);

            EmitEvaluationRequired();
        }
Ejemplo n.º 4
0
        private void StatePort_Disconnected(Connection connection)
        {
            if (!object.ReferenceEquals(connection.SourcePort, this))
            {
                return;
            }
            StateMachineTransition transition = (StateMachineTransition)connection;
            StateMachineChip       stateMachine;
            StateChip targetState = (StateChip)transition.TargetStatePort.Node;

            targetState.Active = false;
            if (transition.SourceStatePort.IsStateRootPort)
            {
                stateMachine = (StateMachineChip)transition.SourceStatePort.Node;
            }
            else
            {
                StateChip sourceState = (StateChip)transition.SourceStatePort.Node;
                stateMachine = sourceState.StateMachineUnchecked;
            }
            DebugUtils.Assert(object.ReferenceEquals(stateMachine, targetState.StateMachineUnchecked));
            if (stateMachine == null)
            {
                if (!transition.SourceStatePort.IsStateRootPort)
                {
                    ((StateChip)transition.SourceStatePort.Node).CheckStateMachine();
                }
                targetState.CheckStateMachine();
                return;
            }
            if (transition.TargetStatePort.connections.Count > 0)
            {
                stateMachine.UpdateConnectedStates();
            }
            else
            {
                stateMachine.connectedStates.Remove(targetState);
                targetState.StateMachine = null;
            }
            if (!transition.SourceStatePort.IsStateRootPort)
            {
                ((StateChip)transition.SourceStatePort.Node).CheckStateMachine();
            }
            targetState.CheckStateMachine();
        }
Ejemplo n.º 5
0
 public InputPort(CircuitNode node, bool isReset)
     : base(node, true, isReset)
 {
     stateChip = node as StateChip;
 }
Ejemplo n.º 6
0
        private void StatePort_Connected(Connection connection)
        {
            DebugUtils.Assert(object.ReferenceEquals(connection.SourcePort, this));
            DebugUtils.Assert(!connection.TargetPort.IsStateRootPort);
            StateMachineTransition transition = (StateMachineTransition)connection;
            StateMachineChip       stateMachine;
            StateChip targetState = (StateChip)transition.TargetStatePort.Node;

            if (transition.SourceStatePort.IsStateRootPort)
            {
                stateMachine = (StateMachineChip)transition.SourceStatePort.Node;
            }
            else
            {
                StateChip sourceState = (StateChip)transition.SourceStatePort.Node;
                stateMachine = sourceState.StateMachineUnchecked;
                if (stateMachine == null)
                {
                    stateMachine = targetState.StateMachineUnchecked;
                }
            }
            if (stateMachine == null)
            {
                if (!transition.SourceStatePort.IsStateRootPort)
                {
                    ((StateChip)transition.SourceStatePort.Node).CheckStateMachine();
                }
                targetState.CheckStateMachine();
                return;
            }

            StateChip newState;

            if (targetState.StateMachineUnchecked == null)
            {
                newState = targetState;
            }
            else
            {
                newState = (StateChip)transition.SourceStatePort.Node;
            }

            if (newState.StateMachineUnchecked == null)
            {
                DebugUtils.Assert(newState.statePort.connections.Count > 0);
                if (newState.statePort.connections.Count > 1)
                {
                    stateMachine.UpdateConnectedStates();
                }
                else
                {
                    DebugUtils.Assert(!stateMachine.connectedStates.Contains(newState));
                    stateMachine.connectedStates.Add(newState);
                    newState.StateMachine = stateMachine;
                }
            }
            else
            {
                DebugUtils.Assert(object.ReferenceEquals(targetState.StateMachine, stateMachine));
            }
            if (!transition.SourceStatePort.IsStateRootPort)
            {
                ((StateChip)transition.SourceStatePort.Node).CheckStateMachine();
            }
            targetState.CheckStateMachine();
        }
Ejemplo n.º 7
0
 private void Chip_StateActiveChanged(StateChip source, bool stateActive)
 {
     stateIconImage.color = stateActive ? Color.white : Color.gray;
 }
Ejemplo n.º 8
0
 private void Chip_StateNameChanged(StateChip source, string stateName)
 {
     stateNameText.text = stateName;
 }