Skip to content

Instantly share code, notes, and snippets.

@openroomxyz
openroomxyz / gist:116a77511c90bcb3e3136b4753bf7cfe
Created April 21, 2020 11:54
Unity C# : How to call constructor of super class from child class?
class XYRGBA : Y2019.December.Day30.XYRGBA
{
public XYRGBA(int n) : base(n)
{
}
public void something()
{
@openroomxyz
openroomxyz / ExampleDrawGizmos.cs
Created April 21, 2020 11:51
Unity : Can i see an example of Using Gizmo Draw as debuging tool?
public class ExampleDrawGizmos : MonoBehaviour
{
//On draw Gizmos can display debugging information in the Unity Editor
//for easy visual debugging
//Gizmos will not show up in your final game.
//Gizmost are a debuging tool only, NOT a tool to make a game with xD
//This will draw in your sceneview, you can also see it in gameview if you would like to (
private void OnDrawGizmos()
@openroomxyz
openroomxyz / ImageFilePixelLevelOperation_Max.cs
Last active April 21, 2020 11:02
Uniy : How to compute pixel level Max on two PNG Images or on Two Texture2D of same size and generate resulting Texture2D or .png image?
class ImageFilePixelLevelOperation_Max
{
//Public functions
public static bool compute(string path_a, string path_b, string path_out)
{
if(!System.IO.File.Exists(path_a)) { return false; }
if(!System.IO.File.Exists(path_b)) { return false; }
Texture2D tex1 = ImageFilePixelLevelOperation_Max.LoadPNG(path_a);
Texture2D tex2 = ImageFilePixelLevelOperation_Max.LoadPNG(path_b);
@openroomxyz
openroomxyz / FileExist.cs
Created April 21, 2020 10:52
Unity : Does files exist?
System.IO.File.Exists(path);
@openroomxyz
openroomxyz / Texture2d_isSameSize.cs
Created April 21, 2020 10:27
Unity : How to find out is two Textures2D are the same size?
static bool Texture2d_isSameSize(in Texture2D a, in Texture2D b) { return ((a.width == b.width) && (a.height == b.height)); }
@openroomxyz
openroomxyz / Save_Texture2D.cs
Created April 21, 2020 10:26
Unity : How to save Texture2D to a File on Disk?
void Save_Texture2D(in Texture2D tex, string path)
{
byte[] bytes = tex.EncodeToPNG();
System.IO.File.WriteAllBytes(path, bytes);
}
//Usage example
//Save_Texture2D(result, @"C:\Users\x\Desktop\x\out.png");
@openroomxyz
openroomxyz / TakeSpherical360.cs
Last active April 20, 2020 10:12
Unity : How to record Spherical 360 Stereoscopic 3d Images ( snapshots, video frame ) ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TakeSpherical360 : MonoBehaviour
{
public Camera cam;
private RenderTexture renderTexture_left;
private RenderTexture renderTexture_right;
@openroomxyz
openroomxyz / freeResources.cs
Last active April 20, 2020 09:32
Unity : How to unload, free resources, memory?
UnityEngine.Resources.UnloadUnusedAssets();
//Resources.UnloadAsset();
//Destroy does nothing to help freeing memory
@openroomxyz
openroomxyz / Image_To_HTML_64_EncodedImage.py
Last active April 19, 2020 20:47
Python : How to generate html with base64 encoded image?
import base64
text = """
<html><body>
<img src="data:image/png;base64,ae8f0c79-2893-4a82-8576-7478e18a5356" alt="Red dot" />
</body></html>
"""
def Image_To_HTML_64_EncodedImage(path_to_image, out_path):
with open(path_to_image, "rb") as image_file:
@openroomxyz
openroomxyz / loopDic.cs
Created April 19, 2020 19:13
Unity C# : What is the best way to loop thru Dictionary ( dic ) ?
foreach(KeyValuePair<string, string> entry in myDictionary)
{
// do something with entry.Value or entry.Key
}