Exemple #1
0
    void handleMessage(FireworkMessage m)
    {
        Debug.Log(JsonUtility.ToJson(m));

        switch (m.handler)
        {
        case "fireworks":
            if (m.type >= 0 && m.type < 9 && m.time >= 1 && m.time <= 10)
            {
                float height = m.height > 1 ? 1 : m.height < 0 ? 0 : m.height;
                if (po[m.type] != null)
                {
                    Loom.QueueOnMainThread(() =>
                    {
                        //onTouch(new Vector3(Screen.width * fx, Screen.height * fy));
                        po[m.type].ParticleObjectPlay(height, m.time, regions[idx % 4].center, regions[idx % 4].area);
                        idx++;     // po.Length;
                        lastEffectTimeStamp = UnixTimeNow();
                    });
                }
            }
            break;

        case "fish":

            break;

        default:
            break;
        }
    }
Exemple #2
0
    void touchControl()
    {
        Debug.Log("touchControl UDP thread start");

        UdpClient udpClient = new UdpClient(12345);

        udpClient.Client.SendTimeout    = 5000;
        udpClient.Client.ReceiveTimeout = 5000;

        Debug.Log("touchControl server started");

        byte[]     buf = null;
        IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);

        while (!workerThreadStopped)
        {
            try
            {
                buf = udpClient.Receive(ref RemoteIpEndPoint);
            }
            catch (SocketException e)
            {
                continue;
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                throw e;
            }

            string result = System.Text.Encoding.UTF8.GetString(buf);

            FireworkMessage m = null;
            try
            {
                m = JsonUtility.FromJson <FireworkMessage>(result);
            }
            catch (Exception e)
            {
                Debug.LogError(e + result);
                continue;
            }

            handleMessage(m);
        }
        Debug.Log("touchControl TCP thread end");
    }