コード例 #1
0
    void AnimationSectionGUI()
    {
        // Handle animations array

        bool changed = false;

        animsFoldout = EditorGUILayout.Foldout(animsFoldout, "Source Animations");
        if (animsFoldout) {
            EditorGUIUtility.LookLikeControls(160);

            if (rebuildGroups || groups == null) {
                rebuildGroups = false;

                bool noGroupsAreUsed = true;

                if (groups == null) {
                    groups = new List<InspectorAnimationGroup>();
                    groups.Add(new InspectorAnimationGroup("No Change"));
                    groups.Add(new InspectorAnimationGroup(""));
                    groups.Add(new InspectorAnimationGroup("Not Used"));
                }
                else {
                    for (int i=0; i<groups.Count; i++)
                        groups[i].motions.Clear();
                }

                InspectorAnimationGroup unusedGroup = groups[groups.Count-1];
                List<AnimationClip> unusedClips = new List<AnimationClip>(AnimationUtility.GetAnimationClips(lc.animation));

                if (lc.sourceAnimations == null)
                    lc.sourceAnimations = new MotionAnalyzer[0];
                for (int m=0; m<lc.sourceAnimations.Length; m++) {
                    MotionAnalyzer ma = lc.sourceAnimations[m];
                    noGroupsAreUsed = false;

                    if (unusedClips.Contains(ma.animation))
                        unusedClips.Remove(ma.animation);

                    if (ma.motionGroup == null)
                        ma.motionGroup = "";

                    bool found = false;
                    for (int g=0; g<groups.Count; g++) {
                        if (ma.motionGroup == groups[g].name) {
                            groups[g].motions.Add(ma);
                            found = true;
                        }
                    }
                    if (!found) {
                        InspectorAnimationGroup group = new InspectorAnimationGroup(ma.motionGroup);
                        group.motions.Add(ma);
                        groups.Insert(groups.Count-1, group);
                    }
                }

                // Populate group of unused motions
                if (unusedClips.Count != unusedGroup.motions.Count) {
                    selectedMotions.Clear();
                    for (int i=0; i<unusedClips.Count; i++) {
                        MotionAnalyzer ma = new MotionAnalyzer();
                        ma.animation = unusedClips[i];
                        unusedGroup.motions.Add(ma);
                    }
                }

                // Check for empty groups
                for (int i=2; i<groups.Count-1; i++) {
                    if (groups[i].motions.Count == 0 || groups[i].name == "") {
                        groups.Remove(groups[i]);
                        i--;
                    }
                }

                // Only have unused group expanded by default if no other groups have any animations in them
                if (!noGroupsAreUsed) {
                    groups[groups.Count-1].expanded = false;
                }
            }

            string[] groupNames = new string[groups.Count+1];
            for (int g=0; g<groups.Count; g++) {
                groupNames[g] = groups[g].name;
            }
            groupNames[1] = "Ungrouped";
            groupNames[groupNames.Length-2] = "New Group";
            groupNames[groupNames.Length-1] = "Not Used";

            for (int g=1; g<groups.Count; g++) {
                InspectorAnimationGroup group = groups[g];
                bool used = true;

                if (g==1 && group.motions.Count == 0)
                    continue;

                GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
                group.expanded = GUILayout.Toggle(group.expanded, "", EditorStyles.foldout, GUILayout.ExpandWidth(false));
                if (g==1) {
                    GUILayout.Label("Ungrouped Animations", GUILayout.ExpandWidth(true));
                }
                else if (group.name == "Not Used") {
                    GUILayout.Label("Not Used (by Locomotion System)", GUILayout.ExpandWidth(true));
                    used = false;
                }
                else {
                    GUILayout.Label("Motion Group:", GUILayout.ExpandWidth(false));
                    string newName = GUILayout.TextField(group.name, GUILayout.ExpandWidth(true));
                    if (newName != group.name) {
                        group.name = newName;
                        changed = true;
                    }
                }
                if (GUILayout.Button("", "toggle", GUILayout.ExpandWidth(false))) {
                    bool allWasSelected = true;
                    for (int m=0; m<group.motions.Count; m++) {
                        if (!selectedMotions.Contains(group.motions[m])) {
                            selectedMotions.Add(group.motions[m]);
                            allWasSelected = false;
                        }
                    }
                    if (allWasSelected) {
                        for (int m=0; m<group.motions.Count; m++) {
                            if (selectedMotions.Contains(group.motions[m])) {
                                selectedMotions.Remove(group.motions[m]);
                            }
                        }
                    }
                }
                GUILayout.EndHorizontal();

                if (group.expanded) {
                    EditorGUI.indentLevel++;

                    for (int m=0; m<group.motions.Count; m++) {
                        MotionAnalyzer ma = group.motions[m];

                        GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));

                        GUILayout.Space(15);

                        // Foldout
                        bool expanded = false;
                        if (used) {
                            bool expandedOld = expandedMotions.Contains(ma);
                            expanded = GUILayout.Toggle(expandedOld, "", EditorStyles.foldout, GUILayout.ExpandWidth(false));
                            if (expanded != expandedOld) {
                                if (expanded)
                                    expandedMotions.Add(ma);
                                else
                                    expandedMotions.Remove(ma);
                            }

                            GUI.changed = false;
                            ma.animation = EditorGUILayout.ObjectField(ma.animation, typeof(AnimationClip), false, GUILayout.ExpandWidth(true)) as AnimationClip;
                            ma.motionType = (MotionType)EditorGUILayout.EnumPopup(ma.motionType, GUILayout.Width(70));
                            if (GUI.changed)
                                changed = true;
                        }
                        else {
                            GUI.enabled = false;
                            GUILayout.Toggle(false, "", EditorStyles.foldout, GUILayout.ExpandWidth(false));
                            EditorGUILayout.ObjectField(ma.animation, typeof(AnimationClip), false, GUILayout.ExpandWidth(true));
                            GUI.enabled = true;
                            GUILayout.Space(70+4);
                        }

                        // Selection
                        bool selectedOld = selectedMotions.Contains(ma);
                        bool selected = GUILayout.Toggle(selectedOld, "", GUILayout.ExpandWidth(false));
                        if (selected != selectedOld) {
                            if (selected)
                                selectedMotions.Add(ma);
                            else
                                selectedMotions.Remove(ma);
                        }

                        GUILayout.EndHorizontal();

                        if (expanded) {
                            GUI.changed = false;
                            EditorGUI.indentLevel += 2;
                            ma.alsoUseBackwards = EditorGUILayout.Toggle("Also Use Backwards", ma.alsoUseBackwards);
                            ma.fixFootSkating = EditorGUILayout.Toggle("Fix Foot Skating", ma.fixFootSkating);
                            EditorGUILayout.LabelField("Native Speed", ""+ma.nativeSpeed);
                            EditorGUI.indentLevel -= 2;
                            if (GUI.changed)
                                changed = true;
                        }
                    }
                    EditorGUI.indentLevel--;

                    EditorGUILayout.Space();
                }
            }

            EditorGUIUtility.LookLikeControls(120);

            // Apply changes to selections
            bool clearInspectorGroups = false;
            GUI.enabled = (selectedMotions.Count > 0);
            int selectedGroup = EditorGUILayout.Popup("Move Selected To", 0, groupNames);
            if (selectedGroup != 0) {
                for (int i=0; i<selectedMotions.Count; i++) {
                    MotionAnalyzer ma = selectedMotions[i];
                    for (int j=0; j<groups.Count; j++) {
                        if (groups[j].motions.Contains(ma)) {
                            groups[j].motions.Remove(ma);
                        }
                    }

                    // Add to unused
                    if (selectedGroup == groupNames.Length-1) {
                        groups[selectedGroup-1].motions.Add(ma);
                    }
                    // Add to new group
                    else if (selectedGroup == groupNames.Length-2) {
                        string newName = "MotionGroup";
                        bool exists = true;
                        int c = 1;
                        while (exists) {
                            newName = "MotionGroup" + c;
                            exists = false;
                            for (int j=0; j<groups.Count; j++) {
                                if (groups[j].name == newName)
                                    exists = true;
                            }
                            c++;
                        }
                        groups.Insert(groups.Count-1, new InspectorAnimationGroup(newName));
                        groups[selectedGroup].motions.Add(ma);
                    }
                    // Add to selected group
                    else {
                        groups[selectedGroup].motions.Add(ma);
                    }
                }
                selectedMotions.Clear();
                clearInspectorGroups = true;
                lc.initialized = false;
                changed = true;
            }
            GUI.enabled = true;

            if (changed) {
                List<MotionAnalyzer> motions = new List<MotionAnalyzer>();
                for (int g=0; g<groups.Count-1; g++) {
                    for (int m=0; m<groups[g].motions.Count; m++) {
                        groups[g].motions[m].motionGroup = groups[g].name;
                        motions.Add(groups[g].motions[m]);
                    }
                }
                lc.sourceAnimations = motions.ToArray();
                lc.initialized = false;
            }

            if (clearInspectorGroups)
                rebuildGroups = true;
        }

        EditorGUILayout.Space();
    }
コード例 #2
0
    void AnimationSectionGUI()
    {
        // Handle animations array

        bool changed = false;

        animsFoldout = EditorGUILayout.Foldout(animsFoldout, "Source Animations");
        if (animsFoldout)
        {
            EditorGUIUtility.LookLikeControls(160);

            if (rebuildGroups || groups == null)
            {
                rebuildGroups = false;

                bool noGroupsAreUsed = true;

                if (groups == null)
                {
                    groups = new List <InspectorAnimationGroup>();
                    groups.Add(new InspectorAnimationGroup("No Change"));
                    groups.Add(new InspectorAnimationGroup(""));
                    groups.Add(new InspectorAnimationGroup("Not Used"));
                }
                else
                {
                    for (int i = 0; i < groups.Count; i++)
                    {
                        groups[i].motions.Clear();
                    }
                }

                InspectorAnimationGroup unusedGroup = groups[groups.Count - 1];
                List <AnimationClip>    unusedClips = new List <AnimationClip>(AnimationUtility.GetAnimationClips(lc.GetComponent <Animation>()));

                if (lc.sourceAnimations == null)
                {
                    lc.sourceAnimations = new MotionAnalyzer[0];
                }
                for (int m = 0; m < lc.sourceAnimations.Length; m++)
                {
                    MotionAnalyzer ma = lc.sourceAnimations[m];
                    noGroupsAreUsed = false;

                    if (unusedClips.Contains(ma.animation))
                    {
                        unusedClips.Remove(ma.animation);
                    }

                    if (ma.motionGroup == null)
                    {
                        ma.motionGroup = "";
                    }

                    bool found = false;
                    for (int g = 0; g < groups.Count; g++)
                    {
                        if (ma.motionGroup == groups[g].name)
                        {
                            groups[g].motions.Add(ma);
                            found = true;
                        }
                    }
                    if (!found)
                    {
                        InspectorAnimationGroup group = new InspectorAnimationGroup(ma.motionGroup);
                        group.motions.Add(ma);
                        groups.Insert(groups.Count - 1, group);
                    }
                }

                // Populate group of unused motions
                if (unusedClips.Count != unusedGroup.motions.Count)
                {
                    selectedMotions.Clear();
                    for (int i = 0; i < unusedClips.Count; i++)
                    {
                        MotionAnalyzer ma = new MotionAnalyzer();
                        ma.animation = unusedClips[i];
                        unusedGroup.motions.Add(ma);
                    }
                }

                // Check for empty groups
                for (int i = 2; i < groups.Count - 1; i++)
                {
                    if (groups[i].motions.Count == 0 || groups[i].name == "")
                    {
                        groups.Remove(groups[i]);
                        i--;
                    }
                }

                // Only have unused group expanded by default if no other groups have any animations in them
                if (!noGroupsAreUsed)
                {
                    groups[groups.Count - 1].expanded = false;
                }
            }

            string[] groupNames = new string[groups.Count + 1];
            for (int g = 0; g < groups.Count; g++)
            {
                groupNames[g] = groups[g].name;
            }
            groupNames[1] = "Ungrouped";
            groupNames[groupNames.Length - 2] = "New Group";
            groupNames[groupNames.Length - 1] = "Not Used";

            for (int g = 1; g < groups.Count; g++)
            {
                InspectorAnimationGroup group = groups[g];
                bool used = true;

                if (g == 1 && group.motions.Count == 0)
                {
                    continue;
                }

                GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
                group.expanded = GUILayout.Toggle(group.expanded, "", EditorStyles.foldout, GUILayout.ExpandWidth(false));
                if (g == 1)
                {
                    GUILayout.Label("Ungrouped Animations", GUILayout.ExpandWidth(true));
                }
                else if (group.name == "Not Used")
                {
                    GUILayout.Label("Not Used (by Locomotion System)", GUILayout.ExpandWidth(true));
                    used = false;
                }
                else
                {
                    GUILayout.Label("Motion Group:", GUILayout.ExpandWidth(false));
                    string newName = GUILayout.TextField(group.name, GUILayout.ExpandWidth(true));
                    if (newName != group.name)
                    {
                        group.name = newName;
                        changed    = true;
                    }
                }
                if (GUILayout.Button("", "toggle", GUILayout.ExpandWidth(false)))
                {
                    bool allWasSelected = true;
                    for (int m = 0; m < group.motions.Count; m++)
                    {
                        if (!selectedMotions.Contains(group.motions[m]))
                        {
                            selectedMotions.Add(group.motions[m]);
                            allWasSelected = false;
                        }
                    }
                    if (allWasSelected)
                    {
                        for (int m = 0; m < group.motions.Count; m++)
                        {
                            if (selectedMotions.Contains(group.motions[m]))
                            {
                                selectedMotions.Remove(group.motions[m]);
                            }
                        }
                    }
                }
                GUILayout.EndHorizontal();

                if (group.expanded)
                {
                    EditorGUI.indentLevel++;

                    for (int m = 0; m < group.motions.Count; m++)
                    {
                        MotionAnalyzer ma = group.motions[m];

                        GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));

                        GUILayout.Space(15);

                        // Foldout
                        bool expanded = false;
                        if (used)
                        {
                            bool expandedOld = expandedMotions.Contains(ma);
                            expanded = GUILayout.Toggle(expandedOld, "", EditorStyles.foldout, GUILayout.ExpandWidth(false));
                            if (expanded != expandedOld)
                            {
                                if (expanded)
                                {
                                    expandedMotions.Add(ma);
                                }
                                else
                                {
                                    expandedMotions.Remove(ma);
                                }
                            }

                            GUI.changed   = false;
                            ma.animation  = EditorGUILayout.ObjectField(ma.animation, typeof(AnimationClip), GUILayout.ExpandWidth(true)) as AnimationClip;
                            ma.motionType = (MotionType)EditorGUILayout.EnumPopup(ma.motionType, GUILayout.Width(70));
                            if (GUI.changed)
                            {
                                changed = true;
                            }
                        }
                        else
                        {
                            GUI.enabled = false;
                            GUILayout.Toggle(false, "", EditorStyles.foldout, GUILayout.ExpandWidth(false));
                            EditorGUILayout.ObjectField(ma.animation, typeof(AnimationClip), GUILayout.ExpandWidth(true));
                            GUI.enabled = true;
                            GUILayout.Space(70 + 4);
                        }

                        // Selection
                        bool selectedOld = selectedMotions.Contains(ma);
                        bool selected    = GUILayout.Toggle(selectedOld, "", GUILayout.ExpandWidth(false));
                        if (selected != selectedOld)
                        {
                            if (selected)
                            {
                                selectedMotions.Add(ma);
                            }
                            else
                            {
                                selectedMotions.Remove(ma);
                            }
                        }

                        GUILayout.EndHorizontal();

                        if (expanded)
                        {
                            GUI.changed            = false;
                            EditorGUI.indentLevel += 2;
                            ma.alsoUseBackwards    = EditorGUILayout.Toggle("Also Use Backwards", ma.alsoUseBackwards);
                            ma.fixFootSkating      = EditorGUILayout.Toggle("Fix Foot Skating", ma.fixFootSkating);
                            EditorGUILayout.LabelField("Native Speed", "" + ma.nativeSpeed);
                            EditorGUI.indentLevel -= 2;
                            if (GUI.changed)
                            {
                                changed = true;
                            }
                        }
                    }
                    EditorGUI.indentLevel--;

                    EditorGUILayout.Space();
                }
            }

            EditorGUIUtility.LookLikeControls(120);

            // Apply changes to selections
            bool clearInspectorGroups = false;
            GUI.enabled = (selectedMotions.Count > 0);
            int selectedGroup = EditorGUILayout.Popup("Move Selected To", 0, groupNames);
            if (selectedGroup != 0)
            {
                for (int i = 0; i < selectedMotions.Count; i++)
                {
                    MotionAnalyzer ma = selectedMotions[i];
                    for (int j = 0; j < groups.Count; j++)
                    {
                        if (groups[j].motions.Contains(ma))
                        {
                            groups[j].motions.Remove(ma);
                        }
                    }

                    // Add to unused
                    if (selectedGroup == groupNames.Length - 1)
                    {
                        groups[selectedGroup - 1].motions.Add(ma);
                    }
                    // Add to new group
                    else if (selectedGroup == groupNames.Length - 2)
                    {
                        string newName = "MotionGroup";
                        bool   exists  = true;
                        int    c       = 1;
                        while (exists)
                        {
                            newName = "MotionGroup" + c;
                            exists  = false;
                            for (int j = 0; j < groups.Count; j++)
                            {
                                if (groups[j].name == newName)
                                {
                                    exists = true;
                                }
                            }
                            c++;
                        }
                        groups.Insert(groups.Count - 1, new InspectorAnimationGroup(newName));
                        groups[selectedGroup].motions.Add(ma);
                    }
                    // Add to selected group
                    else
                    {
                        groups[selectedGroup].motions.Add(ma);
                    }
                }
                selectedMotions.Clear();
                clearInspectorGroups = true;
                lc.initialized       = false;
                changed = true;
            }
            GUI.enabled = true;

            if (changed)
            {
                List <MotionAnalyzer> motions = new List <MotionAnalyzer>();
                for (int g = 0; g < groups.Count - 1; g++)
                {
                    for (int m = 0; m < groups[g].motions.Count; m++)
                    {
                        groups[g].motions[m].motionGroup = groups[g].name;
                        motions.Add(groups[g].motions[m]);
                    }
                }
                lc.sourceAnimations = motions.ToArray();
                lc.initialized      = false;
            }

            if (clearInspectorGroups)
            {
                rebuildGroups = true;
            }
        }

        EditorGUILayout.Space();
    }
コード例 #3
0
	public override void OnInspectorGUI () {
		LegController lc = target as LegController;
		if (!lc)
			return;
		
		EditorGUIUtility.LookLikeControls();
		
		lc.groundPlaneHeight = EditorGUILayout.FloatField("Ground Height", lc.groundPlaneHeight);
		lc.groundedPose = EditorGUILayout.ObjectField("Grounded Pose", lc.groundedPose, typeof(AnimationClip), true) as AnimationClip;
		lc.rootBone = EditorGUILayout.ObjectField("Root Bone", lc.rootBone, typeof(Transform), true) as Transform;
		
		EditorGUILayout.Space();
		
		// Handle legs array
		
		List<LegInfo> legs = new List<LegInfo>(lc.legs);
		if (legs.Count != legFoldouts.Count)
			legFoldouts = new List<bool>(new bool[legs.Count]);
		
		legsFoldout = EditorGUILayout.Foldout(legsFoldout, "Legs");
		
		if (legsFoldout) {
			GUI.changed = false;
			
			int removeIndex = -1;
			for (int l=0; l<legs.Count; l++) {
				GUILayout.BeginHorizontal();
				string str = "Leg " + (l+1) + (legs[l].hip != null ? " (" + legs[l].hip.name + ")" : "");
				legFoldouts[l] = EditorGUILayout.Foldout(legFoldouts[l], str);
				if (GUILayout.Button("Remove", GUILayout.Width(80)))
					removeIndex = l;
				GUILayout.EndHorizontal();
				
				if (legFoldouts[l]) {
					EditorGUI.indentLevel++;
					
					LegInfo li = legs[l];
					li.hip = EditorGUILayout.ObjectField("Hip", li.hip, typeof(Transform), true) as Transform;
					li.ankle = EditorGUILayout.ObjectField("Ankle", li.ankle, typeof(Transform), true) as Transform;
					li.toe = EditorGUILayout.ObjectField("Toe", li.toe, typeof(Transform), true ) as Transform;
					
					GUILayout.BeginHorizontal();
					EditorGUILayout.PrefixLabel("Foot");
					GUILayout.BeginVertical();
					GUILayout.Label("Width", GUILayout.Width(40));
					GUILayout.Label("Length", GUILayout.Width(40));
					GUILayout.EndVertical();
					GUILayout.BeginVertical();
					li.footWidth = EditorGUILayout.FloatField(li.footWidth, GUILayout.Width(50));
					li.footLength = EditorGUILayout.FloatField(li.footLength, GUILayout.Width(50));
					GUILayout.EndVertical();
					GUILayout.BeginVertical();
					GUILayout.Label("Offset", GUILayout.Width(40));
					GUILayout.Label("Offset", GUILayout.Width(40));
					GUILayout.EndVertical();
					GUILayout.BeginVertical();
					li.footOffset.x = EditorGUILayout.FloatField(li.footOffset.x, GUILayout.Width(50));
					li.footOffset.y = EditorGUILayout.FloatField(li.footOffset.y, GUILayout.Width(50));
					GUILayout.EndVertical();
					GUILayout.EndHorizontal();
					
					EditorGUI.indentLevel--;
					
					EditorGUILayout.Space();
				}
			}
			
			// Remove a leg?
			if (removeIndex >= 0) {
				legs.RemoveAt(removeIndex);
				legFoldouts.RemoveAt(removeIndex);
			}
			
			// Add a leg?
			GUILayout.BeginHorizontal();
			GUILayout.Label("");
			if (GUILayout.Button("Add Leg", GUILayout.Width(80))) {
				LegInfo li = new LegInfo();
				if (legs.Count > 0) {
					li.footWidth = legs[legs.Count-1].footWidth;
					li.footLength = legs[legs.Count-1].footLength;
					li.footOffset = legs[legs.Count-1].footOffset;
				}
				legs.Add(li);
				legFoldouts.Add(true);
			}
			GUILayout.EndHorizontal();
			
			lc.legs = legs.ToArray();
		}
		
		EditorGUILayout.Space();
		
		// Handle animations array
		
		animsFoldout = EditorGUILayout.Foldout(animsFoldout, "Source Animations");
		
		if (animsFoldout) {
			GUI.changed = false;
			
			List<InspectorAnimationGroup> groups = new List<InspectorAnimationGroup>();
			groups.Add(new InspectorAnimationGroup(""));
			if (GUILayout.Button("Reset") || lc.sourceAnimations.Length == 0) {
				AnimationClip[] clips = AnimationUtility.GetAnimationClips(lc.GetComponent<Animation>());
				for (int c=0; c<clips.Length; c++) {
					MotionAnalyzer motion = new MotionAnalyzer();
					motion.animation = clips[c];
					//motion.motionGroup = "";
					groups[0].motions.Add(motion);
				}
				GUI.changed = true;
			}
			else {
				for (int m=0; m<lc.sourceAnimations.Length; m++) {
					MotionAnalyzer ma = lc.sourceAnimations[m];
					if (ma.motionGroup == null)
						ma.motionGroup = "";
					
					bool found = false;
					for (int g=0; g<groups.Count; g++) {
						if (ma.motionGroup == groups[g].name) {
							groups[g].motions.Add(ma);
							found = true;
						}
					}
					if (!found) {
						InspectorAnimationGroup group = new InspectorAnimationGroup(ma.motionGroup);
						group.motions.Add(ma);
						groups.Add(group);
					}
				}
			}
			groups.Add(new InspectorAnimationGroup("NewGroup"));
			groups.Add(new InspectorAnimationGroup("Remove"));
			
			string[] groupNames = new string[groups.Count];
			for (int g=0; g<groups.Count; g++) {
				groupNames[g] = groups[g].name;
			}
			groupNames[0] = "Ungrouped";
			
			for (int g=0; g<groups.Count-1; g++) {
				InspectorAnimationGroup group = groups[g];
				
				if (group.motions.Count == 0)
					continue;
				
				if (group.name == "") {
					GUILayout.Label("Ungrouped Animations");
				}
				else {
					GUILayout.BeginHorizontal();
					GUILayout.Label("Animation Group:", GUILayout.ExpandWidth(false));
					group.name = GUILayout.TextField(group.name, GUILayout.ExpandWidth(true));
					GUILayout.EndHorizontal();
				}
				
				for (int m=0; m<group.motions.Count; m++) {
					MotionAnalyzer ma = group.motions[m];
					
					GUILayout.BeginHorizontal();
					
					ma.animation = EditorGUILayout.ObjectField(ma.animation, typeof(AnimationClip), true) as AnimationClip;
					ma.motionType = (MotionType)EditorGUILayout.EnumPopup(ma.motionType, GUILayout.Width(70));
					
					//ma.alsoUseBackwards = GUILayout.Toggle(ma.alsoUseBackwards, "", GUILayout.Width(15));
					//ma.fixFootSkating = GUILayout.Toggle(ma.fixFootSkating, "", GUILayout.Width(15));
					int selectedGroup = EditorGUILayout.Popup(g, groupNames, GUILayout.Width(70));
					if (selectedGroup != g) {
						group.motions.Remove(ma);
						groups[selectedGroup].motions.Add(ma);
						GUI.changed = true;
					}
					
					GUILayout.Label(""+ma.nativeSpeed, GUILayout.Width(40));
					
					GUILayout.EndHorizontal();
				}
				
				if (GUILayout.Button("Add Animation to "+groupNames[g])) {
					MotionAnalyzer motion = new MotionAnalyzer();
					group.motions.Add(motion);
					GUI.changed = true;
				}
				
				EditorGUILayout.Space();
			}
			
			if (GUI.changed) {
				List<MotionAnalyzer> motions = new List<MotionAnalyzer>();
				for (int g=0; g<groups.Count-1; g++) {
					for (int m=0; m<groups[g].motions.Count; m++) {
						groups[g].motions[m].motionGroup = groups[g].name;
						motions.Add(groups[g].motions[m]);
					}
				}
				lc.sourceAnimations = motions.ToArray();
			}
		}
		
	}
コード例 #4
0
    public override void OnInspectorGUI()
    {
        LegController lc = target as LegController;

        if (!lc)
        {
            return;
        }

        EditorGUIUtility.LookLikeControls();

        lc.groundPlaneHeight = EditorGUILayout.FloatField("Ground Height", lc.groundPlaneHeight);
        lc.groundedPose      = EditorGUILayout.ObjectField("Grounded Pose", lc.groundedPose, typeof(AnimationClip)) as AnimationClip;
        lc.rootBone          = EditorGUILayout.ObjectField("Root Bone", lc.rootBone, typeof(Transform)) as Transform;

        EditorGUILayout.Space();

        // Handle legs array

        List <LegInfo> legs = new List <LegInfo>(lc.legs);

        if (legs.Count != legFoldouts.Count)
        {
            legFoldouts = new List <bool>(new bool[legs.Count]);
        }

        legsFoldout = EditorGUILayout.Foldout(legsFoldout, "Legs");

        if (legsFoldout)
        {
            GUI.changed = false;

            int removeIndex = -1;
            for (int l = 0; l < legs.Count; l++)
            {
                GUILayout.BeginHorizontal();
                string str = "Leg " + (l + 1) + (legs[l].hip != null ? " (" + legs[l].hip.name + ")" : "");
                legFoldouts[l] = EditorGUILayout.Foldout(legFoldouts[l], str);
                if (GUILayout.Button("Remove", GUILayout.Width(80)))
                {
                    removeIndex = l;
                }
                GUILayout.EndHorizontal();

                if (legFoldouts[l])
                {
                    EditorGUI.indentLevel++;

                    LegInfo li = legs[l];
                    li.hip   = EditorGUILayout.ObjectField("Hip", li.hip, typeof(Transform)) as Transform;
                    li.ankle = EditorGUILayout.ObjectField("Ankle", li.ankle, typeof(Transform)) as Transform;
                    li.toe   = EditorGUILayout.ObjectField("Toe", li.toe, typeof(Transform)) as Transform;

                    GUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel("Foot");
                    GUILayout.BeginVertical();
                    GUILayout.Label("Width", GUILayout.Width(40));
                    GUILayout.Label("Length", GUILayout.Width(40));
                    GUILayout.EndVertical();
                    GUILayout.BeginVertical();
                    li.footWidth  = EditorGUILayout.FloatField(li.footWidth, GUILayout.Width(50));
                    li.footLength = EditorGUILayout.FloatField(li.footLength, GUILayout.Width(50));
                    GUILayout.EndVertical();
                    GUILayout.BeginVertical();
                    GUILayout.Label("Offset", GUILayout.Width(40));
                    GUILayout.Label("Offset", GUILayout.Width(40));
                    GUILayout.EndVertical();
                    GUILayout.BeginVertical();
                    li.footOffset.x = EditorGUILayout.FloatField(li.footOffset.x, GUILayout.Width(50));
                    li.footOffset.y = EditorGUILayout.FloatField(li.footOffset.y, GUILayout.Width(50));
                    GUILayout.EndVertical();
                    GUILayout.EndHorizontal();

                    EditorGUI.indentLevel--;

                    EditorGUILayout.Space();
                }
            }

            // Remove a leg?
            if (removeIndex >= 0)
            {
                legs.RemoveAt(removeIndex);
                legFoldouts.RemoveAt(removeIndex);
            }

            // Add a leg?
            GUILayout.BeginHorizontal();
            GUILayout.Label("");
            if (GUILayout.Button("Add Leg", GUILayout.Width(80)))
            {
                LegInfo li = new LegInfo();
                if (legs.Count > 0)
                {
                    li.footWidth  = legs[legs.Count - 1].footWidth;
                    li.footLength = legs[legs.Count - 1].footLength;
                    li.footOffset = legs[legs.Count - 1].footOffset;
                }
                legs.Add(li);
                legFoldouts.Add(true);
            }
            GUILayout.EndHorizontal();

            lc.legs = legs.ToArray();
        }

        EditorGUILayout.Space();

        // Handle animations array

        animsFoldout = EditorGUILayout.Foldout(animsFoldout, "Source Animations");

        if (animsFoldout)
        {
            GUI.changed = false;

            List <InspectorAnimationGroup> groups = new List <InspectorAnimationGroup>();
            groups.Add(new InspectorAnimationGroup(""));
            if (GUILayout.Button("Reset") || lc.sourceAnimations.Length == 0)
            {
                AnimationClip[] clips = AnimationUtility.GetAnimationClips(lc.animation);
                for (int c = 0; c < clips.Length; c++)
                {
                    MotionAnalyzer motion = new MotionAnalyzer();
                    motion.animation = clips[c];
                    //motion.motionGroup = "";
                    groups[0].motions.Add(motion);
                }
                GUI.changed = true;
            }
            else
            {
                for (int m = 0; m < lc.sourceAnimations.Length; m++)
                {
                    MotionAnalyzer ma = lc.sourceAnimations[m];
                    if (ma.motionGroup == null)
                    {
                        ma.motionGroup = "";
                    }

                    bool found = false;
                    for (int g = 0; g < groups.Count; g++)
                    {
                        if (ma.motionGroup == groups[g].name)
                        {
                            groups[g].motions.Add(ma);
                            found = true;
                        }
                    }
                    if (!found)
                    {
                        InspectorAnimationGroup group = new InspectorAnimationGroup(ma.motionGroup);
                        group.motions.Add(ma);
                        groups.Add(group);
                    }
                }
            }
            groups.Add(new InspectorAnimationGroup("NewGroup"));
            groups.Add(new InspectorAnimationGroup("Remove"));

            string[] groupNames = new string[groups.Count];
            for (int g = 0; g < groups.Count; g++)
            {
                groupNames[g] = groups[g].name;
            }
            groupNames[0] = "Ungrouped";

            for (int g = 0; g < groups.Count - 1; g++)
            {
                InspectorAnimationGroup group = groups[g];

                if (group.motions.Count == 0)
                {
                    continue;
                }

                if (group.name == "")
                {
                    GUILayout.Label("Ungrouped Animations");
                }
                else
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Animation Group:", GUILayout.ExpandWidth(false));
                    group.name = GUILayout.TextField(group.name, GUILayout.ExpandWidth(true));
                    GUILayout.EndHorizontal();
                }

                for (int m = 0; m < group.motions.Count; m++)
                {
                    MotionAnalyzer ma = group.motions[m];

                    GUILayout.BeginHorizontal();

                    ma.animation  = EditorGUILayout.ObjectField(ma.animation, typeof(AnimationClip)) as AnimationClip;
                    ma.motionType = (MotionType)EditorGUILayout.EnumPopup(ma.motionType, GUILayout.Width(70));

                    //ma.alsoUseBackwards = GUILayout.Toggle(ma.alsoUseBackwards, "", GUILayout.Width(15));
                    //ma.fixFootSkating = GUILayout.Toggle(ma.fixFootSkating, "", GUILayout.Width(15));
                    int selectedGroup = EditorGUILayout.Popup(g, groupNames, GUILayout.Width(70));
                    if (selectedGroup != g)
                    {
                        group.motions.Remove(ma);
                        groups[selectedGroup].motions.Add(ma);
                        GUI.changed = true;
                    }

                    GUILayout.Label("" + ma.nativeSpeed, GUILayout.Width(40));

                    GUILayout.EndHorizontal();
                }

                if (GUILayout.Button("Add Animation to " + groupNames[g]))
                {
                    MotionAnalyzer motion = new MotionAnalyzer();
                    group.motions.Add(motion);
                    GUI.changed = true;
                }

                EditorGUILayout.Space();
            }

            if (GUI.changed)
            {
                List <MotionAnalyzer> motions = new List <MotionAnalyzer>();
                for (int g = 0; g < groups.Count - 1; g++)
                {
                    for (int m = 0; m < groups[g].motions.Count; m++)
                    {
                        groups[g].motions[m].motionGroup = groups[g].name;
                        motions.Add(groups[g].motions[m]);
                    }
                }
                lc.sourceAnimations = motions.ToArray();
            }
        }
    }