A native plugin for Unity that provides simple packet division and restoration.

Overview

uPacketDivision

This is a native plug-in that divides a given data (System.IntPtr or array) into specified sizes and restores them regardless of the input order. It is intended for use cases such as sending large data via UDP.

Install

  • Unity Package
  • Git URL (UPM)
    • Add https://github.com/hecomi/uPacketDivision.git#upm to Package Manager.
  • Scoped Registry (UPM)
    • Add a scoped registry to your project.
      • URL: https://registry.npmjs.com
      • Scope: com.hecomi
    • Install uPacketDivision in Package Manager.

Platforms

Currently, it is only built for Windows.

How to use

Divide

Create a Divider and call Divide() with the array as input (or System.IntPtr with the size). This will divide the packet internally.

Divider divider = new Divider();

void Divide()
{
    Texture2D image;
    var pixels = image.GetPixels32();
    divider.maxPacketSize = packetSize;
    divider.Divide(pixels);
}

Then, send the split data to the remote in some way. The following functions are available.

  • GetChunkCount().
    • the number of chunks.
  • GetChunk()
    • The byte[] array of the split data
  • GetChunkSize(int index).
    • The size of the split data.
  • GetChunkData(int index).
    • The pointer of the split data Here is an example of using uOSC.
uOSC.uOscClient client;

void Send(int width, int height)
{
    client.Send("/Size", width, height);

    for (uint i = 0; i < divider.GetChunkCount(); ++i)
    {
        client.Send("/Data", divider.GetChunk(i));
    }
}

If you want to use the pointer and size directly, please use GetChunkSize() and GetChunkData() instead.

Assemble

Use Assembler to assemble the data sent to you. Here is an example of the receiving part using uOSC.

Assembler assembler = new Assembler();
Texture2D texture;

public void OnDataReceived(uOSC.Message message)
{
    if (message.address == "/Size")
    {
        var w = (int)message.values[0];
        var h = (int)message.values[1];
        OnSize(w, h);
    }
    else if (message.address == "/Data")
    {
        var data = (byte[])message.values[0];
        OnData(data);
        CheckEvent();
    }
}

void OnSize(int w, int h)
{
    texture = new Texture2D(w, h);
}

void OnData(byte[] data)
{
    assembler.timeout = timeout;
    assembler.Add(data);
}

Each time you add data, check for the completion or loss as follows.

void CheckEvent()
{
    switch (assembler.GetEventType())
    {
        case EventType.FrameCompleted:
        {
            OnDataAssembled(assembler.GetAssembledData<Color32>());
            break;
        }
        case EventType.PacketLoss:
        {
            var type = assembler.GetLossType();
            Debug.LogWarning("Loss: " + type);
            break;
        }
        default:
        {
            break;
        }
    }
}

If you want to get a pointer and its size instead of an array, the following APIs are available.

var index = assembler.GetAssembledFrameIndex();
var data = assembler.GetFrameData(index);
var size = assembler.GetFrameSize(index);
OnDataAssembled(data, (int)size);
assembler.RemoveFrame(index);

Then, the data reconstruction will be completed as follows.

void OnDataAssembled(Color32[] pixels)
{
    texture.SetPixels32(pixels);
    texture.Apply();
    GetComponent<Renderer>().material.mainTexture = texture;
}
Owner
hecomi
Unity / C++ / JavaScript
hecomi
Crazy Taxi Dreamcast Restoration 2.0

Crazy Taxi Dreamcast Restoration 2.0 This plugin for Crazy Taxi restores the original licensed brands from the Arcade and Dreamcast versions. The orig

Silent 27 Jul 4, 2022
Restoration of The Linux Scheduler Simulator (LinSched)

Restoration of The Linux Scheduler Simulator (LinSched)

Jim Huang 13 Sep 3, 2021
A lightweight additive chiptune synthesizer (LV2 and Unity Plugin)

OvenMit Synthesizer kenakofer's first ever synthesizer! Coming initially out of BMusic's excellent tutoral series for lv2 synthesizers, the developer

Kenan Schaefkofer 7 Apr 18, 2022
Plays native alert sound and shows native dialogs/alerts in your Flutter app.

flutter_platform_alert 2021 © Weizhong Yang a.k.a zonble. A simple plugin to present native alerts, including playing alert sounds and showing alert d

Weizhong Yang a.k.a zonble 56 Aug 4, 2022
Visual Studio native debugger extension to help debug native applications using Mono.

Unity Mixed Callstack UnityMixedCallstack is a Visual Studio 2017/2019 extension to help debug native applications embedding Mono, like Unity. If you

Unity Technologies 73 Aug 5, 2022
Photon OS DPDK and Packet Generator, RT Test, TF2 docker image.

photongen Photon OS DPDK and packet generator , cyclictest , TF2 with CUDA docker image. DPKD libs The build proccess builds and installs all shared l

spyroot 4 Feb 7, 2022
AX.25 protocol (packet radio and APRS) interface / bridging / switching / terminal related software for Linux

CB3ROB-AX25-TOOLS-LINUX 2021-11-23T00:58:49Z (TUESDAY) cb3rob-kiss-tcp-attach.c links ax0 interface to KISS-TCP TNC, soundmodem (direwolf), or multipl

CB3ROB TACTICAL SYSTEMS 1 Jan 1, 2022
A lib to encode/decode Joycon Bluetooth packet.

libjoycon A Joycon packet encoding and decoding lib Build The library itself only links to the libm (math lib): mkdir build && cd build cmake .. make

Inoki 81 May 31, 2022
A Lilu plugin that makes System Information recognize your Realtek card reader as a native one

Realtek Card Reader Driver Friend Introduction A Lilu plugin that makes System Information recognize your Realtek card reader as a native one. Support

FireWolf 49 Jul 21, 2022
Epidemics is a UG4 Plugin that provides various algorithms for epidemics modeling.

Epidemics is a UG4 Plugin that provides various algorithms for epidemics modeling.

null 73 Mar 12, 2022
Tests to check the determinism of the basic floating point arithmetic operations on different devices, using Unity and Rust.

This repo contains tests to check the determinism (consistency) of the basic floating point arithmetic operations (add, subtract, multiply, divide) on

Erik Roystan 4 Dec 24, 2021
Useful cmake macros that help with: compiler/linker flags, collecting sources, PCHs, Unity builds and other stuff.

ucm - useful cmake macros ucm is a collection of cmake macros that help with: managing compiler/linker flags collecting source files with grouping in

Viktor Kirilov 192 Aug 11, 2022
Powerful automated tool for reverse engineering Unity IL2CPP binaries

Powerful automated tool for reverse engineering Unity IL2CPP binaries

Katy 1.9k Aug 5, 2022
A universal way to create a noclip mod in Unity games (Mono/IIL2CPP)

Universal-Unity-NoClip This projects aim to show how a noclip mod can be created in any unity game, regardless if its using an il2cpp or mono backend.

Jonah 21 Jul 24, 2022
Adds proper Apple Pencil support to Unity's InputSystem.

This project aims to create an Apple Pencil device for Unity's InputSystem package. The problem: Unity does not fully integrate with Apple Pencil. App

Oliver Smith 9 Jul 15, 2022
Unity Scripting in C++

Unity Native Scripting A library to allow writing Unity scripts in native code: C, C++, assembly. Purpose This project aims to give you a viable alter

Jackson Dunstan 1.1k Aug 5, 2022
Open source simulator for autonomous vehicles built on Unreal Engine / Unity, from Microsoft AI & Research

Welcome to AirSim AirSim is a simulator for drones, cars and more, built on Unreal Engine (we now also have an experimental Unity release). It is open

Microsoft 13.4k Aug 9, 2022
Unity project with an example on how to run the depthai library in Android.

depthai-android-unity-example Unity project (built with Unity 2020.3.25f1) with an example on how to run the depthai library in Android. Important Thi

Ibai Gorordo 18 Mar 13, 2022
HLSL to GLSL language translator based on ATI's HLSL2GLSL. Used in Unity.

HLSL to GLSL shader language translator ⚠️ As of mid-2016, the project is unlikely to have any significant developments. At Unity we are moving to a d

Aras Pranckevičius 517 Aug 4, 2022