Skip to content

Instantly share code, notes, and snippets.

@travelhawk
Last active September 10, 2019 15:18
Show Gist options
  • Save travelhawk/49f0672f5f4a3dbbcc0e9d7cb70c5c75 to your computer and use it in GitHub Desktop.
Save travelhawk/49f0672f5f4a3dbbcc0e9d7cb70c5c75 to your computer and use it in GitHub Desktop.
Adds an "IUnified Interface" to the create asset context menu in Unity3D. The template creates the appropriate container needed for IUnified automatically.
using System;
public interface #SCRIPTNAME# {
}
[Serializable]
public class #SCRIPTNAME#Container : IUnifiedContainer<#SCRIPTNAME#> {}
  1. Save script.
  2. Drop these script template in: /Program Files/Unity/Editor/Data/Resources/ScriptTemplates (Win) /Applications/Unity.app/Contents/Resources/ScriptTemplates (Mac) /opt/Unity/Editor/Data/Resources/ScriptTemplates (Linux)
  3. Restart Unity
  4. Create Interface through context menu, enjoy and build better software =)

OR (even easier)

  1. Put DownloadIUnifiedTemplate.cs inside your Asset folder (see script below)
  2. Click Menu -> Tools -> Add IUnified Template
  3. Restart

Link to IUnified: https://assetstore.unity.com/packages/tools/localization/iunified-12117

PS: I'm not related to the author of this awesome little tool.

using System.Collections;
using System.IO;
using UnityEditor;
using UnityEngine;
using UnityEngine.Networking;
/// <summary>
/// Download template from gist. Placed in the menu under "Tools".
/// </summary>
public class DownloadIUnifiedTemplate {
/// <summary>
/// Add IUnified Interface from Gist to context menu.
/// </summary>
[MenuItem("Tools/Add IUnified Template")]
private static void AddCustomTemplate()
{
string gistUrl = @"https://gist.githubusercontent.com/travelhawk/49f0672f5f4a3dbbcc0e9d7cb70c5c75/raw";
UnityWebRequest webRequest = UnityWebRequest.Get(gistUrl);
webRequest.SendWebRequest().completed += (asyncOp) =>
{
if (webRequest.isHttpError || webRequest.isNetworkError)
{
Debug.Log("can't download template: " + webRequest.error);
}
else
{
// save to templates
string fileName = "82-IUnified Interface-INewInterface.cs.txt";
string content = webRequest.downloadHandler.text;
string unityTemplatePath = Path.Combine(EditorApplication.applicationContentsPath, "Resources/ScriptTemplates");
string templateFilePath = Path.Combine(unityTemplatePath, fileName);
if (!File.Exists(templateFilePath))
{
File.WriteAllText(templateFilePath, content);
AssetDatabase.Refresh();
Debug.Log("Saved template successfully. Please restart Unity to see the changes.");
}
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment