Skip to content

Instantly share code, notes, and snippets.

Yurii Selinnyi quizcanners

Block or report user

Report or block quizcanners

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View SimplePegiTemplate.cs
// Article: https://medium.com/@quizcanners/unity-i-have-a-custom-editor-for-every-script-5eddf20fdacc
using System.Collections.Generic;
using PlayerAndEditorGUI;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class SomeScript : MonoBehaviour: IPEGI {
@quizcanners
quizcanners / ImageCropper.cs
Last active Apr 24, 2019
Image cropper for Unity. Doesn't change the texture, only allows to adjust rectangle. Works for a square Raw Image and any size of the texture.
View ImageCropper.cs
public RawImage img;
public float zoom = 1;
public float maxZoom = 2f;
public float scrollSpeed = 0.1f;
public float allignmentSpeed = 1f;
public Vector2 position = Vector2.one * 0.5f;
private Vector2 startPosition;
View GettingSmoothEdge.shader
inline float3 DetectSmoothEdge(float3 edge, float3 junkNorm, float3 sharpNorm, float3 edge0, float3 edge1, float3 edge2) {
edge = max(0, edge -0.965) * 28;
 float allof = edge.r + edge.g + edge.b;
float border = min(1, allof);
float3 edgeN = edge0*edge.r + edge1*edge.g + edge2*edge.b;
float junk = min(1, (edge.g*edge.b + edge.r*edge.b + edge.r*edge.g)*2);
return normalize((sharpNorm*(1- border)+ border*edgeN)*(1- junk) + junk*(junkNorm));
}
View SurfaceShaderCheatSheet.shader
// Transparency
alpha:fade // Means it is not a glass
Tags { "Queue" = "Transparent" "RenderType" = "Transparent" }
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
// Adjusting strength of the Normal
o.Normal = UnpackNormal(bump0);
o.Normal.xy *= wet;
o.Normal.z = 1;
View InspectwithPEGIinitializer.cs
using PlayerAndEditorGUI;
#if UNITY_EDITOR
using UnityEditor;
[CustomEditor(typeof(YourCoolClass))]
public class YourCoolClassDrawer : PEGI_Inspector<YourCoolClass> { }
[CustomEditor(typeof(YourCoolClass2BlaBlaBla))]
public class YourCoolClass2BlaBlaBlaDrawer : PEGI_Inspector<YourCoolClass2BlaBlaBla> { }
View ComparisonWithPEGI.cs
public bool Inspect()
{
if ("Object's Transparency:".edit(ref transparency))
RecalculateShaderParameters();
if (transparency != 0.5f && icon.Refresh.Click("Will load default value",25).nl())
transparency = 0.5f;
return false;
}
View ComparisonWithPEGI_NativeWay.cs
public override void OnInspectorGUI() {
var controller = (MyMaterialController )target;
EditorGUILayout.BeginHorizontal();
EditorGUI.BeginChangeCheck();
controller .transparency = EditorGUILayout.FloatField("Object's Transparency:", controller .transparency);
View MatrixOperations.cs
// https://gist.github.com/hecomi/9580605
//Dirctionary:
View Matrix : camera.worldToCameraMatrix
// How to project a texture:
//cs:
projectionMatrix = camera.projectionMatrix * camera.worldToCameraMatrix
//vert:
View Shader Notes.cs
// All functions: http://developer.download.nvidia.com/CgTutorial/cg_tutorial_appendix_e.html
// Performance
// Accessing with "_Name" is slower
Shader.SetGlobalFloat("_Name", value); // =>
int id = Shader.PropertyToID("_Name"); // Once at Start/ OnEnable
Shader.SetGlobalFloat(id, value);
// Trouble-shooting:
// Black Pixels on some devices = Division by zero
@quizcanners
quizcanners / Circle.shader
Last active Apr 25, 2019
Vert Frag Shader Template
View Circle.shader
// This is a starting point for most effects I make.
Shader "Playtime Painter/Effects/Circle" {
Properties{
_MainTex("Albedo (RGB)", 2D) = "white" {}
[Toggle(_DEBUG)] debugOn("Debug", Float) = 0
}
SubShader{
Tags{
You can’t perform that action at this time.