public override void OnModuleActivate()
        {
            InitStyles();

            Undo.undoRedoPerformed           += UndoRedoPerformed;
            spriteEditor.enableMouseMoveEvent = true;

            IGUIWrapper guiWrapper = new GUIWrapper();

            m_SpriteMeshCache      = ScriptableObject.CreateInstance <SpriteMeshCache>();
            m_Triangulator         = new Triangulator();
            m_WeightGenerator      = new BoundedBiharmonicWeightsGenerator();
            m_OutlineGenerator     = new OutlineGenerator();
            m_UndoObject           = new UndoObject(m_SpriteMeshCache);
            m_SpriteMeshController = new SpriteMeshController();
            m_SpriteMeshView       = new SpriteMeshView(guiWrapper);
            m_BindPoseController   = new BindPoseController();
            m_BindPoseView         = new BindPoseView(guiWrapper);
            m_RectSelectionTool    = new RectSelectionTool(m_SpriteMeshCache);
            m_UnselectTool         = new UnselectTool(m_SpriteMeshCache);
            m_WeightEditor         = new WeightEditor();
            m_BrushWeightTool      = new BrushWeightTool();
            m_SliderWeightTool     = new SliderWeightTool();
            m_WeightInspector      = new WeightInspector(m_SpriteMeshCache);
            m_BoneInspector        = new BoneInspector(m_SpriteMeshCache);
            m_MeshPreview          = new MeshPreview();

            var dataProvider       = spriteEditor.GetDataProvider <ISpriteEditorDataProvider>();
            var boneProvider       = spriteEditor.GetDataProvider <ISpriteBoneDataProvider>();
            var spriteMeshProvider = spriteEditor.GetDataProvider <ISpriteMeshDataProvider>();
            var spriteRects        = dataProvider.GetSpriteRects();
            var textureProvider    = spriteEditor.GetDataProvider <ITextureDataProvider>();

            m_MeshPreview.textureDataProvider = textureProvider;

            for (var i = 0; i < spriteRects.Length; i++)
            {
                var spriteRect     = spriteRects[i];
                var spriteMeshData = new SpriteMeshData();
                spriteMeshData.spriteID = spriteRect.spriteID;
                spriteMeshData.frame    = spriteRect.rect;
                spriteMeshData.pivot    = spriteRect.rect.position + Vector2.Scale(spriteRect.rect.size, spriteRect.pivot);
                spriteMeshData.bones    = MeshModuleUtility.CreateSpriteBoneData(boneProvider.GetBones(spriteRect.spriteID), spriteMeshData.CalculateRootMatrix());

                var metaVertices = spriteMeshProvider.GetVertices(spriteRect.spriteID);
                foreach (var mv in metaVertices)
                {
                    var v = new Vertex2D(mv.position + spriteRect.rect.position, mv.boneWeight);
                    spriteMeshData.vertices.Add(v);
                }

                spriteMeshData.indices = new List <int>(spriteMeshProvider.GetIndices(spriteRect.spriteID));

                Vector2Int[] edges = spriteMeshProvider.GetEdges(spriteRect.spriteID);

                foreach (var e in edges)
                {
                    spriteMeshData.edges.Add(new Edge(e.x, e.y));
                }

                m_SpriteMeshCache.AddSpriteMeshData(spriteMeshData);
            }

            m_WeightEditorWindow = new ModuleWindow(Contents.weightEditor.text, new Rect(0f, 0f, 300f, 195f));
            m_WeightEditorWindow.windowGUICallback = WeightEditorInspector;

            m_InspectorWindow = new ModuleWindow(Contents.inspector.text, new Rect(0f, 0f, 300f, 95f));

            m_GenerateGeometryMenuContents.settings           = m_GenerateGeometrySettings;
            m_GenerateGeometryMenuContents.onGenerateGeometry = OnGenerateGeometry;

            m_BindPoseController.onSkinPreviewChanged += () =>
            {
                m_MeshPreview.SetSkinningDirty();
            };

            m_MeshPreview.SetMeshDirty();

            m_CachedSpriteMeshData = selectedSpriteMeshData;
        }
Beispiel #2
0
 internal override void OnCreate()
 {
     m_SpriteMeshController = new SpriteMeshController();
     m_SpriteMeshView       = new SpriteMeshView(new GUIWrapper());
     m_Triangulator         = new Triangulator();
 }