Esempio n. 1
0
 internal override void OnCreate()
 {
     m_SkeletonController                = new SkeletonController();
     m_SkeletonController.view           = new SkeletonView(new GUIWrapper());
     m_SkeletonController.view.InvalidID = 0;
     m_SkeletonController.selection      = skinningCache.skeletonSelection;
     m_SkeletonToolView = new SkeletonToolView();
     m_SkeletonToolView.onBoneNameChanged     += BoneNameChanged;
     m_SkeletonToolView.onBoneDepthChanged    += BoneDepthChanged;
     m_SkeletonToolView.onBonePositionChanged += BonePositionChanged;
     m_SkeletonToolView.onBoneRotationChanged += BoneRotationChanged;
     m_SkeletonToolView.onBoneColorChanged    += BoneColorChanged;
     m_RectBoneSelector.selection              = skinningCache.skeletonSelection;
     m_RectSelectionTool.rectSelector          = m_RectBoneSelector;
     m_RectSelectionTool.cacheUndo             = skinningCache;
     m_RectSelectionTool.onSelectionUpdate    += () =>
     {
         skinningCache.events.boneSelectionChanged.Invoke();
     };
     m_UnselectTool.cacheUndo   = skinningCache;
     m_UnselectTool.selection   = skinningCache.skeletonSelection;
     m_UnselectTool.onUnselect += () =>
     {
         skinningCache.events.boneSelectionChanged.Invoke();
     };
 }
Esempio n. 2
0
        public NewBonesStore PasteSkeletonBones(SpriteCache sprite, List <SpriteBone> spriteBones, bool flipX, bool flipY, float scale = 1.0f)
        {
            NewBonesStore newBonesStore = new NewBonesStore();

            newBonesStore.newBones = skinningCache.CreateBoneCacheFromSpriteBones(spriteBones.ToArray(), scale);
            if (newBonesStore.newBones.Length == 0)
            {
                return(null);
            }

            if (sprite == null || (skinningCache.mode == SkinningMode.SpriteSheet && skinningCache.hasCharacter))
            {
                return(null);
            }

            var spriteRect = sprite.textureRect;
            var skeleton   = skinningCache.GetEffectiveSkeleton(sprite);

            var rectPosition = spriteRect.position;

            if (skinningCache.mode == SkinningMode.Character)
            {
                var characterPart = sprite.GetCharacterPart();
                if (characterPart == null)
                {
                    return(null);
                }
                rectPosition = characterPart.position;
            }

            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], rectPosition, spriteRect, flipX, flipY);
                newRotations[i] = GetFlippedBoneRotation(newBonesStore.newBones[i], flipX, flipY);
            }
            for (var i = 0; i < newBonesStore.newBones.Length; ++i)
            {
                if (newBonesStore.newBones[i].parent == null)
                {
                    SetBonePositionAndRotation(newBonesStore.newBones, newBonesStore.newBones[i], newPositions, newRotations);
                }
            }

            if (skinningCache.mode == SkinningMode.SpriteSheet)
            {
                newBonesStore.MapAllExistingBones();
                skeleton.SetBones(newBonesStore.newBones);
            }
            else
            {
                var existingBoneNames = skeleton.bones.Select(x => x.name).ToList();

                skeleton.AddBones(newBonesStore.newBones);

                var bones = skeleton.bones;

                // Update names of all newly pasted bones
                foreach (var bone in newBonesStore.newBones)
                {
                    if (existingBoneNames.Contains(bone.name))
                    {
                        var oldBoneName = bone.name;
                        bone.name = SkeletonController.AutoBoneName(bone.parentBone, bones);
                        existingBoneNames.Add(bone.name);
                        newBonesStore.newBoneNameDict.Add(oldBoneName, bone.name);
                    }
                    else
                    {
                        newBonesStore.newBoneNameDict.Add(bone.name, bone.name);
                    }
                }

                skeleton.SetDefaultPose();
            }

            skinningCache.events.skeletonTopologyChanged.Invoke(skeleton);
            return(newBonesStore);
        }