public void Initialize(bool overwrite) { if ((IsValid && !overwrite) || skeletonDataAsset == null) { return; } SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(quiet: false); if (skeletonData == null || skeletonDataAsset.atlasAssets.Length <= 0 || skeletonDataAsset.atlasAssets[0].materials.Length <= 0) { return; } state = new AnimationState(skeletonDataAsset.GetAnimationStateData()); if (state == null) { Clear(); return; } skeleton = new Skeleton(skeletonData) { flipX = initialFlipX, flipY = initialFlipY }; meshBuffers = new DoubleBuffered <MeshRendererBuffers.SmartMesh>(); base.canvasRenderer.SetTexture(mainTexture); if (!string.IsNullOrEmpty(initialSkinName)) { skeleton.SetSkin(initialSkinName); } if (!string.IsNullOrEmpty(startingAnimation)) { state.SetAnimation(0, startingAnimation, startingLoop); Update(0f); } }
public virtual void Initialize(bool overwrite) { if (valid && !overwrite) { return; } if (meshFilter != null) { meshFilter.sharedMesh = null; } meshRenderer = GetComponent <MeshRenderer>(); if (meshRenderer != null) { meshRenderer.sharedMaterial = null; } currentInstructions.Clear(); rendererBuffers.Clear(); meshGenerator.Begin(); skeleton = null; valid = false; if (!skeletonDataAsset) { if (logErrors) { UnityEngine.Debug.LogError("Missing SkeletonData asset.", this); } return; } SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(quiet: false); if (skeletonData != null) { valid = true; meshFilter = GetComponent <MeshFilter>(); meshRenderer = GetComponent <MeshRenderer>(); rendererBuffers.Initialize(); skeleton = new Skeleton(skeletonData) { flipX = initialFlipX, flipY = initialFlipY }; if (!string.IsNullOrEmpty(initialSkinName) && !string.Equals(initialSkinName, "default", StringComparison.Ordinal)) { skeleton.SetSkin(initialSkinName); } separatorSlots.Clear(); for (int i = 0; i < separatorSlotNames.Length; i++) { separatorSlots.Add(skeleton.FindSlot(separatorSlotNames[i])); } LateUpdate(); if (this.OnRebuild != null) { this.OnRebuild(this); } } }
protected override void OnValidate () { // This handles Scene View preview. base.OnValidate (); if (this.IsValid) { if (skeletonDataAsset == null) { Clear(); startingAnimation = ""; } else if (skeletonDataAsset.GetSkeletonData(true) != skeleton.data) { Clear(); Initialize(true); startingAnimation = ""; if (skeletonDataAsset.atlasAssets.Length > 1 || skeletonDataAsset.atlasAssets[0].materials.Length > 1) Debug.LogError("Unity UI does not support multiple textures per Renderer. Your skeleton will not be rendered correctly. Recommend using SkeletonAnimation instead. This requires the use of a Screen space camera canvas."); } else { if (freeze) return; if (!string.IsNullOrEmpty(initialSkinName)) { var skin = skeleton.data.FindSkin(initialSkinName); if (skin != null) { if (skin == skeleton.data.defaultSkin) skeleton.SetSkin((Skin)null); else skeleton.SetSkin(skin); } } // Only provide visual feedback to inspector changes in Unity Editor Edit mode. if (!Application.isPlaying) { skeleton.flipX = this.initialFlipX; skeleton.flipY = this.initialFlipY; skeleton.SetToSetupPose(); if (!string.IsNullOrEmpty(startingAnimation)) skeleton.PoseWithAnimation(startingAnimation, 0f, false); } } } else { if (skeletonDataAsset != null) Initialize(true); } }
public void Initialize() { if (skeletonDataAsset == null) { return; } this.animation = skeletonDataAsset.GetSkeletonData(AnimationReferenceAsset.QuietSkeletonData).FindAnimation(animationName); if (this.animation == null) { Debug.LogWarningFormat("Animation '{0}' not found in SkeletonData : {1}.", animationName, skeletonDataAsset.name); } }
public void Initialize(Animator animator, SkeletonDataAsset skeletonDataAsset) { this.animator = animator; animationTable.Clear(); clipNameHashCodeTable.Clear(); var data = skeletonDataAsset.GetSkeletonData(true); foreach (var a in data.Animations) { animationTable.Add(a.Name.GetHashCode(), a); } }
public void Initialize() { if (skeletonDataAsset == null) { return; } this.eventData = skeletonDataAsset.GetSkeletonData(EventDataReferenceAsset.QuietSkeletonData).FindEvent(eventName); if (this.eventData == null) { Debug.LogWarningFormat("Event Data '{0}' not found in SkeletonData : {1}.", eventName, skeletonDataAsset.name); } }
public void Initialize(Animator animator, SkeletonDataAsset skeletonDataAsset) { this.animator = animator; animationTable.Clear(); clipNameHashCodeTable.Clear(); SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(quiet: true); foreach (Animation animation in skeletonData.Animations) { animationTable.Add(animation.Name.GetHashCode(), animation); } }
public void Initialize(UnityEngine.Animator animator, SkeletonDataAsset skeletonDataAsset) { this.animator = animator; this.previousAnimations.Clear(); this.animationTable.Clear(); foreach (Spine.Animation animation in skeletonDataAsset.GetSkeletonData(true).Animations) { this.animationTable.Add(animation.Name.GetHashCode(), animation); } this.clipNameHashCodeTable.Clear(); this.clipInfoCache.Clear(); this.nextClipInfoCache.Clear(); }
public static SkeletonDataAsset CreateRuntimeInstance(TextAsset skeletonDataFile, AtlasAsset[] atlasAssets, bool initialize, float scale = 0.01f) { SkeletonDataAsset asset = ScriptableObject.CreateInstance <SkeletonDataAsset>(); asset.Clear(); asset.skeletonJSON = skeletonDataFile; asset.atlasAssets = atlasAssets; asset.scale = scale; if (initialize) { asset.GetSkeletonData(true); } return(asset); }
static int GetSkeletonData(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); Spine.Unity.SkeletonDataAsset obj = (Spine.Unity.SkeletonDataAsset)ToLua.CheckObject <Spine.Unity.SkeletonDataAsset>(L, 1); bool arg0 = LuaDLL.luaL_checkboolean(L, 2); Spine.SkeletonData o = obj.GetSkeletonData(arg0); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
protected override void OnValidate() { // This handles Scene View preview. base.OnValidate(); #if !PREUNITY_5_2 if (this.IsValid) { if (skeletonDataAsset == null) { Clear(); startingAnimation = ""; } else if (skeletonDataAsset.GetSkeletonData(true) != skeleton.data) { Clear(); Initialize(true); startingAnimation = ""; if (skeletonDataAsset.atlasAssets.Length > 1 || skeletonDataAsset.atlasAssets[0].materials.Length > 1) { Debug.LogError("Unity UI does not support multiple textures per Renderer. Your skeleton will not be rendered correctly. Recommend using SkeletonAnimation instead. This requires the use of a Screen space camera canvas."); } } else { if (freeze) { return; } skeleton.SetToSetupPose(); if (!string.IsNullOrEmpty(startingAnimation)) { skeleton.PoseWithAnimation(startingAnimation, 0f, false); } } } else { if (skeletonDataAsset != null) { Initialize(true); } } #else Debug.LogWarning("SkeletonGraphic requres Unity 5.2 or higher.\nUnityEngine.UI 5.1 and below does not accept meshes and can't be used to render Spine skeletons. You may delete the SkeletonGraphic folder under `Modules` if you want to exclude it from your project."); #endif }
//public bool tintBlack = false; #if UNITY_EDITOR protected override void OnValidate() { // This handles Scene View preview. base.OnValidate(); if (this.IsValid) { if (skeletonDataAsset == null) { Clear(); startingAnimation = ""; } else if (skeletonDataAsset.GetSkeletonData(true) != skeleton.data) { Clear(); Initialize(true); startingAnimation = ""; if (skeletonDataAsset.atlasAssets.Length > 1 || skeletonDataAsset.atlasAssets[0].materials.Length > 1) { Debug.LogError("Unity UI does not support multiple textures per Renderer. Your skeleton will not be rendered correctly. Recommend using SkeletonAnimation instead. This requires the use of a Screen space camera canvas."); } } else { if (freeze) { return; } skeleton.SetToSetupPose(); if (!string.IsNullOrEmpty(startingAnimation)) { skeleton.PoseWithAnimation(startingAnimation, 0f, false); } } } else { if (skeletonDataAsset != null) { Initialize(true); } } }
public void Initialize(Animator animator, SkeletonDataAsset skeletonDataAsset) { this.animator = animator; previousAnimations.Clear(); animationTable.Clear(); var data = skeletonDataAsset.GetSkeletonData(true); foreach (var a in data.Animations) { animationTable.Add(a.Name.GetHashCode(), a); } clipNameHashCodeTable.Clear(); #if UNITY_CLIPINFOCACHE clipInfoCache.Clear(); nextClipInfoCache.Clear(); #endif }
private void BaseSkillInput(SkillData currSkillData) { #region 基本 MyGUIExtend.Instance.Foldout("基本" + this.currSkillData.id + currSkillData.id, "基本", () => { currSkillData.name = MyGUI.TextFieldWithTitle("name", currSkillData.name); MonoScript component = (MonoScript)AssetDatabase.LoadAssetAtPath(currSkillData.componentPath, typeof(MonoScript)); component = (UnityEditor.MonoScript)EditorGUILayout.ObjectField(new GUIContent("脚本"), component, typeof(UnityEditor.MonoScript), true); if (component != null) { currSkillData.componentPath = AssetDatabase.GetAssetPath(component); currSkillData.componentTypeName = component.GetClass().Namespace + "." + component.GetClass().Name; } currSkillData.SurvivalTime = MyGUI.FloatFieldWithTitle("存活时间", currSkillData.SurvivalTime); // 朝向模式 add by TangJian 2019/4/20 13:24 currSkillData.SkillOrientationMode = (SkillOrientationMode)MyGUI.EnumPopupWithTitle("朝向模式", currSkillData.SkillOrientationMode); }); #endregion #region 渲染 MyGUIExtend.Instance.Foldout("渲染" + this.currSkillData.id + currSkillData.id, "渲染", () => { currSkillData.rendererType = (RendererType)MyGUI.EnumPopupWithTitle("rander类型:", currSkillData.rendererType); switch (currSkillData.rendererType) { case RendererType.SkeletonAnimator: { Spine.Unity.SkeletonDataAsset SkeletonDataAsset = (Spine.Unity.SkeletonDataAsset)AssetDatabase.LoadAssetAtPath( currSkillData.SkeletonDataAssetPath, typeof(Spine.Unity.SkeletonDataAsset)); UnityEditor.Animations.AnimatorController animatorController = (UnityEditor.Animations.AnimatorController)AssetDatabase.LoadAssetAtPath( currSkillData.AnimControllerPath, typeof(UnityEditor.Animations.AnimatorController)); animatorController = (UnityEditor.Animations.AnimatorController)EditorGUILayout.ObjectField( new GUIContent("动画控制器"), animatorController, typeof(UnityEditor.Animations.AnimatorController), true); SkeletonDataAsset = (Spine.Unity.SkeletonDataAsset)EditorGUILayout.ObjectField( new GUIContent("Skeleton"), SkeletonDataAsset, typeof(Spine.Unity.SkeletonDataAsset), true); currSkillData.SkeletonDataAssetPath = AssetDatabase.GetAssetPath(SkeletonDataAsset); currSkillData.AnimControllerPath = AssetDatabase.GetAssetPath(animatorController); if (SkeletonDataAsset != null) { string[] skins = new string[SkeletonDataAsset.GetSkeletonData(false).Skins.Count]; int skinIndex = 0; for (int i = 0; i < skins.Length; i++) { string skinNameString = SkeletonDataAsset.GetSkeletonData(false).Skins .Items[i].Name; skins[i] = skinNameString; if (skinNameString == currSkillData.SkinName) { skinIndex = i; } } skinIndex = EditorGUILayout.Popup("Initial Skin(皮肤)", skinIndex, skins); currSkillData.SkinName = skins[skinIndex]; } } break; case RendererType.Sprite: { currSkillData.SpritePath = MyGUI.ObjectField <Sprite>("精灵: ", currSkillData.SpritePath); } break; case RendererType.Skeleton: Spine.Unity.SkeletonDataAsset skeletonDataAsset = AssetDatabase.LoadAssetAtPath <Spine.Unity.SkeletonDataAsset>(currSkillData.SkeletonPath); skeletonDataAsset = (Spine.Unity.SkeletonDataAsset)EditorGUILayout.ObjectField("Skeleton", skeletonDataAsset, typeof(Spine.Unity.SkeletonDataAsset)); currSkillData.SkeletonPath = AssetDatabase.GetAssetPath(skeletonDataAsset); if (skeletonDataAsset != null) { if (skeletonDataAsset != null && skeletonDataAsset.GetSkeletonData(false) != null && skeletonDataAsset.GetSkeletonData(false).Animations != null) { string[] Animations = new string[skeletonDataAsset.GetSkeletonData(false).Animations.Count]; int skinIndex = 0; for (int i = 0; i < Animations.Length; i++) { string skinNameString = skeletonDataAsset.GetSkeletonData(false).Animations.Items[i].Name; Animations[i] = skinNameString; if (skinNameString == currSkillData.SkeletonClipName) { skinIndex = i; } } skinIndex = EditorGUILayout.Popup("Animation(动画片段)", skinIndex, Animations); currSkillData.SkeletonClipName = Animations[skinIndex]; } } break; case RendererType.Anim: currSkillData.AnimName = EditorGUILayout.TextField("AnimName:", currSkillData.AnimName); break; default: Debug.Log("UnKnown:" + currSkillData.rendererType); break; } currSkillData.shadow = MyGUI.ToggleWithTitle("阴影", currSkillData.shadow); if (currSkillData.shadow) { currSkillData.shadowScale = MyGUI.Vector3WithTitle("阴影scale", currSkillData.shadowScale); currSkillData.CutOffDistance = MyGUI.FloatFieldWithTitle("阴影CutOffDistance", currSkillData.CutOffDistance); currSkillData.MaxScaleMultpler = MyGUI.FloatFieldWithTitle("阴影MaxScaleMultpler", currSkillData.MaxScaleMultpler); } }); #endregion }
/// <summary> /// Initialize this component. Attempts to load the SkeletonData and creates the internal Skeleton object and buffers.</summary> /// <param name="overwrite">If set to <c>true</c>, it will overwrite internal objects if they were already generated. Otherwise, the initialized component will ignore subsequent calls to initialize.</param> public virtual void Initialize(bool overwrite) { if (valid && !overwrite) { return; } // Clear { if (meshFilter != null) { meshFilter.sharedMesh = null; } meshRenderer = GetComponent <MeshRenderer>(); if (meshRenderer != null && meshRenderer.enabled) { meshRenderer.sharedMaterial = null; } currentInstructions.Clear(); rendererBuffers.Clear(); meshGenerator.Begin(); skeleton = null; valid = false; } if (skeletonDataAsset == null) { return; } SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(false); if (skeletonData == null) { return; } valid = true; meshFilter = GetComponent <MeshFilter>(); meshRenderer = GetComponent <MeshRenderer>(); rendererBuffers.Initialize(); skeleton = new Skeleton(skeletonData) { scaleX = initialFlipX ? -1 : 1, scaleY = initialFlipY ? -1 : 1 }; if (!string.IsNullOrEmpty(initialSkinName) && !string.Equals(initialSkinName, "default", System.StringComparison.Ordinal)) { skeleton.SetSkin(initialSkinName); } separatorSlots.Clear(); for (int i = 0; i < separatorSlotNames.Length; i++) { separatorSlots.Add(skeleton.FindSlot(separatorSlotNames[i])); } LateUpdate(); // Generate mesh for the first frame it exists. if (OnRebuild != null) { OnRebuild(this); } }
public static Spine.BoneData GetBoneData(string boneName, SkeletonDataAsset skeletonDataAsset) { var data = skeletonDataAsset.GetSkeletonData(true); return data.FindBone(boneName); }
/// <summary> /// Initialize this component. Attempts to load the SkeletonData and creates the internal Skeleton object and buffers.</summary> /// <param name="overwrite">If set to <c>true</c>, it will overwrite internal objects if they were already generated. Otherwise, the initialized component will ignore subsequent calls to initialize.</param> public virtual void Initialize(bool overwrite, bool quiet = false) { if (valid && !overwrite) { return; } // Clear { // Note: do not reset meshFilter.sharedMesh or meshRenderer.sharedMaterial to null, // otherwise constant reloading will be triggered at prefabs. currentInstructions.Clear(); rendererBuffers.Clear(); meshGenerator.Begin(); skeleton = null; valid = false; } if (skeletonDataAsset == null) { return; } SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(false); if (skeletonData == null) { return; } valid = true; meshFilter = GetComponent <MeshFilter>(); meshRenderer = GetComponent <MeshRenderer>(); rendererBuffers.Initialize(); skeleton = new Skeleton(skeletonData) { ScaleX = initialFlipX ? -1 : 1, ScaleY = initialFlipY ? -1 : 1 }; if (!string.IsNullOrEmpty(initialSkinName) && !string.Equals(initialSkinName, "default", System.StringComparison.Ordinal)) { skeleton.SetSkin(initialSkinName); } separatorSlots.Clear(); for (int i = 0; i < separatorSlotNames.Length; i++) { separatorSlots.Add(skeleton.FindSlot(separatorSlotNames[i])); } LateUpdate(); // Generate mesh for the first frame it exists. if (OnRebuild != null) { OnRebuild(this); } #if UNITY_EDITOR if (!Application.isPlaying) { string errorMessage = null; if (!quiet && MaterialChecks.IsMaterialSetupProblematic(this, ref errorMessage)) { Debug.LogWarningFormat(this, "Problematic material setup at {0}: {1}", this.name, errorMessage); } } #endif }
public static BoneData GetBoneData(string boneName, SkeletonDataAsset skeletonDataAsset) => skeletonDataAsset.GetSkeletonData(true).FindBone(boneName);
public static Spine.Attachment GetAttachment(string attachmentPath, SkeletonDataAsset skeletonDataAsset) { return(GetAttachment(attachmentPath, skeletonDataAsset.GetSkeletonData(true))); }
public static Spine.Attachment GetAttachment (string attachmentPath, SkeletonDataAsset skeletonDataAsset) { return GetAttachment(attachmentPath, skeletonDataAsset.GetSkeletonData(true)); }
public static Spine.BoneData GetBoneData(string boneName, SkeletonDataAsset skeletonDataAsset) { var data = skeletonDataAsset.GetSkeletonData(true); return(data.FindBone(boneName)); }
protected override void OnValidate() { // This handles Scene View preview. base.OnValidate(); if (this.IsValid) { if (skeletonDataAsset == null) { Clear(); } else if (skeletonDataAsset.skeletonJSON == null) { Clear(); } else if (skeletonDataAsset.GetSkeletonData(true) != skeleton.data) { Clear(); Initialize(true); if (skeletonDataAsset.atlasAssets.Length > 1 || skeletonDataAsset.atlasAssets[0].MaterialCount > 1) { Debug.LogError("Unity UI does not support multiple textures per Renderer. Your skeleton will not be rendered correctly. Recommend using SkeletonAnimation instead. This requires the use of a Screen space camera canvas."); } } else { if (freeze) { return; } if (!string.IsNullOrEmpty(initialSkinName)) { var skin = skeleton.data.FindSkin(initialSkinName); if (skin != null) { if (skin == skeleton.data.defaultSkin) { skeleton.SetSkin((Skin)null); } else { skeleton.SetSkin(skin); } } } // Only provide visual feedback to inspector changes in Unity Editor Edit mode. if (!Application.isPlaying) { skeleton.scaleX = this.initialFlipX ? -1 : 1; skeleton.scaleY = this.initialFlipY ? -1 : 1; skeleton.SetToSetupPose(); if (!string.IsNullOrEmpty(startingAnimation)) { skeleton.PoseWithAnimation(startingAnimation, 0f, false); } } } } else { // Under some circumstances (e.g. sometimes on the first import) OnValidate is called // before SpineEditorUtilities.ImportSpineContent, causing an unnecessary exception. // The (skeletonDataAsset.skeletonJSON != null) condition serves to prevent this exception. if (skeletonDataAsset != null && skeletonDataAsset.skeletonJSON != null) { Initialize(true); } } }
protected override void OnValidate() { // This handles Scene View preview. base.OnValidate(); if (this.IsValid) { if (skeletonDataAsset == null) { Clear(); } else if (skeletonDataAsset.skeletonJSON == null) { Clear(); } else if (skeletonDataAsset.GetSkeletonData(true) != skeleton.data) { Clear(); Initialize(true); if (!allowMultipleCanvasRenderers && (skeletonDataAsset.atlasAssets.Length > 1 || skeletonDataAsset.atlasAssets[0].MaterialCount > 1)) { Debug.LogError("Unity UI does not support multiple textures per Renderer. Please enable 'Advanced - Multiple CanvasRenderers' to generate the required CanvasRenderer GameObjects. Otherwise your skeleton will not be rendered correctly.", this); } } else { if (freeze) { return; } if (!string.IsNullOrEmpty(initialSkinName)) { var skin = skeleton.data.FindSkin(initialSkinName); if (skin != null) { if (skin == skeleton.data.defaultSkin) { skeleton.SetSkin((Skin)null); } else { skeleton.SetSkin(skin); } } } // Only provide visual feedback to inspector changes in Unity Editor Edit mode. if (!Application.isPlaying) { skeleton.ScaleX = this.initialFlipX ? -1 : 1; skeleton.ScaleY = this.initialFlipY ? -1 : 1; state.ClearTrack(0); skeleton.SetToSetupPose(); if (!string.IsNullOrEmpty(startingAnimation)) { state.SetAnimation(0, startingAnimation, startingLoop); Update(0f); } } } } else { // Under some circumstances (e.g. sometimes on the first import) OnValidate is called // before SpineEditorUtilities.ImportSpineContent, causing an unnecessary exception. // The (skeletonDataAsset.skeletonJSON != null) condition serves to prevent this exception. if (skeletonDataAsset != null && skeletonDataAsset.skeletonJSON != null) { Initialize(true); } } }
public static Attachment GetAttachment(string attachmentPath, SkeletonDataAsset skeletonDataAsset) => GetAttachment(attachmentPath, skeletonDataAsset.GetSkeletonData(true));