Пример #1
0
        public override void OnModuleActivate()
        {
            m_SkinningCache = Cache.Create <SkinningCache>();

            AddMainUI(spriteEditor.GetMainVisualContainer());

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

                ActivateTool(skinningCache.GetTool(Tools.EditPose));

                m_SpriteOutlineRenderer = new SpriteOutlineRenderer(spriteEditor, 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);

                m_PreviousSkinningMode = skinningCache.mode;

                SetupSpriteEditor();
                if (skinningCache.hasCharacter)
                {
                    m_WeightToolbar.EnableBoneInfluenceWidget();
                    skinningCache.GetTool(Tools.SwitchMode).Deactivate();
                    // Do not select any sprite by default in character mode
                    skinningCache.events.selectedSpriteChanged.Invoke(null);
                }
                else
                {
                    m_WeightToolbar.DisableBoneInfluenceWidget();
                }

                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();
            }
        }