コード例 #1
0
ファイル: Die.cs プロジェクト: wcasanova/ElectronicDice
    public IEnumerator DownloadAnimationSet(AnimationSet outSet)
    {
        // Request the anim set from the die
        SendMessage(new DieMessageRequestAnimSet());

        // Now wait for the setup message back
        int animCount = 0;

        yield return(StartCoroutine(WaitForMessage(DieMessageType.TransferAnimSet, (msg) =>
        {
            var setupMsg = (DieMessageTransferAnimSet)msg;
            animCount = setupMsg.count;
        })));

        // Got the message, acknowledge it
        StartCoroutine(SendMessage(new DieMessageTransferAnimSetAck()));

        outSet.animations = new RGBAnimation[animCount];
        for (int i = 0; i < animCount; ++i)
        {
            byte[] animData = null;
            yield return(StartCoroutine(DownloadBulkData((buf) => animData = buf)));

            outSet.animations[i] = RGBAnimation.FromByteArray(animData);

            // Tell die we're ready for next anim
            StartCoroutine(SendMessage(new DieMessageTransferAnimReadyForNextAnim()));
        }

        // We've read all the anims!
    }
コード例 #2
0
ファイル: Die.cs プロジェクト: wcasanova/ElectronicDice
    public IEnumerator UploadAnimationSet(AnimationSet set)
    {
        // Prepare the die
        var prepareDie = new DieMessageTransferAnimSet();

        prepareDie.count = (byte)set.animations.Length;
        prepareDie.totalAnimationByteSize = (short)set.GetTotalByteSize();
        Debug.Log("sending animation set setup");
        yield return(StartCoroutine(SendMessageWithAck(prepareDie, DieMessageType.TransferAnimSetAck)));

        Debug.Log("die is ready, sending animations");
        // Die is ready, perform bulk transfer for each of the animations
        foreach (var anim in set.animations)
        {
            Debug.Log("sending bulk data");
            byte[] animBytes = RGBAnimation.ToByteArray(anim);
            yield return(StartCoroutine(UploadBulkData(animBytes)));

            Debug.Log("finished sending build data, waiting");
            // Then wait until the die is ready for the next anim bulk transfer
            yield return(StartCoroutine(WaitForMessage(DieMessageType.TransferAnimReadyForNextAnim, null)));

            Debug.Log("die is ready for next anim");
        }

        // We're done!
    }