GetSkeletonData() public method

public GetSkeletonData ( bool quiet ) : SkeletonData
quiet bool
return Spine.SkeletonData
Ejemplo n.º 1
0
        private static bool ValidateForMonster(SkeletonDataAsset skeletonDataAsset)
        {
            var data = skeletonDataAsset.GetSkeletonData(false);
            var hud  = data.FindBone("HUD");

            return(!(hud is null));
        }
    void OnEnable()
    {
        SpineEditorUtilities.ConfirmInitialization();

        try {
            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");
            controller    = serializedObject.FindProperty("controller");

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

            EditorApplication.update += Update;
        } catch {
        }

        m_skeletonData = m_skeletonDataAsset.GetSkeletonData(true);

        showBaking = EditorPrefs.GetBool("SkeletonDataAssetInspector_showBaking", true);

        RepopulateWarnings();
    }
        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;
        }
    static public void GetSpineAnimation()
    {
        if (Selection.objects == null)
        {
            return;
        }
        else
        {
            SkeletonDataAsset pSpineDataAsset = Selection.objects[0] as SkeletonDataAsset;
            if (pSpineDataAsset == null)
            {
                return;
            }

            SkeletonData pData = pSpineDataAsset.GetSkeletonData(false);

            StringBuilder pBuilder = new StringBuilder();
            foreach (var pAnimation in pData.Animations)
            {
                pBuilder.Append(pAnimation.Name);
                pBuilder.Append(", ");
            }

            pBuilder.Remove(pBuilder.Length - 2, 2);
            Debug.Log(pBuilder.ToString());
        }
    }
Ejemplo n.º 5
0
	void OnEnable () {

		SpineEditorUtilities.ConfirmInitialization();

		try {
			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");
			controller = serializedObject.FindProperty("controller");
#if SPINE_TK2D
			spriteCollection = serializedObject.FindProperty("spriteCollection");
#endif

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

			EditorApplication.update += Update;
		} catch {


		}

		m_skeletonData = m_skeletonDataAsset.GetSkeletonData(true);

		showUnity = EditorPrefs.GetBool("SkeletonDataAssetInspector_showUnity", true);

		RepopulateWarnings();
	}
    void OnEnable()
    {
        SpineEditorUtilities.ConfirmInitialization();

        try {
            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");
            controller    = serializedObject.FindProperty("controller");
#if SPINE_TK2D
            spriteCollection = serializedObject.FindProperty("spriteCollection");
#endif

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

            EditorApplication.update += Update;
        } catch {
            // TODO: WARNING: empty catch block supresses errors.
        }

        m_skeletonData = m_skeletonDataAsset.GetSkeletonData(true);

        showUnity = EditorPrefs.GetBool("SkeletonDataAssetInspector_showUnity", true);

        RepopulateWarnings();
    }
    void Selector(SerializedProperty property)
    {
        SpineSkin    attrib = (SpineSkin)attribute;
        SkeletonData data   = skeletonDataAsset.GetSkeletonData(true);

        if (data == null)
        {
            return;
        }

        GenericMenu menu = new GenericMenu();

        menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
        menu.AddSeparator("");

        for (int i = 0; i < data.Skins.Count; i++)
        {
            string name = data.Skins[i].Name;
            if (name.StartsWith(attrib.startsWith))
            {
                menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
            }
        }

        menu.ShowAsContext();
    }
		void OnEnable () {
			SpineEditorUtilities.ConfirmInitialization();

			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_skeletonDataAsset = (SkeletonDataAsset)target;
			m_skeletonDataAssetGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_skeletonDataAsset));
			EditorApplication.update += EditorUpdate;
			m_skeletonData = m_skeletonDataAsset.GetSkeletonData(false);
			RepopulateWarnings();
		}
        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();
        }
		void OnEnable () {

			SpineEditorUtilities.ConfirmInitialization();

			try {
				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;
			} catch {
				// TODO: WARNING: empty catch block supresses errors.

			}

			m_skeletonData = m_skeletonDataAsset.GetSkeletonData(true);

			showBaking = EditorPrefs.GetBool("SkeletonDataAssetInspector_showUnity", false);

			RepopulateWarnings();
		}
		protected virtual void Selector (SerializedProperty property) {
			SkeletonData data = skeletonDataAsset.GetSkeletonData(true);
			if (data == null) return;

			var menu = new GenericMenu();
			PopulateMenu(menu, property, this.TargetAttribute, data);
			menu.ShowAsContext();
		}
Ejemplo n.º 12
0
    public virtual void Initialize()
    {
        mesh = new Mesh();
        GetComponent <MeshFilter>().mesh = mesh;
        mesh.name      = "Skeleton Mesh";
        mesh.hideFlags = HideFlags.HideAndDontSave;

        vertices = new Vector3[0];

        skeleton = new Skeleton(skeletonDataAsset.GetSkeletonData(false));

        if (initialSkinName != null && initialSkinName.Length > 0)
        {
            skeleton.SetSkin(initialSkinName);
            skeleton.SetSlotsToSetupPose();
        }
    }
        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();
        }
Ejemplo n.º 14
0
        private static bool ValidateForPlayer(SkeletonDataAsset skeletonDataAsset)
        {
            var data = skeletonDataAsset.GetSkeletonData(false);
            var hud  = data.FindBone("HUD");

            // TODO: 커스터마이징 슬롯 검사.

            return(!(hud is null));
        }
        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);
            }
        }
Ejemplo n.º 16
0
        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();
                    }
                }
            }
        }
        public static void UpdateBlendModeMaterials(SkeletonDataAsset skeletonDataAsset)
        {
            var skeletonData = skeletonDataAsset.GetSkeletonData(true);

            if (skeletonData == null)
            {
                return;
            }
            UpdateBlendModeMaterials(skeletonDataAsset, ref skeletonData, false);
        }
 public void ResetData()
 {
     baseAsset.Clear();
     baseAsset.GetSkeletonData(true);
     target.skeletonAnimation.skeletonDataAsset = baseAsset;
     target.skeletonAnimation.Initialize(true);
     target.skeletonAnimation.skeleton.SetToSetupPose();
     //Sprite
     target.skeletonAnimation.LateUpdate();
 }
    public static SkeletonAnimation SpawnAnimatedSkeleton(SkeletonDataAsset skeletonDataAsset, string skinName)
    {
        SkeletonData skelData = skeletonDataAsset.GetSkeletonData(false);

        if (skelData == null)
        {
            return(null);
        }
        return(SpawnAnimatedSkeleton(skeletonDataAsset, skelData.FindSkin(skinName)));
    }
        IEnumerator Start()
        {
            if (skeletonDataAsset == null)
            {
                yield break;
            }
            skeletonDataAsset.GetSkeletonData(false);        // Preload SkeletonDataAsset.
            yield return(new WaitForSeconds(1f));            // Pretend stuff is happening.

            var spineAnimation = skeletonDataAsset.GetSkeletonData(false).FindAnimation(startingAnimation);

            for (int i = 0; i < count; i++)
            {
                var sa = SkeletonAnimation.NewSkeletonAnimationGameObject(skeletonDataAsset); // Spawn a new SkeletonAnimation GameObject.
                DoExtraStuff(sa, spineAnimation);                                             // optional stuff for fun.
                sa.gameObject.name = i.ToString();
                yield return(new WaitForSeconds(1f / 8f));
            }
        }
	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();
			}
		}
	}
    void Selector(SerializedProperty property)
    {
        SpineSlot    attrib = (SpineSlot)attribute;
        SkeletonData data   = skeletonDataAsset.GetSkeletonData(true);

        if (data == null)
        {
            return;
        }

        GenericMenu menu = new GenericMenu();

        menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
        menu.AddSeparator("");

        for (int i = 0; i < data.Slots.Count; i++)
        {
            string name = data.Slots[i].Name;
            if (name.StartsWith(attrib.startsWith))
            {
                if (attrib.containsBoundingBoxes)
                {
                    int slotIndex = i;

                    List <Attachment> attachments = new List <Attachment>();
                    foreach (var skin in data.Skins)
                    {
                        skin.FindAttachmentsForSlot(slotIndex, attachments);
                    }

                    bool hasBoundingBox = false;
                    foreach (var attachment in attachments)
                    {
                        if (attachment is BoundingBoxAttachment)
                        {
                            menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
                            hasBoundingBox = true;
                            break;
                        }
                    }

                    if (!hasBoundingBox)
                    {
                        menu.AddDisabledItem(new GUIContent(name));
                    }
                }
                else
                {
                    menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
                }
            }
        }

        menu.ShowAsContext();
    }
Ejemplo n.º 23
0
    public static SkeletonAnimation SpawnAnimatedSkeleton(SkeletonDataAsset skeletonDataAsset, Skin skin = null)
    {
        GameObject        go   = new GameObject(skeletonDataAsset.name.Replace("_SkeletonData", ""), typeof(MeshFilter), typeof(MeshRenderer), typeof(SkeletonAnimation));
        SkeletonAnimation anim = go.GetComponent <SkeletonAnimation>();

        anim.skeletonDataAsset = skeletonDataAsset;

        bool requiresNormals = false;

        foreach (Material m in anim.skeletonDataAsset.atlasAsset.materials)
        {
            if (m.shader.name.Contains("Lit"))
            {
                requiresNormals = true;
                break;
            }
        }

        anim.calculateNormals = requiresNormals;

        if (skin == null)
        {
            skin = skeletonDataAsset.GetSkeletonData(true).DefaultSkin;
        }

        if (skin == null)
        {
            skin = skeletonDataAsset.GetSkeletonData(true).Skins[0];
        }

        anim.Reset();

        anim.skeleton.SetSkin(skin);
        anim.initialSkinName = skin.Name;

        anim.skeleton.Update(1);
        anim.state.Update(1);
        anim.state.Apply(anim.skeleton);
        anim.skeleton.UpdateWorldTransform();

        return(anim);
    }
    public void IEInitAsset()
    {
        //yield return new WaitForSeconds(0.1f);
        SkeletonData.GetSkeletonData(false); // Preload SkeletonDataAsset.
        //yield return new WaitForSeconds(0.25f); // Pretend stuff is happening.

        if (ModelParent.childCount == 0)
        {
            var sa = SkeletonAnimation.NewSkeletonAnimationGameObject(SkeletonData);
            sa.name = "MODE_SINGLEROLE";
            setNewModel(sa);
        }
        else
        {
            if (ModelParent.GetComponentInChildren <CharacterModel_animation>())
            {
                ModelParent.GetComponentInChildren <CharacterModel_animation>()
                .initCharacterModel();
            }
        }
    }
Ejemplo n.º 25
0
    public virtual void Initialize()
    {
        if (Initialized)
        {
            return;
        }

        meshFilter = GetComponent <MeshFilter>();
        mesh1      = newMesh();
        mesh2      = newMesh();

        vertices = new Vector3[0];

        skeleton = new Skeleton(skeletonDataAsset.GetSkeletonData(false));

        if (initialSkinName != null && initialSkinName.Length > 0 && initialSkinName != "default")
        {
            skeleton.SetSkin(initialSkinName);
            skeleton.SetSlotsToSetupPose();
        }
    }
Ejemplo n.º 26
0
        public static SkeletonGraphic InstantiateSkeletonGraphic(SkeletonDataAsset skeletonDataAsset, Skin skin = null)
        {
            string spineGameObjectName = string.Format("SkeletonGraphic ({0})", skeletonDataAsset.name.Replace("_SkeletonData", ""));
            var    go      = NewSkeletonGraphicGameObject(spineGameObjectName);
            var    graphic = go.GetComponent <SkeletonGraphic>();

            graphic.skeletonDataAsset = skeletonDataAsset;

            SkeletonData data = skeletonDataAsset.GetSkeletonData(true);

            if (data == null)
            {
                for (int i = 0; i < skeletonDataAsset.atlasAssets.Length; i++)
                {
                    string reloadAtlasPath = AssetDatabase.GetAssetPath(skeletonDataAsset.atlasAssets[i]);
                    skeletonDataAsset.atlasAssets[i] = (AtlasAsset)AssetDatabase.LoadAssetAtPath(reloadAtlasPath, typeof(AtlasAsset));
                }

                data = skeletonDataAsset.GetSkeletonData(true);
            }

            if (skin == null)
            {
                skin = data.DefaultSkin;
            }

            if (skin == null)
            {
                skin = data.Skins.Items[0];
            }

            graphic.Initialize(false);
            graphic.Skeleton.SetSkin(skin);
            graphic.initialSkinName = skin.Name;
            graphic.Skeleton.UpdateWorldTransform();
            graphic.UpdateMesh();

            return(graphic);
        }
    public void SpawnFromSpineData(Transform spawnPlace, SkeletonDataAsset SpineData, string Name)
    {
        if (SpineData == null)
        {
            return;
        }
        SpineData.GetSkeletonData(false);
        var anim = SpineData.GetSkeletonData(false)
                   .FindAnimation(SDConstants.AnimName_IDLE);
        var sa = SkeletonAnimation.NewSkeletonAnimationGameObject(SpineData);

        //
        sa.gameObject.name = Name + "_Mode";
        Transform s = sa.transform;

        s.SetParent(spawnPlace);
        s.localScale = Vector3.one;
        s.position   = spawnPlace.position;
        //
        sa.Initialize(false);
        sa.AnimationState.SetAnimation(0, anim, true);
    }
Ejemplo n.º 28
0
        public static void DrawSelectBone(SkeletonDataAsset skeletonDataAsset, string current, Action <string> selectFunc)
        {
            SkeletonData data = skeletonDataAsset.GetSkeletonData(true);

            if (data == null)
            {
                return;
            }

            var menu = new GenericMenu();

            DrawBonePopulateMenu(menu, skeletonDataAsset, current, selectFunc);
            menu.ShowAsContext();
        }
        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;
        }
Ejemplo n.º 30
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="asset"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public void SetSpine(SkeletonDataAsset asset, int width, int height, Vector2 anchor)
        {
            if (_spineAnimation != null)
            {
                FreeSpine();
            }

            _spineAnimation = SkeletonRenderer.NewSpineGameObject <SkeletonAnimation>(asset);
            Spine.SkeletonData dat = asset.GetSkeletonData(false);
            _spineAnimation.gameObject.transform.localScale    = new Vector3(100, 100, 1);
            _spineAnimation.gameObject.transform.localPosition = new Vector3(anchor.x, -anchor.y, 0);
            SetWrapTarget(_spineAnimation.gameObject, false, width, height);

            OnChangeSpine(null);
        }
Ejemplo n.º 31
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);
 }
Ejemplo n.º 32
0
        public static SkeletonGraphic InstantiateSkeletonGraphic(SkeletonDataAsset skeletonDataAsset, Skin skin = null)
        {
            string spineGameObjectName = string.Format("SkeletonGraphic ({0})", skeletonDataAsset.name.Replace("_SkeletonData", ""));
            var    go      = NewSkeletonGraphicGameObject(spineGameObjectName);
            var    graphic = go.GetComponent <SkeletonGraphic>();

            graphic.skeletonDataAsset = skeletonDataAsset;

            SkeletonData data = skeletonDataAsset.GetSkeletonData(true);

            if (data == null)
            {
                for (int i = 0; i < skeletonDataAsset.atlasAssets.Length; i++)
                {
                    string reloadAtlasPath = AssetDatabase.GetAssetPath(skeletonDataAsset.atlasAssets[i]);
                    skeletonDataAsset.atlasAssets[i] = (AtlasAssetBase)AssetDatabase.LoadAssetAtPath(reloadAtlasPath, typeof(AtlasAssetBase));
                }

                data = skeletonDataAsset.GetSkeletonData(true);
            }

            skin = skin ?? data.DefaultSkin ?? data.Skins.Items[0];
            graphic.MeshGenerator.settings.zSpacing = SpineEditorUtilities.Preferences.defaultZSpacing;

            graphic.startingLoop = SpineEditorUtilities.Preferences.defaultInstantiateLoop;
            graphic.Initialize(false);
            if (skin != null)
            {
                graphic.Skeleton.SetSkin(skin);
            }
            graphic.initialSkinName = skin.Name;
            graphic.Skeleton.UpdateWorldTransform();
            graphic.UpdateMesh();

            return(graphic);
        }
    void OnEnable()
    {
        SpineEditorUtilities.ConfirmInitialization();

        try {
            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");

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

            EditorApplication.update += Update;
        } catch {

        }

        m_skeletonData = m_skeletonDataAsset.GetSkeletonData(true);

        RepopulateWarnings();
    }
Ejemplo n.º 34
0
	public static SkeletonAnimator InstantiateSkeletonAnimator (SkeletonDataAsset skeletonDataAsset, Skin skin = null) {
		GameObject go = new GameObject(skeletonDataAsset.name.Replace("_SkeletonData", ""), typeof(MeshFilter), typeof(MeshRenderer), typeof(Animator), typeof(SkeletonAnimator));

		if (skeletonDataAsset.controller == null) {
			SkeletonBaker.GenerateMecanimAnimationClips(skeletonDataAsset);
		}

		go.GetComponent<Animator>().runtimeAnimatorController = skeletonDataAsset.controller;

		SkeletonAnimator anim = go.GetComponent<SkeletonAnimator>();
		anim.skeletonDataAsset = skeletonDataAsset;

		bool requiresNormals = false;

		foreach (AtlasAsset atlasAsset in anim.skeletonDataAsset.atlasAssets) {
			foreach (Material m in atlasAsset.materials) {
				if (m.shader.name.Contains("Lit")) {
					requiresNormals = true;
					break;
				}
			}
		}

		anim.calculateNormals = requiresNormals;

		SkeletonData data = skeletonDataAsset.GetSkeletonData(true);

		if (data == null) {
			for (int i = 0; i < skeletonDataAsset.atlasAssets.Length; i++) {
				string reloadAtlasPath = AssetDatabase.GetAssetPath(skeletonDataAsset.atlasAssets[i]);
				skeletonDataAsset.atlasAssets[i] = (AtlasAsset)AssetDatabase.LoadAssetAtPath(reloadAtlasPath, typeof(AtlasAsset));
			}

			data = skeletonDataAsset.GetSkeletonData(true);
		}

		if (skin == null)
			skin = data.DefaultSkin;

		if (skin == null)
			skin = data.Skins.Items[0];

		anim.Reset();

		anim.skeleton.SetSkin(skin);
		anim.initialSkinName = skin.Name;

		anim.skeleton.Update(1);
		anim.skeleton.UpdateWorldTransform();
		anim.LateUpdate();

		return anim;
	}
Ejemplo n.º 35
0
	public static SkeletonAnimator InstantiateSkeletonAnimator (SkeletonDataAsset skeletonDataAsset, string skinName) {
		return InstantiateSkeletonAnimator(skeletonDataAsset, skeletonDataAsset.GetSkeletonData(true).FindSkin(skinName));
	}
		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();
		}
		public static SkeletonGraphic InstantiateSkeletonGraphic (SkeletonDataAsset skeletonDataAsset, string skinName) {
			return InstantiateSkeletonGraphic(skeletonDataAsset, skeletonDataAsset.GetSkeletonData(true).FindSkin(skinName));
		}
Ejemplo n.º 38
0
	public static Spine.BoneData GetBoneData(string boneName, SkeletonDataAsset skeletonDataAsset) {
		var data = skeletonDataAsset.GetSkeletonData(true);

		return data.FindBone(boneName);
	}
Ejemplo n.º 39
0
	public static void BakeToPrefab (SkeletonDataAsset skeletonDataAsset, List<Skin> skins, string outputPath = "", bool bakeAnimations = true, bool bakeIK = true, SendMessageOptions eventOptions = SendMessageOptions.DontRequireReceiver) {
		if (skeletonDataAsset == null || skeletonDataAsset.GetSkeletonData(true) == null) {
			Debug.LogError("Could not export Spine Skeleton because SkeletonDataAsset is null or invalid!");
			return;
		}

		if (outputPath == "") {
			outputPath = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(skeletonDataAsset)) + "/Baked";
			System.IO.Directory.CreateDirectory(outputPath);
		}

		var skeletonData = skeletonDataAsset.GetSkeletonData(true);
		bool hasAnimations = bakeAnimations && skeletonData.Animations.Count > 0;
#if UNITY_5
		UnityEditor.Animations.AnimatorController controller = null;
#else
		UnityEditorInternal.AnimatorController controller = null;
#endif
		if (hasAnimations) {
			string controllerPath = outputPath + "/" + skeletonDataAsset.skeletonJSON.name + " Controller.controller";
			bool newAnimContainer = false;

			var runtimeController = AssetDatabase.LoadAssetAtPath(controllerPath, typeof(RuntimeAnimatorController));

#if UNITY_5
			if (runtimeController != null) {
				controller = (UnityEditor.Animations.AnimatorController)runtimeController;
			} else {
				controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(controllerPath);
				newAnimContainer = true;
			}
#else
			if (runtimeController != null) {
				controller = (UnityEditorInternal.AnimatorController)runtimeController;
			} else {
				controller = UnityEditorInternal.AnimatorController.CreateAnimatorControllerAtPath(controllerPath);
				newAnimContainer = true;
			}
#endif

			Dictionary<string, AnimationClip> existingClipTable = new Dictionary<string, AnimationClip>();
			List<string> unusedClipNames = new List<string>();
			Object[] animObjs = AssetDatabase.LoadAllAssetsAtPath(controllerPath);

			foreach (Object o in animObjs) {
				if (o is AnimationClip) {
					var clip = (AnimationClip)o;
					existingClipTable.Add(clip.name, clip);
					unusedClipNames.Add(clip.name);
				}
			}

			Dictionary<int, List<string>> slotLookup = new Dictionary<int, List<string>>();

			int skinCount = skins.Count;

			for (int s = 0; s < skeletonData.Slots.Count; s++) {
				List<string> attachmentNames = new List<string>();
				for (int i = 0; i < skinCount; i++) {
					var skin = skins[i];
					List<string> temp = new List<string>();
					skin.FindNamesForSlot(s, temp);
					foreach (string str in temp) {
						if (!attachmentNames.Contains(str))
							attachmentNames.Add(str);
					}
				}
				slotLookup.Add(s, attachmentNames);
			}

			foreach (var anim in skeletonData.Animations) {

				AnimationClip clip = null;
				if (existingClipTable.ContainsKey(anim.Name)) {
					clip = existingClipTable[anim.Name];
				}

				clip = ExtractAnimation(anim.Name, skeletonData, slotLookup, bakeIK, eventOptions, clip);

				if (unusedClipNames.Contains(clip.name)) {
					unusedClipNames.Remove(clip.name);
				} else {
					AssetDatabase.AddObjectToAsset(clip, controller);
#if UNITY_5
					controller.AddMotion(clip);
#else
					UnityEditorInternal.AnimatorController.AddAnimationClipToController(controller, clip);
#endif

				}
			}

			if (newAnimContainer) {
				EditorUtility.SetDirty(controller);
				AssetDatabase.SaveAssets();
				AssetDatabase.ImportAsset(controllerPath, ImportAssetOptions.ForceUpdate);
				AssetDatabase.Refresh();
			} else {

				foreach (string str in unusedClipNames) {
					AnimationClip.DestroyImmediate(existingClipTable[str], true);
				}

				EditorUtility.SetDirty(controller);
				AssetDatabase.SaveAssets();
				AssetDatabase.ImportAsset(controllerPath, ImportAssetOptions.ForceUpdate);
				AssetDatabase.Refresh();
			}
		}

		foreach (var skin in skins) {
			bool newPrefab = false;

			string prefabPath = outputPath + "/" + skeletonDataAsset.skeletonJSON.name + " (" + skin.Name + ").prefab";


			Object prefab = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject));
			if (prefab == null) {
				prefab = PrefabUtility.CreateEmptyPrefab(prefabPath);
				newPrefab = true;
			}

			Dictionary<string, Mesh> meshTable = new Dictionary<string, Mesh>();
			List<string> unusedMeshNames = new List<string>();
			Object[] assets = AssetDatabase.LoadAllAssetsAtPath(prefabPath);
			foreach (var obj in assets) {
				if (obj is Mesh) {
					meshTable.Add(obj.name, (Mesh)obj);
					unusedMeshNames.Add(obj.name);
				}
			}

			GameObject prefabRoot = new GameObject("root");

			Dictionary<string, Transform> slotTable = new Dictionary<string, Transform>();
			Dictionary<string, Transform> boneTable = new Dictionary<string, Transform>();
			List<Transform> boneList = new List<Transform>();

			//create bones
			for (int i = 0; i < skeletonData.Bones.Count; i++) {
				var boneData = skeletonData.Bones[i];
				Transform boneTransform = new GameObject(boneData.Name).transform;
				boneTransform.parent = prefabRoot.transform;
				boneTable.Add(boneTransform.name, boneTransform);
				boneList.Add(boneTransform);
			}

			for (int i = 0; i < skeletonData.Bones.Count; i++) {

				var boneData = skeletonData.Bones[i];
				Transform boneTransform = boneTable[boneData.Name];
				Transform parentTransform = null;
				if (i > 0)
					parentTransform = boneTable[boneData.Parent.Name];
				else
					parentTransform = boneTransform.parent;

				boneTransform.parent = parentTransform;
				boneTransform.localPosition = new Vector3(boneData.X, boneData.Y, 0);
				if (boneData.InheritRotation)
					boneTransform.localRotation = Quaternion.Euler(0, 0, boneData.Rotation);
				else
					boneTransform.rotation = Quaternion.Euler(0, 0, boneData.Rotation);

				if (boneData.InheritScale)
					boneTransform.localScale = new Vector3(boneData.ScaleX, boneData.ScaleY, 1);
			}

			//create slots and attachments
			for (int i = 0; i < skeletonData.Slots.Count; i++) {
				var slotData = skeletonData.Slots[i];
				Transform slotTransform = new GameObject(slotData.Name).transform;
				slotTransform.parent = prefabRoot.transform;
				slotTable.Add(slotData.Name, slotTransform);

				List<Attachment> attachments = new List<Attachment>();
				List<string> attachmentNames = new List<string>();

				skin.FindAttachmentsForSlot(i, attachments);
				skin.FindNamesForSlot(i, attachmentNames);

				if (skin != skeletonData.DefaultSkin) {
					skeletonData.DefaultSkin.FindAttachmentsForSlot(i, attachments);
					skeletonData.DefaultSkin.FindNamesForSlot(i, attachmentNames);
				}

				for (int a = 0; a < attachments.Count; a++) {
					var attachment = attachments[a];
					var attachmentName = attachmentNames[a];
					var attachmentMeshName = "[" + slotData.Name + "] " + attachmentName;
					Vector3 offset = Vector3.zero;
					float rotation = 0;
					Mesh mesh = null;
					Material material = null;

					if (meshTable.ContainsKey(attachmentMeshName))
						mesh = meshTable[attachmentMeshName];
					if (attachment is RegionAttachment) {
						var regionAttachment = (RegionAttachment)attachment;
						offset.x = regionAttachment.X;
						offset.y = regionAttachment.Y;
						rotation = regionAttachment.Rotation;
						mesh = ExtractRegionAttachment(attachmentMeshName, regionAttachment, mesh);
						material = ExtractMaterial((RegionAttachment)attachment);
						unusedMeshNames.Remove(attachmentMeshName);
						if (newPrefab || meshTable.ContainsKey(attachmentMeshName) == false)
							AssetDatabase.AddObjectToAsset(mesh, prefab);
					} else if (attachment is MeshAttachment) {
						var meshAttachment = (MeshAttachment)attachment;
						offset.x = 0;
						offset.y = 0;
						rotation = 0;
						mesh = ExtractMeshAttachment(attachmentMeshName, meshAttachment, mesh);
						material = ExtractMaterial((MeshAttachment)attachment);
						unusedMeshNames.Remove(attachmentMeshName);
						if (newPrefab || meshTable.ContainsKey(attachmentMeshName) == false)
							AssetDatabase.AddObjectToAsset(mesh, prefab);
					} else if (attachment is SkinnedMeshAttachment) {
						var meshAttachment = (SkinnedMeshAttachment)attachment;
						offset.x = 0;
						offset.y = 0;
						rotation = 0;
						mesh = ExtractSkinnedMeshAttachment(attachmentMeshName, meshAttachment, i, skeletonData, boneList, mesh);
						material = ExtractMaterial((SkinnedMeshAttachment)attachment);
						unusedMeshNames.Remove(attachmentMeshName);
						if (newPrefab || meshTable.ContainsKey(attachmentMeshName) == false)
							AssetDatabase.AddObjectToAsset(mesh, prefab);
					} else
						continue;  //disregard unsupported types for now

					Transform attachmentTransform = new GameObject(attachmentName).transform;

					attachmentTransform.parent = slotTransform;
					attachmentTransform.localPosition = offset;
					attachmentTransform.localRotation = Quaternion.Euler(0, 0, rotation);

					if (attachment is SkinnedMeshAttachment) {
						attachmentTransform.position = Vector3.zero;
						attachmentTransform.rotation = Quaternion.identity;
						var skinnedMeshRenderer = attachmentTransform.gameObject.AddComponent<SkinnedMeshRenderer>();
						skinnedMeshRenderer.rootBone = boneList[0];
						skinnedMeshRenderer.bones = boneList.ToArray();
						skinnedMeshRenderer.sharedMesh = mesh;

					} else {
						attachmentTransform.gameObject.AddComponent<MeshFilter>().sharedMesh = mesh;
						attachmentTransform.gameObject.AddComponent<MeshRenderer>();
					}

					attachmentTransform.GetComponent<Renderer>().sharedMaterial = material;
					attachmentTransform.GetComponent<Renderer>().sortingOrder = i;

					if (attachmentName != slotData.AttachmentName)
						attachmentTransform.gameObject.SetActive(false);
				}

			}

			foreach (var slotData in skeletonData.Slots) {
				Transform slotTransform = slotTable[slotData.Name];
				slotTransform.parent = boneTable[slotData.BoneData.Name];
				slotTransform.localPosition = Vector3.zero;
				slotTransform.localRotation = Quaternion.identity;
				slotTransform.localScale = Vector3.one;
			}

			if (hasAnimations) {
				var animator = prefabRoot.AddComponent<Animator>();
				animator.applyRootMotion = false;
				animator.runtimeAnimatorController = (RuntimeAnimatorController)controller;
				EditorGUIUtility.PingObject(controller);
			}


			if (newPrefab) {
				PrefabUtility.ReplacePrefab(prefabRoot, prefab, ReplacePrefabOptions.ConnectToPrefab);
			} else {

				foreach (string str in unusedMeshNames) {
					Mesh.DestroyImmediate(meshTable[str], true);
				}

				PrefabUtility.ReplacePrefab(prefabRoot, prefab, ReplacePrefabOptions.ReplaceNameBased);
			}

			EditorGUIUtility.PingObject(prefab);

			AssetDatabase.Refresh();
			AssetDatabase.SaveAssets();

			GameObject.DestroyImmediate(prefabRoot);
		}

	}
	public static SkeletonAnimation SpawnAnimatedSkeleton(SkeletonDataAsset skeletonDataAsset, Skin skin = null){
		
		GameObject go = new GameObject(skeletonDataAsset.name.Replace("_SkeletonData", ""), typeof(MeshFilter), typeof(MeshRenderer), typeof(SkeletonAnimation));
		SkeletonAnimation anim = go.GetComponent<SkeletonAnimation>();
		anim.skeletonDataAsset = skeletonDataAsset;

		bool requiresNormals = false;

		foreach(Material m in anim.skeletonDataAsset.atlasAsset.materials){
			if(m.shader.name.Contains("Lit")){
				requiresNormals = true;
				break;
			}
		}

		anim.calculateNormals = requiresNormals;

		if(skin == null)
			skin = skeletonDataAsset.GetSkeletonData(true).DefaultSkin;
			
		if(skin == null)
			skin = skeletonDataAsset.GetSkeletonData(true).Skins[0];

		anim.Reset();
		
		anim.skeleton.SetSkin(skin);
		anim.initialSkinName = skin.Name;
		
		anim.skeleton.Update(1);
		anim.state.Update(1);
		anim.state.Apply(anim.skeleton);
		anim.skeleton.UpdateWorldTransform();

		return anim;
	}
		public static SkeletonAnimator InstantiateSkeletonAnimator (SkeletonDataAsset skeletonDataAsset, Skin skin = null) {
			string spineGameObjectName = string.Format("Spine Mecanim GameObject ({0})", skeletonDataAsset.name.Replace("_SkeletonData", ""));
			GameObject go = new GameObject(spineGameObjectName, typeof(MeshFilter), typeof(MeshRenderer), typeof(Animator), typeof(SkeletonAnimator));

			if (skeletonDataAsset.controller == null) {
				SkeletonBaker.GenerateMecanimAnimationClips(skeletonDataAsset);
				Debug.Log(string.Format("Mecanim controller was automatically generated and assigned for {0}", skeletonDataAsset.name));
			}

			go.GetComponent<Animator>().runtimeAnimatorController = skeletonDataAsset.controller;

			SkeletonAnimator anim = go.GetComponent<SkeletonAnimator>();
			anim.skeletonDataAsset = skeletonDataAsset;

			// Detect "Lit" shader and automatically enable calculateNormals.
//			bool requiresNormals = false;
//			foreach (AtlasAsset atlasAsset in anim.skeletonDataAsset.atlasAssets) {
//				foreach (Material m in atlasAsset.materials) {
//					if (m.shader.name.Contains("Lit")) {
//						requiresNormals = true;
//						break;
//					}
//				}
//			}
//			anim.calculateNormals = requiresNormals;

			SkeletonData data = skeletonDataAsset.GetSkeletonData(true);
			if (data == null) {
				for (int i = 0; i < skeletonDataAsset.atlasAssets.Length; i++) {
					string reloadAtlasPath = AssetDatabase.GetAssetPath(skeletonDataAsset.atlasAssets[i]);
					skeletonDataAsset.atlasAssets[i] = (AtlasAsset)AssetDatabase.LoadAssetAtPath(reloadAtlasPath, typeof(AtlasAsset));
				}
				data = skeletonDataAsset.GetSkeletonData(true);
			}

			skin = skin ?? data.DefaultSkin ?? data.Skins.Items[0];

			anim.Initialize(false);
			anim.skeleton.SetSkin(skin);
			anim.initialSkinName = skin.Name;

			anim.skeleton.Update(0);
			anim.skeleton.UpdateWorldTransform();
			anim.LateUpdate();

			return anim;
		}
	public static SkeletonAnimation SpawnAnimatedSkeleton (SkeletonDataAsset skeletonDataAsset, Skin skin = null) {
		GameObject go = new GameObject(skeletonDataAsset.name.Replace("_SkeletonData", ""), typeof(MeshFilter), typeof(MeshRenderer), typeof(SkeletonAnimation));
		SkeletonAnimation anim = go.GetComponent<SkeletonAnimation>();
		anim.skeletonDataAsset = skeletonDataAsset;



		SkeletonData data = skeletonDataAsset.GetSkeletonData(false);

		if (data == null) {
			return null;
		}

		if (skin == null)
			skin = data.DefaultSkin;
			
		if (skin == null)
			skin = data.Skins[0];

		anim.Reset();
		
		anim.skeleton.SetSkin(skin);
		anim.initialSkinName = skin.Name;
		
		anim.skeleton.Update(1);
		anim.state.Update(1);
		anim.state.Apply(anim.skeleton);
		anim.skeleton.UpdateWorldTransform();

		return anim;
	}
		public static SkeletonAnimation InstantiateSkeletonAnimation (SkeletonDataAsset skeletonDataAsset, string skinName, bool destroyInvalid = true) {
			var skeletonData = skeletonDataAsset.GetSkeletonData(true);
			var skin = skeletonData != null ? skeletonData.FindSkin(skinName) : null;
			return InstantiateSkeletonAnimation(skeletonDataAsset, skin, destroyInvalid);
		}
		public static SkeletonGraphic InstantiateSkeletonGraphic (SkeletonDataAsset skeletonDataAsset, Skin skin = null) {
			string spineGameObjectName = string.Format("SkeletonGraphic ({0})", skeletonDataAsset.name.Replace("_SkeletonData", ""));
			var go = NewSkeletonGraphicGameObject(spineGameObjectName);
			var graphic = go.GetComponent<SkeletonGraphic>();
			graphic.skeletonDataAsset = skeletonDataAsset;

			SkeletonData data = skeletonDataAsset.GetSkeletonData(true);

			if (data == null) {
				for (int i = 0; i < skeletonDataAsset.atlasAssets.Length; i++) {
					string reloadAtlasPath = AssetDatabase.GetAssetPath(skeletonDataAsset.atlasAssets[i]);
					skeletonDataAsset.atlasAssets[i] = (AtlasAsset)AssetDatabase.LoadAssetAtPath(reloadAtlasPath, typeof(AtlasAsset));
				}

				data = skeletonDataAsset.GetSkeletonData(true);
			}

			if (skin == null)
				skin = data.DefaultSkin;

			if (skin == null)
				skin = data.Skins.Items[0];

			graphic.Initialize(false);
			graphic.Skeleton.SetSkin(skin);
			graphic.initialSkinName = skin.Name;
			graphic.Skeleton.UpdateWorldTransform();
			graphic.UpdateMesh();

			return graphic;
		}
Ejemplo n.º 45
0
		public static void GenerateMecanimAnimationClips (SkeletonDataAsset skeletonDataAsset) {
			//skeletonDataAsset.Clear();
			var data = skeletonDataAsset.GetSkeletonData(true);
			if (data == null) {
				Debug.LogError("SkeletonData failed!", skeletonDataAsset);
				return;
			}

			string dataPath = AssetDatabase.GetAssetPath(skeletonDataAsset);
			string controllerPath = dataPath.Replace("_SkeletonData", "_Controller").Replace(".asset", ".controller");

		#if UNITY_5
			UnityEditor.Animations.AnimatorController controller;

			if (skeletonDataAsset.controller != null) {
				controller = (UnityEditor.Animations.AnimatorController)skeletonDataAsset.controller;
				controllerPath = AssetDatabase.GetAssetPath(controller);
			} else {
				if (File.Exists(controllerPath)) {
					if (EditorUtility.DisplayDialog("Controller Overwrite Warning", "Unknown Controller already exists at: " + controllerPath, "Update", "Overwrite")) {
						controller = (UnityEditor.Animations.AnimatorController)AssetDatabase.LoadAssetAtPath(controllerPath, typeof(RuntimeAnimatorController));
					} else {
						controller = (UnityEditor.Animations.AnimatorController)UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(controllerPath);
					}
				} else {
					controller = (UnityEditor.Animations.AnimatorController)UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(controllerPath);
				}

			}
		#else
		UnityEditorInternal.AnimatorController controller;

		if (skeletonDataAsset.controller != null) {
			controller = (UnityEditorInternal.AnimatorController)skeletonDataAsset.controller;
			controllerPath = AssetDatabase.GetAssetPath(controller);
		} else {
			if (File.Exists(controllerPath)) {
				if (EditorUtility.DisplayDialog("Controller Overwrite Warning", "Unknown Controller already exists at: " + controllerPath, "Update", "Overwrite")) {
					controller = (UnityEditorInternal.AnimatorController)AssetDatabase.LoadAssetAtPath(controllerPath, typeof(RuntimeAnimatorController));
				} else {
					controller = (UnityEditorInternal.AnimatorController)UnityEditorInternal.AnimatorController.CreateAnimatorControllerAtPath(controllerPath);
				}
			} else {
				controller = (UnityEditorInternal.AnimatorController)UnityEditorInternal.AnimatorController.CreateAnimatorControllerAtPath(controllerPath);
			}
		}
		#endif

			skeletonDataAsset.controller = controller;
			EditorUtility.SetDirty(skeletonDataAsset);

			UnityEngine.Object[] objs = AssetDatabase.LoadAllAssetsAtPath(controllerPath);

			var unityAnimationClipTable = new Dictionary<string, AnimationClip>();
			var spineAnimationTable = new Dictionary<string, Spine.Animation>();

			foreach (var o in objs) {
				//Debug.LogFormat("({0}){1} : {3} + {2} + {4}", o.GetType(), o.name, o.hideFlags, o.GetInstanceID(), o.GetHashCode());
				// There is a bug in Unity 5.3.3 (and likely before) that creates
				// a duplicate AnimationClip when you duplicate a Mecanim Animator State.
				// These duplicates seem to be identifiable by their HideFlags, so we'll exclude them.
				if (o is AnimationClip) {
					var clip = o as AnimationClip;
					if (!clip.HasFlag(HideFlags.HideInHierarchy)) {
						if (unityAnimationClipTable.ContainsKey(clip.name)) {
							Debug.LogWarningFormat("Duplicate AnimationClips were found named {0}", clip.name);
						}
						unityAnimationClipTable.Add(clip.name, clip);
					}				
				}
			}

			foreach (var anim in data.Animations) {
				string name = anim.Name;
				spineAnimationTable.Add(name, anim);

				if (unityAnimationClipTable.ContainsKey(name) == false) {
					//generate new dummy clip
					AnimationClip newClip = new AnimationClip();
					newClip.name = name;
					#if !(UNITY_5)
					AnimationUtility.SetAnimationType(newClip, ModelImporterAnimationType.Generic);
					#endif
					AssetDatabase.AddObjectToAsset(newClip, controller);
					unityAnimationClipTable.Add(name, newClip);
				}

				AnimationClip clip = unityAnimationClipTable[name];

				clip.SetCurve("", typeof(GameObject), "dummy", AnimationCurve.Linear(0, 0, anim.Duration, 0));
				var settings = AnimationUtility.GetAnimationClipSettings(clip);
				settings.stopTime = anim.Duration;

				SetAnimationSettings(clip, settings);

				AnimationUtility.SetAnimationEvents(clip, new AnimationEvent[0]);

				foreach (Timeline t in anim.Timelines) {
					if (t is EventTimeline) {
						ParseEventTimeline((EventTimeline)t, clip, SendMessageOptions.DontRequireReceiver);
					}
				}

				EditorUtility.SetDirty(clip);

				unityAnimationClipTable.Remove(name);
			}

			//clear no longer used animations
			foreach (var clip in unityAnimationClipTable.Values) {
				AnimationClip.DestroyImmediate(clip, true);
			}

			AssetDatabase.Refresh();
			AssetDatabase.SaveAssets();
		}
Ejemplo n.º 46
0
	public static Spine.Attachment GetAttachment(string attachmentPath, SkeletonDataAsset skeletonDataAsset) {
		return GetAttachment(attachmentPath, skeletonDataAsset.GetSkeletonData(true));
	}
Ejemplo n.º 47
0
	public static SkeletonAnimation InstantiateSkeletonAnimation (SkeletonDataAsset skeletonDataAsset, Skin skin = null) {
		string spineGameObjectName = string.Format("Spine GameObject ({0})", skeletonDataAsset.name.Replace("_SkeletonData", ""));
		GameObject go = new GameObject(spineGameObjectName, typeof(MeshFilter), typeof(MeshRenderer), typeof(SkeletonAnimation));
		SkeletonAnimation anim = go.GetComponent<SkeletonAnimation>();
		anim.skeletonDataAsset = skeletonDataAsset;

		bool requiresNormals = false;

		foreach (AtlasAsset atlasAsset in anim.skeletonDataAsset.atlasAssets) {
			foreach (Material m in atlasAsset.materials) {
				if (m.shader.name.Contains("Lit")) {
					requiresNormals = true;
					break;
				}
			}
		}



		anim.calculateNormals = requiresNormals;

		SkeletonData data = skeletonDataAsset.GetSkeletonData(true);

		if (data == null) {
			for (int i = 0; i < skeletonDataAsset.atlasAssets.Length; i++) {
				string reloadAtlasPath = AssetDatabase.GetAssetPath(skeletonDataAsset.atlasAssets[i]);
				skeletonDataAsset.atlasAssets[i] = (AtlasAsset)AssetDatabase.LoadAssetAtPath(reloadAtlasPath, typeof(AtlasAsset));
			}

			data = skeletonDataAsset.GetSkeletonData(true);
		}

		if (skin == null)
			skin = data.DefaultSkin;

		if (skin == null)
			skin = data.Skins.Items[0];

		anim.Initialize(false);

		anim.skeleton.SetSkin(skin);
		anim.initialSkinName = skin.Name;

		anim.skeleton.Update(1);
		anim.state.Update(1);
		anim.state.Apply(anim.skeleton);
		anim.skeleton.UpdateWorldTransform();

		return anim;
	}
	public static SkeletonAnimation SpawnAnimatedSkeleton (SkeletonDataAsset skeletonDataAsset, string skinName) {
		SkeletonData skelData = skeletonDataAsset.GetSkeletonData(false);
		if(skelData == null){
			return null;
		}
		return SpawnAnimatedSkeleton(skeletonDataAsset, skelData.FindSkin(skinName));
	}
		public static SkeletonAnimation InstantiateSkeletonAnimation (SkeletonDataAsset skeletonDataAsset, Skin skin = null, bool destroyInvalid = true) {
			SkeletonData data = skeletonDataAsset.GetSkeletonData(true);

			if (data == null) {
				for (int i = 0; i < skeletonDataAsset.atlasAssets.Length; i++) {
					string reloadAtlasPath = AssetDatabase.GetAssetPath(skeletonDataAsset.atlasAssets[i]);
					skeletonDataAsset.atlasAssets[i] = (AtlasAsset)AssetDatabase.LoadAssetAtPath(reloadAtlasPath, typeof(AtlasAsset));
				}
				data = skeletonDataAsset.GetSkeletonData(false);
			}

			if (data == null) {
				Debug.LogWarning("InstantiateSkeletonAnimation tried to instantiate a skeleton from an invalid SkeletonDataAsset.");
				return null;
			}

			if (skin == null) skin = data.DefaultSkin;
			if (skin == null) skin = data.Skins.Items[0];

			string spineGameObjectName = string.Format("Spine GameObject ({0})", skeletonDataAsset.name.Replace("_SkeletonData", ""));
			GameObject go = new GameObject(spineGameObjectName, typeof(MeshFilter), typeof(MeshRenderer), typeof(SkeletonAnimation));
			SkeletonAnimation newSkeletonAnimation = go.GetComponent<SkeletonAnimation>();
			newSkeletonAnimation.skeletonDataAsset = skeletonDataAsset;

			{
				bool requiresNormals = false;
				foreach (AtlasAsset atlasAsset in skeletonDataAsset.atlasAssets) {
					foreach (Material m in atlasAsset.materials) {
						if (m.shader.name.Contains("Lit")) {
							requiresNormals = true;
							break;
						}
					}
				}
				newSkeletonAnimation.calculateNormals = requiresNormals;
			}

			try {
				newSkeletonAnimation.Initialize(false);
			} catch (System.Exception e) {
				if (destroyInvalid) {
					Debug.LogWarning("Editor-instantiated SkeletonAnimation threw an Exception. Destroying GameObject to prevent orphaned GameObject.");
					GameObject.DestroyImmediate(go);
				}
				throw e;
			}

			newSkeletonAnimation.skeleton.SetSkin(skin);
			newSkeletonAnimation.initialSkinName = skin.Name;

			newSkeletonAnimation.skeleton.Update(1);
			newSkeletonAnimation.state.Update(1);
			newSkeletonAnimation.state.Apply(newSkeletonAnimation.skeleton);
			newSkeletonAnimation.skeleton.UpdateWorldTransform();

			return newSkeletonAnimation;
		}
Ejemplo n.º 50
0
	public static void GenerateMecanimAnimationClips (SkeletonDataAsset skeletonDataAsset) {
		var data = skeletonDataAsset.GetSkeletonData(true);
		if (data == null) {
			Debug.LogError("SkeletonData failed!", skeletonDataAsset);
			return;
		}

		string dataPath = AssetDatabase.GetAssetPath(skeletonDataAsset);
		string controllerPath = dataPath.Replace("_SkeletonData", "_Controller").Replace(".asset", ".controller");


#if UNITY_5
		UnityEditor.Animations.AnimatorController controller;

		if (skeletonDataAsset.controller != null) {
			controller = (UnityEditor.Animations.AnimatorController)skeletonDataAsset.controller;
			controllerPath = AssetDatabase.GetAssetPath(controller);
		} else {
			if (File.Exists(controllerPath)) {
				if (EditorUtility.DisplayDialog("Controller Overwrite Warning", "Unknown Controller already exists at: " + controllerPath, "Update", "Overwrite")) {
					controller = (UnityEditor.Animations.AnimatorController)AssetDatabase.LoadAssetAtPath(controllerPath, typeof(RuntimeAnimatorController));
				} else {
					controller = (UnityEditor.Animations.AnimatorController)UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(controllerPath);
				}
			} else {
				controller = (UnityEditor.Animations.AnimatorController)UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(controllerPath);
			}
			
		}
#else
		UnityEditorInternal.AnimatorController controller;

		if (skeletonDataAsset.controller != null) {
			controller = (UnityEditorInternal.AnimatorController)skeletonDataAsset.controller;
			controllerPath = AssetDatabase.GetAssetPath(controller);
		} else {
			if (File.Exists(controllerPath)) {
				if (EditorUtility.DisplayDialog("Controller Overwrite Warning", "Unknown Controller already exists at: " + controllerPath, "Update", "Overwrite")) {
					controller = (UnityEditorInternal.AnimatorController)AssetDatabase.LoadAssetAtPath(controllerPath, typeof(RuntimeAnimatorController));
				} else {
					controller = (UnityEditorInternal.AnimatorController)UnityEditorInternal.AnimatorController.CreateAnimatorControllerAtPath(controllerPath);
				}
			} else {
				controller = (UnityEditorInternal.AnimatorController)UnityEditorInternal.AnimatorController.CreateAnimatorControllerAtPath(controllerPath);
			}
		}
#endif

		skeletonDataAsset.controller = controller;
		EditorUtility.SetDirty(skeletonDataAsset);

		Object[] objs = AssetDatabase.LoadAllAssetsAtPath(controllerPath);

		Dictionary<string, AnimationClip> clipTable = new Dictionary<string, AnimationClip>();
		Dictionary<string, Spine.Animation> animTable = new Dictionary<string, Spine.Animation>();

		foreach (var o in objs) {
			if (o is AnimationClip) {
				clipTable.Add(o.name, (AnimationClip)o);
			}
		}

		foreach (var anim in data.Animations) {
			string name = anim.Name;
			animTable.Add(name, anim);

			if (clipTable.ContainsKey(name) == false) {
				//generate new dummy clip
				AnimationClip newClip = new AnimationClip();
				newClip.name = name;
#if UNITY_5
#else
				AnimationUtility.SetAnimationType(newClip, ModelImporterAnimationType.Generic);
#endif

				AssetDatabase.AddObjectToAsset(newClip, controller);
				clipTable.Add(name, newClip);
			}

			AnimationClip clip = clipTable[name];

			clip.SetCurve("", typeof(GameObject), "dummy", AnimationCurve.Linear(0, 0, anim.Duration, 0));
			var settings = AnimationUtility.GetAnimationClipSettings(clip);
			settings.stopTime = anim.Duration;

			SetAnimationSettings(clip, settings);

			AnimationUtility.SetAnimationEvents(clip, new AnimationEvent[0]);

			foreach (Timeline t in anim.Timelines) {
				if (t is EventTimeline) {
					ParseEventTimeline((EventTimeline)t, clip, SendMessageOptions.DontRequireReceiver);
				}
			}

			EditorUtility.SetDirty(clip);

			clipTable.Remove(name);
		}

		//clear no longer used animations
		foreach (var clip in clipTable.Values) {
			AnimationClip.DestroyImmediate(clip, true);
		}

		AssetDatabase.Refresh();
		AssetDatabase.SaveAssets();
	}
	public static SkeletonAnimation SpawnAnimatedSkeleton(SkeletonDataAsset skeletonDataAsset, string skinName){
		return SpawnAnimatedSkeleton(skeletonDataAsset, skeletonDataAsset.GetSkeletonData(true).FindSkin(skinName));
	}