static int FindBindInfo(BindInfo bindInfo, SpriteMeshData spriteMeshData)
		{
			if(bindInfo && spriteMeshData)
			{
				for(int i = 0; i < spriteMeshData.bindPoses.Length; ++i)
				{
					BindInfo l_bindInfo = spriteMeshData.bindPoses[i];
					
					if(bindInfo.name == l_bindInfo.name /*&& Mathf.Approximately(bindInfo.boneLength,l_bindInfo.boneLength)*/)
					{
						return i;
					}
				}
			}

			return -1;
		}
		static void SetBindPoses(SpriteMeshData spriteMeshData, SpriteMesh.BindInfo[] bindPoses)
		{
			if(bindPoses != null && bindPoses.Length > 0)
			{
				BindInfo[] array = new BindInfo[bindPoses.Length];
				
				for(int i = 0; i < array.Length; ++i)
				{
					BindInfo b = new BindInfo();
					b.bindPose = bindPoses[i].bindPose;
					b.boneLength = bindPoses[i].boneLength;
					b.color = bindPoses[i].color;
					b.name = bindPoses[i].name;
					b.path = bindPoses[i].path;
					b.zOrder = bindPoses[i].zOrder;
					
					array[i] = b;
				}
				
				FieldInfo fieldInfo = typeof(SpriteMeshData).GetField("m_BindPoses",BindingFlags.Instance | BindingFlags.NonPublic);
				
				if(fieldInfo != null)
				{
					fieldInfo.SetValue(spriteMeshData,array);
				}
				
				EditorUtility.SetDirty(spriteMeshData);
			}
		}
Exemple #3
0
		public void BindBone(Bone2D bone)
		{
			if(spriteMeshInstance && bone)
			{
				BindInfo bindInfo = new BindInfo();
				bindInfo.bindPose = bone.transform.worldToLocalMatrix * spriteMeshInstance.transform.localToWorldMatrix;
				bindInfo.boneLength = bone.localLength;
				bindInfo.path = BoneUtils.GetBonePath (bone);
				bindInfo.name = bone.name;
				bindInfo.color = ColorRing.GetColor(bindPoses.Count);
				
				if(!bindPoses.Contains(bindInfo))
				{
					bindPoses.Add (bindInfo);
					
					isDirty = true;
				}
			}
		}
		static int FindBindInfo(BindInfo bindInfo, SpriteMeshInstance spriteMeshInstance)
		{
			if(spriteMeshInstance)
			{
				return FindBindInfo(bindInfo, SpriteMeshUtils.LoadSpriteMeshData(spriteMeshInstance.spriteMesh));

			}

			return -1;
		}
Exemple #5
0
		public void Unassign(List<Node> targetNodes, BindInfo bindPose)
		{
			if(bindPose)
			{
				foreach(Node node in targetNodes)
				{
					BoneWeight boneWeight = GetBoneWeight(node);
					boneWeight.Unassign(bindPoses.IndexOf(bindPose));
					SetBoneWeight(node,boneWeight);
				}
			}
		}
Exemple #6
0
		public void Unassign(BindInfo bindPose)
		{
			Unassign(nodes,bindPose);
		}
Exemple #7
0
		public void DeleteBindPose(BindInfo bindPose)
		{
			if(bindPose)
			{
				if(selectedBindPose == bindPose)
				{
					selectedBindPose = null;
				}
				
				int index = bindPoses.IndexOf(bindPose);
				
				Unassign(bindPose);
				bindPoses.Remove(bindPose);
				
				for(int i = 0; i < boneWeights.Count; i++)
				{
					BoneWeight boneWeight = boneWeights[i];
					boneWeight.DeleteBoneIndex(index);
					SetBoneWeight(nodes[i],boneWeight);
				}
				
				isDirty = true;
			}
		}
Exemple #8
0
        static void HandleDragAndDrop(bool createOnEnter, Transform parent)
        {
            switch (Event.current.type)
            {
            case EventType.DragUpdated:

                if (!init)
                {
                    spriteMesh = GetSpriteMesh();

                    if (createOnEnter)
                    {
                        parentTransform = null;
                        CreateInstance();
                    }

                    Event.current.Use();

                    init = true;
                }

                if (instance)
                {
                    instance.transform.position = instancePosition;

                    SpriteMeshInstance l_currentDestination = GetClosestBindeableIntersectingSpriteMeshInstance();

                    if (currentDestination != l_currentDestination)
                    {
                        currentDestination = l_currentDestination;

                        if (currentDestination)
                        {
                            List <Bone2D> destinationBones = currentDestination.bones;
                            List <Bone2D> newBones         = new List <Bone2D>();

                            SpriteMeshData data = SpriteMeshUtils.LoadSpriteMeshData(instance.spriteMesh);

                            for (int i = 0; i < data.bindPoses.Length; ++i)
                            {
                                BindInfo bindInfo = data.bindPoses[i];
                                int      index    = FindBindInfo(bindInfo, currentDestination);
                                if (index >= 0 && index < destinationBones.Count)
                                {
                                    newBones.Add(destinationBones[index]);
                                }
                            }

                            instance.transform.parent = currentDestination.transform.parent;
                            instance.bones            = newBones;
                            SpriteMeshUtils.UpdateRenderer(instance, false);

                            foreach (Bone2D bone in s_InstanceBones)
                            {
                                bone.hideFlags = HideFlags.HideAndDontSave;
                                bone.gameObject.SetActive(false);
                            }
                        }
                        else
                        {
                            foreach (Bone2D bone in s_InstanceBones)
                            {
                                bone.hideFlags = HideFlags.None;
                                bone.gameObject.SetActive(true);
                            }

                            instance.transform.parent = null;
                            instance.bones            = s_InstanceBones;
                            SpriteMeshUtils.UpdateRenderer(instance, false);
                        }

                        SceneView.RepaintAll();
                    }
                }

                break;

            case EventType.DragExited:

                if (instance)
                {
                    GameObject.DestroyImmediate(instance.gameObject);
                    Event.current.Use();
                }
                Cleanup();
                break;

            case EventType.DragPerform:

                if (!createOnEnter)
                {
                    CreateInstance();
                }

                if (instance)
                {
                    if (currentDestination)
                    {
                        foreach (Bone2D bone in s_InstanceBones)
                        {
                            if (bone)
                            {
                                GameObject.DestroyImmediate(bone.gameObject);
                            }
                        }
                    }

                    Undo.RegisterCreatedObjectUndo(instance.gameObject, "create SpriteMeshInstance");
                }

                Cleanup();
                break;
            }

            if (instance)
            {
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
            }
        }
		public void Unassign(BindInfo bindPose)
		{
			Unassign(nodes,bindPose);
		}