public void OnPasteActivated(bool bone, bool mesh, bool flipX, bool flipY) { var copyBuffer = m_CopyToolStringStore.stringStore; if (!SkinningCopyUtility.CanDeserializeStringToSkinningCopyData(copyBuffer)) { Debug.LogError(TextContent.copyError1); return; } var skinningCopyData = SkinningCopyUtility.DeserializeStringToSkinningCopyData(copyBuffer); if (skinningCopyData == null || skinningCopyData.copyData.Count == 0) { Debug.LogError(TextContent.copyError2); return; } var scale = 1f; if (skinningCopyData.pixelsPerUnit > 0f) { scale = pixelsPerUnit / skinningCopyData.pixelsPerUnit; } var sprites = skinningCache.GetSprites(); var copyMultiple = skinningCopyData.copyData.Count > 1; if (copyMultiple && skinningCopyData.copyData.Count != sprites.Length && mesh) { Debug.LogError(String.Format(TextContent.copyError3, sprites.Length, skinningCopyData.copyData.Count)); return; } using (skinningCache.UndoScope(TextContent.pasteData)) { NewBonesStore newBonesStore = null; if (bone && copyMultiple && skinningCache.hasCharacter) { newBonesStore = new NewBonesStore(); var skinningSpriteData = skinningCopyData.copyData[0]; newBonesStore.newBones = skinningCache.CreateBoneCacheFromSpriteBones(skinningSpriteData.spriteBones.ToArray(), scale); if (flipX || flipY) { var characterRect = new Rect(Vector2.zero, skinningCache.character.dimension); var newPositions = new Vector3[newBonesStore.newBones.Length]; var newRotations = new Quaternion[newBonesStore.newBones.Length]; for (var i = 0; i < newBonesStore.newBones.Length; ++i) { newPositions[i] = GetFlippedBonePosition(newBonesStore.newBones[i], Vector2.zero, characterRect, flipX, flipY); newRotations[i] = GetFlippedBoneRotation(newBonesStore.newBones[i], flipX, flipY); } for (var i = 0; i < newBonesStore.newBones.Length; ++i) { newBonesStore.newBones[i].position = newPositions[i]; newBonesStore.newBones[i].rotation = newRotations[i]; } } newBonesStore.MapAllExistingBones(); var skeleton = skinningCache.character.skeleton; skeleton.SetBones(newBonesStore.newBones); skinningCache.events.skeletonTopologyChanged.Invoke(skeleton); } foreach (var skinningSpriteData in skinningCopyData.copyData) { SpriteCache sprite = null; if (!String.IsNullOrEmpty(skinningSpriteData.spriteName)) { sprite = sprites.FirstOrDefault(x => x.name == skinningSpriteData.spriteName); } if (sprite == null && (skinningCopyData.copyData.Count == 1 || String.IsNullOrEmpty(skinningSpriteData.spriteName))) { sprite = skinningCache.selectedSprite; } if (sprite == null) { continue; } if (bone && (!skinningCache.hasCharacter || !copyMultiple)) { newBonesStore = PasteSkeletonBones(sprite, skinningSpriteData.spriteBones, flipX, flipY, scale); } if (mesh && meshTool != null) { PasteMesh(sprite, skinningSpriteData, flipX, flipY, scale, newBonesStore); } } if (newBonesStore != null && newBonesStore.newBones != null) { skinningCache.skeletonSelection.elements = newBonesStore.newBones; skinningCache.events.boneSelectionChanged.Invoke(); } } skinningCache.events.paste.Invoke(bone, mesh, flipX, flipY); }
public void OnPasteActivated(bool bone, bool mesh, bool flipX, bool flipY) { var copyBuffer = EditorGUIUtility.systemCopyBuffer; if (!SkinningCopyUtility.CanDeserializeStringToSkinningCopyData(copyBuffer)) { Debug.LogError(TextContent.copyError1); return; } var skinningCopyData = SkinningCopyUtility.DeserializeStringToSkinningCopyData(copyBuffer); if (skinningCopyData == null || skinningCopyData.copyData.Count == 0) { Debug.LogError(TextContent.copyError2); return; } var scale = 1f; if (skinningCopyData.pixelsPerUnit > 0f) { scale = pixelsPerUnit / skinningCopyData.pixelsPerUnit; } var sprites = skinningCache.GetSprites(); var copyMultiple = skinningCopyData.copyData.Count > 1; if (copyMultiple && skinningCopyData.copyData.Count != sprites.Length && mesh) { Debug.LogError(String.Format(TextContent.copyError3, sprites.Length, skinningCopyData.copyData.Count)); return; } using (skinningCache.UndoScope(TextContent.pasteData)) { BoneCache[] newBones = null; if (copyMultiple && skinningCache.hasCharacter) { var skinningSpriteData = skinningCopyData.copyData[0]; newBones = skinningCache.CreateBoneCacheFromSpriteBones(skinningSpriteData.spriteBones.ToArray(), scale); var skeleton = skinningCache.character.skeleton; skeleton.SetBones(newBones); skinningCache.events.skeletonTopologyChanged.Invoke(skeleton); } foreach (var skinningSpriteData in skinningCopyData.copyData) { SpriteCache sprite; if (!String.IsNullOrEmpty(skinningSpriteData.spriteName)) { sprite = sprites.FirstOrDefault(x => x.name == skinningSpriteData.spriteName); } else { sprite = skinningCache.selectedSprite; } if (sprite == null) { continue; } if (bone && (!skinningCache.hasCharacter || !copyMultiple)) { newBones = PasteSkeletonBones(sprite, skinningSpriteData.spriteBones, flipX, flipY, scale); } if (mesh && meshTool != null) { PasteMesh(sprite, skinningSpriteData, flipX, flipY, scale, newBones); } } if (newBones != null) { skinningCache.skeletonSelection.elements = newBones; skinningCache.events.boneSelectionChanged.Invoke(); } } skinningCache.events.paste.Invoke(bone, mesh, flipX, flipY); }