Search Unity

Timeline w/ multiple animations - custom EditorWindow issues

Discussion in 'Scripting' started by livemixlove, Mar 15, 2010.

  1. livemixlove

    livemixlove

    Joined:
    Sep 16, 2009
    Posts:
    17
    Hi There,

    I need to make an editor extension that can control the current time of animations of more than one animation. I'm trying to sync up a bunch of different animations with a music file, so I need to be able to quickly fast forward/rewind/go_to_end (etc) while STILL IN EDIT MODE. My plan was to make a slider that controls one master GameObject's animation. That game object would then signal all of it's followers to be at the same time in their animations.

    Any good ideas for how to do this?

    How I've been trying to do it is by making a custom EditorWindow class in my Editor folder that tries to communicate with a gameobject that will act as the coordinator/timeline manager. However, I get issues when I try to reference a GameObject's components from the EditorWindow class. Is it possible to communicate between an custom EditorWindow class and components attached to GameObjects? Can I do this in edit mode?

    This is how I have been trying to access an component from my editor class... I know there must be way to do this.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEditor;
    4. [ExecuteInEditMode]
    5. [CustomEditor(typeof(TimeKeeper))]
    6. public class SongWindow : EditorWindow
    7. {
    8.     public TimeKeeper timeKeeper;
    9.     bool first = true;
    10.  
    11.     // Add menu item
    12.     [MenuItem("Window/Song Window")]
    13.     static void Init()
    14.     {
    15.         // Get existing open window or if none, make a new one:
    16.         SongWindow window = (SongWindow)EditorWindow.GetWindow(typeof(SongWindow));
    17.         window.Show();
    18.     }
    19.  
    20.     void OnGUI()
    21.     {
    22.         if (first)
    23.         {
    24.             GameObject g = GameObject.Find("TimeKeeper");
    25.             timeKeeper = (TimeKeeper)g.GetComponent("TimeKeeper");
    26.             first = false;
    27.         }
    28.         GUILayout.Label("Song Window", EditorStyles.boldLabel);
    29.         float sliderplace = EditorGUILayout.Slider("Slider", timeKeeper.percentDone, -3, 3);// this causes unity to crash every time.
    30.     }
    31.  
    32. }
    33.  
    Thanks for reading!!