static void RemapCharacterPartsToNewBones(SkinningCache skinningCache, SpriteBone[] newBones)
        {
            var skeleton           = skinningCache.character.skeleton;
            var previousStateBones = skeleton.bones;
            var skeletonBones      = skinningCache.CreateBoneCacheFromSpriteBones(newBones, 1.0f);

            skeleton.SetBones(skeletonBones);

            for (var i = 0; i < skinningCache.character.parts.Length; i++)
            {
                var characterPart = skinningCache.character.parts[i];
                var useGuids      = !skeletonBones.All(newBone => previousStateBones.All(oldBone => newBone.guid != oldBone.guid));
                characterPart.bones = useGuids ?
                                      characterPart.bones.Select(partBone => Array.Find(skeletonBones, skeletonBone => partBone.guid == skeletonBone.guid)).ToArray() :
                                      characterPart.bones.Select(partBone => skeletonBones.ElementAtOrDefault(Array.FindIndex(previousStateBones, oldBone => partBone.guid == oldBone.guid))).ToArray();

                var mesh = skinningCache.GetMesh(characterPart.sprite);
                if (mesh != null)
                {
                    mesh.SetCompatibleBoneSet(characterPart.bones);
                }

                skinningCache.character.parts[i] = characterPart;
            }
        }
Example #2
0
 static internal void ApplyChanges(SkinningCache skinningCache, ISpriteEditorDataProvider dataProvider)
 {
     skinningCache.applyingChanges = true;
     skinningCache.RestoreBindPose();
     ApplyBone(skinningCache, dataProvider);
     ApplyMesh(skinningCache, dataProvider);
     ApplyCharacter(skinningCache, dataProvider);
     skinningCache.applyingChanges = false;
 }
 public SpriteVisibilityTool(SkinningCache s)
 {
     m_SkinningCache = s;
     m_Data          = skinningCache.CreateCache <SpriteVisibilityToolData>();
     m_Controller    = new SpriteVisibilityToolController(this, skinningCache.events);
     m_View          = new SpriteVisibilityToolView()
     {
         GetController = () => m_Controller
     };
 }
Example #4
0
        static void ApplyBone(SkinningCache skinningCache, ISpriteEditorDataProvider dataProvider)
        {
            var boneDataProvider = dataProvider.GetDataProvider <ISpriteBoneDataProvider>();

            if (boneDataProvider != null)
            {
                var sprites = skinningCache.GetSprites();
                foreach (var sprite in sprites)
                {
                    var bones = sprite.GetSkeleton().bones;
                    boneDataProvider.SetBones(new GUID(sprite.id), bones.ToSpriteBone(sprite.localToWorldMatrix).ToList());
                }
            }
        }
        public MeshVisibilityToolView(SkinningCache s)
        {
            skinningCache = s;
            var columns = new MultiColumnHeaderState.Column[2];

            columns[0] = new MultiColumnHeaderState.Column
            {
                headerContent       = new GUIContent(TextContent.name),
                headerTextAlignment = TextAlignment.Center,
                width                 = 200,
                minWidth              = 130,
                autoResize            = true,
                allowToggleVisibility = false
            };
            columns[1] = new MultiColumnHeaderState.Column
            {
                headerContent       = new GUIContent(EditorGUIUtility.FindTexture("visibilityOn")),
                headerTextAlignment = TextAlignment.Center,
                width                 = 32,
                minWidth              = 32,
                maxWidth              = 32,
                autoResize            = false,
                allowToggleVisibility = true
            };
            var multiColumnHeaderState = new MultiColumnHeaderState(columns);
            var multiColumnHeader      = new VisibilityToolColumnHeader(multiColumnHeaderState)
            {
                GetAllVisibility = InternalGetAllVisibility,
                SetAllVisibility = InternalSetAllVisibility,
                canSort          = false,
                height           = 20,
                visibilityColumn = 1
            };

            m_TreeView = new MeshTreeView(m_TreeViewState, multiColumnHeader)
            {
                GetModel = InternalGetModel
            };
            SetupSearchField();
        }
Example #6
0
        static void ApplyMesh(SkinningCache skinningCache, ISpriteEditorDataProvider dataProvider)
        {
            var meshDataProvider = dataProvider.GetDataProvider <ISpriteMeshDataProvider>();

            if (meshDataProvider != null)
            {
                var sprites = skinningCache.GetSprites();
                foreach (var sprite in sprites)
                {
                    var mesh = sprite.GetMesh();
                    var guid = new GUID(sprite.id);
                    meshDataProvider.SetVertices(guid, mesh.vertices.Select(x =>
                                                                            new Vertex2DMetaData()
                    {
                        boneWeight = x.editableBoneWeight.ToBoneWeight(false),
                        position   = x.position
                    }
                                                                            ).ToArray());
                    meshDataProvider.SetIndices(guid, mesh.indices.ToArray());
                    meshDataProvider.SetEdges(guid, mesh.edges.Select(x => new Vector2Int(x.index1, x.index2)).ToArray());
                }
            }
        }
Example #7
0
        static void ApplyCharacter(SkinningCache skinningCache, ISpriteEditorDataProvider dataProvider)
        {
            var characterDataProvider = dataProvider.GetDataProvider <ICharacterDataProvider>();
            var character             = skinningCache.character;

            if (characterDataProvider != null && character != null)
            {
                var data           = new CharacterData();
                var characterBones = character.skeleton.bones;
                data.bones = characterBones.ToSpriteBone(Matrix4x4.identity);

                var parts = character.parts;
                data.parts = parts.Select(x =>
                                          new CharacterPart()
                {
                    spriteId       = x.sprite.id,
                    spritePosition = new RectInt((int)x.position.x, (int)x.position.y, (int)x.sprite.textureRect.width, (int)x.sprite.textureRect.height),
                    bones          = x.bones.Select(bone => Array.IndexOf(characterBones, bone)).ToArray()
                }
                                          ).ToArray();

                characterDataProvider.SetCharacterData(data);
            }
        }
Example #8
0
        public override void OnModuleActivate()
        {
            m_SkinningCache = Cache.Create <SkinningCache>();

            AddMainUI(spriteEditor.GetMainVisualContainer());

            using (skinningCache.DisableUndoScope())
            {
                skinningCache.Create(spriteEditor, SkinningCachePersistentState.instance);
                skinningCache.CreateToolCache(spriteEditor, m_LayoutOverlay);
                m_CharacterSpriteTool = skinningCache.CreateTool <SpriteBoneInfluenceTool>();
                m_CharacterSpriteTool.Initialize(m_LayoutOverlay);
                m_MeshPreviewTool = skinningCache.CreateTool <MeshPreviewTool>();
                SetupModuleToolGroup();
                m_MeshPreviewTool.Activate();

                m_SpriteOutlineRenderer = new SpriteOutlineRenderer(skinningCache.events);

                spriteEditor.enableMouseMoveEvent = true;

                Undo.undoRedoPerformed += UndoRedoPerformed;
                skinningCache.events.skeletonTopologyChanged.AddListener(SkeletonTopologyChanged);
                skinningCache.events.skeletonPreviewPoseChanged.AddListener(SkeletonPreviewPoseChanged);
                skinningCache.events.skeletonBindPoseChanged.AddListener(SkeletonBindPoseChanged);
                skinningCache.events.characterPartChanged.AddListener(CharacterPartChanged);
                skinningCache.events.skinningModeChanged.AddListener(OnViewModeChanged);
                skinningCache.events.meshChanged.AddListener(OnMeshChanged);
                skinningCache.events.boneNameChanged.AddListener(OnBoneNameChanged);
                skinningCache.events.boneDepthChanged.AddListener(OnBoneDepthChanged);
                skinningCache.events.spriteLibraryChanged.AddListener(OnSpriteLibraryChanged);
                skinningCache.events.meshPreviewBehaviourChange.AddListener(OnMeshPreviewBehaviourChange);

                skinningCache.RestoreFromPersistentState();
                ActivateTool(skinningCache.selectedTool);
                skinningCache.RestoreToolStateFromPersistentState();

                // Set state for Switch Mode tool
                m_PreviousSkinningMode = skinningCache.mode;
                if (skinningCache.mode == SkinningMode.Character)
                {
                    skinningCache.GetTool(Tools.SwitchMode).Deactivate();
                }
                else
                {
                    skinningCache.GetTool(Tools.SwitchMode).Activate();
                }
                SetupSpriteEditor(true);

                m_HorizontalToggleTools = new HorizontalToggleTools(skinningCache)
                {
                    onActivateTool = (b) =>
                    {
                        using (skinningCache.UndoScope(TextContent.setTool))
                        {
                            ActivateTool(b);
                        }
                    }
                };

                var ai = spriteEditor.GetDataProvider <ISpriteEditorDataProvider>() as AssetImporter;
                m_Analytics = new AnimationAnalytics(new UnityAnalyticsStorage(),
                                                     skinningCache.events,
                                                     new SkinningModuleAnalyticsModel(skinningCache),
                                                     ai == null ? -1 : ai.GetInstanceID());

                UpdateCollapseToolbar();
            }
        }
 public MeshVisibilityTool(SkinningCache s)
 {
     m_SkinningCache = s;
 }
 public BoneVisibilityTool(SkinningCache s)
 {
     m_SkinningCache = s;
 }
Example #11
0
 public void Setup(SkinningCache s)
 {
     skinningCache = s;
     skinningCache.events.skinningModeChanged.AddListener(OnSkinningModeChange);
 }
Example #12
0
 public BoneReparentToolModel(SkinningCache cache, IBoneVisibilityToolView view)
 {
     m_SkinningCache = cache;
     m_View          = view;
     m_Data          = skinningCache.CreateCache <BoneVisibilityToolData>();
 }
Example #13
0
 internal HorizontalToggleTools(SkinningCache s)
 {
     skinningCache = s;
 }
 public SkinningModuleAnalyticsModel(SkinningCache s)
 {
     skinningCache = s;
 }