public static GameObjectSelectionItem Create(GameObject gameObject)
        {
            GameObjectSelectionItem selectionItem = ScriptableObject.CreateInstance(typeof(GameObjectSelectionItem)) as GameObjectSelectionItem;

            selectionItem.gameObject    = gameObject;
            selectionItem.animationClip = null;
            selectionItem.id            = 0;
            if (selectionItem.rootGameObject != null)
            {
                AnimationClip[] animationClips = AnimationUtility.GetAnimationClips(selectionItem.rootGameObject);
                if (selectionItem.animationClip == null && selectionItem.gameObject != null)
                {
                    selectionItem.animationClip = ((animationClips.Length <= 0) ? null : animationClips[0]);
                }
                else if (!Array.Exists <AnimationClip>(animationClips, (AnimationClip x) => x == selectionItem.animationClip))
                {
                    selectionItem.animationClip = ((animationClips.Length <= 0) ? null : animationClips[0]);
                }
            }
            return(selectionItem);
        }
Пример #2
0
        public static GameObjectSelectionItem Create(GameObject gameObject)
        {
            GameObjectSelectionItem selectionItem = CreateInstance(typeof(GameObjectSelectionItem)) as GameObjectSelectionItem;

            selectionItem.gameObject    = gameObject;
            selectionItem.animationClip = null;
            selectionItem.id            = 0; // no need for id since there's only one item in selection.

            if (selectionItem.rootGameObject != null)
            {
                AnimationClip[] allClips = AnimationUtility.GetAnimationClips(selectionItem.rootGameObject);

                if (selectionItem.animationClip == null && selectionItem.gameObject != null) // there is activeGO but clip is still null
                {
                    selectionItem.animationClip = allClips.Length > 0 ? allClips[0] : null;
                }
                else if (!Array.Exists(allClips, x => x == selectionItem.animationClip))  // clip doesn't belong to the currently active GO
                {
                    selectionItem.animationClip = allClips.Length > 0 ? allClips[0] : null;
                }
            }

            return(selectionItem);
        }