Skip to content

Instantly share code, notes, and snippets.

@DashW
DashW / ScreenRecorder.cs
Last active June 22, 2025 23:29
ScreenRecorder - High Performance Unity Video Capture Script
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Threading;
class BitmapEncoder
{
public static void WriteBitmap(Stream stream, int width, int height, byte[] imageData)
@nzhul
nzhul / LayersToPNG.jsx
Created January 26, 2016 23:09
Spine 2D - LayersToPNG.jsx fix for Photoshop CC
// This script exports photoshop layers as individual PNGs. It also
// writes a JSON file that can be imported into Spine where the images
// will be displayed in the same positions and draw order.
// Setting defaults.
var writePngs = true;
var writeTemplate = false;
var writeJson = true;
var ignoreHiddenLayers = true;
var pngScale = 1;
@xDavidLeon
xDavidLeon / UnityStandardBRDF.cginc
Created March 26, 2016 10:38
UnityStandardBRDF modification for Cel Shading.
#ifndef UNITY_STANDARD_BRDF_INCLUDED
#define UNITY_STANDARD_BRDF_INCLUDED
#include "UnityCG.cginc"
#include "UnityStandardConfig.cginc"
#include "UnityLightingCommon.cginc"
//-------------------------------------------------------------------------------------
// Legacy, to keep backwards compatibility for (pre Unity 5.3) custom user shaders:
#define unity_LightGammaCorrectionConsts_PIDiv4 (IsGammaSpace()? (UNITY_PI/4)*(UNITY_PI/4): (UNITY_PI/4))
@radiatoryang
radiatoryang / SkinnedMeshObjectPreviewExample.cs
Last active December 27, 2024 06:25
An example of a custom ObjectPreview rendering out a SkinnedMesh for Unity Editor C#... I used it for facial expressions and blendshape editing, you might want to use it for something else. I hereby place it under MIT License. Full write-up here: http://www.blog.radiator.debacle.us/2016/06/working-with-custom-objectpreviews-and.html
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
[CustomPreview(typeof(YourCustomScriptableObject))] // THIS IS VERY IMPORTANT, this is so the editor knows what this is supposed to be previewing at all
public class SkinnedMeshObjectPreviewExample : ObjectPreview {
PreviewRenderUtility m_PreviewUtility;
@luispedrofonseca
luispedrofonseca / RectUtils.cs
Created October 8, 2016 19:07
Unity Custom Rect Editor
using UnityEngine;
using UnityEditor;
public class RectUtils
{
public static Rect ResizeRect(Rect rect, Handles.DrawCapFunction capFunc, Color capCol, Color fillCol, float capSize, float snap)
{
Vector2 halfRectSize = new Vector2(rect.size.x * 0.5f, rect.size.y * 0.5f);
Vector3[] rectangleCorners =
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour {
public float moveSpeed = 3;
public float rotateSpeed = 3;
private GameObject lookTarget;
private GameObject cameraPositionTarget;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class PlayerMove : MonoBehaviour {
private Rigidbody rb;
public float speed = 20;
public float QBPower = 120;
@unitycoder
unitycoder / GyroAttitude.cs
Last active January 2, 2023 17:30
Gyroscope Camera Script
// https://www.digikey.com/Site/Global/Layouts/DownloadPdf.ashx?pdfUrl=E7EEB830E57D43B09CE51BD7DF0E74D8
void Start()
{
gyro = Input.gyro; // Store the reference for Gyroscope sensor gyro.enabled = true; //Enable the Gyroscope sensor
}
void Update()
{
if (Time.timeScale != 0)
{
@QXSoftware
QXSoftware / dependency_test.md
Last active March 25, 2024 14:59
资源依赖正确性测试

资源依赖正确性测试

本次测试包含对AssetDatabase.GetDependenciesEditorUtility.CollectDependencies这两个获取资源的依赖资源的 API 的测试,以及对于meta残留对打AssetBundle的影响。

AssetDatabase.GetDependencies

输入资源路径,例如Assets/Material/demo.mat,以路径形式返回该资源依赖的资源列表,例如Assets/Texture/demo.jpg

这个 API 返回的结果是“错误”的,也就是带残留的。比如某个材质,原本的shader引用了4个纹理,然后切换其shader为新的shader使之只引用一个纹理,这时AssetDatabase.GetDependencies返回的结果还是4个纹理。

@benloong
benloong / AssetBundleTool.cs
Created April 11, 2017 02:23
Unity4.x Build AssetBundle and generate dependence
using UnityEngine;
using System.Collections.Generic;
using UnityEditor;
using System.Linq;
public class AssetBundleManifest
{
public string AssetPath;
public HashSet<AssetBundleManifest> Parents = new HashSet<AssetBundleManifest>();
public HashSet<AssetBundleManifest> Children = new HashSet<AssetBundleManifest>();