Skip to content

Instantly share code, notes, and snippets.

@openroomxyz
openroomxyz / CreateMaterial.cs
Created April 21, 2020 12:26
Unity : How can we generate material in code?
Vector3 pos = new Vector3(x, y, z);
GameObject cube = GameObject.Instantiate(block, pos, Quaternion.identity);
cube.GetComponent<Renderer>().material = new Material(Shader.Find("Standard"));
cube.GetComponent<Renderer>().material.color = Random.ColorHSV();
cube.name = x + "_" + y + "_" + z;
@openroomxyz
openroomxyz / CreateQuard.cs
Created April 21, 2020 12:24
Unity : How can i procedural generate geometry, create object, attach material to it? (example)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CreateQuard : MonoBehaviour
{
public Material material;
// Start is called before the first frame update
void Start()
@openroomxyz
openroomxyz / example.py
Created April 21, 2020 12:23
Blender Python : How we can create animations in CODE? [ An example ]
import bpy
start_position = [-31, 138, 2.7]
positions = [ [0,3,2], [4, 1, 6], [3, -5, 1], [3, 10, 1], [1, 8, 1]]
def set_object_a_keyframe_for_location(name, xyz, frame_num):
ob = bpy.data.objects[name]
bpy.context.scene.frame_set(frame_num)
ob.location = xyz
ob.keyframe_insert(data_path="location", index = -1)
@openroomxyz
openroomxyz / SaveSystem.cs
Created April 21, 2020 12:19
Unity : How to save game data in bin format at runtime by serializing objects ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
public static class SaveSystem
{
@openroomxyz
openroomxyz / ProceduralPlate.cs
Created April 21, 2020 12:14
Unity : Can i see an example of how to generate Procedural Geometry and Material and Texture -s?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ProceduralPlate : MonoBehaviour
{
public Material material;
// Start is called before the first frame update
void Start()
@openroomxyz
openroomxyz / Threadqueuer.cs
Created April 21, 2020 12:12
Unity : Can i see an example of how to do simple native threaded code?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading;
using System;
public class Threadqueuer : MonoBehaviour
{
List<Action> functionsToRunInMainThread;
@openroomxyz
openroomxyz / list.txt
Created April 21, 2020 12:09
Unity Shaders Cg : Can i get the list of build in function -s ?
Appendix A - CG Function List
abs( x )
Absolute value of x .
acos( x )
Arccos of x in range [0, pi], x in [-1, 1].
all( x )
true if all components of x != 0 - false otherwise.
@openroomxyz
openroomxyz / TagsAndLayers.cs
Created April 21, 2020 12:05
Unity : How to in code create / delete / check for existence of tags and layers ?
using UnityEditor;
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Cosmos
{
@openroomxyz
openroomxyz / addTagToGameObject.cs
Created April 21, 2020 12:01
Unity : How do we set tag to gameObject?
this.gameObject.tag = "Terrain"; //Note that you can’t attract gameObject to a tag that was not created, … but you can create is in code
@openroomxyz
openroomxyz / BasicObjectSpawner.cs
Created April 21, 2020 11:58
Unity : How to make simple Editor script?
using UnityEditor;
using UnityEngine;
public class BasicObjectSpawner : EditorWindow
{
string objectBaseName = "";
int objectId = 1;
GameObject objectToSpawn;
float objectScale;
float spawnRadius = 5f;