Created
May 12, 2014 11:24
-
-
Save snaka/a79a03ae177f39c1d841 to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class TweenGroupManager : EditorWindow { | |
class TweenGroup { | |
public int GroupNo = 0; | |
public List<UITweener> Tweeners = new List<UITweener>(); | |
public TweenGroup(int a_groupNo) { | |
GroupNo = a_groupNo; | |
} | |
} | |
SortedDictionary<int, TweenGroup> m_tweenGroups = new SortedDictionary<int, TweenGroup>(); | |
Stack<bool> m_guiEnableFlagBackups = new Stack<bool>(); | |
[MenuItem("Window/TweenGroupManager")] | |
public static void ShowWindow() { | |
EditorWindow win = EditorWindow.GetWindow<TweenGroupManager>(); | |
win.title = "TweenGroupManager"; | |
} | |
void OnInspectorUpdate() { | |
// reset collection | |
foreach(TweenGroup grp in m_tweenGroups.Values) { | |
if (grp.Tweeners == null) continue; | |
grp.Tweeners.Clear(); | |
} | |
m_tweenGroups.Clear(); | |
// Collect all UITweener by each tweenGroup | |
UITweener[] newTweeners = (UITweener[])GameObject.FindObjectsOfType(typeof(UITweener)); | |
foreach(UITweener tw in newTweeners) { | |
if (!m_tweenGroups.ContainsKey(tw.tweenGroup)) { | |
m_tweenGroups.Add(tw.tweenGroup, new TweenGroup(tw.tweenGroup)); | |
} | |
m_tweenGroups[tw.tweenGroup].Tweeners.Add (tw); | |
} | |
} | |
void OnGUI() { | |
GameObject go = NGUIEditorTools.SelectedRoot(); | |
BeginGUIEnableIfPlaying(); | |
foreach(TweenGroup grp in m_tweenGroups.Values) { | |
// Label : #(tweenGroup) | |
EditorGUILayout.LabelField(string.Format ("#{0}", grp.GroupNo)); | |
GUILayout.BeginHorizontal(); | |
GUILayout.BeginHorizontal(GUILayout.Width(90)); | |
// Button : PlayAll | |
if (GUILayout.Button ("PlayAll", GUILayout.Width(50))) { | |
foreach(UITweener tw in grp.Tweeners) { | |
if (!NGUITools.GetActive(go)) { | |
NGUITools.SetActive(go, true); | |
} | |
// Play tween froward | |
tw.Play (true); | |
tw.Reset (); | |
} | |
} | |
// Button : PlayAll(reverse) | |
if (GUILayout.Button ("<<", GUILayout.Width(30))) { | |
foreach(UITweener tw in grp.Tweeners) { | |
if (!NGUITools.GetActive(go)) { | |
NGUITools.SetActive(go, true); | |
} | |
// Play tween reverse | |
tw.Play (false); | |
tw.Reset (); | |
} | |
} | |
GUILayout.EndHorizontal(); | |
GUILayout.BeginVertical(); | |
if (grp.Tweeners != null) { | |
foreach(UITweener tw in grp.Tweeners) { | |
GUILayout.BeginHorizontal(); | |
// BUtton : play forward | |
if (GUILayout.Button(tw.gameObject.name)) { | |
tw.Play (true); | |
tw.Reset (); | |
} | |
// Button : play reverse | |
if (GUILayout.Button ("<<", GUILayout.Width (30))) { | |
tw.Play (false); | |
tw.Reset (); | |
} | |
GUILayout.EndHorizontal(); | |
} | |
} | |
GUILayout.EndVertical(); | |
GUILayout.EndHorizontal(); | |
} | |
EndGUIEnableIfPlaying(); | |
} | |
void BeginGUIEnableIfPlaying() { | |
m_guiEnableFlagBackups.Push(GUI.enabled); | |
GUI.enabled = Application.isPlaying; | |
} | |
void EndGUIEnableIfPlaying() { | |
GUI.enabled = m_guiEnableFlagBackups.Pop (); | |
} | |
void BeginGUIEnableIfEditing() { | |
m_guiEnableFlagBackups.Push (GUI.enabled); | |
GUI.enabled = !Application.isPlaying; | |
} | |
void EndGUIEnableIfEditing() { | |
GUI.enabled = m_guiEnableFlagBackups.Pop (); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment