Пример #1
0
        public static Component AddRequiredComponent(GameObject go, TrackAsset asset)
        {
            Component result;

            if (go == null || asset == null)
            {
                result = null;
            }
            else
            {
                IEnumerable <PlayableBinding> outputs = asset.get_outputs();
                if (!outputs.Any <PlayableBinding>())
                {
                    result = null;
                }
                else
                {
                    PlayableBinding playableBinding = outputs.First <PlayableBinding>();
                    if (playableBinding.get_streamType() == null)
                    {
                        Animator animator = go.GetComponent <Animator>();
                        if (animator == null)
                        {
                            animator = Undo.AddComponent <Animator>(go);
                            animator.set_applyRootMotion(true);
                        }
                        result = animator;
                    }
                    else if (playableBinding.get_streamType() == 1)
                    {
                        AudioSource audioSource = go.GetComponent <AudioSource>();
                        if (audioSource == null)
                        {
                            audioSource = Undo.AddComponent <AudioSource>(go);
                        }
                        result = audioSource;
                    }
                    else if (playableBinding.get_streamType() == 3 && typeof(Component).IsAssignableFrom(playableBinding.get_sourceBindingType()))
                    {
                        Component component = go.GetComponent(playableBinding.get_sourceBindingType());
                        if (component == null)
                        {
                            component = Undo.AddComponent(go, playableBinding.get_sourceBindingType());
                        }
                        result = component;
                    }
                    else
                    {
                        result = null;
                    }
                }
            }
            return(result);
        }
Пример #2
0
        private static Type GetRequiredBindingType(PlayableBinding binding)
        {
            Type result = binding.get_sourceBindingType();

            if (binding.get_streamType() == null)
            {
                result = typeof(Animator);
            }
            else if (binding.get_streamType() == 1)
            {
                result = typeof(AudioSource);
            }
            return(result);
        }
 public static void SetSceneGameObject(PlayableDirector director, TrackAsset asset, GameObject go)
 {
     if (!(director == null) && !(asset == null))
     {
         asset = TimelineUtility.GetSceneReferenceTrack(asset);
         IEnumerable <PlayableBinding> outputs = asset.get_outputs();
         if (outputs.Count <PlayableBinding>() != 0)
         {
             PlayableBinding playableBinding = outputs.First <PlayableBinding>();
             if (playableBinding.get_streamType() == null || playableBinding.get_sourceBindingType() == typeof(GameObject))
             {
                 TimelineHelpers.AddRequiredComponent(go, asset);
                 TimelineUtility.SetBindingInDirector(director, asset, go);
             }
             else
             {
                 TimelineUtility.SetBindingInDirector(director, asset, TimelineHelpers.AddRequiredComponent(go, asset));
             }
         }
     }
 }