Skip to content

Instantly share code, notes, and snippets.

@openroomxyz
openroomxyz / run.cs
Created April 1, 2020 09:24
Unity : How can i generate easily mesh that is bigger than 65535 vertex ? (The 16-bit limit)
mesh = new Mesh();
mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; //using 32 bit index insted 16 bit
@openroomxyz
openroomxyz / IntHexBinConverter.cs
Created April 1, 2020 09:28
Unity Editor : How to convert between Int <-> Hex <-> Bin ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class IntHexBinConverter : EditorWindow
{
//Converter 1 Variables
int converter_1_input_int = 0;
@openroomxyz
openroomxyz / TrinagleArea.cs
Created April 1, 2020 09:41
Unity : How to calculate the Area of Triangle in 3D?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class AreaOfTrinagle : EditorWindow
{
string objectBaseName = "";
int objectId = 1;
@openroomxyz
openroomxyz / MatrixRotateScaleTranslate.cs
Created April 1, 2020 09:48
Unity : How to rotate,scale, translate with matrix?
public static Matrix4x4 RotateX(float aAngleRad)
{
Matrix4x4 m = Matrix4x4.identity; // 1 0 0 0
m.m11 = m.m22 = Mathf.Cos(aAngleRad); // 0 cos -sin 0
m.m21 = Mathf.Sin(aAngleRad); // 0 sin cos 0
m.m12 = -m.m21; // 0 0 0 1
return m;
}
public static Matrix4x4 RotateY(float aAngleRad)
{
@openroomxyz
openroomxyz / GeneratorExample.cs
Created April 1, 2020 10:15
Unity C# : How to use Generators example?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Generator : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
var allNumbers = CosmosCount();
@openroomxyz
openroomxyz / HowdoIConvertAnArrayOfFloatsToAByteAndBack.cs
Created April 1, 2020 10:17
How do I convert an array of floats to a byte[] and back?
var floatArray1 = new float[] { 123.45f, 123f, 45f, 1.2f, 34.5f };
// create a byte array and copy the floats into it...
var byteArray = new byte[floatArray1.Length * 4];
Buffer.BlockCopy(floatArray1, 0, byteArray, 0, byteArray.Length);
// create a second float array and copy the bytes into it...
var floatArray2 = new float[byteArray.Length / 4];
Buffer.BlockCopy(byteArray, 0, floatArray2, 0, byteArray.Length);
@openroomxyz
openroomxyz / LearningFileStreams.cs
Created April 1, 2020 10:20
Unity : How to do bin File-streams?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class LearningFileStreams : MonoBehaviour
{
//https://www.tutorialspoint.com/csharp/csharp_binary_files.htm
void StartSSS()
{
@openroomxyz
openroomxyz / CalculateFPS.cs
Created April 1, 2020 10:21
How To calculate FSP?
//Call it in Update()
void CalculateFPS()
{
fps = (int)(1.0f / Time.smoothDeltaTime);
}
@openroomxyz
openroomxyz / CartesianToPolar.cs
Created April 1, 2020 10:22
Unity : How to convert from Cartesian to Polar 2d?
//Cartesian to polar 2d
float radius = Mathf.Sqrt((x * x) + (y * y));
float angle = Mathf.Atan2(y, x);
float angle = Mathf.Atan2(py, px) * Mathf.Rad2Deg; //To get degress much more usefull
//TO get from zero to 1 angle / (float)(365)
https://docs.unity3d.com/ScriptReference/Mathf.Atan2.html
@openroomxyz
openroomxyz / LineRendererExample_000.cs
Created April 1, 2020 10:25
Unity : Example Line-render Chaos ( FPS dependent rendering ).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//[ExecuteInEditMode]
public class LineRendererExample_000 : MonoBehaviour
{
public LineRenderer lineRenderer;