Skip to content

Instantly share code, notes, and snippets.

@prodigga
prodigga / SSE_Download_Handler.md
Last active October 22, 2024 14:35
SSE's (Server-Sent Events) Download Handler

Whats this?

This is a custom UnityWebRequest Download Handler to support SSE's (Server-Sent Events) in Unity!

How to use it

Simply inhert SseDownloadHandlerBase and supply your own logic (Deserialise incoming lines, expose events, etc).

Then set the download handler to be an instance of your class.

webRequest.downloadHandler = new LogSseExampleDownloadHandler();
private static unsafe void ForceSetByteArrayLength(ref byte[] targetArray, long length)
{
if (length != 0)
{
fixed (byte* targetArrayPtr = &targetArray[0])
{
byte* lengthPtr = (byte*)&(length);
targetArrayPtr[-8] = lengthPtr[0];
targetArrayPtr[-7] = lengthPtr[1];
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(ThreadsafeCurve))]
public class ThreadsafeCurvePropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
@prodigga
prodigga / ThreadsafeCurve.cs
Last active May 5, 2018 10:22
Thread Safe Curve, Unity
[System.Serializable]
public class ThreadsafeCurve : ISerializationCallbackReceiver
{
[SerializeField]
private AnimationCurve _curve;
private Dictionary<int, float> _precalculatedValues;
//Returns the Y value of the curve at X = time. Time must be between 0 - 1.
public float Evaluate(float time)
@prodigga
prodigga / Transform.java
Last active April 23, 2018 18:23
3D transform system similar to Unity3D for libGDX
package com.pigeoncoop.extensions;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.*;
import com.badlogic.gdx.utils.Array;
/**
* 3D transform system similar to Unity3D for libGDX
* @author Tim Aksu - timur.s.aksu@gmail.com
*/
@prodigga
prodigga / ScriptableAssetCreator.cs
Last active May 13, 2018 07:06
Right click on any script in your project that defines a ScriptableObject and create a ScriptableObject asset out of it! See here http://imgur.com/a/e7FDR#0 NOTE: This script was made somewhat redundant with the introduction of the [CreateAssetMenu] attribute - look it up :)
using UnityEditor;
using UnityEngine;
/// <summary>
/// Right click on any script in your project that defines a ScriptableObject
/// and create a ScriptableObject asset out of it! See here http://imgur.com/a/e7FDR#0
/// </summary>
/// <author>Tim Aksu</author>
/// <email>timur.s.aksu@gmail.com</email>
public static class ScriptableObjectUtility