示例#1
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        AnimatorControlClip obj      = (AnimatorControlClip)property.serializedObject.targetObject;
        Animator            animator = obj.template.animator;

        if (animator == null)
        {
            names.Clear();
            return;
        }
        AnimatorController controller = animator ? animator.runtimeAnimatorController as AnimatorController : null;
        int N = controller.animationClips.Length;

        if (names.Count <= 0 && N > 0)
        {
            for (int i = 0; i < N; i++)
            {
                names.Add(controller.animationClips[i].name);
            }
        }

        select = EditorGUILayout.Popup("Select Clip", select, names.ToArray());

        obj.template.ClipName = controller.animationClips[select].name;
        obj.template.Clip     = controller.animationClips[select];
        obj.ClipName          = obj.template.ClipName;
        // SerializedProperty colorProp = property.FindPropertyRelative("ClipName");

        //  Rect singleFieldRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
        // EditorGUI.PropertyField(singleFieldRect, colorProp);
    }
示例#2
0
    public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
    {
#if UNITY_EDITOR
        foreach (TimelineClip clip in m_Clips)
        {
            AnimatorControlClip mouthClip = clip.asset as AnimatorControlClip;
            // the template variable comes from classes made with the playable wizard
            AnimatorControlBehavior behaviour = mouthClip.template;
            // name the track with my variables value
            clip.displayName = behaviour.ClipName;
            if (behaviour.Clip)
            {
                clip.duration = behaviour.Clip.length;
            }
            behaviour.animator = go.GetComponent <PlayableDirector>().GetGenericBinding(this) as Animator;
        }
#endif
        ScriptPlayable <AnimatorControlMixerBehaviour> playable = ScriptPlayable <AnimatorControlMixerBehaviour> .Create(graph, inputCount);

        return(playable);
    }
示例#3
0
        //填充替换字典
        public void FillReplaceDict()
        {
            TimelineData     data     = (TimelineData)target;
            PlayableDirector Director = data.Director;

            replaceDict = data.replaceDict;
            replaceDict.Clear();
            referDict.Clear();
            replacebindingCount.Clear();

            SerializedObject serializedObject = new UnityEditor.SerializedObject(Director);

            SerializedProperty m_SceneBindings = serializedObject.FindProperty("m_SceneBindings");

            List <int> propertyArray = new List <int>();

            for (int i = 0; i < m_SceneBindings.arraySize; i++)
            {
                SerializedProperty property = m_SceneBindings.GetArrayElementAtIndex(i);
                if (property.FindPropertyRelative("key").objectReferenceValue == null)
                {
                    propertyArray.Add(i);
                }
            }
            foreach (int property in propertyArray)
            {
                m_SceneBindings.DeleteArrayElementAtIndex(property);
            }
            serializedObject.ApplyModifiedProperties();

            var timelineAsset = Director.playableAsset as TimelineAsset;

            data.PlayAseetName = timelineAsset.name;
            //轨道唯一性操作
            foreach (var at in timelineAsset.GetOutputTracks())
            {
                ReplaceInfo info = new ReplaceInfo();
                if (!replaceDict.ContainsKey(at.name))
                {
                    replaceDict.Add(at.name, info);
                    replacebindingCount.Add(at.name, 0);
                }
                else
                {
                    int n = replacebindingCount[at.name];
                    n++;
                    replacebindingCount[at.name] = n;
                    at.name = at.name + "_" + n;
                    replaceDict.Add(at.name, info);
                    if (!replacebindingCount.ContainsKey(at.name))
                    {
                        replacebindingCount.Add(at.name, 0);
                    }
                    else
                    {
                        int n2 = replacebindingCount[at.name];
                        n2++;
                        replacebindingCount[at.name] = n2;
                    }
                }
            }
            //
            foreach (var at in timelineAsset.outputs)
            {
                if (replaceDict.ContainsKey(at.streamName))
                {
                    GameObject obj = GetObj(Director, at.sourceObject);

                    ReplaceInfo info = replaceDict[at.streamName];

                    if (obj != null)
                    {
                        string tpath = "";
                        GetNodePath(obj.transform, ref tpath);
                        //判断GameObject是否为一个Prefab的引用
                        PrefabType tt = PrefabUtility.GetPrefabType(obj);
                        if (PrefabUtility.GetPrefabType(obj) == PrefabType.PrefabInstance || PrefabUtility.GetPrefabType(obj) == PrefabType.ModelPrefabInstance)
                        {
                            UnityEngine.Object prfabObject = PrefabUtility.GetPrefabParent(obj);
                            info.res = prfabObject.name;
                        }
                        else
                        {
                            info.res = obj.name;
                        }

                        info.path = tpath;
                        string[] list  = info.path.Split('/');
                        int      start = list[0].Length + 1;
                        int      last  = tpath.Length - list[list.Length - 1].Length;
                        Debug.Log(info.parentPath + "  " + start + " last" + last);
                        string objpath = info.path.Substring(start);
                        if (last > start)
                        {
                            info.parentPath = info.path.Substring(start, last - start - 1);
                        }
                        else
                        {
                            info.parentPath = "";
                        }

                        info.path      = objpath;
                        info.isReplace = false;
                        Animator animator = obj.GetComponent <Animator>();
                        if (animator)
                        {
                            info.isAnimator = true;
                            if (animator.runtimeAnimatorController)
                            {
                                info.controller = animator.runtimeAnimatorController.name;
                            }
                        }
                        else
                        {
                            info.isAnimator = false;
                        }

                        if (!referDict.ContainsKey(obj))
                        {
                            referDict.Add(obj, new List <string>()
                            {
                                at.streamName
                            });
                        }
                        else
                        {
                            referDict[obj].Add(at.streamName);
                        }
                    }
                }
            }
            foreach (var at in timelineAsset.outputs)
            {
                if (replaceDict.ContainsKey(at.streamName))
                {
                    GameObject obj = GetObj(Director, at.sourceObject);
                    if (obj)
                    {
                        ReplaceInfo info = replaceDict[at.streamName];
                        GetReferInfo(obj, ref info);
                    }
                }
            }

            foreach (var at in timelineAsset.GetOutputTracks())
            {
                if (at is AnimatorControlTrack)
                {
                    foreach (var clip in at.GetClips())
                    {
                        AnimatorControlClip mouthClip = clip.asset as AnimatorControlClip;
                        // the template variable comes from classes made with the playable wizard
                        AnimatorControlBehavior behaviour = mouthClip.template;
                        behaviour.Clip              = null;
                        behaviour.animator          = null;
                        mouthClip.template.Clip     = null;
                        mouthClip.template.animator = null;
                    }
                }
                ReplaceInfo info = replaceDict[at.name];
            }
            foreach (var obj in replaceDict)
            {
                Debug.Log(obj.Key + " ---- " + obj.Value.res + "--- path : " + obj.Value.path);
            }
        }