private void OnDestroy() { for (int i = 0; i < _spineIdArray.Length; i++) { SpineUtil.UnloadLater(_spineIdArray[i]); } }
/// <summary> /// 设置Spine的动画状态 /// </summary> /// <param name="gameObject"></param> /// <param name="aniname"></param> /// <param name="State"></param> private void SetSupporterSpine(GameObject gameObject, string aniname, bool State = false) { var _skg = gameObject.GetComponent <SkeletonGraphic>(); if (_skg == null) { // Debug.LogError("_skg==null"); return; } SkeletonDataAsset sdData; if (_skg.skeletonDataAsset == null) { sdData = SpineUtil.BuildSkeletonDataAsset(aniname, _skg); _skg.skeletonDataAsset = sdData; _skg.Initialize(true); } else if (_skg.skeletonDataAsset.name != aniname) { sdData = SpineUtil.BuildSkeletonDataAsset(aniname, _skg); _skg.skeletonDataAsset = sdData; _skg.Initialize(true); } _skg.transform.localScale = Vector3.one * 1.67f; // Debug.LogError(aniname); _skg.AnimationState.SetAnimation(0, "doing", true); _skg.timeScale = State ? 1 : 0; }
private void SpawnFansAnimation(Transform fansroot) { for (int i = 0; i < fansroot.childCount; i++) { var dialogTran = fansroot.GetChild(i).transform.Find("Dialog"); var dialog = fansroot.GetChild(i).transform.Find("Dialog/Text").GetComponent <Text>(); dialogTran.gameObject.Hide(); var _skg = fansroot.GetChild(i).Find("SpineSkeletonGraphic").GetComponent <SkeletonGraphic>(); //在这里可以随机生成Spine动画 var ani = RandomAni(); SkeletonDataAsset sdData = SpineUtil.BuildSkeletonDataAsset(ani, _skg); _skg.skeletonDataAsset = sdData; _skg.Initialize(true); _skg.AnimationState.SetAnimation(0, GlobalData.NpcModel.GetAnimationState(1), true); _skg.transform.localScale = Vector3.one * 0.5f; fansroot.GetChild(i).transform.localPosition = new Vector2(RandomX(), fansroot.GetChild(i).transform.localPosition.y); _skg.transform.localEulerAngles = new Vector3(0, RandomForward()); _skg.timeScale = RandomRate(); PointerClickListener.Get(fansroot.GetChild(i).gameObject).onClick = go => { if (_skg.AnimationState.ToString() == GlobalData.NpcModel.GetAnimationState(2) || dialogTran.gameObject.activeInHierarchy) { //Debug.LogError(_skg.AnimationState.ToString()); return; } dialog.text = RandomDia(); if (_skg.AnimationState.ToString() == GlobalData.NpcModel.GetAnimationState(3)) { dialog.text = I18NManager.Get("Supporter_Hint6"); //"请收下礼物~(ノ>ω<)ノ"; } DOTween.Sequence().AppendCallback(() => { dialogTran.gameObject.SetActive(true); }) .AppendInterval(2f).OnComplete(() => { dialogTran.gameObject.SetActive(false); if (_skg.AnimationState.ToString() == GlobalData.NpcModel.GetAnimationState(2)) { return; } else if (_skg.AnimationState.ToString() == GlobalData.NpcModel.GetAnimationState(3)) { //dialog.text = "请收下礼物"; return; } _skg.AnimationState.SetAnimation(0, GlobalData.NpcModel.GetAnimationState(1), true); }); }; } fansroot.gameObject.Show(); }
public void Init(string spineId, SkeletonGraphic skg, string animationName) { _skg = skg; _animationName = animationName; SkeletonDataAsset skData = SpineUtil.BuildSkeletonDataAsset(spineId, skg); skg.skeletonDataAsset = skData; skg.Initialize(true); skg.AnimationState.SetAnimation(0, animationName, true); _rect = skg.GetComponent <RectTransform>(); _rect.pivot = new Vector2(0.5f, 0f); _rect.anchorMin = new Vector2(0.5f, 0.5f); _rect.anchorMax = new Vector2(0.5f, 0.5f); _rect.sizeDelta = new Vector2(300, 500); _rect.localScale = new Vector3(0.5f, 0.5f, 1); CurDerection = 0; }