Unity3D/Problems
Spine Sprite Attacher
일등하이
2018. 11. 6. 11:02
반응형
UnityException: Texture '1201001' is not readable, the texture memory can not be accessed from scripts. You can make the texture readable in the Texture Import Settings.
UnityEngine.Texture2D.GetPixel (Int32 x, Int32 y) (at C:/buildslave/unity/build/Runtime/Export/Texture.cs:382)
Spine.Unity.Examples.SpriteAttacher.OnValidate () (at Assets/Spine Examples/Scripts/Sample Components/Legacy/SpriteAttacher.cs:64)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
Atlas Region Attacher
https://drive.google.com/open?id=1m5FooeHxLEVm38MgAM6feKyqZFIf5Itc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | using System.Collections; using System.Collections.Generic; using UnityEngine; using Spine.Unity; using Spine.Unity.Modules; using Spine; using Spine.Unity.Modules.AttachmentTools; public class Hero : MonoBehaviour { public SkeletonAnimation skelAnim; public int weaponId; public SpineAtlasAsset atlasAsset; public Sprite[] arrWeaponSprite; private Coroutine routine; // Use this for initialization void Start () { Application.runInBackground = true; skelAnim.AnimationState.Complete += AnimationState_Complete; this.SwapRandomWeapon(); this.skelAnim.AnimationState.SetAnimation(0, "attack", false);//.TimeScale = 1.2f; //routine = StartCoroutine(this.WaitForSimulation()); } private void SwapRandomWeapon() { var skeletonRenderer = this.skelAnim.GetComponent<SkeletonRenderer>(); float scale = skeletonRenderer.skeletonDataAsset.scale; var regionName = this.arrWeaponSprite[Random.Range(0, arrWeaponSprite.Length)].name; Debug.LogFormat("regionName: {0}", regionName); AtlasRegion region = this.atlasAsset.GetAtlas().FindRegion(regionName); var newRegionAttachment = region.ToRegionAttachment(region.name, scale); skelAnim.skeleton.FindSlot("slot_weapon").Attachment = newRegionAttachment; } private int attackCount = 0; private void AnimationState_Complete(Spine.TrackEntry trackEntry) { Debug.LogFormat("{0}", trackEntry.Animation.Name); if (trackEntry.Animation.Name == "attack") { attackCount++; if (this.attackCount > 10) { this.attackCount = 0; if (this.routine != null) StopCoroutine(this.routine); this.skelAnim.AnimationState.SetAnimation(0, "idle", true).TimeScale = 1; this.routine = StartCoroutine(this.WaitForSeconds(3f, () => { this.SwapRandomWeapon(); //StopCoroutine(this.routine); //this.routine = StartCoroutine(this.WaitForSimulation()); this.skelAnim.AnimationState.SetAnimation(0, "attack", false);//.TimeScale = 1.2f; })); } else { this.skelAnim.AnimationState.SetAnimation(0, "attack", false);//.TimeScale = 1.2f; } } } private IEnumerator WaitForSeconds(float t, System.Action onComple) { yield return new WaitForSeconds(t); onComple(); } // Update is called once per frame void Update () { if (Input.GetMouseButtonUp(0)) { } } } | cs |
var skeletonRenderer = this.skelAnim.GetComponent<SkeletonRenderer>();float scale = skeletonRenderer.skeletonDataAsset.scale;var regionName = this.arrWeaponSprite[Random.Range(0, arrWeaponSprite.Length)].name;regionName = "1201001";Debug.LogFormat("regionName: {0}", regionName);AtlasRegion region = this.atlasAsset.GetAtlas().FindRegion(regionName);this.newRegionAttachment = region.ToRegionAttachment(region.name, scale);newRegionAttachment.RegionOffsetX = -81.08f;newRegionAttachment.RegionOffsetY = 83.75f;skelAnim.skeleton.FindSlot("slot_weapon").Attachment = newRegionAttachment;newRegionAttachment.UpdateOffset();
반응형