12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using FairyGUI;
- using System;
- using UnityEngine;
- namespace GFGGame
- {
- //实现换装对象在UI界面上显示
- public class DressUpObjUI
- {
- public GameObject sceneObject;
- public GoWrapper wrapper;
- public DressUpObj dressUpObj;
- string prefabName;
- private Action onShowAction;
- public DressUpObjUI(string prefabName = "SceneDressUp", Action onShowAction = null)
- {
- this.prefabName = prefabName;
- this.onShowAction = onShowAction;
- dressUpObj = new DressUpObj();
- wrapper = new GoWrapper();
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="scale"></param>
- /// <param name="needSetMask">如果UI界面的组件有遮罩,那么这里也需要设置为true才能生效</param>
- /// <param name="showSceneType">是否显示场景道具类型</param>
- /// <param name="roleObj"></param>
- /// <param name="showBg">是否显示背景</param>
- public void ResetSceneObj(int scale = 100, bool needSetMask = false, bool showSceneType = true, GameObject roleObj = null, bool showBg = true)
- {
- //这里每次都要实例化新的,复用会有bug
- sceneObject = PrefabManager.Instance.InstantiateSync(ResPathUtil.GetPrefabPath(this.prefabName));
- sceneObject.transform.localScale = new Vector3(scale, scale, scale);
- dressUpObj.setSceneObj(sceneObject, needSetMask, showSceneType, roleObj, showBg, OnShow);
- }
- public void UpdateWrapper(GGraph holder)
- {
- holder.SetNativeObject(wrapper);
- wrapper.wrapTarget = sceneObject;
- }
-
- public void Dispose()
- {
- onShowAction = null;
- if (sceneObject != null)
- {
- PrefabManager.Instance.Restore(sceneObject);
- sceneObject = null;
- }
- if (dressUpObj != null)
- {
- dressUpObj.Dispose();
- dressUpObj = null;
- }
- if (wrapper != null)
- {
- if (wrapper.wrapTarget != null)
- {
- wrapper.wrapTarget = null;
- }
- wrapper.Dispose();
- wrapper = null;
- }
- }
- private void OnShow()
- {
- onShowAction?.Invoke();
- if (sceneObject == null)
- {
- return;
- }
- if(wrapper != null)
- {
- wrapper.wrapTarget = sceneObject;
- //wrapper.CacheRenderers();
- }
- }
- }
- }
|