12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- //================================================================================
- //
- //================================================================================
- using UnityEngine;
- using UnityEditor;
- using System.Collections;
- using System.IO;
- //================================================================================
- //
- //================================================================================
- namespace ReaderRabbit
- {
- //================================================================================
- //
- //================================================================================
- public class SpriteChildren : EditorWindow
- {
- //================================================================================
- //
- //================================================================================
- [MenuItem ("RR1ST Animation/Set sprite in children (for [Character]_Animator child objects)")]
- static void WindowSetSpriteInChildren()
- {
- SpriteChildren window = (SpriteChildren)EditorWindow.GetWindow(typeof(SpriteChildren));
- }
- string m_ParentFolderName = "";
- string m_FolderName = "";
- //================================================================================
- //
- //================================================================================
- void OnGUI()
- {
- EditorGUILayout.LabelField("1. Select the child of [Character]_Animator (e.g. Characters->Reader->Reader_Animator->Blink).", EditorStyles.label);
- EditorGUILayout.LabelField("2. Set the folder name containing all the children frames in the text field below (e.g. 10055).", EditorStyles.label);
- m_ParentFolderName = EditorGUILayout.TextField("Parent folder name (leave blank for default)", m_ParentFolderName);
- m_FolderName = EditorGUILayout.TextField("Folder name", m_FolderName);
- EditorGUILayout.LabelField("3. Hit the button below.", EditorStyles.label);
- if (GUILayout.Button("Set Sprite In Children"))
- SetChildren();
- }
-
- //================================================================================
- //
- //================================================================================
- void SetChildren()
- {
- // Get scene name, based on scene.unity filename.
- string sceneName = "";
- if (string.IsNullOrEmpty(m_ParentFolderName))
- {
- sceneName = System.IO.Path.GetFileName(EditorApplication.currentScene);
- sceneName = sceneName.Substring(0, sceneName.Length - ".unity".Length);
- }
- else
- {
- sceneName = m_ParentFolderName;
- }
- Transform parent = Selection.activeTransform;
- string oldName = "";
- SpriteRenderer spriteRenderer = null;
- int index = 0;
-
- foreach (Transform child in parent.transform)
- {
- // Rename children with prefix and add _N at the end.
- oldName = child.name;
- child.name = m_FolderName + "_" + index;
- KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Renamed child \'" + oldName + "\' to \'" + child.name + "\'");
- // Associate the prefix_N.png sprite filename to the object's SpriteRenderer.
- spriteRenderer = child.GetComponent<SpriteRenderer>();
- spriteRenderer.sprite = AssetDatabase.LoadAssetAtPath("Assets/Sprites/" + sceneName + "/" + m_FolderName + "/" + m_FolderName + "_" + index + ".png", typeof(Sprite)) as Sprite;
- ++index;
- }
- ShowNotification(new GUIContent("Done."));
- }
- } // public class SpriteChildren : EditorWindow
- } // namespace KishiTechUnity
|