public void SetItem(Sprite icon, RuntimeAnimatorController animator, SkeletonDataAsset skeletonData, int id) { iconIndex = id; sprIcon = icon; if (skeleton != null && skeletonData != null) { skeleton.skeletonDataAsset = skeletonData; skeleton.Clear(); skeleton.Initialize(true); skeleton.AnimationState.SetAnimation(0, skeletonAnimName, skeletonLoop); } if (anim != null && animator != null) { anim.runtimeAnimatorController = animator; anim.enabled = true; anim.SetTrigger(animStateIdle); } else if (animator == null) { if (anim != null) { anim.enabled = false; anim.runtimeAnimatorController = null; } } imgIcon.sprite = icon; }
public void SeSkeletonData(string dataAssetName) { if (_dataAsstName != dataAssetName) { LoadModelSetting(dataAssetName); skeletonGraphic.skeletonDataAsset = null; skeletonGraphic.Clear(); LoadSkeletonData(dataAssetName).Run(); } }
public void Init(string name, string text, SkeletonDataAsset skeletonDataAsset, AnimationReferenceAsset animation, Color backColor) { if (!string.IsNullOrEmpty(name) && nameTextField) { nameTextField.text = name; } textTextField.text = text; if (avatar) { avatar.gameObject?.SetActive(false); } back.color = backColor; spineParent.gameObject.SetActive(true); spineSkeleton.Clear(); spineSkeleton.skeletonDataAsset = skeletonDataAsset; spineSkeleton.Initialize(true); spineSkeleton.AnimationState.SetAnimation(0, animation, true); }
//--以下是Editor支持部分--// /** 处理一个prefab */ public static void makeOnePrefab(GameObject obj) { #if UNITY_EDITOR ImageLoader[] imageLoaders = obj.GetComponentsInChildren <ImageLoader>(true); foreach (ImageLoader imageLoader in imageLoaders) { imageLoader.source = null; Image image = imageLoader.GetComponent <Image>(); if (image.sprite) { string path = Path.GetFileName(AssetDatabase.GetAssetPath(image.sprite)); if (path == "unity_builtin_extra") { continue; } imageLoader.source = FileUtils.getBundleResourcePath(AssetDatabase.GetAssetPath(image.sprite)); image.sprite = null; } } RawImageLoader[] rawImageLoaders = obj.GetComponentsInChildren <RawImageLoader>(true); foreach (RawImageLoader rawImageLoader in rawImageLoaders) { rawImageLoader.source = null; RawImage image = rawImageLoader.GetComponent <RawImage>(); if (image.texture) { string path = Path.GetFileName(AssetDatabase.GetAssetPath(image.texture)); if (path == "unity_builtin_extra") { continue; } rawImageLoader.source = FileUtils.getBundleResourcePath(AssetDatabase.GetAssetPath(image.texture)); image.texture = null; } } SkeletonGraphicLoader[] skeletonGraphicLoaders = obj.GetComponentsInChildren <SkeletonGraphicLoader>(true); foreach (SkeletonGraphicLoader skeletonGraphicLoader in skeletonGraphicLoaders) { SkeletonGraphic skeletonGraphic = skeletonGraphicLoader.GetComponent <SkeletonGraphic>(); if (skeletonGraphic.skeletonDataAsset) { skeletonGraphicLoader.source = FileUtils.getBundleResourcePath(AssetDatabase.GetAssetPath(skeletonGraphic.skeletonDataAsset)); skeletonGraphic.skeletonDataAsset = null; skeletonGraphic.Clear(); } else { skeletonGraphicLoader.source = null; } } SScrollView[] sScrollViews = obj.GetComponentsInChildren <SScrollView>(true); foreach (SScrollView scrollView in sScrollViews) { GameObject tmpObj = scrollView.gameObject; Transform tmpTrans = tmpObj.transform; SList <GameObject> tmpList = new SList <GameObject>(); for (int i = 0; i < tmpTrans.childCount; i++) { GameObject tmpGo = tmpTrans.GetChild(i).gameObject; if (tmpGo.name != "g0") { tmpList.add(tmpGo); } } for (var i = 0; i < tmpList.Count; i++) { Object.DestroyImmediate(tmpList[i]); } } SPageView[] sPageViews = obj.GetComponentsInChildren <SPageView>(true); foreach (SPageView sPageView in sPageViews) { GameObject tmpObj = sPageView.gameObject; Transform tmpTrans = tmpObj.transform; SList <GameObject> tmpList = new SList <GameObject>(); for (int i = 0; i < tmpTrans.childCount; i++) { GameObject tmpGo = tmpTrans.GetChild(i).gameObject; if (tmpGo.name != "g0") { tmpList.add(tmpGo); } } for (var i = 0; i < tmpList.Count; i++) { Object.DestroyImmediate(tmpList[i]); } } #endif }