Inheritance: UnityEditor.AssetPostprocessor
        void RepopulateWarnings()
        {
            warnings.Clear();

            if (skeletonJSON.objectReferenceValue == null)
            {
                warnings.Add("Missing Skeleton JSON");
            }
            else
            {
                if (SpineEditorUtilities.IsValidSpineData((TextAsset)skeletonJSON.objectReferenceValue) == false)
                {
                    warnings.Add("Skeleton data file is not a valid JSON or binary file.");
                }
                else
                {
                    bool detectedNullAtlasEntry = false;
                    var  atlasList = new List <Atlas>();
                    for (int i = 0; i < atlasAssets.arraySize; i++)
                    {
                        if (atlasAssets.GetArrayElementAtIndex(i).objectReferenceValue == null)
                        {
                            detectedNullAtlasEntry = true;
                            break;
                        }
                        else
                        {
                            atlasList.Add(((AtlasAsset)atlasAssets.GetArrayElementAtIndex(i).objectReferenceValue).GetAtlas());
                        }
                    }

                    if (detectedNullAtlasEntry)
                    {
                        warnings.Add("AtlasAsset elements cannot be Null");
                    }
                    else
                    {
                        //get requirements
                        var missingPaths = SpineEditorUtilities.GetRequiredAtlasRegions(AssetDatabase.GetAssetPath((TextAsset)skeletonJSON.objectReferenceValue));

                        foreach (var atlas in atlasList)
                        {
                            for (int i = 0; i < missingPaths.Count; i++)
                            {
                                if (atlas.FindRegion(missingPaths[i]) != null)
                                {
                                    missingPaths.RemoveAt(i);
                                    i--;
                                }
                            }
                        }

                        foreach (var str in missingPaths)
                        {
                            warnings.Add("Missing Region: '" + str + "'");
                        }
                    }
                }
            }
        }
 void DoReimport()
 {
     SpineEditorUtilities.ImportSpineContent(new [] { AssetDatabase.GetAssetPath(skeletonJSON.objectReferenceValue) }, true);
     preview.Clear();
     InitializeEditor();
     EditorUtility.SetDirty(targetSkeletonDataAsset);
 }
        private void CreatePreviewInstances()
        {
            this.DestroyPreviewInstances();
            if (this.m_previewInstance == null)
            {
                try {
                    string skinName = EditorPrefs.GetString(m_skeletonDataAssetGUID + "_lastSkin", "");

                    m_previewInstance           = SpineEditorUtilities.InstantiateSkeletonAnimation((SkeletonDataAsset)target, skinName).gameObject;
                    m_previewInstance.hideFlags = HideFlags.HideAndDontSave;
                    m_previewInstance.layer     = 0x1f;


                    m_skeletonAnimation = m_previewInstance.GetComponent <SkeletonAnimation>();
                    m_skeletonAnimation.initialSkinName = skinName;
                    m_skeletonAnimation.LateUpdate();

                    m_skeletonData = m_skeletonAnimation.skeletonDataAsset.GetSkeletonData(true);

                    m_previewInstance.GetComponent <Renderer>().enabled = false;

                    m_initialized = true;
                    AdjustCameraGoals(true);
                } catch {
                    // WARNING: Suppresses errors.
                }
            }
        }
        void CreatePreviewInstances()
        {
            this.DestroyPreviewInstances();

            var skeletonDataAsset = (SkeletonDataAsset)target;

            if (skeletonDataAsset.GetSkeletonData(false) == null)
            {
                return;
            }

            if (this.m_previewInstance == null)
            {
                string skinName = EditorPrefs.GetString(m_skeletonDataAssetGUID + "_lastSkin", "");
                m_previewInstance = SpineEditorUtilities.InstantiateSkeletonAnimation(skeletonDataAsset, skinName).gameObject;

                if (m_previewInstance != null)
                {
                    m_previewInstance.hideFlags         = HideFlags.HideAndDontSave;
                    m_previewInstance.layer             = 0x1f;
                    m_skeletonAnimation                 = m_previewInstance.GetComponent <SkeletonAnimation>();
                    m_skeletonAnimation.initialSkinName = skinName;
                    m_skeletonAnimation.LateUpdate();
                    m_skeletonData = m_skeletonAnimation.skeletonDataAsset.GetSkeletonData(true);
                    m_previewInstance.GetComponent <Renderer>().enabled = false;
                    m_initialized = true;
                }

                AdjustCameraGoals(true);
            }
        }
        void OnSceneGUI()
        {
            if (skeleton == null)
            {
                OnEnable();
                return;
            }

            var m = transform.localToWorldMatrix;

            foreach (Bone b in skeleton.Bones)
            {
                Vector3     pos   = new Vector3(b.WorldX, b.WorldY, 0);
                Quaternion  rot   = Quaternion.Euler(0, 0, b.WorldRotationX - 90f);
                Vector3     scale = Vector3.one * b.Data.Length * b.WorldScaleX;
                const float mx    = 2.5f;
                scale.x = Mathf.Clamp(scale.x, -mx, mx);
                SpineEditorUtilities.DrawBone(m * Matrix4x4.TRS(pos, rot, scale));
            }

            foreach (Slot s in skeleton.DrawOrder)
            {
                var p = s.Attachment as PathAttachment;
                if (p != null)
                {
                    SpineEditorUtilities.DrawPath(s, p, transform);
                }
            }
        }
        void UpdateBakedList()
        {
            AtlasAsset asset = (AtlasAsset)target;

            baked        = new List <bool>();
            bakedObjects = new List <GameObject>();
            if (atlasFile.objectReferenceValue != null)
            {
                Atlas              atlas             = asset.GetAtlas();
                FieldInfo          field             = typeof(Atlas).GetField("regions", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.NonPublic);
                List <AtlasRegion> regions           = (List <AtlasRegion>)field.GetValue(atlas);
                string             atlasAssetPath    = AssetDatabase.GetAssetPath(atlasAsset);
                string             atlasAssetDirPath = Path.GetDirectoryName(atlasAssetPath);
                string             bakedDirPath      = Path.Combine(atlasAssetDirPath, atlasAsset.name);


                for (int i = 0; i < regions.Count; i++)
                {
                    AtlasRegion region          = regions[i];
                    string      bakedPrefabPath = Path.Combine(bakedDirPath, SpineEditorUtilities.GetPathSafeRegionName(region) + ".prefab").Replace("\\", "/");
                    GameObject  prefab          = (GameObject)AssetDatabase.LoadAssetAtPath(bakedPrefabPath, typeof(GameObject));
                    baked.Add(prefab != null);
                    bakedObjects.Add(prefab);
                }
            }
        }
        void OnEnable()
        {
            SpineEditorUtilities.ConfirmInitialization();

            atlasAssets            = serializedObject.FindProperty("atlasAssets");
            atlasAssets.isExpanded = true;
            skeletonJSON           = serializedObject.FindProperty("skeletonJSON");
            scale         = serializedObject.FindProperty("scale");
            fromAnimation = serializedObject.FindProperty("fromAnimation");
            toAnimation   = serializedObject.FindProperty("toAnimation");
            duration      = serializedObject.FindProperty("duration");
            defaultMix    = serializedObject.FindProperty("defaultMix");
                        #if SPINE_SKELETON_ANIMATOR
            controller = serializedObject.FindProperty("controller");
                        #endif
                        #if SPINE_TK2D
            spriteCollection = serializedObject.FindProperty("spriteCollection");
                        #endif

            m_skeletonDataAsset     = (SkeletonDataAsset)target;
            m_skeletonDataAssetGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_skeletonDataAsset));

            EditorApplication.update += Update;

            m_skeletonData = m_skeletonDataAsset.GetSkeletonData(false);

                        #if SPINE_BAKING
            showBaking = EditorPrefs.GetBool("SkeletonDataAssetInspector_showUnity", false);
                        #endif

            InitPreview();
            RepopulateWarnings();
        }
Beispiel #8
0
        override public void OnInspectorGUI()
        {
            bool multi = serializedObject.isEditingMultipleObjects;

            DrawInspectorGUI(multi);
            HandleSkinChange();
            if (serializedObject.ApplyModifiedProperties() || SpineInspectorUtility.UndoRedoPerformed(Event.current) ||
                AreAnyMaskMaterialsMissing())
            {
                if (!Application.isPlaying)
                {
                    if (multi)
                    {
                        foreach (var o in targets)
                        {
                            SpineEditorUtilities.ReinitializeComponent((SkeletonRenderer)o);
                        }
                    }
                    else
                    {
                        SpineEditorUtilities.ReinitializeComponent((SkeletonRenderer)target);
                    }
                    SceneView.RepaintAll();
                }
            }
        }
        void OnEnable()
        {
            SpineEditorUtilities.ConfirmInitialization();
            m_skeletonDataAsset = (SkeletonDataAsset)target;

            atlasAssets   = serializedObject.FindProperty("atlasAssets");
            skeletonJSON  = serializedObject.FindProperty("skeletonJSON");
            scale         = serializedObject.FindProperty("scale");
            fromAnimation = serializedObject.FindProperty("fromAnimation");
            toAnimation   = serializedObject.FindProperty("toAnimation");
            duration      = serializedObject.FindProperty("duration");
            defaultMix    = serializedObject.FindProperty("defaultMix");

                        #if SPINE_SKELETON_ANIMATOR
            controller = serializedObject.FindProperty("controller");
                        #endif

                        #if SPINE_TK2D
            atlasAssets.isExpanded = false;
            spriteCollection       = serializedObject.FindProperty("spriteCollection");
                        #else
            atlasAssets.isExpanded = true;
                        #endif

                        #if SPINE_BAKING
            isBakingExpanded = EditorPrefs.GetBool(ShowBakingPrefsKey, false);
                        #endif

            m_skeletonDataAssetGUID   = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_skeletonDataAsset));
            EditorApplication.update += EditorUpdate;
            RepopulateWarnings();
            m_skeletonData = warnings.Count == 0 ? m_skeletonDataAsset.GetSkeletonData(false) : null;
        }
        void OnEnable()
        {
            SpineEditorUtilities.ConfirmInitialization();
            m_skeletonDataAsset = (SkeletonDataAsset)target;

            // Clear empty atlas array items.
            {
                bool hasNulls = false;
                foreach (var a in m_skeletonDataAsset.atlasAssets)
                {
                    if (a == null)
                    {
                        hasNulls = true;
                        break;
                    }
                }
                if (hasNulls)
                {
                    var trimmedAtlasAssets = new List <AtlasAsset>();
                    foreach (var a in m_skeletonDataAsset.atlasAssets)
                    {
                        if (a != null)
                        {
                            trimmedAtlasAssets.Add(a);
                        }
                    }
                    m_skeletonDataAsset.atlasAssets = trimmedAtlasAssets.ToArray();
                }
            }

            atlasAssets   = serializedObject.FindProperty("atlasAssets");
            skeletonJSON  = serializedObject.FindProperty("skeletonJSON");
            scale         = serializedObject.FindProperty("scale");
            fromAnimation = serializedObject.FindProperty("fromAnimation");
            toAnimation   = serializedObject.FindProperty("toAnimation");
            duration      = serializedObject.FindProperty("duration");
            defaultMix    = serializedObject.FindProperty("defaultMix");

                        #if SPINE_SKELETON_ANIMATOR
            controller = serializedObject.FindProperty("controller");
                        #endif

                        #if SPINE_TK2D
            atlasAssets.isExpanded = false;
            spriteCollection       = serializedObject.FindProperty("spriteCollection");
                        #else
            atlasAssets.isExpanded = true;
                        #endif

                        #if SPINE_BAKING
            isBakingExpanded = EditorPrefs.GetBool(ShowBakingPrefsKey, false);
                        #endif

            m_skeletonDataAssetGUID   = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_skeletonDataAsset));
            EditorApplication.update += EditorUpdate;
            m_skeletonData            = m_skeletonDataAsset.GetSkeletonData(false);
            RepopulateWarnings();
        }
Beispiel #11
0
        protected virtual void OnEnable()
        {
#if NEW_PREFAB_SYSTEM
            isInspectingPrefab = false;
#else
            isInspectingPrefab = (PrefabUtility.GetPrefabType(target) == PrefabType.Prefab);
#endif
            SpineEditorUtilities.ConfirmInitialization();

            // Labels
            SkeletonDataAssetLabel       = new GUIContent("SkeletonData Asset", Icons.spine);
            SkeletonUtilityButtonContent = new GUIContent("Add Skeleton Utility", Icons.skeletonUtility);
            ImmubleTrianglesLabel        = new GUIContent("Immutable Triangles", "Enable to optimize rendering for skeletons that never change attachment visbility");
            PMAVertexColorsLabel         = new GUIContent("PMA Vertex Colors", "Use this if you are using the default Spine/Skeleton shader or any premultiply-alpha shader.");
            ClearStateOnDisableLabel     = new GUIContent("Clear State On Disable", "Use this if you are pooling or enabling/disabling your Spine GameObject.");
            ZSpacingLabel             = new GUIContent("Z Spacing", "A value other than 0 adds a space between each rendered attachment to prevent Z Fighting when using shaders that read or write to the depth buffer. Large values may cause unwanted parallax and spaces depending on camera setup.");
            NormalsLabel              = new GUIContent("Add Normals", "Use this if your shader requires vertex normals. A more efficient solution for 2D setups is to modify the shader to assume a single normal value for the whole mesh.");
            TangentsLabel             = new GUIContent("Solve Tangents", "Calculates the tangents per frame. Use this if you are using lit shaders (usually with normal maps) that require vertex tangents.");
            TintBlackLabel            = new GUIContent("Tint Black (!)", "Adds black tint vertex data to the mesh as UV2 and UV3. Black tinting requires that the shader interpret UV2 and UV3 as black tint colors for this effect to work. You may also use the default [Spine/Skeleton Tint Black] shader.\n\nIf you only need to tint the whole skeleton and not individual parts, the [Spine/Skeleton Tint] shader is recommended for better efficiency and changing/animating the _Black material property via MaterialPropertyBlock.");
            SingleSubmeshLabel        = new GUIContent("Use Single Submesh", "Simplifies submesh generation by assuming you are only using one Material and need only one submesh. This is will disable multiple materials, render separation, and custom slot materials.");
            UpdateWhenInvisibleLabel  = new GUIContent("Update When Invisible", "Update mode used when the MeshRenderer becomes invisible. Update mode is automatically reset to UpdateMode.FullUpdate when the mesh becomes visible again.");
            FixDrawOrderLabel         = new GUIContent("Fix Draw Order", "Applies only when 3+ submeshes are used (2+ materials with alternating order, e.g. \"A B A\"). If true, GPU instancing will be disabled at all materials and MaterialPropertyBlocks are assigned at each material to prevent aggressive batching of submeshes by e.g. the LWRP renderer, leading to incorrect draw order (e.g. \"A1 B A2\" changed to \"A1A2 B\"). You can disable this parameter when everything is drawn correctly to save the additional performance cost. Note: the GPU instancing setting will remain disabled at affected material assets after exiting play mode, you have to enable it manually if you accidentally enabled this parameter.");
            MaskInteractionLabel      = new GUIContent("Mask Interaction", "SkeletonRenderer's interaction with a Sprite Mask.");
            MaskMaterialsHeadingLabel = new GUIContent("Mask Interaction Materials", "Materials used for different interaction with sprite masks.");
            MaskMaterialsNoneLabel    = new GUIContent("Normal Materials", "Normal materials used when Mask Interaction is set to None.");
            MaskMaterialsInsideLabel  = new GUIContent("Inside Mask", "Materials used when Mask Interaction is set to Inside Mask.");
            MaskMaterialsOutsideLabel = new GUIContent("Outside Mask", "Materials used when Mask Interaction is set to Outside Mask.");
            SetMaterialButtonLabel    = new GUIContent("Set", "Prepares material references for switching to the corresponding Mask Interaction mode at runtime. Creates the required materials if they do not exist.");
            ClearMaterialButtonLabel  = new GUIContent("Clear", "Clears unused material references. Note: when switching to the corresponding Mask Interaction mode at runtime, a new material is generated on the fly.");
            DeleteMaterialButtonLabel = new GUIContent("Delete", "Clears unused material references and deletes the corresponding assets. Note: when switching to the corresponding Mask Interaction mode at runtime, a new material is generated on the fly.");

            var so = this.serializedObject;
            skeletonDataAsset    = so.FindProperty("skeletonDataAsset");
            initialSkinName      = so.FindProperty("initialSkinName");
            initialFlipX         = so.FindProperty("initialFlipX");
            initialFlipY         = so.FindProperty("initialFlipY");
            normals              = so.FindProperty("addNormals");
            tangents             = so.FindProperty("calculateTangents");
            immutableTriangles   = so.FindProperty("immutableTriangles");
            pmaVertexColors      = so.FindProperty("pmaVertexColors");
            clearStateOnDisable  = so.FindProperty("clearStateOnDisable");
            tintBlack            = so.FindProperty("tintBlack");
            updateWhenInvisible  = so.FindProperty("updateWhenInvisible");
            singleSubmesh        = so.FindProperty("singleSubmesh");
            fixDrawOrder         = so.FindProperty("fixDrawOrder");
            maskInteraction      = so.FindProperty("maskInteraction");
            maskMaterialsNone    = so.FindProperty("maskMaterials.materialsMaskDisabled");
            maskMaterialsInside  = so.FindProperty("maskMaterials.materialsInsideMask");
            maskMaterialsOutside = so.FindProperty("maskMaterials.materialsOutsideMask");

            separatorSlotNames            = so.FindProperty("separatorSlotNames");
            separatorSlotNames.isExpanded = true;

            zSpacing = so.FindProperty("zSpacing");

            SerializedObject renderersSerializedObject = SpineInspectorUtility.GetRenderersSerializedObject(serializedObject);             // Allows proper multi-edit behavior.
            sortingProperties = new SpineInspectorUtility.SerializedSortingProperties(renderersSerializedObject);
        }
 void OnEnable()
 {
     SpineEditorUtilities.ConfirmInitialization();
     atlasFile            = serializedObject.FindProperty("atlasFile");
     materials            = serializedObject.FindProperty("materials");
     materials.isExpanded = true;
     atlasAsset           = (AtlasAsset)target;
     UpdateBakedList();
 }
        public void Initialize(SkeletonDataAsset skeletonDataAsset, string skinName = "")
        {
            if (skeletonDataAsset == null)
            {
                return;
            }
            if (skeletonDataAsset.GetSkeletonData(false) == null)
            {
                return;
            }

            this.skeletonDataAsset = skeletonDataAsset;
            this.skeletonData      = skeletonDataAsset.GetSkeletonData(false);

            if (previewRenderUtility == null)
            {
                previewRenderUtility = new PreviewRenderUtility(true);
                animationLastTime    = Time.realtimeSinceStartup;

                const int PreviewLayer             = 31;
                const int PreviewCameraCullingMask = 1 << PreviewLayer;

                {
                    var c = this.PreviewUtilityCamera;
                    c.orthographic     = true;
                    c.orthographicSize = 1;
                    c.cullingMask      = PreviewCameraCullingMask;
                    c.nearClipPlane    = 0.01f;
                    c.farClipPlane     = 1000f;
                }

                DestroyPreviewGameObject();

                if (previewGameObject == null)
                {
                    try {
                        previewGameObject = SpineEditorUtilities.InstantiateSkeletonAnimation(skeletonDataAsset, skinName).gameObject;

                        if (previewGameObject != null)
                        {
                            previewGameObject.hideFlags       = HideFlags.HideAndDontSave;
                            previewGameObject.layer           = PreviewLayer;
                            skeletonAnimation                 = previewGameObject.GetComponent <SkeletonAnimation>();
                            skeletonAnimation.initialSkinName = skinName;
                            skeletonAnimation.LateUpdate();
                            previewGameObject.GetComponent <Renderer>().enabled = false;
                            previewRenderUtility.AddSingleGO(previewGameObject);
                        }

                        AdjustCameraGoals(true);
                    } catch {
                        DestroyPreviewGameObject();
                    }
                }
            }
        }
        void InitializeEditor()
        {
            SpineEditorUtilities.ConfirmInitialization();
            targetSkeletonDataAsset           = (SkeletonDataAsset)target;
            targetSkeletonDataAssetGUIDString = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(targetSkeletonDataAsset));

            bool newAtlasAssets = atlasAssets == null;

            if (newAtlasAssets)
            {
                atlasAssets = serializedObject.FindProperty("atlasAssets");
            }
            skeletonJSON  = serializedObject.FindProperty("skeletonJSON");
            scale         = serializedObject.FindProperty("scale");
            fromAnimation = serializedObject.FindProperty("fromAnimation");
            toAnimation   = serializedObject.FindProperty("toAnimation");
            duration      = serializedObject.FindProperty("duration");
            defaultMix    = serializedObject.FindProperty("defaultMix");

                        #if SPINE_SKELETON_ANIMATOR
            controller = serializedObject.FindProperty("controller");
                        #endif

                        #if SPINE_TK2D
            if (newAtlasAssets)
            {
                atlasAssets.isExpanded = false;
            }
            spriteCollection = serializedObject.FindProperty("spriteCollection");
                        #else
            // Analysis disable once ConvertIfToOrExpression
            if (newAtlasAssets)
            {
                atlasAssets.isExpanded = true;
            }
                        #endif

            EditorApplication.update -= EditorUpdate;
            EditorApplication.update += EditorUpdate;
            preview.OnSkinChanged    -= HandlePreviewSkinChanged;
            preview.OnSkinChanged    += HandlePreviewSkinChanged;

            PopulateWarnings();
            if (targetSkeletonDataAsset.skeletonJSON == null)
            {
                targetSkeletonData = null;
                return;
            }

            targetSkeletonData = warnings.Count == 0 ? targetSkeletonDataAsset.GetSkeletonData(false) : null;

            if (targetSkeletonData != null && warnings.Count <= 0)
            {
                preview.Initialize(targetSkeletonDataAsset, this.LastSkinName);
            }
        }
Beispiel #15
0
        internal static void PostprocessBuild()
        {
            isBuilding = false;
#if HAS_ON_POSTPROCESS_PREFAB
            foreach (string assetPath in prefabsToRestore)
            {
                GameObject g = AssetDatabase.LoadAssetAtPath <GameObject>(assetPath);
                SpineEditorUtilities.SetupSpinePrefabMesh(g, null);
            }
            AssetDatabase.SaveAssets();
#endif
        }
        void DoReimport()
        {
            SpineEditorUtilities.ImportSpineContent(new string[] { AssetDatabase.GetAssetPath(skeletonJSON.objectReferenceValue) }, true);
            if (m_previewUtility != null)
            {
                m_previewUtility.Cleanup();
                m_previewUtility = null;
            }

            OnEnable();             // Should call RepopulateWarnings.
            EditorUtility.SetDirty(m_skeletonDataAsset);
        }
Beispiel #17
0
 static void EditorDeleteMaskMaterials(SkeletonRenderer component, SpriteMaskInteraction maskType)
 {
     if (component == null)
     {
         return;
     }
     if (!SpineEditorUtilities.SkeletonDataAssetIsValid(component.SkeletonDataAsset))
     {
         return;
     }
     SpineMaskUtilities.EditorDeleteMaskMaterials(component.maskMaterials, maskType);
 }
        void OnEnable()
        {
            SpineEditorUtilities.ConfirmInitialization();
            m_skeletonDataAsset = (SkeletonDataAsset)target;

            bool newAtlasAssets = atlasAssets == null;

            if (newAtlasAssets)
            {
                atlasAssets = serializedObject.FindProperty("atlasAssets");
            }
            skeletonJSON  = serializedObject.FindProperty("skeletonJSON");
            scale         = serializedObject.FindProperty("scale");
            fromAnimation = serializedObject.FindProperty("fromAnimation");
            toAnimation   = serializedObject.FindProperty("toAnimation");
            duration      = serializedObject.FindProperty("duration");
            defaultMix    = serializedObject.FindProperty("defaultMix");

                        #if SPINE_SKELETON_ANIMATOR
            controller = serializedObject.FindProperty("controller");
                        #endif

                        #if SPINE_TK2D
            if (newAtlasAssets)
            {
                atlasAssets.isExpanded = false;
            }
            spriteCollection = serializedObject.FindProperty("spriteCollection");
                        #else
            if (newAtlasAssets)
            {
                atlasAssets.isExpanded = true;
            }
                        #endif

            m_skeletonDataAssetGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_skeletonDataAsset));

            EditorApplication.update -= EditorUpdate;
            EditorApplication.update += EditorUpdate;

            RepopulateWarnings();
            if (m_skeletonDataAsset.skeletonJSON == null)
            {
                m_skeletonData = null;
                return;
            }

            m_skeletonData = warnings.Count == 0 ? m_skeletonDataAsset.GetSkeletonData(false) : null;
        }
Beispiel #19
0
        void OnEnable()
        {
#if NEW_PREFAB_SYSTEM
            isInspectingPrefab = false;
#else
            isInspectingPrefab = (PrefabUtility.GetPrefabType(target) == PrefabType.Prefab);
#endif
            SpineEditorUtilities.ConfirmInitialization();

            // Labels
            SkeletonDataAssetLabel = new GUIContent("SkeletonData Asset", Icons.spine);

            var so = this.serializedObject;
            thisSkeletonGraphic = target as SkeletonGraphic;

            // MaskableGraphic
            material      = so.FindProperty("m_Material");
            color         = so.FindProperty("m_Color");
            raycastTarget = so.FindProperty("m_RaycastTarget");

            // SkeletonRenderer
            additiveMaterial = so.FindProperty("additiveMaterial");
            multiplyMaterial = so.FindProperty("multiplyMaterial");
            screenMaterial   = so.FindProperty("screenMaterial");

            skeletonDataAsset = so.FindProperty("skeletonDataAsset");
            initialSkinName   = so.FindProperty("initialSkinName");

            initialFlipX = so.FindProperty("initialFlipX");
            initialFlipY = so.FindProperty("initialFlipY");

            // SkeletonAnimation
            startingAnimation   = so.FindProperty("startingAnimation");
            startingLoop        = so.FindProperty("startingLoop");
            timeScale           = so.FindProperty("timeScale");
            unscaledTime        = so.FindProperty("unscaledTime");
            freeze              = so.FindProperty("freeze");
            updateWhenInvisible = so.FindProperty("updateWhenInvisible");

            meshGeneratorSettings            = so.FindProperty("meshGenerator").FindPropertyRelative("settings");
            meshGeneratorSettings.isExpanded = SkeletonRendererInspector.advancedFoldout;

            allowMultipleCanvasRenderers = so.FindProperty("allowMultipleCanvasRenderers");
            updateSeparatorPartLocation  = so.FindProperty("updateSeparatorPartLocation");
            enableSeparatorSlots         = so.FindProperty("enableSeparatorSlots");

            separatorSlotNames            = so.FindProperty("separatorSlotNames");
            separatorSlotNames.isExpanded = true;
        }
        void OnEnable()
        {
            SpineEditorUtilities.ConfirmInitialization();
            atlasFile            = serializedObject.FindProperty("spriteAtlasFile");
            materials            = serializedObject.FindProperty("materials");
            materials.isExpanded = true;
            atlasAsset           = (SpineSpriteAtlasAsset)target;

            if (!SpineSpriteAtlasAsset.AnySpriteAtlasNeedsRegionsLoaded())
            {
                return;
            }
            EditorApplication.update -= SpineSpriteAtlasAsset.UpdateWhenEditorPlayModeStarted;
            EditorApplication.update += SpineSpriteAtlasAsset.UpdateWhenEditorPlayModeStarted;
        }
        void DoRenderPreview(bool drawHandles)
        {
            GameObject go = this.m_previewInstance;

            if (m_requireRefresh && go != null)
            {
                go.GetComponent <Renderer>().enabled = true;

                if (!EditorApplication.isPlaying)
                {
                    m_skeletonAnimation.Update((Time.realtimeSinceStartup - m_lastTime));
                }

                m_lastTime = Time.realtimeSinceStartup;

                if (!EditorApplication.isPlaying)
                {
                    m_skeletonAnimation.LateUpdate();
                }

                if (drawHandles)
                {
                    Handles.SetCamera(m_previewUtility.m_Camera);
                    Handles.color = m_originColor;

                    Handles.DrawLine(new Vector3(-1000 * m_skeletonDataAsset.scale, 0, 0), new Vector3(1000 * m_skeletonDataAsset.scale, 0, 0));
                    Handles.DrawLine(new Vector3(0, 1000 * m_skeletonDataAsset.scale, 0), new Vector3(0, -1000 * m_skeletonDataAsset.scale, 0));
                }

                this.m_previewUtility.m_Camera.Render();

                if (drawHandles)
                {
                    Handles.SetCamera(m_previewUtility.m_Camera);
                    foreach (var slot in m_skeletonAnimation.skeleton.Slots)
                    {
                        var boundingBoxAttachment = slot.Attachment as BoundingBoxAttachment;
                        if (boundingBoxAttachment != null)
                        {
                            SpineEditorUtilities.DrawBoundingBox(slot, boundingBoxAttachment);
                        }
                    }
                }

                go.GetComponent <Renderer>().enabled = false;
            }
        }
Beispiel #22
0
        internal static void PreprocessBuild()
        {
            isBuilding = true;
#if HAS_ON_POSTPROCESS_PREFAB
            var assets = AssetDatabase.FindAssets("t:Prefab");
            foreach (var asset in assets)
            {
                string     assetPath = AssetDatabase.GUIDToAssetPath(asset);
                GameObject g         = AssetDatabase.LoadAssetAtPath <GameObject>(assetPath);
                if (SpineEditorUtilities.CleanupSpinePrefabMesh(g))
                {
                    prefabsToRestore.Add(assetPath);
                }
            }
            AssetDatabase.SaveAssets();
#endif
        }
Beispiel #23
0
		static string[] OnWillSaveAssets(string[] paths)
		{
			if (SpineEditorUtilities.Preferences.textureImporterWarning) {
				foreach (string path in paths) {
					if ((path != null) &&
						(path.EndsWith(".png.meta", System.StringComparison.Ordinal) ||
						 path.EndsWith(".jpg.meta", System.StringComparison.Ordinal))) {

						string texturePath = System.IO.Path.ChangeExtension(path, null); // .meta removed
						string atlasPath = System.IO.Path.ChangeExtension(texturePath, "atlas.txt");
						if (System.IO.File.Exists(atlasPath))
							SpineEditorUtilities.IssueWarningsForUnrecommendedTextureSettings(texturePath);
					}
				}
			}
			return paths;
		}
Beispiel #24
0
        void CreatePreviewInstances()
        {
            return;

            this.DestroyPreviewInstances();

            if (warnings.Count > 0)
            {
                m_skeletonDataAsset.Clear();
                return;
            }

            var skeletonDataAsset = (SkeletonDataAsset)target;

            if (skeletonDataAsset.GetSkeletonData(false) == null)
            {
                return;
            }

            if (this.m_previewInstance == null)
            {
                string skinName = EditorPrefs.GetString(m_skeletonDataAssetGUID + "_lastSkin", "");

                try {
                    m_previewInstance = SpineEditorUtilities.InstantiateSkeletonAnimation(skeletonDataAsset, skinName).gameObject;
                    // var t = GameObject.CreatePrimitive(PrimitiveType.Cube).transform;
                    // t.SetParent(this.m_previewInstance.transform);
                    // t.localPosition = Vector3.zero;
                    if (m_previewInstance != null)
                    {
                        m_previewInstance.hideFlags         = HideFlags.HideAndDontSave;
                        m_previewInstance.layer             = 0x1f;
                        m_skeletonAnimation                 = m_previewInstance.GetComponent <SkeletonAnimation>();
                        m_skeletonAnimation.initialSkinName = skinName;
                        m_skeletonAnimation.LateUpdate();
                        m_skeletonData = m_skeletonAnimation.skeletonDataAsset.GetSkeletonData(true);
                        m_previewInstance.GetComponent <Renderer>().enabled = false;
                        m_initialized = true;
                    }

                    AdjustCameraGoals(true);
                } catch {
                    DestroyPreviewInstances();
                }
            }
        }
        protected virtual void OnEnable()
        {
            SpineEditorUtilities.ConfirmInitialization();
            skeletonDataAsset             = serializedObject.FindProperty("skeletonDataAsset");
            initialSkinName               = serializedObject.FindProperty("initialSkinName");
            normals                       = serializedObject.FindProperty("calculateNormals");
            tangents                      = serializedObject.FindProperty("calculateTangents");
            meshes                        = serializedObject.FindProperty("renderMeshes");
            immutableTriangles            = serializedObject.FindProperty("immutableTriangles");
            separatorSlotNames            = serializedObject.FindProperty("separatorSlotNames");
            separatorSlotNames.isExpanded = true;

            front    = serializedObject.FindProperty("frontFacing");
            zSpacing = serializedObject.FindProperty("zSpacing");

            var renderer = ((SkeletonRenderer)target).GetComponent <Renderer>();

            sortingProperties = new SpineInspectorUtility.SerializedSortingProperties(renderer);
        }
Beispiel #26
0
        void HandleOnEnablePreview()
        {
            if (ThisSkeletonDataAsset != null && ThisSkeletonDataAsset.skeletonJSON == null)
            {
                return;
            }
            SpineEditorUtilities.ConfirmInitialization();

            // This handles the case where the managed editor assembly is unloaded before recompilation when code changes.
            AppDomain.CurrentDomain.DomainUnload -= OnDomainUnload;
            AppDomain.CurrentDomain.DomainUnload += OnDomainUnload;

            preview.Initialize(this.Repaint, ThisSkeletonDataAsset, LastSkinName);
            preview.PlayPauseAnimation(ThisAnimationName, true);
            preview.OnSkinChanged    -= HandleOnSkinChanged;
            preview.OnSkinChanged    += HandleOnSkinChanged;
            EditorApplication.update -= preview.HandleEditorUpdate;
            EditorApplication.update += preview.HandleEditorUpdate;
        }
        protected virtual void OnEnable()
        {
            isInspectingPrefab = (PrefabUtility.GetPrefabType(target) == PrefabType.Prefab);

            SpineEditorUtilities.ConfirmInitialization();

            // Labels
            SkeletonDataAssetLabel       = new GUIContent("SkeletonData Asset", Icons.spine);
            SkeletonUtilityButtonContent = new GUIContent("Add Skeleton Utility", Icons.skeletonUtility);
            MeshesLabel              = new GUIContent("Render MeshAttachments", "Disable to optimize rendering for skeletons that don't use Mesh Attachments");
            ImmubleTrianglesLabel    = new GUIContent("Immutable Triangles", "Enable to optimize rendering for skeletons that never change attachment visbility");
            PMAVertexColorsLabel     = new GUIContent("PMA Vertex Colors", "Use this if you are using the default Spine/Skeleton shader or any premultiply-alpha shader.");
            ClearStateOnDisableLabel = new GUIContent("Clear State On Disable", "Use this if you are pooling or enabling/disabling your Spine GameObject.");
            ZSpacingLabel            = new GUIContent("Z Spacing", "A value other than 0 adds a space between each rendered attachment to prevent Z Fighting when using shaders that read or write to the depth buffer. Large values may cause unwanted parallax and spaces depending on camera setup.");
            NormalsLabel             = new GUIContent("Add Normals", "Use this if your shader requires vertex normals. A more efficient solution for 2D setups is to modify the shader to assume a single normal value for the whole mesh.");
            TangentsLabel            = new GUIContent("Solve Tangents", "Calculates the tangents per frame. Use this if you are using lit shaders (usually with normal maps) that require vertex tangents.");
            TintBlackLabel           = new GUIContent("Tint Black (!)", "Adds black tint vertex data to the mesh as UV2 and UV3. Black tinting requires that the shader interpret UV2 and UV3 as black tint colors for this effect to work. You may also use the default [Spine/Skeleton Tint Black] shader.\n\nIf you only need to tint the whole skeleton and not individual parts, the [Spine/Skeleton Tint] shader is recommended for better efficiency and changing/animating the _Black material property via MaterialPropertyBlock.");
            SingleSubmeshLabel       = new GUIContent("Use Single Submesh", "Simplifies submesh determination by assuming you are only using one Material and need only one submesh. This is will disable render separation and custom slot materials.");

            var so = this.serializedObject;

            skeletonDataAsset   = so.FindProperty("skeletonDataAsset");
            initialSkinName     = so.FindProperty("initialSkinName");
            initialFlipX        = so.FindProperty("initialFlipX");
            initialFlipY        = so.FindProperty("initialFlipY");
            normals             = so.FindProperty("addNormals");
            tangents            = so.FindProperty("calculateTangents");
            meshes              = so.FindProperty("renderMeshes");
            immutableTriangles  = so.FindProperty("immutableTriangles");
            pmaVertexColors     = so.FindProperty("pmaVertexColors");
            clearStateOnDisable = so.FindProperty("clearStateOnDisable");
            tintBlack           = so.FindProperty("tintBlack");
            singleSubmesh       = so.FindProperty("singleSubmesh");

            separatorSlotNames            = so.FindProperty("separatorSlotNames");
            separatorSlotNames.isExpanded = true;

            zSpacing = so.FindProperty("zSpacing");

            SerializedObject rso = SpineInspectorUtility.GetRenderersSerializedObject(serializedObject);

            sortingProperties = new SpineInspectorUtility.SerializedSortingProperties(rso);
        }
        void UpdateBakedList()
        {
            AtlasAsset asset = (AtlasAsset)target;

            baked        = new List <bool>();
            bakedObjects = new List <GameObject>();
            if (atlasFile.objectReferenceValue != null)
            {
                List <AtlasRegion> regions           = this.Regions;
                string             atlasAssetPath    = AssetDatabase.GetAssetPath(atlasAsset);
                string             atlasAssetDirPath = Path.GetDirectoryName(atlasAssetPath);
                string             bakedDirPath      = Path.Combine(atlasAssetDirPath, atlasAsset.name);
                for (int i = 0; i < regions.Count; i++)
                {
                    AtlasRegion region          = regions[i];
                    string      bakedPrefabPath = Path.Combine(bakedDirPath, SpineEditorUtilities.GetPathSafeRegionName(region) + ".prefab").Replace("\\", "/");
                    GameObject  prefab          = (GameObject)AssetDatabase.LoadAssetAtPath(bakedPrefabPath, typeof(GameObject));
                    baked.Add(prefab != null);
                    bakedObjects.Add(prefab);
                }
            }
        }
        protected virtual void OnEnable()
        {
            isInspectingPrefab = (PrefabUtility.GetPrefabType(target) == PrefabType.Prefab);

            SpineEditorUtilities.ConfirmInitialization();
            skeletonDataAsset             = serializedObject.FindProperty("skeletonDataAsset");
            initialSkinName               = serializedObject.FindProperty("initialSkinName");
            normals                       = serializedObject.FindProperty("calculateNormals");
            tangents                      = serializedObject.FindProperty("calculateTangents");
            meshes                        = serializedObject.FindProperty("renderMeshes");
            immutableTriangles            = serializedObject.FindProperty("immutableTriangles");
            pmaVertexColors               = serializedObject.FindProperty("pmaVertexColors");
            separatorSlotNames            = serializedObject.FindProperty("separatorSlotNames");
            separatorSlotNames.isExpanded = true;

            frontFacing = serializedObject.FindProperty("frontFacing");
            zSpacing    = serializedObject.FindProperty("zSpacing");

            SerializedObject rso = SpineInspectorUtility.GetRenderersSerializedObject(serializedObject);

            sortingProperties = new SpineInspectorUtility.SerializedSortingProperties(rso);
        }
        protected virtual void OnEnable()
        {
            isInspectingPrefab = (PrefabUtility.GetPrefabType(target) == PrefabType.Prefab);

            SpineEditorUtilities.ConfirmInitialization();

            // Labels
            SkeletonDataAssetLabel       = new GUIContent("SkeletonData Asset", SpineEditorUtilities.Icons.spine);
            SkeletonUtilityButtonContent = new GUIContent("Add Skeleton Utility", SpineEditorUtilities.Icons.skeletonUtility);
            MeshesLabel              = new GUIContent("Render MeshAttachments", "Disable to optimize rendering for skeletons that don't use Mesh Attachments");
            ImmubleTrianglesLabel    = new GUIContent("Immutable Triangles", "Enable to optimize rendering for skeletons that never change attachment visbility");
            PMAVertexColorsLabel     = new GUIContent("PMA Vertex Colors", "Use this if you are using the default Spine/Skeleton shader or any premultiply-alpha shader.");
            ClearStateOnDisableLabel = new GUIContent("Clear State On Disable", "Use this if you are pooling or enabling/disabling your Spine GameObject.");
            ZSpacingLabel            = new GUIContent("Z Spacing", "A value other than 0 adds a space between each rendered attachment to prevent Z Fighting when using shaders that read or write to the depth buffer. Large values may cause unwanted parallax and spaces depending on camera setup.");
            NormalsLabel             = new GUIContent("Add Normals", "Use this if your shader requires vertex normals. A more efficient solution for 2D setups is to modify the shader to assume a single normal value for the whole mesh.");
            TangentsLabel            = new GUIContent("Solve Tangents", "Calculates the tangents per frame. Use this if you are using lit shaders (usually with normal maps) that require vertex tangents.");

            var so = this.serializedObject;

            skeletonDataAsset   = so.FindProperty("skeletonDataAsset");
            initialSkinName     = so.FindProperty("initialSkinName");
            normals             = so.FindProperty("calculateNormals");
            tangents            = so.FindProperty("calculateTangents");
            meshes              = so.FindProperty("renderMeshes");
            immutableTriangles  = so.FindProperty("immutableTriangles");
            pmaVertexColors     = so.FindProperty("pmaVertexColors");
            clearStateOnDisable = so.FindProperty("clearStateOnDisable");

            separatorSlotNames            = so.FindProperty("separatorSlotNames");
            separatorSlotNames.isExpanded = true;

            frontFacing = so.FindProperty("frontFacing");
            zSpacing    = so.FindProperty("zSpacing");

            SerializedObject rso = SpineInspectorUtility.GetRenderersSerializedObject(serializedObject);

            sortingProperties = new SpineInspectorUtility.SerializedSortingProperties(rso);
        }