Beispiel #1
0
        public static void Bind(TrackAsset track, Object obj, PlayableDirector director)
        {
            if (director != null && track != null)
            {
                var bindType = TypeUtility.GetTrackBindingAttribute(track.GetType());
                if (bindType == null || bindType.type == null)
                {
                    return;
                }

                if (obj == null || bindType.type.IsInstanceOfType(obj))
                {
                    TimelineUndo.PushUndo(director, "Bind Track");
                    director.SetGenericBinding(track, obj);
                }
                else if (obj is GameObject && typeof(Component).IsAssignableFrom(bindType.type))
                {
                    var component = (obj as GameObject).GetComponent(bindType.type);
                    if (component == null)
                    {
                        component = Undo.AddComponent(obj as GameObject, bindType.type);
                    }

                    TimelineUndo.PushUndo(director, "Bind Track");
                    director.SetGenericBinding(track, component);
                }
            }
        }
        public static void BindWithInteractiveEditorValidation(PlayableDirector director, TrackAsset bindTo, Object objectToBind)
        {
            TrackEditor trackEditor = CustomTimelineEditorCache.GetTrackEditor(bindTo);

            if (trackEditor.SupportsBindingAssign())
            {
                BindWithEditorValidation(director, bindTo, objectToBind);
            }
            else
            {
                Type          bindingType = TypeUtility.GetTrackBindingAttribute(bindTo.GetType())?.type;
                BindingAction action      = GetBindingAction(bindingType, objectToBind);
                if (action == BindingAction.BindToMissingComponent)
                {
                    InteractiveBindToMissingComponent(director, bindTo, objectToBind, bindingType);
                }
                else
                {
                    var validatedObject = GetBinding(action, objectToBind, bindingType);
                    Bind(director, bindTo, validatedObject);
                }
            }
        }