Created
October 17, 2017 17:10
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
namespace Emilio.Utilities | |
{ | |
public class PrefixAdder : ScriptableWizard { | |
[SerializeField] string prefix; | |
[SerializeField] string subfix; | |
[MenuItem("Tools/PreFix Subfix Adder", true)] | |
static bool CreateWizardValidator(){ | |
Transform[] transforms = Selection.GetTransforms(SelectionMode.ExcludePrefab); | |
return transforms.Length >= 1; | |
} | |
[MenuItem("Tools/PreFix Subfix Adder", false)] | |
static void CreateWizard(){ | |
ScriptableWizard.DisplayWizard("Prefix and Subfix Adder", typeof(PrefixAdder), "Create and Close" , | |
"Create"); | |
} | |
void OnWizardCreate(){ | |
ApplyPrefix(); | |
} | |
void ApplyPrefix() | |
{ | |
GameObject[] gos = Selection.gameObjects; | |
foreach (GameObject go in gos) | |
{ | |
var children = go.GetComponentsInChildren(typeof(Transform)); | |
foreach (Transform child in children) | |
{ | |
Undo.RegisterCompleteObjectUndo (child.gameObject, | |
"Added: " + (string.IsNullOrEmpty (prefix) ? "" : prefix + " ") + | |
(string.IsNullOrEmpty (subfix) ? "" : subfix)); | |
// Don't apply to root object. | |
if (child == go.transform) | |
continue; | |
if (!string.IsNullOrEmpty (prefix)) { | |
child.name = prefix + child.name; | |
} | |
if (!string.IsNullOrEmpty (subfix)) { | |
child.name = child.name + subfix; | |
} | |
} | |
} | |
} | |
void OnWizardOtherButton (){ | |
ApplyPrefix(); | |
} | |
void OnWizardUpdate(){ | |
Transform[] transforms = Selection.GetTransforms(SelectionMode.ExcludePrefab); | |
helpString = "Objects selected: " + transforms.Length; | |
errorString = ""; | |
isValid = true; | |
if(transforms.Length < 1){ | |
errorString += "No object selected to rename"; | |
} | |
isValid = string.IsNullOrEmpty(errorString); | |
} | |
void OnSelectionChange(){ | |
OnWizardUpdate(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment