Skip to content

Instantly share code, notes, and snippets.

@openroomxyz
openroomxyz / UnixEpochTime.cs
Created April 10, 2020 09:30
Unity : How to get number of seconds since 1970 ( Epochtime ) ?
public static int GetCurrentTime()
{
System.DateTime epochStart = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);
int cur_time = (int)(System.DateTime.UtcNow - epochStart).TotalSeconds;
return cur_time;
}
@openroomxyz
openroomxyz / WritingToBinaryFilesAppend.cs
Created April 10, 2020 11:17
Unity : How to write by appending to binary Files using FileStreams ?
using System.IO;
using (var fileStream = new FileStream(file_path, FileMode.Append, FileAccess.Write, FileShare.None))
using (var bw = new BinaryWriter(fileStream))
{
bw.Write(0.0f);
byte[] lotsOfData;
bw.Write(lotsOfData);
}
@openroomxyz
openroomxyz / ReadingBinFileUntilTheEnd.cs
Last active April 10, 2020 11:37
Unity : How to read Binary File Until The End of it (size not written inside file )?
private void ReadBinFile(string path, System.Action<Vector3, float> f)
{
if (!File.Exists(path)) //if file does not exist we will not try reading it
{
return;
}
BinaryReader br;
//reading from the file
@openroomxyz
openroomxyz / RenameFilesInFolderToGetUUIDNames.py
Created April 11, 2020 08:52
Python : How do i rename all files in folder so that they get UUID name (renaming all files in folder ) ?
import uuid
import os
def get_extension(name):
return name.split('.')[-1]
def get_list_of_files_only_in_folder(folder_path):
return [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))] #
def rename_all_files_inside_folder(folder_path):
@openroomxyz
openroomxyz / GenerateUUID?
Created April 11, 2020 08:57
Python : How to generate UUID?
import uuid
#How to generate random uuid?
print(str(uuid.uuid4()))
@openroomxyz
openroomxyz / ResizeImage.py
Last active April 11, 2020 10:07
Python : How to resize the image?
from PIL import Image
import os
def resizeImage(path_input, new_size):
folder = os.path.dirname(path_input)
name = os.path.basename(path_input)
out_file_extension = name.split('.')[-1] #you can use different than input if needed
img = Image.open(path_input)
img = img.resize((new_size[0],new_size[1]), Image.ANTIALIAS)
@openroomxyz
openroomxyz / GetPartsOfPath.py
Created April 11, 2020 10:06
Python : How to get parts of file path ( folder path, filename with extension, without , only extension ) ?
import os
def getPartsOfPath(path):
path_to_folder = os.path.dirname(path)
file_name_with_extension = os.path.basename(path)
file_name_without_extension, extension = os.path.splitext(file_name_with_extension)
return (path_to_folder, file_name_with_extension, file_name_without_extension, extension)
getPartsOfPath("C:\\Users\\C\\Desktop\\Cosmos\\test.png")
@openroomxyz
openroomxyz / HowToSetRenderTextureAsTextureProgramaticallyUnderHDRP.cs
Created April 11, 2020 21:04
Unity : How to set render texture as texture pragmatically under HDRP?
public static void SetBaseColorMap(ref Renderer renderer, in RenderTexture render_texture)
{
renderer.material.SetTexture("_BaseColorMap", render_texture);
}
@openroomxyz
openroomxyz / HowToSetRenderTextureAsTextureProgramaticallyUnderClassirRenderPipeline.cs
Created April 11, 2020 21:09
Unity : How to set render texture as texture pragmatically (classic render pipeline ) ?
//Make sure to enable the Keywords (You may not need todo this in a loop)
rend.material.EnableKeyword("_NORMALMAP");
rend.material.EnableKeyword("_METALLICGLOSSMAP");
//After that you can use this
rend.material.SetTexture("_MainTex", result_render_texture);
@openroomxyz
openroomxyz / ConvertOggToMp3.py
Created April 13, 2020 14:49
Python : How can i convert from ogg to mp3?
#you need to have installed pydub and conda
#conda install -c conda-forge ffmpeg
#conda install -c conda-forge pydub
from pydub import AudioSegment
path_file_input = "C://Users//X//Downloads//t_voice5812054872861705901.ogg"
path_file_output = "C://Users//X//Desktop//bip//audioX.mp3"
ogg_version = AudioSegment.from_ogg(path_file_input)
ogg_version.export(path_file_output, format="mp3")