123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- using FairyGUI;
- using System;
- using UI.DressUp;
- using UnityEngine;
- using UnityEngine.EventSystems;
- namespace GFGGame
- {
- public class PhotographView : BaseView
- {
- private UI_PhotographUI _ui;
- private GameObject _scenePrefab;
- private GameObject _sceneObject;
- private DressUpObjDataCache equipDataCache;
- protected override void OnInit()
- {
- base.OnInit();
- packageName = UI_PhotographUI.PACKAGE_NAME;
- _ui = UI_PhotographUI.Create();
- viewCom = _ui.target;
- isfullScreen = true;
- _ui.m_btnBack.onClick.Add(OnClickBtnBack);
- _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("ScenePhotograph"));
- }
- protected override void OnShown()
- {
- base.OnShown();
- // Debug.Log("Length:" + EquipDataCache.cacher.equipDatas.Length);
- // Debug.Log("bgId:" + EquipDataCache.cacher.bgId);
- // Debug.Log("suitId:" + EquipDataCache.cacher.suitId);
- if (_sceneObject == null)
- {
- _sceneObject = GameObject.Instantiate(_scenePrefab);
- // _sceneObject.sortingOrder = 1000;
- EquipDataCache.cacher.setSceneObj(_sceneObject);
- }
- equipDataCache = EquipDataCache.cacher;
- UpdateBg();
- UpdateBody();
- Timers.inst.Add(0.001f, 0, OnClickListener);
- }
- private void OnClickListener(object param)
- {
- // Debug.Log("点击鼠标:" + Input.GetMouseButtonDown(0));
- if (Input.GetMouseButtonDown(0))
- {
- if (Stage.isTouchOnUI) //点在了UI上
- {
- Debug.Log("点击UI");
- }
- else //没有点在UI上
- {
- Debug.Log("点击场景");
- }
- //从摄像机发出到点击坐标的射线
- RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
- Vector2 pos = Input.mousePosition;
- // Debug.Log("pos:" + pos);
- if (hit.collider != null)
- {
- //划出射线,只有在scene视图中才能看到
- // Debug.DrawLine(ray.origin, hitInfo.point, Color.red);
- GameObject gameObj = hit.collider.gameObject;
- Debug.Log("click object name is :" + gameObj.name);
- //当射线碰撞目标为boot类型的物品,执行拾取操作
- if (gameObj.tag == "boot")
- {
- Debug.Log("pickup!");
- }
- }
- }
- }
- //背景
- private void UpdateBg()
- {
- Transform tf = _sceneObject.transform.Find("Bg");
- SpriteRenderer spr = tf.GetComponent<SpriteRenderer>();
- ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(equipDataCache.bgId);
- var resPath = ResPathUtil.GetDressUpPath(itemCfg.res, ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType));
- Sprite sp = GFGAsset.Load<Sprite>(resPath);
- DressUpUtil.AddAssetReleaser(tf.gameObject, resPath);
- spr.sprite = sp;
- int[] bgId = { equipDataCache.bgId };
- GameObject obj = _sceneObject.transform.Find("Bg").gameObject;
- SceneController.UpdateRole(bgId, _sceneObject, false, null, false, obj);
- SetObjSize(obj.transform.GetChild(0).gameObject);
- }
- private void SetObjSize(GameObject obj)
- {
- obj.AddComponent<BoxCollider2D>();
- }
- //主角
- private void UpdateBody()
- {
- // CustomSuitData suitSavedData = CustomSuitDataManager.GetCurrentSuitList();
- int[] equipDatas = equipDataCache.equipDatas;
- SceneController.UpdateRole(equipDatas, _sceneObject, false, null, false);
- if (equipDataCache.IsSuitPic && equipDataCache.suitId > 0)
- {
- SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(equipDataCache.suitId);
- DressUpUtil.UpdateBody(suitCfg.picRes, _sceneObject);
- }
- }
- //合照NPC
- private void UpdateNpc()
- {
- }
- //场景道具
- private void UpdateScene()
- {
- }
- //边框
- private void UpdateBorder()
- {
- }
- //滤镜效果
- private void UpdateEffect()
- {
- }
- private void OnClickBtnBack()
- {
- this.Hide();
- // ViewManager.Show(ViewName.DRESS_UP_VIEW);
- EventAgent.DispatchEvent(ConstMessage.CLOSE_PHOTOGRAPHVIEW);
- }
- protected override void OnHide()
- {
- base.OnHide();
- if (_sceneObject != null)
- {
- GameObject.Destroy(_sceneObject);
- _sceneObject = null;
- }
- equipDataCache = null;
- }
- public override void Dispose()
- {
- if (_scenePrefab != null)
- {
- GameObject.Destroy(_scenePrefab);
- _scenePrefab = null;
- }
- base.Dispose();
- }
- }
- }
|