Unity package with Editor and Runtime tools.
Note: If you use Assembly Definitions you have to add references to your Assembly Definition.
Add Archie.UnityTools.Editor.asmdef
in order to use Editor Tools.
Add Archie.UnityTools.Runtime.asmdef
in order to use Runtime Tools.
You can add the package dependency via Unity's Package Manager .
https://github.com/AnisimovArthur/UnityTools.git
in the input field.The second option is to install via the manifest.
To use the package you have to add the dependency to the project's Packages/manifest.json file.
"com.archie.unitytools": "https://github.com/AnisimovArthur/UnityTools.git#1.0.5",
To update the package you have to update the dependency version in the project's Packages/manifest.json file.
For example:
Old: #0.5.1-preview
New: #1.0.5
Tool for delayed event execution.
using UnityEngine;
using UnityTools;
public class SchedulerExample : MonoBehaviour
{
private void Awake()
{
// Debug.Log should happens in 2 seconds.
var scheduled = Scheduler.Schedule(2.0f, () => Debug.Log("Hello World!"));
// First option to cancel Debug.Log("Hello World!") above
scheduled.Cancel();
// Second option to cancel Debug.Log("Hello World!") above
// Scheduler.Cancel(scheduled);
// As a result, you will see only "I'm a cat." in the console because "scheduled" was canceled above
Scheduler.Schedule(0.5f, delegate
{
Debug.Log("I'm a cat.");
});
}
}
Generic Event System. The Event System allows components to Subscribe, Unsubscribe, and Execute events.
using UnityEngine;
using UnityTools;
public class ExampleComponent : MonoBehaviour
{
private void Awake()
{
EventHandler.Subscribe<string, GameObject>("FirstEvent", PrintMessage);
EventHandler.Subscribe("SecondEvent", PrintHello);
EventHandler.Unsubscribe("SecondEvent", PrintHello);
EventHandler.Execute("FirstEvent", Time.time.ToString(), gameObject);
EventHandler.Execute("SecondEvent");
EventHandler.Subscribe(gameObject, "LocalEvent", PrintName);
EventHandler.Execute(gameObject, "LocalEvent");
}
private void PrintHello()
{
Debug.Log("Hello");
}
private void PrintName()
{
Debug.Log(name);
}
private void PrintMessage(string message, GameObject obj)
{
Debug.Log(message + " " + obj.name);
}
}
As a result, you will see in the console
1) 0 GameObject
You will not see "Hello" a second time because you are unsubscribing from this event in the code.
Then you will see the names of the components as much as you have GameObjects with that component because, we are using "LocalEvent" to use the local Event system on the local object.
Tool to use Pooled GameObjects.
using System.Collections.Generic;
using UnityEngine;
using UnityTools;
public class Example : MonoBehaviour
{
[SerializeField] private GameObject prefab;
void Start()
{
var pooledObjects = new List<GameObject>();
for (int i = 0; i < 100; i++)
pooledObjects.Add(ObjectPool.Get(prefab));
for (int i = 0; i < 100; i++)
ObjectPool.Return(pooledObjects[i]);
}
}
Extra gizmos for default UnityEngine.Gizmos.
using UnityEngine;
using UnityTools;
private void OnDrawGizmos()
{
GizmosPro.DrawWireCylinder(transform.position, transform.up, 2.5f, 5, Color.green);
GizmosPro.DrawWireCircle(transform.position, transform.up, 2.5f, Color.red);
}
Using PlayerPrefsPro to save/get a value of custom types from PlayerPrefs.
Supported types:
using UnityTools;
// Boolean
PlayerPrefsPro.GetBool("BoolKey");
// System.DateTime
PlayerPrefsPro.SetDateTime("DateTimeKey", System.DateTime.Now);
Easy-to-use Singleton implementation.
using UnityTools;
public class Example : Singleton<Example>
{
}
The minimum code to add a custom tool to the toolbar:
using UnityEditor;
using UnityTools.Editor;
[InitializeOnLoad]
public class ToolbarExample
{
static ToolbarExample()
{
ToolbarTools.AddTool(new ToolbarButton(), ToolbarSide.Right);
}
}
static ToolbarExample()
{
ToolbarTools.AddTool(new ToolbarButton("Button", PrintMessage), ToolbarSide.Left);
}
private static void PrintMessage()
{
UnityEngine.Debug.Log("Editor button clicked.");
}
static ToolbarExample()
{
var genericMenu = new GenericMenu();
genericMenu.AddItem(new UnityEngine.GUIContent("Load scene Game"), false, () => LoadSceneByName("Game"));
ToolbarTools.AddTool(new ToolbaPopup(genericMenu, "My Popup"), ToolbarSide.Right);
}
private static void LoadSceneByName(string name)
{
UnityEditor.SceneManagement.EditorSceneManager.LoadScene(name);
}
static ToolbarExample()
{
ToolbarTools.AddTool(new ToolbarLabel("My Label"), ToolbarSide.Left);
}
You can provide a tool icon as shown below.
static ToolbarExample()
{
var icon = Resources.Load<Texture>($"YOUR_PATH_TO_ICON");
ToolbarTools.AddTool(new ToolbarButton("Button", icon), ToolbarSide.Left);
}
This tool is developed by Toolbar functionality. You can easily add quick access to your scenes.
using UnityEditor;
using UnityTools.Editor;
[InitializeOnLoad]
public static class ToolbarLoaderToolExample
{
static ToolbarLoaderToolExample()
{
ToolbarSceneLoader.AddScene("Scene 1", "Content/Scenes/1.unity");
ToolbarSceneLoader.AddSeparator("Other Scenes");
ToolbarSceneLoader.AddScene("Test Scenes/Test Scene 1", "Content/Scenes/Test/Test 1");
}
}
using UnityEngine;
#if UNITY_EDITOR
using UnityTools.Editor;
#endif
public class Example : MonoBehaviour
{
private const string ExampleString = "Example string";
#if UNITY_EDITOR
[Button("Do Log ExampleString")]
private void DoSomething()
{
Debug.Log(ExampleString);
}
#endif
}
Note: you have to use Platform dependent compilation in order to have an Inspector Button in Runtime code.
Using EditorPrefsPro to save/get a value of custom types from EditorPrefs.
Supported types:
using UnityTools.Editor;
// Bool
EditorPrefsPro.SetBool("BoolKey", true);
// System.DateTime
EditorPrefsPro.SetDateTime("DateTimeKey", System.DateTime.Now);
This package licensed under the MIT license.