Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
‏‏‎

mika unitycoder

‏‏‎
View GitHub Profile
@aras-p
aras-p / foo.md
Last active October 7, 2025 16:28
Controlling fixed function states from materials/scripts in Unity

(typing off the top of my head, might not compile)

Since Unity 4.3:

In the shader, instead of writing Cull Off, write Cull [_MyCullVariable], the value will be fetched from the material or global float/int variable _MyCullVariable then.

You could have it be part of material, e.g. inside Properties block:

[Enum(Off,0,Front,1,Back,2)] _MyCullVariable ("Cull", Int) = 1
@JakubNei
JakubNei / Occlusion.Area.cs
Last active April 28, 2025 13:03
Lame Implementation of Area and Portal Occlusion Culling based on DOOM 3 BFG http://www.iddevnet.com/doom3/visportals.php https://github.com/id-Software/DOOM-3-BFG
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Extensions;
namespace Occlusion
{
public class Area : MonoBehaviour
{
@jimfleming
jimfleming / GrabScreenSwatch.cs
Created December 7, 2014 06:50
Uses an internal Unity3D utility function to grab chunks of the screen for blurring.
public static class GrabScreenSwatch {
public static Texture GrabScreenSwatch(Rect rect) {
int width = (int)rect.width;
int height = (int)rect.height;
int x = (int)rect.x;
int y = (int)rect.y;
Vector2 position = new Vector2(x, y);
Color[] pixels = UnityEditorInternal.InternalEditorUtility.ReadScreenPixel(position, width, height);
using (var client = new HttpClient())
{
var values = new List<KeyValuePair<string, string>>();
values.Add(new KeyValuePair<string, int>("n", "42"));
values.Add(new KeyValuePair<string, string>("s", "string value"));
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync("http://www.domain.org/receiver.aspx", content);
@MattRix
MattRix / MonoBehaviourInspector
Last active October 12, 2021 02:51
Allows you to use OnInspectorGUI in MonoBehaviour directly, rather than having to create a CustomEditor
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
[CustomEditor (typeof(MonoBehaviour),true)]
[CanEditMultipleObjects]
public class MonoBehaviourInspector : Editor
{
@FreyaHolmer
FreyaHolmer / ScriptableObjectSpawner.cs
Last active January 8, 2020 06:51
ScriptableObject asset spawner for Unity
// Adds a menu item for easy creation of your ScriptableObject types
// Usage: Right click in project view -> Create -> ScriptableObject... -> Select your type
// It will land in the root of your assets folder with the same name as your class
// Freya Holmér - webmaster@acegikmo.com
using UnityEngine;
using UnityEditor;
using System.Reflection;
using System.Linq;
using System.IO;
@3v1n0
3v1n0 / gpControl.json
Last active November 2, 2020 22:05
GoPro Hero4 Remote tools
{
"version":2.0,
"display_hints":[
{
"key":"GPCAMERA_GROUP_VIDEO",
"display_name":"Video Settings",
"settings":[
{
"setting_id":5,
"widget_type":"select",
@miketucker
miketucker / PhotoshopBlendModes
Created March 6, 2015 23:19
photoshop blending modes
/*
** Copyright (c) 2012, Romain Dura romain@shazbits.com
**
** Permission to use, copy, modify, and/or distribute this software for any
** purpose with or without fee is hereby granted, provided that the above
** copyright notice and this permission notice appear in all copies.
**
** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
** WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
@paralleltree
paralleltree / priorityqueue.cs
Created March 23, 2015 08:13
Implementation of priority queue in C#.
class PriorityQueue
{
public List<int> list;
public int Count { get { return list.Count; } }
public PriorityQueue()
{
list = new List<int>();
}
@xanathar
xanathar / MoonSharp_UserData_Runtime_Extension
Created March 31, 2015 15:52
Extend MoonSharp userdata at script runtime
public class MyObject
{
public int GetSomething()
{
return 10;
}
}
[Test]
public void MetatableExtensibleObjectSample()