Creating Basic Editor Tools
Tutorial
Intermediate
55 Mins
Overview
Overview
You have completed 0% of this Tutorial.
1.
Creating Basic Editor Tools
Summary
In this recorded training session from October 2016, we explore the basics of editor scripting, with a focus on creating tools which improve workflow for programmers, as well as for artists and level designers. We'll create simple tools to optimize the asset import workflow and to help place objects in your scene.
Topics we'll cover
Language
English
Recommended Unity Versions
5.4
Tutorial
Creating Basic Editor Tools
1.
Creating Basic Editor Tools
SpriteProcessor
using UnityEngine; using System.Collections; using UnityEditor; public class SpriteProcessor : AssetPostprocessor { void OnPostprocessTexture(Texture2D texture) { string lowerCaseAssetPath = assetPath.ToLower (); bool isInSpritesDirectory = lowerCaseAssetPath.IndexOf ("/sprites/") != -1; if (isInSpritesDirectory) { TextureImporter textureImporter = (TextureImporter) assetImporter; textureImporter.textureType = TextureImporterType.Sprite; } } }
SelectAllOfTag
using UnityEngine; using System.Collections; using UnityEditor; public class SelectAllOfTag : ScriptableWizard { public string searchTag = "Your tag here"; [MenuItem ("My Tools/Select All Of Tag...")] static void SelectAllOfTagWizard() { ScriptableWizard.DisplayWizard<SelectAllOfTag> ("Select All Of Tag...", "Make Selection"); } void OnWizardCreate() { GameObject[] gameObjects = GameObject.FindGameObjectsWithTag (searchTag); Selection.objects = gameObjects; } }
Character
using UnityEngine; using System.Collections; public class Character : MonoBehaviour { public Texture2D portrait; public string nickname; public Color color; public PlayerMovement playerMovement; }
CreateCharacterWizard
using UnityEngine; using System.Collections; using UnityEditor; public class CreateCharacterWizard : ScriptableWizard { public Texture2D portraitTexture; public Color color = Color.white; public string nickname = "Default nickname"; [MenuItem ("My Tools/Create Character Wizard...")] static void CreateWizard() { ScriptableWizard.DisplayWizard<CreateCharacterWizard> ("Create Character", "Create new", "Update selected"); } void OnWizardCreate() { GameObject characterGO = new GameObject (); Character characterComponent = characterGO.AddComponent<Character> (); characterComponent.portrait = portraitTexture; characterComponent.color = color; characterComponent.nickname = nickname; PlayerMovement playerMovement = characterGO.AddComponent<PlayerMovement> (); characterComponent.playerMovement = playerMovement; } void OnWizardOtherButton() { if (Selection.activeTransform != null) { Character characterComponent = Selection.activeTransform.GetComponent<Character>(); if (characterComponent != null) { characterComponent.portrait = portraitTexture; characterComponent.color = color; characterComponent.nickname = nickname; } } } void OnWizardUpdate() { helpString = "Enter character details"; } }