Exemplo n.º 1
0
        public static void SetSceneGameObject(PlayableDirector director, TrackAsset asset, GameObject go)
        {
            if (director == null || asset == null)
            {
                return;
            }

            asset = GetSceneReferenceTrack(asset);
            var bindings = asset.outputs;

            if (bindings.Count() == 0)
            {
                return;
            }

            var binding = bindings.First();

            if (binding.outputTargetType == typeof(GameObject))
            {
                BindingUtility.Bind(director, asset, go);
            }
            else
            {
                BindingUtility.Bind(director, asset, TimelineHelpers.AddRequiredComponent(go, asset));
            }
        }
Exemplo n.º 2
0
        static void PasteTracks()
        {
            var trackData = TimelineEditor.clipboard.GetTracks().ToList();

            if (trackData.Any())
            {
                SelectionManager.RemoveTimelineSelection();
            }

            foreach (var track in trackData)
            {
                var newTrack = track.item.Duplicate(TimelineEditor.clipboard.exposedPropertyTable, TimelineEditor.inspectedDirector, TimelineEditor.inspectedAsset);
                if (track.binding != null)
                {
                    BindingUtility.Bind(TimelineEditor.inspectedDirector, newTrack, track.binding);
                }

                SelectionManager.Add(newTrack);
                foreach (var childTrack in newTrack.GetFlattenedChildTracks())
                {
                    SelectionManager.Add(childTrack);
                }

                if (track.parent != null && track.parent.timelineAsset == TimelineEditor.inspectedAsset)
                {
                    TrackExtensions.ReparentTracks(new List <TrackAsset> {
                        newTrack
                    }, track.parent, track.item);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Override this method to determine which object to bind to <paramref name="track"/>.
        /// A binding object should be determined from <paramref name="candidate"/>.
        ///
        /// By default, the `TrackBindingType` attribute from <paramref name="track"/> will be used to determine the binding.
        /// </summary>
        /// <param name="candidate">The source object from which a track binding should be determined.</param>
        /// <param name="track">The track to bind an object to.</param>
        /// <returns>The object to bind to <paramref name="track"/>.</returns>
        /// <seealso cref="UnityEngine.Timeline.TrackBindingTypeAttribute"/>
        /// <seealso cref="UnityEngine.Timeline.TrackAsset"/>
        public virtual UnityEngine.Object GetBindingFrom(UnityEngine.Object candidate, TrackAsset track)
        {
            Type bindingType = GetBindingType(track);

            BindingUtility.BindingAction action = BindingUtility.GetBindingAction(bindingType, candidate);
            return(BindingUtility.GetBinding(action, candidate, bindingType));
        }
Exemplo n.º 4
0
        static void ObjectBindingField(Rect position, Object obj, PlayableBinding binding)
        {
            bool allowScene =
                typeof(GameObject).IsAssignableFrom(binding.outputTargetType) ||
                typeof(Component).IsAssignableFrom(binding.outputTargetType);

            EditorGUI.BeginChangeCheck();
            // FocusType.Passive so it never gets focused when pressing tab
            int controlId = GUIUtility.GetControlID("s_ObjectFieldHash".GetHashCode(), FocusType.Passive, position);
            var newObject = EditorGUI.DoObjectField(EditorGUI.IndentedRect(position), EditorGUI.IndentedRect(position), controlId, obj, binding.outputTargetType, null, null, allowScene, EditorStyles.objectField);

            if (EditorGUI.EndChangeCheck())
            {
                BindingUtility.Bind(TimelineEditor.inspectedDirector, binding.sourceObject as TrackAsset, newObject);
            }
        }
Exemplo n.º 5
0
        static void ObjectBindingField(Rect position, Object obj, PlayableBinding binding)
        {
            bool allowScene =
                typeof(GameObject).IsAssignableFrom(binding.outputTargetType) ||
                typeof(Component).IsAssignableFrom(binding.outputTargetType);

            using (var check = new EditorGUI.ChangeCheckScope())
            {
                // FocusType.Passive so it never gets focused when pressing tab
                int controlId = GUIUtility.GetControlID("s_ObjectFieldHash".GetHashCode(), FocusType.Passive, position);
                var newObject = UnityEditorInternals.DoObjectField(EditorGUI.IndentedRect(position), obj, binding.outputTargetType, controlId, allowScene);
                if (check.changed)
                {
                    BindingUtility.Bind(TimelineEditor.inspectedDirector, binding.sourceObject as TrackAsset, newObject);
                }
            }
        }
Exemplo n.º 6
0
        void DoTrackBindingGUI(Rect rect, Rect headerRect)
        {
            var bindingRect = new Rect(
                rect.xMin,
                rect.y + (rect.height - WindowConstants.trackHeaderButtonSize) / 2f,
                headerRect.xMax - WindowConstants.trackHeaderMaxButtonsWidth - rect.xMin,
                WindowConstants.trackHeaderButtonSize);

            if (bindingRect.Contains(Event.current.mousePosition) && TimelineDragging.IsDraggingEvent() && DragAndDrop.objectReferences.Length == 1)
            {
                TimelineDragging.HandleBindingDragAndDrop(track, BindingUtility.GetRequiredBindingType(m_TrackDrawData.m_Binding));
                Event.current.Use();
            }
            else
            {
                if (m_TrackDrawData.m_Binding.outputTargetType != null && typeof(Object).IsAssignableFrom(m_TrackDrawData.m_Binding.outputTargetType))
                {
                    ObjectBindingField(bindingRect, m_TrackDrawData.m_TrackBinding, m_TrackDrawData.m_Binding);
                }
            }
        }
        void DoTrackBindingGUI(Rect rect, Rect headerRect, WindowState state)
        {
            var spaceUsedByButtons = 2f + ((5 + WindowConstants.trackHeaderButtonPadding) * WindowConstants.trackHeaderButtonSize);

            rect.y     += (rect.height - 16.0f) / 2f;
            rect.height = 16f;
            rect.width  = (headerRect.xMax - spaceUsedByButtons - rect.xMin);

            var binding = state.editSequence.director.GetGenericBinding(track);

            if (rect.Contains(Event.current.mousePosition) && TimelineDragging.IsDraggingEvent() && DragAndDrop.objectReferences.Length == 1)
            {
                TimelineDragging.HandleBindingDragAndDrop(track, BindingUtility.GetRequiredBindingType(m_Bindings[0]));
            }
            else
            {
                if (m_Bindings[0].outputTargetType != null && typeof(Object).IsAssignableFrom(m_Bindings[0].outputTargetType))
                {
                    ObjectBindingField(rect, binding, m_Bindings[0]);
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Override this method to validate if a binding for <paramref name="track"/>
        /// can be determined from <paramref name="candidate"/>.
        ///
        /// The default implementation of this method will return true if
        /// - <paramref name="candidate"/> is not null or,
        /// - <paramref name="candidate"/> is not part of a Prefab Asset or,
        /// - <paramref name="candidate"/> is a Component that can be bound to <paramref name="track"/>
        /// </summary>
        /// <param name="candidate"></param>
        /// <param name="track">TBD</param>
        /// <returns>True if a binding can be determined from <paramref name="candidate"/>.</returns>
        /// <seealso cref="UnityEngine.Timeline.TrackBindingTypeAttribute"/>
        /// <seealso cref="UnityEngine.Timeline.TrackAsset"/>
        public virtual bool IsBindingAssignableFrom(UnityEngine.Object candidate, TrackAsset track)
        {
            var action = BindingUtility.GetBindingAction(GetBindingType(track), candidate);

            return(action != BindingUtility.BindingAction.DoNotBind);
        }