| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031 |
- using ET;
- using FairyGUI;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using UI.DressUp;
- using UnityEditor;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using System.Threading.Tasks;
- using cfg.GfgCfg;
- namespace GFGGame
- {
- public class PhotographView : BaseView
- {
- private UI_PhotographUI _ui;
- private GameObject _sceneObject;
- private const int MAX_COUNT = 20;
- private const float MaxScale = 2;
- private const float MinScale = 0.1f;
- // private const string BgResPath = "Bg/BgRes";
- // private const string BorderResPath = "Border/BorderRes";
- // private const string NpcResPath = "Scene/Npc/NpcRes";
- private const string RolePath = "Scene/Role";
- private const string RoleName = "Role";
- private const string BodyResName = "Body";
- private const string BodyResName1 = "Body_a";
- // private const string NpcPath = "Scene/Npc";
- private const string NpcName = "Npc";
- private const string BgResName = "BgRes";
- private const string Border = "Border";
- private List<int> _listData = null; //当前选择的资源数据
- private List<GameObject> _itemGameObjs; // = new List<GameObject>();
- public Dictionary<int, List<int>> _equipSceneData = new Dictionary<int, List<int>>(); //当前穿戴的场景数据
- private Dictionary<GameObject, float> _equipDistance = new Dictionary<GameObject, float>();
- private GameObject hitGameObj; //当前选中的物体(单指拖动,双指缩放旋转)
- private GameObject memoryHitGameObj; //当前选中的物体(单指缩放旋转)
- private Vector3 distance = Vector3.zero; //点击位置和点击物体原点的距离,用于
- private Vector2 lastPos = Vector2.zero; //上一次移动后从物体中心到鼠标位置的方向
- private float lastDistance = 0; //上一次移动后从物体中心到鼠标位置的方向
- // private float _startDistance;//从物体中心到缩放按钮的距离
- private SwipeGesture swipeGesture;
- private PinchGesture pinchGesture;
- private RotationGesture rotationGesture;
- // 以下两个属于单选,单独保存
- private int lastChooseBorder; // 上一次选择的边框
- private int lastChooseBg; // 上一次选择的背景
- public override void Dispose()
- {
- if (_sceneObject != null)
- {
- PrefabManager.Instance.Restore(_sceneObject);
- _sceneObject = null;
- }
- if (_ui != null)
- {
- _ui.Dispose();
- _ui = null;
- }
- base.Dispose();
- }
- protected override void OnInit()
- {
- base.OnInit();
- packageName = UI_PhotographUI.PACKAGE_NAME;
- _ui = UI_PhotographUI.Create();
- viewCom = _ui.target;
- isfullScreen = true;
- //isReturnView = true;
- _ui.m_btnBg.onClick.Add(OnClickBtnBg);
- _ui.m_btnChoose.onClick.Add(OnClickBtnChoose);
- _ui.m_btnBack.onClick.Add(OnClickBtnBack);
- _ui.m_btnPhotograph.onClick.Add(OnClickBtnPhotograph);
- _ui.m_btnGalleryJoin.onClick.Add(OnClickBtnGalleryJoin);
- _ui.m_ComSelectRes.m_list.itemRenderer = RenderListItem;
- _ui.m_ComSelectRes.m_list.onClickItem.Add(OnListItemClick);
- _ui.m_ComSelectRes.m_comBtnTab.m_c1.onChanged.Add(OnContorllerChanged);
- _ui.target.onTouchBegin.Add(OnTouchUIBegin);
- _ui.target.onTouchMove.Add(OnTouchUIMove);
- _ui.target.onTouchEnd.Add(OnTouchUIEnd);
- _ui.m_comSelectBox.m_btnSize.onTouchBegin.Add(OnTouchBtnSizeBegin);
- _ui.m_comSelectBox.m_btnSize.onTouchMove.Add(OnTouchBtnSizeMove);
- _ui.m_comSelectBox.m_btnSize.onTouchEnd.Add(OnTouchBtnSizeEnd);
- _ui.m_comSelectBox.m_btnFlip.onTouchBegin.Add(OnTouchBtnFlipBegin);
- // _ui.m_comSelectBox.m_btnFlip.onTouchEnd.Add(OnTouchBtnFlipEnd);
- _ui.m_comSelectBox.m_btnDelete.onTouchBegin.Add(OnTouchBtnDeleteBegin);
- _ui.m_btnUp.onClick.Add(OnClickBtnUp);
- _ui.m_btnDown.onClick.Add(OnClickBtnDown);
- _ui.m_btnDelete.onTouchBegin.Add(OnClickBtnDelete);
- }
- protected override async void OnShown()
- {
- base.OnShown();
- Input.multiTouchEnabled = true;
- if (this.viewData != null)
- {
- _ui.m_c1.selectedIndex = (int)this.viewData;
- }
- PhotographDataManager.Instance.ClassifyEquipData();
- _equipSceneData = PhotographDataManager.Instance._equipSceneData;
- PhotographDataManager.Instance.itemGameObjs.Clear();
- MatchingCompetitionDataManager.Instance.DressPropTransInfoDic.Clear();
- _itemGameObjs = PhotographDataManager.Instance.itemGameObjs;
- void SetupAfterInstantiate()
- {
- PhotographSceneManager.Instance.sceneObject = _sceneObject;
- pinchGesture = new PinchGesture(_ui.target);
- pinchGesture.onAction.Add(OnPinch);
- rotationGesture = new RotationGesture(_ui.target);
- rotationGesture.onAction.Add(OnRotate);
- _ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex = 0;
- MatchingCompetitionDataManager.Instance.itemGameObjs.Clear();
- RefreshList(EnumPhotographType.BG);
- SetUIView();
- PhotographSceneManager.Instance.AddBgItem(
- CommonDataManager.Tables.TblItemCfg.GetOrDefault(MyDressUpHelper.dressUpObj.bgId));
- SetListScrollByID(MyDressUpHelper.dressUpObj.bgId);
- PhotographSceneManager.Instance.AddBodyItem();
- UpdateScene();
- PhotographUtil.Instance.SetLayer(null, "refresh");
- _ui.m_txtCount.text = string.Format("{0}/{1}", PoemGalleryDataManager.Instance.MyWorksCountOfTheme,
- CommonDataManager.Tables.TblGlobalCfg.MaxGalleryWorksCount);
- Timers.inst.AddUpdate(CheckGuide);
- if (this.viewData != null && (int)this.viewData == 2)
- {
- if (MyDressUpHelper.dressUpObj.bgId != 0)
- {
- MatchingCompetitionDataManager.Instance.DressUpBgID = MyDressUpHelper.dressUpObj.bgId;
- MatchingCompetitionDataManager.Instance.MathingDressDate.bgId =
- MatchingCompetitionDataManager.Instance.DressUpBgID;
- }
- }
- }
- if (_sceneObject == null)
- {
- PrefabManager.Instance.InstantiateAsync(
- ResPathUtil.GetPrefabPath("ScenePhotograph"),
- (go) =>
- {
- if (go != null)
- {
- _sceneObject = go;
- SetupAfterInstantiate();
- }
- else
- {
- Debug.LogError("场景对象异步加载失败: ScenePhotograph");
- }
- });
- }
- else
- {
- SetupAfterInstantiate();
- }
- }
- /************************************************************UI界面*********************************************************/
- private void OnContorllerChanged(EventContext context)
- {
- int index = _ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex;
- RefreshList((EnumPhotographType)index);
- }
- private void RefreshList(EnumPhotographType index)
- {
- _ui.m_ComSelectRes.m_list.numItems = 0;
- _listData = PhotographDataManager.Instance.GetListData(index);
- _ui.m_ComSelectRes.m_list.numItems = _listData.Count;
- bool setTop = false;
- switch (index)
- {
- case EnumPhotographType.BORDER:
- _ui.m_ComSelectRes.m_list.selectedIndex = lastChooseBorder;
- break;
- case EnumPhotographType.BG:
- _ui.m_ComSelectRes.m_list.selectedIndex = lastChooseBg;
- break;
- default:
- setTop = true;
- break;
- }
- if (!setTop)
- {
- if (_ui.m_ComSelectRes.m_list.selectedIndex >= 0)
- {
- _ui.m_ComSelectRes.m_list.ScrollToView(_ui.m_ComSelectRes.m_list.selectedIndex);
- }
- }
- else
- {
- _ui.m_ComSelectRes.m_list.scrollPane.ScrollTop();
- }
- //if (index == EnumPhotographType.BORDER || index == EnumPhotographType.EFFECT)
- //{
- // _ui.m_ComSelectRes.m_list.selectedIndex = 0;
- //}
- }
- private void SetListScrollByID(int id)
- {
- for (int i = 0; i < _listData.Count; i++)
- {
- if (id == _listData[i])
- {
- _ui.m_ComSelectRes.m_list.selectedIndex = i;
- _ui.m_ComSelectRes.m_list.ScrollToView(_ui.m_ComSelectRes.m_list.selectedIndex);
- lastChooseBg = i;
- }
- }
- }
- private void RenderListItem(int index, GObject obj)
- {
- ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_listData[index]);
- string resPath = ResPathUtil.GetIconPath(itemCfg);
- UI_ListItem item = UI_ListItem.Proxy(obj);
- item.target.data = _listData[index];
- item.m_loaIcon.url = resPath;
- item.m_txtName.text = itemCfg.Name;
- UI_ListItem.ProxyEnd();
- }
- private void OnListItemClick(EventContext context)
- {
- EnumPhotographType type = (EnumPhotographType)_ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex;
- if (type == EnumPhotographType.SCENE && _itemGameObjs.Count >= MAX_COUNT)
- {
- PromptController.Instance.ShowFloatTextPrompt("最多穿戴" + MAX_COUNT + "件物品");
- return;
- }
- switch (type)
- {
- case EnumPhotographType.BORDER:
- lastChooseBorder = _ui.m_ComSelectRes.m_list.selectedIndex;
- break;
- case EnumPhotographType.BG:
- lastChooseBg = _ui.m_ComSelectRes.m_list.selectedIndex;
- break;
- }
- int itemID = (int)((context.data as GObject).data);
- ChangeItem(itemID);
- }
- private void ChangeItem(int itemID)
- {
- ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemID);
- EnumPhotographType type = (EnumPhotographType)_ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex;
- switch (type)
- {
- case EnumPhotographType.BG:
- MatchingCompetitionDataManager.Instance.DressUpBgID = itemCfg.Id;
- MatchingCompetitionDataManager.Instance.MathingDressDate.bgId = itemCfg.Id;
- PhotographSceneManager.Instance.AddBgItem(itemCfg);
- break;
- case EnumPhotographType.BORDER:
- if (itemCfg.Id != ConstItemID.BORDERID)
- {
- MatchingCompetitionDataManager.Instance.BorderID = itemCfg.Id;
- }
- else
- {
- MatchingCompetitionDataManager.Instance.BorderID = 0;
- }
- PhotographSceneManager.Instance.AddBorderItem(itemCfg);
- break;
- case EnumPhotographType.NPC:
- MatchingCompetitionDataManager.Instance.NpcID = itemCfg.Id;
- PhotographSceneManager.Instance.AddNpcItem(itemCfg);
- break;
- case EnumPhotographType.SCENE:
- if (this.viewData == null || (int)this.viewData != 2)
- {
- AddSceneItem(itemCfg, true);
- }
- else
- {
- MatchingCompetitionDataManager.Instance.AddSceneItem(itemCfg, true);
- }
- break;
- case EnumPhotographType.EFFECT:
- break;
- }
- }
- //添加初始场景道具
- private void UpdateScene()
- {
- if (this.viewData == null || (int)this.viewData != 2)
- {
- ICollection keys = _equipSceneData.Keys;
- foreach (int key in keys)
- {
- for (int i = 0; i < _equipSceneData[key].Count; i++)
- {
- ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(key);
- AddSceneItem(itemCfg, false);
- }
- }
- }
- else
- {
- ICollection keys = _equipSceneData.Keys;
- foreach (int key in keys)
- {
- for (int i = 0; i < _equipSceneData[key].Count; i++)
- {
- bool isAdd = false;
- foreach (var item in MatchingCompetitionDataManager.Instance.DressPropTransInfoDic)
- {
- if (MatchingCompetitionDataManager.Instance.GetIDByString(item.Key).ToString() ==
- _equipSceneData[key][0].ToString())
- {
- isAdd = true;
- break;
- }
- }
- if (!isAdd)
- {
- MatchingCompetitionDataManager.Instance.DressPropTransInfoDic.Add(key.ToString(),
- new TransformData());
- }
- }
- }
- //对搭配赛特殊处理
- foreach (var item in MatchingCompetitionDataManager.Instance.DressPropTransInfoDic)
- {
- if (item.Key == MatchingCompetitionDataManager.Instance.roleID)
- {
- continue;
- }
- else
- {
- List<int> idList = MatchingCompetitionDataManager.Instance.GetIDListByString(item.Key);
- ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(idList[0]);
- if (itemCfg.ItemType == ConstItemType.PHOTOGRAPH &&
- itemCfg.SubType == ConstItemSubType.PHOTOGRAPH_BOREDR)
- {
- PhotographSceneManager.Instance.AddBorderItem(itemCfg);
- }
- else if (itemCfg.ItemType == ConstItemType.PHOTOGRAPH &&
- itemCfg.SubType == ConstItemSubType.PHOTOGRAPH_NPC)
- {
- PhotographSceneManager.Instance.AddNpcItem(itemCfg);
- }
- else
- {
- if (idList.Count > 1)
- {
- MatchingCompetitionDataManager.Instance.AddSceneItemOne(itemCfg, idList[1], idList[2]);
- }
- else
- {
- MatchingCompetitionDataManager.Instance.AddSceneItem(itemCfg, false);
- }
- }
- }
- }
- }
- }
- public async Task UpdateSceneTransform()
- {
- //int time = 5 * (MatchingCompetitionDataManager.Instance.TransformDataList.Count+1);
- if (MatchingCompetitionDataManager.Instance.DressUpBgID == 0)
- {
- PhotographSceneManager.Instance.AddBgItem(CommonDataManager.Tables.TblItemCfg.GetOrDefault(180001));
- }
- else
- {
- PhotographSceneManager.Instance.AddBgItem(
- CommonDataManager.Tables.TblItemCfg.GetOrDefault(
- MatchingCompetitionDataManager.Instance.DressUpBgID));
- }
- await Task.Delay(100);
- if (MatchingCompetitionDataManager.Instance.BorderID != 0)
- {
- GameObject borderGameObj =
- PhotographSceneManager.Instance.sceneObject.transform.Find("Border").gameObject;
- MatchingCompetitionDataManager.Instance.itemGameObjs.Add(borderGameObj);
- }
- if (MatchingCompetitionDataManager.Instance.NpcID != 0)
- {
- GameObject NpcGameObj =
- PhotographSceneManager.Instance.sceneObject.transform.Find("Scene/Npc").gameObject;
- MatchingCompetitionDataManager.Instance.itemGameObjs.Add(NpcGameObj);
- }
- MatchingCompetitionDataManager.Instance.InsertGameObjectList();
- for (int i = 0; i < MatchingCompetitionDataManager.Instance.itemGameObjs.Count; i++)
- {
- GameObject itemGObj = MatchingCompetitionDataManager.Instance.itemGameObjs[i];
- TransformData itemdata = new TransformData();
- if (MatchingCompetitionDataManager.Instance.DressPropTransInfoDic.ContainsKey(itemGObj.name))
- {
- itemdata = MatchingCompetitionDataManager.Instance.DressPropTransInfoDic[itemGObj.name];
- }
- MatchingCompetitionDataManager.Instance.itemGameObjs[i].transform.position = itemdata.position;
- MatchingCompetitionDataManager.Instance.itemGameObjs[i].transform.Rotate(
- itemGObj.transform.eulerAngles.x, itemGObj.transform.eulerAngles.y, itemdata.rotationZ);
- MatchingCompetitionDataManager.Instance.itemGameObjs[i].transform.localScale = itemdata.scale;
- PhotographUtil.Instance.ChangeLayer(MatchingCompetitionDataManager.Instance.itemGameObjs[i],
- i * PhotographDataManager.layerCount, "up");
- }
- }
- private async void AddSceneItem(ItemCfg itemCfg, bool setLayer)
- {
- Vector3 pos = Vector3.zero;
- if (!string.IsNullOrEmpty(itemCfg.ResLayer3))
- {
- GameObject parentGameObj3 = new GameObject(string.Format("{0}_{1}", itemCfg.Id, 3));
- await PhotographSceneManager.Instance.AddSceneItem(parentGameObj3, itemCfg, 3, setLayer);
- if (setLayer)
- {
- if (parentGameObj3.transform.childCount > 0)
- {
- parentGameObj3.transform.localPosition = -parentGameObj3.transform.GetChild(0).localPosition;
- pos = parentGameObj3.transform.localPosition;
- }
- }
- }
- if (!string.IsNullOrEmpty(itemCfg.ResLayer2))
- {
- GameObject parentGameObj2 = new GameObject(string.Format("{0}_{1}", itemCfg.Id, 2));
- await PhotographSceneManager.Instance.AddSceneItem(parentGameObj2, itemCfg, 2, setLayer);
- if (setLayer)
- {
- if (parentGameObj2.transform.childCount > 0)
- {
- parentGameObj2.transform.localPosition = pos == Vector3.zero
- ? -parentGameObj2.transform.GetChild(0).localPosition
- : pos;
- pos = parentGameObj2.transform.localPosition;
- }
- }
- }
- if (!string.IsNullOrEmpty(itemCfg.ResLayer1))
- {
- GameObject parentGameObj1 = new GameObject(string.Format("{0}_{1}", itemCfg.Id, 1));
- await PhotographSceneManager.Instance.AddSceneItem(parentGameObj1, itemCfg, 1, setLayer);
- if (setLayer)
- {
- if (parentGameObj1.transform.childCount > 0)
- {
- parentGameObj1.transform.localPosition = pos == Vector3.zero
- ? -parentGameObj1.transform.GetChild(0).localPosition
- : pos;
- pos = parentGameObj1.transform.localPosition;
- }
- }
- }
- }
- /************************************************************场景*********************************************************/
- private void OnTouchUIBegin(EventContext context)
- {
- context.CaptureTouch();
- if (_ui.m_ComSelectRes.target.visible == true) return; //添加道具不监听场景点击
- if (Stage.inst.touchCount > 1 && hitGameObj != null ||
- Stage.inst.touchCount == 1 && context.inputEvent.touchId != 0) return; //两根手指&&两指不是同时按下||一根手指但属于中途换指
- if (PhotographUtil.Instance.IsTouchUI(this.viewCom)) return;
- RaycastHit2D[] hit2Ds =
- Physics2D.RaycastAll(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
- if (hit2Ds.Length > 0)
- {
- lastPos = Vector2.zero;
- hitGameObj = PhotographUtil.Instance.GetFirstHitObj(hit2Ds);
- _ui.m_comSelectBox.m_btnDelete.visible = true;
- if (hitGameObj.transform.parent.name == RoleName) //主角不可删除
- {
- _ui.m_comSelectBox.m_btnDelete.visible = false;
- }
- _ui.m_comSelectBox.target.visible = false;
- if (hitGameObj.name != BgResName) //背景不可改动层级
- {
- hitGameObj = hitGameObj.transform.parent.gameObject;
- _ui.m_comSelectBox.target.visible = true;
- if (hitGameObj.name != Border)
- {
- PhotographUtil.Instance.SetLayer(hitGameObj, "top");
- }
- }
- memoryHitGameObj = hitGameObj;
- distance = Input.mousePosition - Camera.main.WorldToScreenPoint(hitGameObj.transform.position);
- Vector3 localEulerAngles = hitGameObj.transform.localEulerAngles;
- float rotation = 0;
- if (localEulerAngles.y == 0)
- {
- rotation = -hitGameObj.transform.localEulerAngles.z;
- }
- else
- {
- if (hitGameObj.transform.localEulerAngles.z > 180)
- {
- rotation = hitGameObj.transform.localEulerAngles.z - 360;
- }
- else
- {
- rotation = hitGameObj.transform.localEulerAngles.z;
- }
- }
- _ui.m_comSelectBox.target.rotation = rotation;
- _ui.m_comSelectBox.target.size = PhotographUtil.Instance.GetGameObjectBoundsSize(hitGameObj);
- ControllerSelectBoxPos();
- }
- }
- private void OnTouchUIMove(EventContext context)
- {
- if (hitGameObj == null) return; //未选中任何物体
- if (Stage.inst.touchCount > 1) return; //只监听1根手指
- if (PhotographUtil.Instance.IsTouchUI(this.viewCom)) return;
- ControllerObjectPos();
- ControllerSelectBoxPos();
- }
- private void OnTouchUIEnd(EventContext context)
- {
- hitGameObj = null;
- }
- //选中物体的位置
- private void ControllerObjectPos()
- {
- hitGameObj.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition - distance);
- if (hitGameObj.name == BgResName)
- {
- PhotographUtil.Instance.SetBgPos(hitGameObj, _ui.target.size);
- }
- }
- //选中框的位置
- private void ControllerSelectBoxPos()
- {
- Vector2 objScreenPos = Camera.main.WorldToScreenPoint(hitGameObj.transform.position);
- Vector2 localPos =
- this.viewCom.GlobalToLocal(new Vector2(objScreenPos.x, (Screen.height - objScreenPos.y)));
- _ui.m_comSelectBox.target.position = localPos;
- }
- private void OnTouchBtnSizeBegin(EventContext context)
- {
- InputEvent inputEvent = (InputEvent)context.data;
- Vector2 pt0 = this.viewCom.GlobalToLocal(new Vector2(inputEvent.x, inputEvent.y));
- Vector2 screenPos = this.viewCom.GlobalToLocal(_ui.m_comSelectBox.m_btnSize.LocalToGlobal(Vector2.zero));
- Vector2 pt1 = new Vector2(screenPos.x, screenPos.y);
- Vector2 pt2 = new Vector2(_ui.m_comSelectBox.target.x, _ui.m_comSelectBox.target.y);
- lastDistance = Vector2.Distance(pt0, pt2);
- if (!_equipDistance.ContainsKey(memoryHitGameObj))
- {
- float distance = Vector2.Distance(pt1, pt2) / memoryHitGameObj.transform.localScale.x;
- Debug.Log("distance:" + distance + " pt1:" + pt1 + " pt2:" + pt2);
- _equipDistance.Add(memoryHitGameObj, distance);
- }
- }
- private void OnTouchBtnSizeMove(EventContext context)
- {
- if (memoryHitGameObj == null) return;
- InputEvent inputEvent = (InputEvent)context.data;
- Vector2 pt1 = this.viewCom.GlobalToLocal(inputEvent.position);
- Vector2 pt2 = _ui.m_comSelectBox.target.xy;
- Vector2 curPos = pt1 - pt2;
- float angle = Vector3.Angle(lastPos, curPos); //求出两向量之间的夹角
- Vector3 normal = Vector3.Cross(lastPos, curPos); //叉乘求出法线向量
- angle *= Mathf.Sign(Vector3.Dot(normal,
- Vector3.forward)); //Mathf.Sign()求符号,Vector3.Dot()求方向,求法线向量与物体上方向向量点乘,结果为1或-1,修正旋转方向
- lastPos = curPos;
- ControllerRotate(angle, memoryHitGameObj);
- float dist = Vector2.Distance(pt1, pt2);
- float ss = dist / lastDistance;
- float curValue = Math.Abs(memoryHitGameObj.transform.localScale.x);
- float newValue = Mathf.Clamp(ss * curValue, 0.1f, 2);
- ControllerScale(newValue, memoryHitGameObj, Math.Sign(memoryHitGameObj.transform.localScale.x));
- if (newValue <= 0.1f)
- {
- lastDistance = Vector2.Distance(_ui.m_comSelectBox.m_btnDelete.xy, _ui.m_comSelectBox.m_btnSize.xy) / 2;
- }
- else
- {
- lastDistance = dist;
- }
- }
- private void OnTouchBtnSizeEnd(EventContext context)
- {
- lastPos = Vector2.zero;
- }
- //双指缩放
- private void OnPinch(EventContext context)
- {
- if (hitGameObj == null) return;
- if (hitGameObj.name == BgResName) return; //背景不可以缩放、旋转
- GTween.Kill(hitGameObj);
- PinchGesture gesture = (PinchGesture)context.sender;
- float newValue = Mathf.Clamp(hitGameObj.transform.localScale.x + gesture.delta, 0.3f, 2);
- Debug.Log("双指缩放:" + newValue);
- ControllerScale(newValue, hitGameObj, Math.Sign(hitGameObj.transform.localScale.x));
- }
- //双指旋转
- private void OnRotate(EventContext context)
- {
- Debug.Log("双指旋转hitGameObj:" + hitGameObj);
- if (hitGameObj == null) return;
- Debug.Log("双指旋转name:" + hitGameObj.name);
- if (hitGameObj.name == BgResName) return; //背景不可以缩放、旋转
- // isTwoTouchPoint = true;
- GTween.Kill(hitGameObj.transform);
- RotationGesture gesture = (RotationGesture)context.sender;
- Debug.Log("双指旋转:" + gesture.delta);
- ControllerRotate(gesture.delta, hitGameObj);
- }
- private void ControllerScale(float value, GameObject gameObject, int sign)
- {
- if (value > MaxScale || value < MinScale) return;
- gameObject.transform.localScale = new Vector3(value * sign, value, value);
- Vector2 size = PhotographUtil.Instance.GetGameObjectBoundsSize(gameObject);
- _ui.m_comSelectBox.target.size = size;
- }
- private void ControllerRotate(float value, GameObject gameObject)
- {
- gameObject.transform.Rotate(Vector3.forward, -value, Space.World);
- _ui.m_comSelectBox.target.rotation += value;
- }
- private void OnClickBtnBg()
- {
- _ui.m_ComSelectRes.target.visible = false;
- }
- private void OnTouchBtnFlipBegin() //翻转
- {
- Transform transform = memoryHitGameObj.transform;
- var value = Math.Abs(transform.localScale.x);
- // transform.localScale = new Vector3(-value, Math.Abs(value), 1);
- ControllerScale(value, memoryHitGameObj, -Math.Sign(transform.localScale.x));
- }
- private void OnTouchBtnDeleteBegin() //删除
- {
- if (memoryHitGameObj.transform.name == RolePath)
- {
- return;
- }
- else if (memoryHitGameObj.transform.name == Border || memoryHitGameObj.transform.name == NpcName)
- {
- memoryHitGameObj.transform.localPosition = Vector3.zero;
- memoryHitGameObj.transform.localRotation = Quaternion.Euler(Vector3.zero);
- memoryHitGameObj.transform.localScale = Vector3.one;
- GameObject gameObject = memoryHitGameObj.transform.GetChild(0).gameObject;
- PhotographSceneManager.Instance.DeleteSpriteRendererFromGameObject(gameObject);
- PhotographSceneManager.Instance.DeleteBoxCollider2DFromGameObject(gameObject);
- }
- else
- {
- MatchingCompetitionDataManager.Instance.DressPropTransInfoDic.Remove(memoryHitGameObj.name);
- GameObject.DestroyImmediate(memoryHitGameObj);
- }
- _itemGameObjs.Remove(memoryHitGameObj);
- _ui.m_comSelectBox.target.visible = false;
- }
- private void SetUIView()
- {
- _ui.m_ComSelectRes.target.visible = true;
- _ui.m_comSelectBox.target.visible = false;
- hitGameObj = null;
- memoryHitGameObj = null;
- lastChooseBorder = 0;
- lastChooseBg = 0;
- _ui.m_ComSelectRes.m_comBtnTab.target.scrollPane.SetPercX(0, false);
- _ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex = 0;
- if (_ui.m_ComSelectRes.m_list.numItems > 0)
- {
- _ui.m_ComSelectRes.m_list.ScrollToView(0);
- _ui.m_ComSelectRes.m_list.selectedIndex = 0;
- }
- }
- private void OnClickBtnChoose()
- {
- _ui.m_ComSelectRes.target.visible = true;
- _ui.m_comSelectBox.target.visible = false;
- hitGameObj = null;
- memoryHitGameObj = null;
- }
- private void OnClickBtnUp()
- {
- PhotographUtil.Instance.SetLayer(memoryHitGameObj, "up");
- }
- private void OnClickBtnDown()
- {
- PhotographUtil.Instance.SetLayer(memoryHitGameObj, "down");
- }
- private void OnClickBtnDelete()
- {
- if (memoryHitGameObj == null || !_ui.m_comSelectBox.target.visible ||
- !_ui.m_comSelectBox.m_btnDelete.visible)
- {
- return;
- }
- OnTouchBtnDeleteBegin();
- }
- private void OnClickBtnPhotograph()
- {
- // GRoot.inst.visible = false;
- Timers.inst.StartCoroutine(ScreenShotTex()); // ();
- }
- private void OnClickBtnGalleryJoin()
- {
- // GRoot.inst.visible = false;
- Timers.inst.StartCoroutine(ScreenShotTex()); // ();
- }
- private IEnumerator ScreenShotTex()
- {
- GRoot.inst.visible = false;
- yield return new WaitForEndOfFrame();
- Rect rect = new Rect(0, 0, UnityEngine.Screen.width, UnityEngine.Screen.height);
- Texture2D tex =
- new Texture2D((int)rect.width, (int)rect.height, TextureFormat.ARGB32, false); //新建一个Texture2D对象
- tex.ReadPixels(rect, 0, 0); //读取像素,屏幕左下角为0点
- tex.Apply(); //保存像素信息
- GRoot.inst.visible = true;
- if (_ui.m_c1.selectedIndex == 0)
- {
- ViewManager.Show<PhotographSaveView>(tex);
- LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.PAI_ZHAO, 2);
- }
- else if (_ui.m_c1.selectedIndex == 1)
- {
- AlertUI.Show("是否确认上传此作品?")
- .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
- {
- ViewManager.Show<ModalStatusView>("上传中...");
- object[] rsp = await PoemGallerySProxy.ReqUpLoadGalleryWorks();
- if (rsp == null) return;
- byte[] bytes = tex.EncodeToJPG();
- bool pushResult = await PictureStorageHelper.PushToHWCloud(rsp[0].ToString(), bytes);
- if (!pushResult) return;
- bool result = await PoemGallerySProxy.ReqNoticeGalleryWorksUploaded((long)(rsp[1]), tex);
- if (result)
- {
- _ui.m_txtCount.text = string.Format("{0}/{1}",
- PoemGalleryDataManager.Instance.MyWorksCountOfTheme,
- CommonDataManager.Tables.TblGlobalCfg.MaxGalleryWorksCount);
- ViewManager.Hide<ModalStatusView>();
- OnClickBtnBack();
- ViewManager.GoBackFrom(typeof(DressUpView).FullName);
- }
- });
- }
- else if (_ui.m_c1.selectedIndex == 2)
- {
- MatchingCompetitionDataManager.Instance.itemGameObjs = _itemGameObjs.ToList();
- if (MatchingCompetitionDataManager.Instance.BorderID != 0)
- {
- GameObject borderGameObj =
- PhotographSceneManager.Instance.sceneObject.transform.Find("Border").gameObject;
- MatchingCompetitionDataManager.Instance.itemGameObjs.Add(borderGameObj);
- }
- if (MatchingCompetitionDataManager.Instance.NpcID != 0)
- {
- GameObject NpcGameObj = PhotographSceneManager.Instance.sceneObject.transform.Find("Scene/Npc")
- .gameObject;
- //MatchingCompetitionDataManager.Instance.itemGameObjs.Add(NpcGameObj);
- }
- MatchingCompetitionDataManager.Instance.MathingDressDate =
- MyDressUpHelper.dressUpObj.DressUpDataClone();
- MatchingCompetitionDataManager.Instance.SetTransformData();
- if (MatchingCompetitionDataManager.Instance.WorksID == 0)
- {
- OnUpLoad(tex);
- }
- else
- {
- AlertUI.Show("作品已保存,是否确认上传并替换作品?")
- .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
- {
- ViewManager.Show<ModalStatusView>("上传中...");
- //await MatchingCompetitionSproxy.ReqMatchingCompetitionInfo();
- object[] rsp = await MatchingCompetitionSproxy.UpLoadMatchingCompetitionDressData();
- if (rsp == null) return;
- byte[] bytes = tex.EncodeToJPG();
- MatchingCompetitionDataManager.Instance.MyNtextture = new NTexture(tex);
- if (rsp[0] == null)
- {
- ViewManager.Hide<ModalStatusView>();
- PromptController.Instance.ShowFloatTextPrompt("网络异常,上传失败!");
- return;
- }
- bool pushResult = await PictureStorageHelper.PushToHWCloud(rsp[0].ToString(), bytes);
- if (!pushResult)
- {
- ViewManager.Hide<ModalStatusView>();
- PromptController.Instance.ShowFloatTextPrompt("网络异常,上传失败!");
- return;
- }
- bool result = await MatchingCompetitionSproxy.UploadSuccess();
- if (result)
- {
- ViewManager.Hide<ModalStatusView>();
- PromptController.Instance.ShowFloatTextPrompt("上传成功!");
- this.Hide();
- EventAgent.DispatchEvent(ConstMessage.CLOSE_PHOTOGRAPHVIEW);
- ViewManager.GoBackFrom(typeof(DressUpView).FullName);
- }
- ViewManager.Hide<ModalStatusView>();
- });
- }
- }
- }
- private async void OnUpLoad(Texture2D tex)
- {
- ViewManager.Show<ModalStatusView>("上传中...");
- object[] rsp = await MatchingCompetitionSproxy.UpLoadMatchingCompetitionDressData();
- if (rsp == null) return;
- byte[] bytes = tex.EncodeToJPG();
- MatchingCompetitionDataManager.Instance.MyNtextture = new NTexture(tex);
- if (rsp[0] == null)
- {
- ViewManager.Hide<ModalStatusView>();
- PromptController.Instance.ShowFloatTextPrompt("网络异常,上传失败!");
- return;
- }
- bool pushResult = await PictureStorageHelper.PushToHWCloud(rsp[0].ToString(), bytes);
- if (!pushResult)
- {
- ViewManager.Hide<ModalStatusView>();
- PromptController.Instance.ShowFloatTextPrompt("网络异常,上传失败!");
- return;
- }
- bool result = await MatchingCompetitionSproxy.UploadSuccess();
- if (result)
- {
- ViewManager.Hide<ModalStatusView>();
- PromptController.Instance.ShowFloatTextPrompt("上传成功!");
- this.Hide();
- EventAgent.DispatchEvent(ConstMessage.CLOSE_PHOTOGRAPHVIEW);
- ViewManager.GoBackFrom(typeof(DressUpView).FullName);
- }
- ViewManager.Hide<ModalStatusView>();
- }
- private void OnClickBtnBack()
- {
- //ViewManager.Show<DressUpView>();
- if (_ui.m_c1.selectedIndex == 2)
- {
- AlertUI.Show("返回将清空搭配道具,是否确定返回?")
- .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
- {
- this.Hide();
- EventAgent.DispatchEvent(ConstMessage.CLOSE_PHOTOGRAPHVIEW);
- ViewManager.GoBackFrom(typeof(PhotographView).FullName);
- });
- }
- else
- {
- this.Hide();
- EventAgent.DispatchEvent(ConstMessage.CLOSE_PHOTOGRAPHVIEW);
- }
- }
- protected override void OnHide()
- {
- base.OnHide();
- if (_sceneObject != null)
- {
- PrefabManager.Instance.Restore(_sceneObject);
- _sceneObject = null;
- }
- MatchingCompetitionDataManager.Instance.DressPropIndex = 0;
- _equipSceneData.Clear();
- hitGameObj = null;
- memoryHitGameObj = null;
- pinchGesture.onAction.Remove(OnPinch);
- rotationGesture.onAction.Remove(OnRotate);
- pinchGesture = null;
- rotationGesture = null;
- _ui.m_c1.selectedIndex = 0;
- Timers.inst.Remove(CheckGuide);
- //Timers.inst.Remove(UpdateSceneTransform);
- }
- private void CheckGuide(object param)
- {
- if (GuideDataManager.IsGuideFinish(ConstGuideId.FREEDOM_DRESS) <= 0 ||
- GuideDataManager.IsGuideFinish(ConstGuideId.ENTER_CHAPTER) <= 0)
- {
- UpdateToCheckGuide(null);
- }
- else
- {
- Timers.inst.Remove(CheckGuide);
- }
- }
- protected override void UpdateToCheckGuide(object param)
- {
- if (!ViewManager.CheckIsTopView(this.viewCom)) return;
- GuideController.TryGuide(null, ConstGuideId.FREEDOM_DRESS, 7, "在这里可以选择已获得的背景、道具等,也可以放大缩小物品,增加画面丰富度。", -1,
- true, _ui.target.height - _ui.m_ComSelectRes.target.height - 250);
- GuideController.TryGuide(_ui.m_btnPhotograph, ConstGuideId.FREEDOM_DRESS, 8, "来记录下这一刻吧。");
- // GuideController.TryCompleteGuide(ConstGuideId.FREEDOM_DRESS, 8);
- GuideController.TryGuide(_ui.m_btnBack, ConstGuideId.ENTER_CHAPTER, 1, "");
- }
- protected override void TryCompleteGuide()
- {
- base.TryCompleteGuide();
- // GuideController.TryCompleteGuide(ConstGuideId.FREEDOM_DRESS, 8);
- }
- }
- }
|