예제 #1
0
    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!
    }
예제 #2
0
파일: Die.cs 프로젝트: ManicDesigns/Dice4
    IEnumerator UploadAnimationSetCr(AnimationSet set, System.Action <bool> callBack)
    {
        // Prepare the die
        var prepareDie = new DieMessageTransferAnimSet();

        prepareDie.paletteSize    = set.getPaletteSize();
        prepareDie.keyFrameCount  = set.getKeyframeCount();
        prepareDie.rgbTrackCount  = set.getRGBTrackCount();
        prepareDie.trackCount     = set.getTrackCount();
        prepareDie.animationCount = set.getAnimationCount();
        Debug.Log("Animation Data to be sent:");
        Debug.Log("palette: " + prepareDie.paletteSize * Marshal.SizeOf <byte>());
        Debug.Log("keyframes: " + prepareDie.keyFrameCount + " * " + Marshal.SizeOf <Animations.RGBKeyframe>());
        Debug.Log("rgb tracks: " + prepareDie.rgbTrackCount + " * " + Marshal.SizeOf <Animations.RGBTrack>());
        Debug.Log("tracks: " + prepareDie.trackCount + " * " + Marshal.SizeOf <Animations.AnimationTrack>());
        Debug.Log("animations: " + prepareDie.animationCount + " * " + Marshal.SizeOf <Animations.Animation>());
        bool timeout = false;

        yield return(StartCoroutine(SendMessageWithAckOrTimeoutCr(prepareDie, DieMessageType.TransferAnimSetAck, 3.0f, null, () => timeout = true)));

        if (!timeout)
        {
            Debug.Log("die is ready, sending animations");
            Debug.Log("byte array should be: " + set.ComputeAnimationDataSize());
            var setData = set.ToByteArray();
            yield return(StartCoroutine(UploadBulkDataCr(setData)));

            // We're done!
            Debug.Log("Done!");
            callBack?.Invoke(true);
        }
        else
        {
            Debug.Log("TimedOut");
            callBack?.Invoke(false);
        }
    }