Various tools or code snippets I developed when I was a Unity Game Developer
- Select Core.Complete asset
- Press on Build and Pack in the Inspector
- Wait for the compilation process to finish
- Save the resulting Unity Asset Package
- There are "normal" error displaying in Unity's console after the build is completed.
-
❗
Reload Assembly called from managed code directly. This will cause a crash. You should never refresh assets in synchronous mode or enter playmode synchronously from script code.
-
❗
InvalidOperationException: Operation is not valid due to the current state of the object
-
- Import this package to your project
- Follow the extra step of Core.Drawing Installation Notes
It is highly recommended to clone the project and try it yourself. Source
Sometimes you want to have an object in your scene accessible from everywhere. There is a well documented design pattern called "Singleton" and there are several examples on the internet on how to do it with Unity MonoBehaviours. Like this very good implementation
The default singletons use the RAII idiom which means "Resource aquisition is initialization" and they are persistent for the rest of the execution of the application. However, in Unity, you may not want this behavior all the time. For example, you may want a MonoBehaviour to be accessible everywhere from a scene but not necessarily lasting longer than the scene. You may also want to initialize fields on the MonoBehaviour in the scene.
There are 4 classes you can inherit from depending on which type of behavior you need.
Lifetime↓ / Creation method→ | RAII | Scene |
---|---|---|
Persistent | PersistentRAIISingleton | PersistentSceneSingleton |
Non-Persistent | RAIISingleton | SceneSingleton |
To appropriately clean up the singletons during scene destruction or execution ending in Unity Editor, your singletons should be implemented this way:
using UnityEngine;
using CoreEngine;
public class DemoRAIISingleton : RAIISingleton<DemoRAIISingleton>
{
int i = 0;
// Using public static methods provides better encapsulation for these implementations
public static void Foo()
{
// This check prevents the Singleton to be created while Unity Editor is quitting play or when switching scene. It causes bad object leaks.
if (IsAvailable)
{
// Call to Instance will create the instance
Debug.Log("DemoRAIISceneSingleton Bar " + Instance.i++);
}
}
}
using UnityEngine;
using CoreEngine;
public class DemoSceneSingleton : SceneSingleton<DemoSceneSingleton>
{
int i = 0;
// Using public static methods provides better encapsulation for these implementations
public static void Foo()
{
// This check prevents a null reference exception when the scene singleton is not present
if (IsAvailable)
{
// Instance does not create anything
Debug.Log("DemoSceneSingleton Bar " + Instance.i++);
}
}
}
- Right-click on an asset
- Select Find Reference(s)
- Look at Unity's console for this kind of output:
[ Selected File(s) ]
Assets/Varia/Stencils/3DimensionCube/Shader/3DStandardMask.shader
[ Direct Reference(s) ]
Assets/Varia/Stencils/3DimensionCube/Material/XMask.mat
Assets/Varia/Stencils/3DimensionCube/Material/YMask.mat
Assets/Varia/Stencils/3DimensionCube/Material/ZMask.mat
[ Indirect Reference(s) or Rare Assets that have both direct AND indirect reference on the selected asset(s) ]
Assets/Varia/Stencils/3DimensionCube/3DimensionCube.prefab
Assets/Varia/UnityUICommonMistakes/FindTheMistakes.unity
This tool helps to find "Missing" (even not visible ones) on several asset types (".prefab", ".asset" ".mat", ".unity", ".GUISkin", ".anim", and ".controller").
Open with "Window/Find Broken References"
You can instantiate any scriptable
through the Asset/Create/ScriptableObject
menu or Right-click and select Create/ScriptableObject
. A pop-up will appear somewhere in your screen, then select the type of scriptable object you want.
Unity sorts selection by "instance id" which is fine most of the time. When you need to drag ordered assets in an array or in the Hierarchy it can be a real hassle.
With Ordered Drag you just drag what you need ordered on the Ordered Drag window then you drag it out on where you need it. The result will be sorted in alphabetical order instead of using "instance id".
This feature is accessible through menu item "Window/Ordered Drag".
Note: It may not be the most intuitive tool to use however it is the only way I found to do this. It is not possible to sort a selection while it is dragged (Ex: through shortcut or with a mouse over).
Unity pretty much opens all text files in the External Script Editor configured in External Tools (Ex: MonoDevelop or Visual Studio). If you want to use other editors for certain type of files, check the file and it will open it with the operating system's default editor. You can specify the syntax when Unity wants to open it at a specific line. See the documentation of the editor.
Examples:
"{0}":{1}
will send"path/to_the_file.cs":154
"{0}" --line {1}
will send"path/to_the_file.cs" --line 154
Some text editors are much more complicated to configure. This tool allows you to specify the exact terminal command to execute the desired text editor.
Through the menu Help/Open Project Documentation (readme.md)
you can open the documentation of your project. It makes it more accessible.
Original | RGBA Without Dithering | RGBA With Dithering |
---|---|---|
. |
This tool automatically converts 16bit images assets using dithering through ImageMagick.
- After installing the Unity Asset Package in your project
- locate the zip file located in Assets/Core.Drawing/ExternalTools.zip
- Unzip this archive at the root of your project folder (At the same level of
Assets
,Library
,ProjectSettings
, etc.) - Delete the folder
Assets/Core.Drawing
Adds a second normalized coordinate relative to the UI element. It allows to create special shaders in order to overlay the element (or else).
A 3 dimensional cube (not a pleonasm)
Special thanks to @elaberge for several contributions.
Note: The image belongs to it's original owner and therefore is not part of this repository's licence.