Anima2D.SpriteMeshCache.GetBoneNames C# (CSharp) Method

GetBoneNames() public method

public GetBoneNames ( string noBoneText ) : string[]
noBoneText string
return string[]
		public string[] GetBoneNames(string noBoneText)
		{
			List<string> names = new List<string>(bindPoses.Count);
			List<int> repetitions = new List<int>(bindPoses.Count);
			
			names.Add(noBoneText);
			repetitions.Add(0);
			
			foreach(BindInfo bindInfo in bindPoses)
			{
				List<string> repetedNames = names.Where( s => s == bindInfo.name ).ToList();
				
				names.Add(bindInfo.name);
				repetitions.Add(repetedNames.Count);
			}
			
			for (int i = 1; i < names.Count; i++)
			{
				string name = names[i];
				int count = repetitions[i] + 1;
				if(count > 1)
				{
					name += " (" + count.ToString() + ")";
					names[i] = name;
				}
			}
			
			return names.ToArray();
		}
		

Usage Example

示例#1
0
        protected override void DoWindow(int windowId)
        {
            float labelWidth = EditorGUIUtility.labelWidth;
            bool  wideMode   = EditorGUIUtility.wideMode;

            EditorGUIUtility.wideMode = true;

            EditorGUILayout.BeginHorizontal();

            string[] names = spriteMeshCache.GetBoneNames("None");
            int      index = spriteMeshCache.bindPoses.IndexOf(spriteMeshCache.selectedBindPose);

            index = EditorGUILayout.Popup(index + 1, names, GUILayout.Width(75f)) - 1;

            if (index >= 0 && index < spriteMeshCache.bindPoses.Count)
            {
                spriteMeshCache.selectedBindPose = spriteMeshCache.bindPoses[index];
            }
            else
            {
                spriteMeshCache.selectedBindPose = null;
            }

            EditorGUI.BeginChangeCheck();

            EditorGUI.BeginDisabledGroup(spriteMeshCache.selectedBindPose == null);

            if (Event.current.type == EventType.MouseUp ||
                Event.current.type == EventType.MouseDown)
            {
                m_Weight = 0f;

                m_TempWeights.Clear();

                if (spriteMeshCache.selection.Count == 0)
                {
                    m_TempWeights = spriteMeshCache.boneWeights.ToList();
                }
                else
                {
                    m_TempWeights = spriteMeshCache.selectedNodes.ConvertAll(n => spriteMeshCache.GetBoneWeight(n));
                }
            }

            EditorGUIUtility.fieldWidth = 35f;

            m_Weight = EditorGUILayout.Slider(m_Weight, -1f, 1f);

            EditorGUIUtility.fieldWidth = 0f;

            if (EditorGUI.EndChangeCheck())
            {
                spriteMeshCache.RegisterUndo("modify weights");

                List <Node> nodes = null;

                if (spriteMeshCache.selection.Count == 0)
                {
                    nodes = spriteMeshCache.nodes;
                }
                else
                {
                    nodes = spriteMeshCache.selectedNodes;
                }

                for (int i = 0; i < nodes.Count; i++)
                {
                    Node       node       = nodes[i];
                    BoneWeight tempWeight = m_TempWeights[i];
                    tempWeight.SetBoneIndexWeight(index, tempWeight.GetBoneWeight(index) + m_Weight, !EditorGUI.actionKey, true);
                    spriteMeshCache.SetBoneWeight(node, tempWeight);
                }
            }

            EditorGUI.EndDisabledGroup();

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(new GUIContent("Smooth", "Smooth weights")))
            {
                spriteMeshCache.RegisterUndo("smooth weights");

                List <Node> targetNodes = spriteMeshCache.nodes;

                if (spriteMeshCache.selection.Count > 0)
                {
                    targetNodes = spriteMeshCache.selectedNodes;
                }

                spriteMeshCache.SmoothWeights(targetNodes);
            }

            if (GUILayout.Button(new GUIContent("Auto", "Calculate automatic weights")))
            {
                spriteMeshCache.RegisterUndo("calculate weights");

                List <Node> targetNodes = spriteMeshCache.nodes;

                if (spriteMeshCache.selection.Count > 0)
                {
                    targetNodes = spriteMeshCache.selectedNodes;
                }

                spriteMeshCache.CalculateAutomaticWeights(targetNodes);
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            EditorGUIUtility.labelWidth = 50f;

            overlayColors = EditorGUILayout.Toggle("Overlay", overlayColors);

            EditorGUIUtility.labelWidth = 30f;

            showPie = EditorGUILayout.Toggle("Pies", showPie);

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            EditorGUIUtility.labelWidth = labelWidth;
            EditorGUIUtility.wideMode   = wideMode;
        }
All Usage Examples Of Anima2D.SpriteMeshCache::GetBoneNames