Ejemplo n.º 1
0
        /// <summary>
        /// Changes the set of displayed animation events.
        /// </summary>
        /// <param name="events">Events to display on the timeline.</param>
        /// <param name="selected">Array of the same size as the <paramref name="events"/> array, determining which
        ///                        events should be displayed as selected.</param>
        public void SetEvents(AnimationEvent[] events, bool[] selected)
        {
            int numEvents;
            if (events != null)
                numEvents = events.Length;
            else
                numEvents = 0;

            this.events = new AnimationEvent[numEvents];
            if(events != null)
                Array.Copy(events, this.events, numEvents);

            selectedEvents = new bool[numEvents];
            if(selected != null)
                Array.Copy(selected, selectedEvents, MathEx.Min(numEvents, selected.Length));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the drop down window by creating the necessary GUI. Must be called after construction and before
        /// use.
        /// </summary>
        /// <param name="animEvent">Event whose properties to edit.</param>
        /// <param name="componentNames">List of component names that the user can select from.</param>
        /// <param name="updateCallback">Callback triggered when event values change.</param>
        /// <param name="closeCallback">Callback triggered just before the window closes.</param>
        internal void Initialize(AnimationEvent animEvent, string[] componentNames, Action updateCallback, 
            Action<bool> closeCallback)
        {
            int selectedIndex = -1;
            string methodName = "";
            if (!string.IsNullOrEmpty(animEvent.Name))
            {
                string[] nameEntries = animEvent.Name.Split('/');
                if (nameEntries.Length > 1)
                {
                    string typeName = nameEntries[0];
                    for (int i = 0; i < componentNames.Length; i++)
                    {
                        if (componentNames[i] == typeName)
                        {
                            selectedIndex = i;
                            break;
                        }
                    }

                    methodName = nameEntries[nameEntries.Length - 1];
                }
            }

            GUIFloatField timeField = new GUIFloatField(new LocEdString("Time"), 40, "");
            timeField.Value = animEvent.Time;
            timeField.OnChanged += x => { animEvent.Time = x; changesMade = true; updateCallback(); };

            GUIListBoxField componentField = new GUIListBoxField(componentNames, new LocEdString("Component"), 40);
            if (selectedIndex != -1)
                componentField.Index = selectedIndex;

            componentField.OnSelectionChanged += x =>
            {
                string compName = "";
                if (x != -1)
                    compName = componentNames[x] + "/";

                animEvent.Name = compName + x;

                changesMade = true;
                updateCallback();
            };

            GUITextField methodField = new GUITextField(new LocEdString("Method"), 40, false, "", GUIOption.FixedWidth(190));
            methodField.Value = methodName;
            methodField.OnChanged += x =>
            {
                string compName = "";
                if(componentField.Index != -1)
                    compName = componentNames[componentField.Index] + "/";

                animEvent.Name = compName + x;

                changesMade = true;
                updateCallback();
            };

            GUILayoutY vertLayout = GUI.AddLayoutY();

            vertLayout.AddFlexibleSpace();
            GUILayoutX horzLayout = vertLayout.AddLayoutX();
            horzLayout.AddFlexibleSpace();
            GUILayout contentLayout = horzLayout.AddLayoutY();
            GUILayout timeLayout = contentLayout.AddLayoutX();
            timeLayout.AddSpace(5);
            timeLayout.AddElement(timeField);
            timeLayout.AddFlexibleSpace();
            GUILayout componentLayout = contentLayout.AddLayoutX();
            componentLayout.AddSpace(5);
            componentLayout.AddElement(componentField);
            componentLayout.AddFlexibleSpace();
            GUILayout methodLayout = contentLayout.AddLayoutX();
            methodLayout.AddSpace(5);
            methodLayout.AddElement(methodField);
            methodLayout.AddFlexibleSpace();
            horzLayout.AddFlexibleSpace();
            vertLayout.AddFlexibleSpace();

            this.closeCallback = closeCallback;
        }
Ejemplo n.º 3
0
 private static extern void Internal_SetAnimationEvents(IntPtr thisPtr, AnimationEvent[] events);
Ejemplo n.º 4
0
        /// <summary>
        /// Rebuilds GUI displaying the animation events list.
        /// </summary>
        private void UpdateEventsGUI()
        {
            AnimationEvent[] animEvents = new AnimationEvent[events.Count];
            bool[] selected = new bool[events.Count];

            for (int i = 0; i < events.Count; i++)
            {
                animEvents[i] = events[i].animEvent;
                selected[i] = events[i].selected;
            }

            guiEvents.SetEvents(animEvents, selected);
            guiEvents.Rebuild();
        }