public void ResetData()
 {
     baseAsset.Clear();
     baseAsset.GetSkeletonData(true);
     target.skeletonAnimation.skeletonDataAsset = baseAsset;
     target.skeletonAnimation.Initialize(true);
     target.skeletonAnimation.skeleton.SetToSetupPose();
     //Sprite
     target.skeletonAnimation.LateUpdate();
 }
	override public void OnInspectorGUI () {
		serializedObject.Update();
		SkeletonDataAsset asset = (SkeletonDataAsset)target;

		tk2dSpriteCollection sprites = EditorGUILayout.ObjectField("Sprite Collection", asset.spriteCollection, typeof(tk2dSpriteCollection), false) as tk2dSpriteCollection;
		if (sprites != null)
			spriteCollection.objectReferenceValue = sprites.spriteCollection;

		EditorGUILayout.PropertyField(skeletonJSON);
		EditorGUILayout.PropertyField(scale);
		
		SkeletonData skeletonData = asset.GetSkeletonData(asset.spriteCollection == null || asset.skeletonJSON == null);
		if (skeletonData != null) {
			showAnimationStateData = EditorGUILayout.Foldout(showAnimationStateData, "Animation State Data");
			if (showAnimationStateData) {
				// Animation names.
				String[] animations = new String[skeletonData.Animations.Count];
				for (int i = 0; i < animations.Length; i++)
					animations[i] = skeletonData.Animations[i].Name;
			
				for (int i = 0; i < fromAnimation.arraySize; i++) {
					SerializedProperty from = fromAnimation.GetArrayElementAtIndex(i);
					SerializedProperty to = toAnimation.GetArrayElementAtIndex(i);
					SerializedProperty durationProp = duration.GetArrayElementAtIndex(i);
					EditorGUILayout.BeginHorizontal();
					from.stringValue = animations[EditorGUILayout.Popup(Math.Max(Array.IndexOf(animations, from.stringValue), 0), animations)];
					to.stringValue = animations[EditorGUILayout.Popup(Math.Max(Array.IndexOf(animations, to.stringValue), 0), animations)];
					durationProp.floatValue = EditorGUILayout.FloatField(durationProp.floatValue);
					if (GUILayout.Button("Delete")) {
						duration.DeleteArrayElementAtIndex(i);
						toAnimation.DeleteArrayElementAtIndex(i);
						fromAnimation.DeleteArrayElementAtIndex(i);
					}
					EditorGUILayout.EndHorizontal();
				}
				EditorGUILayout.BeginHorizontal();
				EditorGUILayout.Space();
				if (GUILayout.Button("Add Mix")) {
					duration.arraySize++;
					toAnimation.arraySize++;
					fromAnimation.arraySize++;
				}
				EditorGUILayout.Space();
				EditorGUILayout.EndHorizontal();
			}
		}
		
		if (!Application.isPlaying) {
			if (serializedObject.ApplyModifiedProperties() ||
				(UnityEngine.Event.current.type == EventType.ValidateCommand && UnityEngine.Event.current.commandName == "UndoRedoPerformed")
			) {
				asset.Clear();
			}
		}
	}
Ejemplo n.º 3
0
 public static void ReloadSkeletonDataAsset(SkeletonDataAsset skeletonDataAsset)
 {
     if (skeletonDataAsset != null)
     {
         foreach (AtlasAssetBase aa in skeletonDataAsset.atlasAssets)
         {
             if (aa != null)
             {
                 aa.Clear();
             }
         }
         skeletonDataAsset.Clear();
     }
     skeletonDataAsset.GetSkeletonData(true);
 }
        public static void UpdateBlendModeMaterials(SkeletonDataAsset skeletonDataAsset, ref SkeletonData skeletonData,
                                                    bool upgradeFromModifierAssets = ShallUpgradeBlendModeMaterials)
        {
            TemplateMaterials templateMaterials = new TemplateMaterials();
            bool anyMaterialsChanged            = ClearUndesiredMaterialEntries(skeletonDataAsset);

            var blendModesModifierAsset = FindBlendModeMaterialsModifierAsset(skeletonDataAsset);

            if (blendModesModifierAsset)
            {
                if (upgradeFromModifierAssets)
                {
                    TransferSettingsFromModifierAsset(blendModesModifierAsset,
                                                      skeletonDataAsset, templateMaterials);
                    UpdateBlendmodeMaterialsRequiredState(skeletonDataAsset, skeletonData);
                }
                else
                {
                    return;
                }
            }
            else
            {
                if (!UpdateBlendmodeMaterialsRequiredState(skeletonDataAsset, skeletonData))
                {
                    return;
                }
                AssignPreferencesTemplateMaterials(templateMaterials);
            }
            bool success = CreateAndAssignMaterials(skeletonDataAsset, templateMaterials, ref anyMaterialsChanged);

            if (success)
            {
                if (blendModesModifierAsset != null)
                {
                    RemoveObsoleteModifierAsset(blendModesModifierAsset, skeletonDataAsset);
                }
            }

            skeletonDataAsset.Clear();
            skeletonData = skeletonDataAsset.GetSkeletonData(true);
            if (anyMaterialsChanged)
            {
                ReloadSceneSkeletons(skeletonDataAsset);
            }
            AssetDatabase.SaveAssets();
        }
Ejemplo n.º 5
0
        public static void DoSplit(string assetPath, string exportAnimationPath, int limitCount, bool fromBackUp = false)
        {
            SkeletonDataAsset skelAsset = (SkeletonDataAsset)AssetDatabase.LoadAssetAtPath(assetPath, typeof(SkeletonDataAsset));

            if (skelAsset == null)
            {
                return;
            }


            TextAsset _asset    = skelAsset.skeletonJSON;
            string    _skelPath = AssetDatabase.GetAssetPath(_asset);

            if (fromBackUp)
            {
                int       _length      = _skelPath.LastIndexOf(".");
                string    _backupPath  = _skelPath.Insert(_length, "_backup");
                TextAsset _assetBackup = AssetDatabase.LoadAssetAtPath(_backupPath, typeof(TextAsset)) as TextAsset;
                if (_assetBackup != null)
                {
                    AssetDatabase.CopyAsset(_backupPath, _skelPath);
                    AssetDatabase.Refresh();
                }
            }

            if (!_skelPath.ToLower().Contains(".skel"))
            {
                Debug.LogErrorFormat("skipped json format, path:{0}", assetPath);
                return;
            }

            // if (skelAsset.controller == null) //没有生成,有了更新。
            // SkeletonBaker.GenerateMecanimAnimationClips(skelAsset);
            SkeletonBaker.GenerateMecanimAnimationClips(skelAsset);

            //拆分并备份
            GetRequiredAtlasRegions(_skelPath, exportAnimationPath, limitCount);

            skelAsset.Clear();
            skelAsset.GetSkeletonData(true);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
        override public void OnInspectorGUI()
        {
            if (serializedObject.isEditingMultipleObjects)
            {
                using (new SpineInspectorUtility.BoxScope()) {
                    EditorGUILayout.LabelField("SkeletonData", EditorStyles.boldLabel);
                    EditorGUILayout.PropertyField(skeletonJSON, new GUIContent(skeletonJSON.displayName, Icons.spine));
                    EditorGUILayout.PropertyField(scale);
                }

                using (new SpineInspectorUtility.BoxScope()) {
                    EditorGUILayout.LabelField("Atlas", EditorStyles.boldLabel);
                                        #if !SPINE_TK2D
                    EditorGUILayout.PropertyField(atlasAssets, true);
                                        #else
                    using (new EditorGUI.DisabledGroupScope(spriteCollection.objectReferenceValue != null)) {
                        EditorGUILayout.PropertyField(atlasAssets, true);
                    }
                    EditorGUILayout.LabelField("spine-tk2d", EditorStyles.boldLabel);
                    EditorGUILayout.PropertyField(spriteCollection, true);
                                        #endif
                }

                using (new SpineInspectorUtility.BoxScope()) {
                    EditorGUILayout.LabelField("Mix Settings", EditorStyles.boldLabel);
                    SpineInspectorUtility.PropertyFieldWideLabel(defaultMix, DefaultMixLabel, 160);
                    EditorGUILayout.Space();
                }
                return;
            }

            {
                // Lazy initialization because accessing EditorStyles values in OnEnable during a recompile causes UnityEditor to throw null exceptions. (Unity 5.3.5)
                idlePlayButtonStyle = idlePlayButtonStyle ?? new GUIStyle(EditorStyles.miniButton);
                if (activePlayButtonStyle == null)
                {
                    activePlayButtonStyle = new GUIStyle(idlePlayButtonStyle);
                    activePlayButtonStyle.normal.textColor = Color.red;
                }
            }

            serializedObject.Update();

            EditorGUILayout.LabelField(new GUIContent(target.name + " (SkeletonDataAsset)", Icons.spine), EditorStyles.whiteLargeLabel);
            if (m_skeletonData != null)
            {
                EditorGUILayout.LabelField("(Drag and Drop to instantiate.)", EditorStyles.miniLabel);
            }

            EditorGUI.BeginChangeCheck();

            // SkeletonData
            using (new SpineInspectorUtility.BoxScope()) {
                using (new EditorGUILayout.HorizontalScope()) {
                    EditorGUILayout.LabelField("SkeletonData", EditorStyles.boldLabel);
//					if (m_skeletonData != null) {
//						var sd = m_skeletonData;
//						string m = string.Format("{8} - {0} {1}\nBones: {2}\tConstraints: {5} IK + {6} Path + {7} Transform\nSlots: {3}\t\tSkins: {4}\n",
//							sd.Version, string.IsNullOrEmpty(sd.Version) ? "" : "export", sd.Bones.Count, sd.Slots.Count, sd.Skins.Count, sd.IkConstraints.Count, sd.PathConstraints.Count, sd.TransformConstraints.Count, skeletonJSON.objectReferenceValue.name);
//						EditorGUILayout.LabelField(new GUIContent("SkeletonData"), new GUIContent("+", m), EditorStyles.boldLabel);
//					}
                }

                EditorGUILayout.PropertyField(skeletonJSON, new GUIContent(skeletonJSON.displayName, Icons.spine));
                EditorGUILayout.PropertyField(scale);
            }

//			if (m_skeletonData != null) {
//				if (SpineInspectorUtility.CenteredButton(new GUIContent("Instantiate", Icons.spine, "Creates a new Spine GameObject in the active scene using this Skeleton Data.\nYou can also instantiate by dragging the SkeletonData asset from Project view into Scene View.")))
//					SpineEditorUtilities.ShowInstantiateContextMenu(this.m_skeletonDataAsset, Vector3.zero);
//			}

            // Atlas
            using (new SpineInspectorUtility.BoxScope()) {
                EditorGUILayout.LabelField("Atlas", EditorStyles.boldLabel);
                                #if !SPINE_TK2D
                EditorGUILayout.PropertyField(atlasAssets, true);
                                #else
                using (new EditorGUI.DisabledGroupScope(spriteCollection.objectReferenceValue != null)) {
                    EditorGUILayout.PropertyField(atlasAssets, true);
                }
                EditorGUILayout.LabelField("spine-tk2d", EditorStyles.boldLabel);
                EditorGUILayout.PropertyField(spriteCollection, true);
                                #endif
            }

            if (EditorGUI.EndChangeCheck())
            {
                if (serializedObject.ApplyModifiedProperties())
                {
                    if (m_previewUtility != null)
                    {
                        m_previewUtility.Cleanup();
                        m_previewUtility = null;
                    }
                    m_skeletonDataAsset.Clear();
                    m_skeletonData = null;
                    OnEnable();                     // Should call RepopulateWarnings.
                    return;
                }
            }

            // Some code depends on the existence of m_skeletonAnimation instance.
            // If m_skeletonAnimation is lazy-instantiated elsewhere, this can cause contents to change between Layout and Repaint events, causing GUILayout control count errors.
            InitPreview();
            if (m_skeletonData != null)
            {
                GUILayout.Space(20f);

                using (new SpineInspectorUtility.BoxScope()) {
                    EditorGUILayout.LabelField("Mix Settings", EditorStyles.boldLabel);
                    DrawAnimationStateInfo();
                    EditorGUILayout.Space();
                }

                EditorGUILayout.LabelField("Preview", EditorStyles.boldLabel);
                DrawAnimationList();
                EditorGUILayout.Space();
                DrawSlotList();
                EditorGUILayout.Space();
                DrawUnityTools();
            }
            else
            {
                                #if !SPINE_TK2D
                // Reimport Button
                using (new EditorGUI.DisabledGroupScope(skeletonJSON.objectReferenceValue == null)) {
                    if (GUILayout.Button(new GUIContent("Attempt Reimport", Icons.warning)))
                    {
                        DoReimport();
                    }
                }
                                #else
                EditorGUILayout.HelpBox("Couldn't load SkeletonData.", MessageType.Error);
                                #endif

                // List warnings.
                foreach (var line in warnings)
                {
                    EditorGUILayout.LabelField(new GUIContent(line, Icons.warning));
                }
            }

            if (!Application.isPlaying)
            {
                serializedObject.ApplyModifiedProperties();
            }
        }
 void Clear()
 {
     preview.Clear();
     targetSkeletonDataAsset.Clear();
     targetSkeletonData = null;
 }
    override public void OnInspectorGUI()
    {
        serializedObject.Update();
        SkeletonDataAsset asset = (SkeletonDataAsset)target;

        EditorGUIUtility.LookLikeInspector();
        EditorGUILayout.PropertyField(atlasAsset);
        EditorGUILayout.PropertyField(skeletonJSON);
        EditorGUILayout.PropertyField(scale);

        SkeletonData skeletonData = asset.GetSkeletonData(true);

        if (skeletonData != null)
        {
            showAnimationStateData = EditorGUILayout.Foldout(showAnimationStateData, "Animation State Data");
            if (showAnimationStateData)
            {
                // Animation names.
                String[] animations = new String[skeletonData.Animations.Count];
                for (int i = 0; i < animations.Length; i++)
                {
                    animations[i] = skeletonData.Animations[i].Name;
                }

                for (int i = 0; i < fromAnimation.arraySize; i++)
                {
                    SerializedProperty from         = fromAnimation.GetArrayElementAtIndex(i);
                    SerializedProperty to           = toAnimation.GetArrayElementAtIndex(i);
                    SerializedProperty durationProp = duration.GetArrayElementAtIndex(i);
                    EditorGUILayout.BeginHorizontal();
                    from.stringValue        = animations[EditorGUILayout.Popup(Math.Max(Array.IndexOf(animations, from.stringValue), 0), animations)];
                    to.stringValue          = animations[EditorGUILayout.Popup(Math.Max(Array.IndexOf(animations, to.stringValue), 0), animations)];
                    durationProp.floatValue = EditorGUILayout.FloatField(durationProp.floatValue);
                    if (GUILayout.Button("Delete"))
                    {
                        duration.DeleteArrayElementAtIndex(i);
                        toAnimation.DeleteArrayElementAtIndex(i);
                        fromAnimation.DeleteArrayElementAtIndex(i);
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.Space();
                if (GUILayout.Button("Add Mix"))
                {
                    duration.InsertArrayElementAtIndex(fromAnimation.arraySize);
                    toAnimation.InsertArrayElementAtIndex(fromAnimation.arraySize);
                    fromAnimation.InsertArrayElementAtIndex(fromAnimation.arraySize);
                }
                EditorGUILayout.Space();
                EditorGUILayout.EndHorizontal();
            }
        }

        if (serializedObject.ApplyModifiedProperties() ||
            (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed")
            )
        {
            asset.Clear();
        }
    }
        protected static bool CreateAndAssignMaterials(SkeletonDataAsset skeletonDataAsset,
                                                       TemplateMaterials templateMaterials, ref bool anyReplacementMaterialsChanged)
        {
            bool anyCreationFailed     = false;
            var  blendModeMaterials    = skeletonDataAsset.blendModeMaterials;
            bool applyAdditiveMaterial = blendModeMaterials.applyAdditiveMaterial;

            var skinEntries = new List <Skin.SkinEntry>();

            skeletonDataAsset.Clear();
            skeletonDataAsset.isUpgradingBlendModeMaterials = true;
            SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(true);

            var slotsItems = skeletonData.Slots.Items;

            for (int slotIndex = 0, slotCount = skeletonData.Slots.Count; slotIndex < slotCount; slotIndex++)
            {
                var slot = slotsItems[slotIndex];
                if (slot.BlendMode == BlendMode.Normal)
                {
                    continue;
                }
                if (!applyAdditiveMaterial && slot.BlendMode == BlendMode.Additive)
                {
                    continue;
                }

                List <BlendModeMaterials.ReplacementMaterial> replacementMaterials = null;
                Material materialTemplate = null;
                string   materialSuffix   = null;
                switch (slot.BlendMode)
                {
                case BlendMode.Multiply:
                    replacementMaterials = blendModeMaterials.multiplyMaterials;
                    materialTemplate     = templateMaterials.multiplyTemplate;
                    materialSuffix       = MATERIAL_SUFFIX_MULTIPLY;
                    break;

                case BlendMode.Screen:
                    replacementMaterials = blendModeMaterials.screenMaterials;
                    materialTemplate     = templateMaterials.screenTemplate;
                    materialSuffix       = MATERIAL_SUFFIX_SCREEN;
                    break;

                case BlendMode.Additive:
                    replacementMaterials = blendModeMaterials.additiveMaterials;
                    materialTemplate     = templateMaterials.additiveTemplate;
                    materialSuffix       = MATERIAL_SUFFIX_ADDITIVE;
                    break;
                }

                skinEntries.Clear();
                foreach (var skin in skeletonData.Skins)
                {
                    skin.GetAttachments(slotIndex, skinEntries);
                }

                foreach (var entry in skinEntries)
                {
                    var renderableAttachment = entry.Attachment as IHasRendererObject;
                    if (renderableAttachment != null)
                    {
                        var  originalRegion    = (AtlasRegion)renderableAttachment.RendererObject;
                        bool replacementExists = replacementMaterials.Exists(
                            replacement => replacement.pageName == originalRegion.page.name);
                        if (!replacementExists)
                        {
                            bool createdNewMaterial;
                            var  replacement = CreateOrLoadReplacementMaterial(originalRegion, materialTemplate, materialSuffix, out createdNewMaterial);
                            if (replacement != null)
                            {
                                replacementMaterials.Add(replacement);
                                anyReplacementMaterialsChanged = true;
                                if (createdNewMaterial)
                                {
                                    Debug.Log(string.Format("Created blend mode Material '{0}' for SkeletonDataAsset '{1}'.",
                                                            replacement.material.name, skeletonDataAsset), replacement.material);
                                }
                            }
                            else
                            {
                                Debug.LogError(string.Format("Failed creating blend mode Material for SkeletonDataAsset '{0}'," +
                                                             " atlas page '{1}', template '{2}'.",
                                                             skeletonDataAsset.name, originalRegion.page.name, materialTemplate.name),
                                               skeletonDataAsset);
                                anyCreationFailed = true;
                            }
                        }
                    }
                }
            }

            skeletonDataAsset.isUpgradingBlendModeMaterials = false;
            EditorUtility.SetDirty(skeletonDataAsset);
            return(!anyCreationFailed);
        }