Taken from http://nielson.io/2016/04/2d-sprite-outlines-in-unity/ for safe keeping
using UnityEditor; | |
using UnityEngine; | |
[CustomEditor(typeof(MeshFilter))] | |
public class NormalsVisualizer : Editor { | |
private const string EDITOR_PREF_KEY = "_normals_length"; | |
private Mesh mesh; | |
private MeshFilter mf; | |
private Vector3[] verts; |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.EventSystems; | |
using UnityEngine.UI; | |
[RequireComponent(typeof(ScrollRect))] | |
public class ScrollRectAutoScroll : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler | |
{ | |
public float scrollSpeed = 10f; | |
private bool mouseOver = false; |
using System; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public enum State { | |
Idle = 0, | |
InMenu = 1, | |
InGame = 2, | |
InGameMuffled = 3, | |
EndGame = 4, |
// Original shader by @bgolus, modified slightly by @alexanderameye for URP, modified slightly more | |
// by @gravitonpunch for ECS/DOTS/HybridRenderer. | |
// https://twitter.com/bgolus | |
// https://medium.com/@bgolus/the-quest-for-very-wide-outlines-ba82ed442cd9 | |
// https://alexanderameye.github.io/ | |
// https://twitter.com/alexanderameye/status/1332286868222775298 | |
Shader "Hidden/Outline" | |
{ | |
Properties |
Some code allocates memory when running in the editor and not on the device. This is due to Unity doing some extra error handling so possible error messages can be output in the console. Much of this code is stripped during build. It's therefore important to profile on device, and do it regularly.
Optimizations often makes code more rigid and harder to reason. Don't do it until you really need to.
When profiling, wrap methods or portions of a method in Profiler.BeginSample(string name) and Profiler.EndSample() to make them easier to find in the profiler.
public class SomeClass {
- Understanding your data.
Mike Acton from Insomniac Games said that in order to understand the problem, you need to understand the data. If you don’t understand any of them you will never find the optimal solution.
- Focusing on the data flow and how data is read and written.
Copied from https://jakobknudsen.wordpress.com/2013/08/06/altitude-fog/ for archival purpose.
When you submerge an object in water you expect it to become more and more obscured as it sinks further into the depths. As far as I can see, this is usually accomplished in Unity3D with a fullscreen image-effect like the global fog standard asset. But that only works in the pro-version of Unity, and I want something that works in the free version. This post shows my solution.
In Unity3D, you can implement your own custom fog on a material by writing your own final color function in a custom shader. The final color function is applied after any lightning has been applied, so we wont have lightsources brightening up objects that are supposed to be hidden. The incredibly useful Surface Shader Examples page in the Unity documentation includes an example titled “Custom Fog with Final Color Modifier”, where a custom finalcolor function is used to apply fog based on the vertical position of the pixel in screenspace. Thi
IEnumerator Shake() { | |
float elapsed = 0.0f; | |
Vector3 originalCamPos = Camera.main.transform.position; | |
while (elapsed < duration) { | |
elapsed += Time.deltaTime; | |
// For Unity versions newer than 2017.1 | |
using UnityEditor; | |
[InitializeOnLoad] | |
public class DetectPlayModeChanges { | |
static DetectPlayModeChanges() { | |
EditorApplication.playModeStateChanged += OnPlayModeStateChanged; | |
} |