Ejemplo n.º 1
0
    private void SetValue(string key, string value)
    {
        // 由于上位机会重复发送当前的事件,因此需要判断
        // 如果获得的时间存在重复,则跳过
        if (m_currentKey == key && m_currentValue == value)
        {
            return;
        }

        // 如果没有数值,则直接返回
        if (string.IsNullOrEmpty(value))
        {
            return;
        }

        Debug.Log("捕捉到事件: Key: " + key + ",Value: " + value);

        // 把该事件存到事件序列里,依序触发
        var evt = new GrindEvent(key, value);

        eventQueue.Enqueue(evt);

        Debug.Log("加入触发事件: " + evt);

        m_currentKey   = key;
        m_currentValue = value;
    }
Ejemplo n.º 2
0
    private void TriggerEvent(GrindEvent evt)
    {
        switch (evt.key)
        {
        case "CJ":
            // 任务开始事件
            Debug.Log("Train Start");
            if (onTestStarted != null)
            {
                onTestStarted();
            }

            break;

        case "CB":
            // 如果没有数值则直接跳过
            if (string.IsNullOrEmpty(evt.value))
            {
                return;
            }

            // 如果获取CB:0001则表示顺利完成任务
            // 反之获取CB:0002则表示任务失败,需要重来
            bool result = evt.value == "1";
            Debug.Log("Train Finished, Result: " + result);
            if (onTestFinished != null)
            {
                onTestFinished(result);
            }

            break;

        case "CC":
            // 砂磨板消除灯之后获取的事件
            Debug.Log("On Turn Off Light: " + evt.value);

            if (onTurnOffLight != null)
            {
                onTurnOffLight(CodeToNode(evt.value));
            }
            break;
        }
    }