123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- //================================================================================
- //
- //================================================================================
- using UnityEngine;
- using UnityEditor;
- using System.Collections;
- using System.IO;
- //================================================================================
- //
- //================================================================================
- namespace ReaderRabbit
- {
- //================================================================================
- //
- //================================================================================
- public class SetSpeechFrames : EditorWindow
- {
- //================================================================================
- //
- //================================================================================
- [MenuItem ("RR1ST Animation/Set speech frames (for [Character]_Speech object)")]
- static void WindowSetSpriteInChildren()
- {
- SetSpeechFrames window = (SetSpeechFrames)EditorWindow.GetWindow(typeof(SetSpeechFrames));
- }
-
- string m_FolderName = "";
- string m_BodyName = "";
- string m_FrameCount = "9";
- //================================================================================
- //
- //================================================================================
- void OnGUI()
- {
- EditorGUILayout.LabelField("1. Select the [Character]_Speech object (e.g. Characters->Reader->Reader_Speech).", EditorStyles.label);
- EditorGUILayout.LabelField("2. Set the folder name containing all the children frames in the text field below (e.g. 10050).", EditorStyles.label);
- m_FolderName = EditorGUILayout.TextField("Folder name", m_FolderName);
- EditorGUILayout.LabelField("3. Set the folder name containing the character body sprite in the text field below (e.g. 10051).", EditorStyles.label);
- m_BodyName = EditorGUILayout.TextField("Folder (body) name", m_BodyName);
- EditorGUILayout.LabelField("4. Set how many frames there are for the speech animation in the text field below (e.g. 9).", EditorStyles.label);
- m_FrameCount = EditorGUILayout.TextField("Frame count", m_FrameCount);
- EditorGUILayout.LabelField("5. Hit the button below.", EditorStyles.label);
- if (GUILayout.Button("Set Speech Frames"))
- SetChildren();
- }
-
- //================================================================================
- //
- //================================================================================
- void SetChildren()
- {
- // Get scene name, based on scene.unity filename.
- string sceneName = System.IO.Path.GetFileName(EditorApplication.currentScene);
- sceneName = sceneName.Substring(0, sceneName.Length - ".unity".Length);
- Transform parent = Selection.activeTransform;
- SpeechAnimation speechAnimation = parent.GetComponent<SpeechAnimation>();
- int frameCount = int.Parse(m_FrameCount);
- speechAnimation.SpriteFrames = new Sprite[frameCount];
- for (int i = 0; i < frameCount; ++i)
- {
- speechAnimation.SpriteFrames[i] = AssetDatabase.LoadAssetAtPath("Assets/Sprites/" + sceneName + "/" + m_FolderName + "/" + m_FolderName + "_" + i + ".png", typeof(Sprite)) as Sprite;
- }
- int index = 0;
- string oldName = "";
- SpriteRenderer spriteRenderer = null;
- string folderName = "";
- foreach (Transform child in parent.transform)
- {
- if (index == 0)
- {
- folderName = m_BodyName;
- }
- else if (index == 1)
- {
- folderName = m_FolderName;
- }
- // Rename children with prefix and add _0 at the end.
- oldName = child.name;
- child.name = folderName + "_0";
- KishiTechUnity.KishiTechDebug.KTDebug.Instance().Log("Renamed child \'" + oldName + "\' to \'" + child.name + "\'");
- // Associate the prefix_0.png sprite filename to the object's SpriteRenderer.
- spriteRenderer = child.GetComponent<SpriteRenderer>();
- spriteRenderer.sprite = AssetDatabase.LoadAssetAtPath("Assets/Sprites/" + sceneName + "/" + folderName + "/" + folderName + "_0.png", typeof(Sprite)) as Sprite;
- ++index;
- }
- ShowNotification(new GUIContent("Done."));
- }
- } // public class SetSpeechFrames : EditorWindow
- } // namespace KishiTechUnity
|