コード例 #1
0
ファイル: Block.cs プロジェクト: MarkHenryC/UnityStateFrame
 public virtual void UpdateConnection(Circuit.TraceTrigger trigger)
 {
     if (circuit)
     {
         circuit.Trace(trigger);
     }
 }
コード例 #2
0
        private void OnTraceComplete(Circuit.CircuitType ct, Circuit.TraceTrigger trigger)
        {
            Circuit.CircuitType previousState = circuitState;
            circuitState = ct;
            bool changedState = (previousState != circuitState) &&
                                (previousState != Circuit.CircuitType.Short) &&
                                (circuitState != Circuit.CircuitType.Short);

            switch (circuitState)
            {
            case Circuit.CircuitType.Closed:
                closedCount++;
                if (infoPanel)
                {
                    infoPanel.SetText("Light on");
                }
                break;

            case Circuit.CircuitType.Short:
                if (infoPanel)
                {
                    infoPanel.SetText("Short circuit!");
                }
                shortCount++;
                break;

            case Circuit.CircuitType.Open:
                if (infoPanel)
                {
                    infoPanel.SetText("Light off");
                }
                break;
            }

            if (trigger == Circuit.TraceTrigger.Rewire || circuitState == Circuit.CircuitType.Short)
            {
                Debug.Log("Reset after short or rewire");

                switch1Test.ResetTests();
                switch2Test.ResetTests();
            }
            else if (trigger == Circuit.TraceTrigger.Switch)
            {
                if (changedState)
                {
                    if (switch1Test.actionPending || switch2Test.actionPending)
                    {
                        if (switch1Test.actionPending && circuitState == Circuit.CircuitType.Closed)
                        {
                            switchedOn1 = true;
                        }
                        else if (switch2Test.actionPending && circuitState == Circuit.CircuitType.Closed)
                        {
                            switchedOn2 = true;
                        }

                        switch1Test.TestStatus(switch1.IsUp, circuitState == Circuit.CircuitType.Open);
                        switch2Test.TestStatus(switch2.IsUp, circuitState == Circuit.CircuitType.Open);
                    }
                }
                else // if we've flicked a switch and no change then it's wired incorrectly
                {
                    switch1Test.ResetTests();
                    switch2Test.ResetTests();
                }

                if (switch1Test.TestComplete && switch2Test.TestComplete || (switchedOn1 && switchedOn2))
                {
                    testComplete = true;
                    complete     = true;

                    Finish();

                    Debug.Log("Testing successfully completed");
                }
            }

            switch1Test.actionPending = switch2Test.actionPending = false;
        }
コード例 #3
0
        private void OnTraceComplete(Circuit.CircuitType ct, Circuit.TraceTrigger trigger)
        {
            Circuit.CircuitType previousState = circuitState;
            circuitState = ct;
            bool changedState = (previousState != circuitState) &&
                                (previousState != Circuit.CircuitType.Short) &&
                                (circuitState != Circuit.CircuitType.Short);

            switch (circuitState)
            {
            case Circuit.CircuitType.Closed:
                closedCount++;
                infoPanel.SetText("Light on");
                if (!directWired)
                {
                    var ps = device1 as PowerSource;
                    ps.live.ClearOutgoingConnection();
                    ps.neutral.ClearOutgoingConnection();
                    directWired = true;
                    switch1.gameObject.SetActive(true);
                    PlayReward();
                    infoPanel.SetText("Great. Now let's try it with a switch. Run one of the cables through the switch and test it off and on.");
                }
                break;

            case Circuit.CircuitType.Short:
                infoPanel.SetText("Short circuit!");
                shortCount++;
                break;

            case Circuit.CircuitType.Open:
                infoPanel.SetText("Light off");
                break;
            }

            if (trigger == Circuit.TraceTrigger.Rewire || circuitState == Circuit.CircuitType.Short)
            {
                Debug.Log("Reset after short or rewire");

                switch1Test.ResetTests();
            }
            else if (trigger == Circuit.TraceTrigger.Switch)
            {
                if (changedState)
                {
                    if (switch1Test.actionPending)
                    {
                        switch1Test.TestStatus(switch1.IsUp, circuitState == Circuit.CircuitType.Open);
                    }
                }
                else // if we've flicked a switch and no change then it's wired incorrectly
                {
                    switch1Test.ResetTests();
                }

                if (switch1Test.SingleSwitchTestComplete)
                {
                    testComplete = true;

                    PlayReward();

                    Finish();

                    Debug.Log("Testing successfully completed");
                }
            }

            switch1Test.actionPending = false;
        }