Browse Source

拍照背景拖动

zhaoyang 3 years ago
parent
commit
5521ea787a

+ 17 - 0
FGUIProject/assets/DressUp/ComChecked.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<component size="446,291">
+  <displayList>
+    <image id="n9_g3xa" name="n9" src="7dea4g" fileName="images/kp_kprk_4.png" xy="32,35" size="381,220">
+      <relation target="" sidePair="width-width,height-height"/>
+    </image>
+    <component id="n10_g3xa" name="btnDelete" src="g3xa4i" fileName="components/Button9.xml" xy="356,-10">
+      <relation target="" sidePair="right-right,top-top"/>
+    </component>
+    <component id="n11_g3xa" name="btnFlip" src="g3xa4j" fileName="components/Button10.xml" xy="0,6" size="82,62" aspect="true">
+      <relation target="" sidePair="left-left,top-top"/>
+    </component>
+    <component id="n12_g3xa" name="btnSize" src="g3xa4k" fileName="components/Button11.xml" xy="373,209">
+      <relation target="" sidePair="right-right,bottom-bottom"/>
+    </component>
+  </displayList>
+</component>

+ 4 - 1
FGUIProject/assets/DressUp/PhotographUI.xml

@@ -1,7 +1,10 @@
 <?xml version="1.0" encoding="utf-8"?>
-<component size="1080,1920" overflow="hidden" opaque="false" scroll="both">
+<component size="1080,1920" overflow="hidden" scroll="both">
   <displayList>
+    <loader id="n8_g3xa" name="btnBg" xy="0,0" size="1080,1920"/>
     <component id="n1_yd72" name="btnBack" src="9xlo8" fileName="components/ButtonBack1.xml" pkg="eg2y0ldp" xy="35,80"/>
+    <component id="n6_g3xa" name="btnChoose" src="g3xa4h" fileName="components/Button8.xml" xy="972,1016"/>
     <component id="n5_7dea" name="ComSelect" src="7dea4f" fileName="components/ComSelect.xml" xy="30,1174"/>
+    <component id="n9_g3xa" name="comChecked" src="g3xa4l" fileName="ComChecked.xml" xy="320,445" pivot="0.5,0.5" anchor="true" size="382,450"/>
   </displayList>
 </component>

+ 13 - 0
FGUIProject/assets/DressUp/components/Button10.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<component size="48,36" extention="Button">
+  <controller name="button" pages="0,up,1,down,2,over,3,selectedOver" selected="0"/>
+  <displayList>
+    <image id="n0_g3xa" name="n0" src="q08x4" fileName="images/hz_dakai.png" xy="0,1">
+      <relation target="" sidePair="width-width,height-height"/>
+    </image>
+    <image id="n1_g3xa" name="n1" src="q08x4" fileName="images/hz_dakai.png" xy="24,1" flip="hz">
+      <relation target="" sidePair="width-width,height-height"/>
+    </image>
+  </displayList>
+  <Button/>
+</component>

+ 10 - 0
FGUIProject/assets/DressUp/components/Button11.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<component size="66,66" extention="Button">
+  <Button/>
+  <controller name="button" pages="0,up,1,down,2,over,3,selectedOver"/>
+  <displayList>
+    <image id="n0_g3xa" src="k6he17" name="n0" xy="0,0">
+      <relation target="" sidePair="width,height"/>
+    </image>
+  </displayList>
+</component>

+ 8 - 0
FGUIProject/assets/DressUp/components/Button8.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<component size="66,66" extention="Button">
+  <controller name="button" pages="0,up,1,down,2,over,3,selectedOver" selected="0"/>
+  <displayList>
+    <loader id="n1_g3xa" name="n1" xy="0,0" size="66,66" url="ui://mbo439wbk6he17" autoSize="true"/>
+  </displayList>
+  <Button/>
+</component>

+ 10 - 0
FGUIProject/assets/DressUp/components/Button9.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<component size="91,92" extention="Button">
+  <Button/>
+  <controller name="button" pages="0,up,1,down,2,over,3,selectedOver"/>
+  <displayList>
+    <image id="n0_g3xa" src="ih753m" name="n0" xy="0,0">
+      <relation target="" sidePair="width,height"/>
+    </image>
+  </displayList>
+</component>

+ 5 - 0
FGUIProject/assets/DressUp/package.xml

@@ -139,6 +139,11 @@
     <component id="7dea4e" name="ListItem.xml" path="/components/"/>
     <component id="7dea4f" name="ComSelect.xml" path="/components/"/>
     <image id="7dea4g" name="kp_kprk_4.png" path="/images/" scale="9grid" scale9grid="52,90,104,180"/>
+    <component id="g3xa4h" name="Button8.xml" path="/components/"/>
+    <component id="g3xa4i" name="Button9.xml" path="/components/"/>
+    <component id="g3xa4j" name="Button10.xml" path="/components/"/>
+    <component id="g3xa4k" name="Button11.xml" path="/components/"/>
+    <component id="g3xa4l" name="ComChecked.xml" path="/"/>
   </resources>
   <publish name="" path="..\GameClient\Assets\ResIn\UI\DressUp" packageCount="2" genCode="true" extractAlpha="true"/>
 </packageDescription>

+ 1 - 1
GameClient/Assets/Game/HotUpdate/DressUp/DressUpUtil.cs

@@ -46,7 +46,7 @@ namespace GFGGame
                     updateLayerRes(itemCfg, parentObj, 2, itemCfg.resLayer2 == 2, needSetMask, showAni);
                 }
                 //特效
-                if (itemCfg.effLayer > 0)
+                if (itemCfg.effLayer > 0 && showAni)
                 {
                     var objName = string.Format(FORMAT_EFFECT_OBJ_NAME, itemCfg.subType);
                     ItemTypeCfg typeCfg = ItemTypeCfgArray.Instance.GetCfg(itemCfg.subType);

+ 77 - 0
GameClient/Assets/Game/HotUpdate/FairyGUI/GenCode/DressUp/UI_ComChecked.cs

@@ -0,0 +1,77 @@
+/** This is an automatically generated class by FairyGUI. Please do not modify it. **/
+
+using FairyGUI;
+
+namespace UI.DressUp
+{
+    public partial class UI_ComChecked
+    {
+        public GComponent target;
+        public GButton m_btnDelete;
+        public GButton m_btnFlip;
+        public GButton m_btnSize;
+        public const string URL = "ui://mbo439wbg3xa4l";
+        public const string PACKAGE_NAME = "DressUp";
+        public const string RES_NAME = "ComChecked";
+        private static UI_ComChecked _proxy;
+
+        public static UI_ComChecked Create(GObject gObject = null)
+        {
+            var ui = new UI_ComChecked();
+            if(gObject == null)
+            	ui.target =  (GComponent)UIPackage.CreateObject(PACKAGE_NAME, RES_NAME);
+            else
+            	ui.target =  (GComponent)gObject;
+            ui.Init(ui.target);
+            return ui;
+        }
+
+        public static UI_ComChecked Proxy(GObject gObject = null)
+        {
+            if(_proxy == null)
+            {
+                _proxy = new UI_ComChecked();
+            }
+            var ui = _proxy;
+            if(gObject == null)
+            	ui.target =  (GComponent)UIPackage.CreateObject(PACKAGE_NAME, RES_NAME);
+            else
+            	ui.target =  (GComponent)gObject;
+            ui.Init(ui.target);
+            return ui;
+        }
+
+        public static void ProxyEnd()
+        {
+            if (_proxy != null)
+            {
+                _proxy.Dispose();
+            }
+        }
+
+        public static void ClearProxy()
+        {
+            ProxyEnd();
+            _proxy = null;
+        }
+
+        private void Init(GComponent comp)
+        {
+            m_btnDelete = (GButton)comp.GetChild("btnDelete");
+            m_btnFlip = (GButton)comp.GetChild("btnFlip");
+            m_btnSize = (GButton)comp.GetChild("btnSize");
+        }
+        public void Dispose(bool disposeTarget = false)
+        {
+            m_btnDelete = null;
+            m_btnFlip = null;
+            m_btnSize = null;
+            if(disposeTarget && target != null)
+            {
+                target.RemoveFromParent();
+                target.Dispose();
+            }
+            target = null;
+        }
+    }
+}

+ 11 - 0
GameClient/Assets/Game/HotUpdate/FairyGUI/GenCode/DressUp/UI_ComChecked.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 42910201a0c1b4a44932af81a1a0549a
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 10 - 0
GameClient/Assets/Game/HotUpdate/FairyGUI/GenCode/DressUp/UI_PhotographUI.cs

@@ -7,8 +7,11 @@ namespace UI.DressUp
     public partial class UI_PhotographUI
     {
         public GComponent target;
+        public GLoader m_btnBg;
         public GButton m_btnBack;
+        public GButton m_btnChoose;
         public UI_ComSelect m_ComSelect;
+        public UI_ComChecked m_comChecked;
         public const string URL = "ui://mbo439wbbe944a";
         public const string PACKAGE_NAME = "DressUp";
         public const string RES_NAME = "PhotographUI";
@@ -56,14 +59,21 @@ namespace UI.DressUp
 
         private void Init(GComponent comp)
         {
+            m_btnBg = (GLoader)comp.GetChild("btnBg");
             m_btnBack = (GButton)comp.GetChild("btnBack");
+            m_btnChoose = (GButton)comp.GetChild("btnChoose");
             m_ComSelect = (UI_ComSelect)UI_ComSelect.Create(comp.GetChild("ComSelect"));
+            m_comChecked = (UI_ComChecked)UI_ComChecked.Create(comp.GetChild("comChecked"));
         }
         public void Dispose(bool disposeTarget = false)
         {
+            m_btnBg = null;
             m_btnBack = null;
+            m_btnChoose = null;
             m_ComSelect.Dispose();
             m_ComSelect = null;
+            m_comChecked.Dispose();
+            m_comChecked = null;
             if(disposeTarget && target != null)
             {
                 target.RemoveFromParent();

+ 109 - 29
GameClient/Assets/Game/HotUpdate/Views/DressUp/PhotographView.cs

@@ -16,9 +16,10 @@ namespace GFGGame
         private DressUpObjDataCache equipDataCache;
 
         private List<int> _listData = null;//当前选择的资源数据
-        private List<int> equipRoleData = new List<int>();//当前穿戴的角色数据
-        // private List<int> equipSceneData = new List<int>();
-        private Dictionary<int, List<int>> equipSceneData = new Dictionary<int, List<int>>();//当前穿戴的场景数据
+        private List<int> _equipRoleData = new List<int>();//当前穿戴的角色数据
+        private Dictionary<int, List<int>> _equipSceneData = new Dictionary<int, List<int>>();//当前穿戴的场景数据
+
+        private Vector3 distance = Vector3.zero;
         protected override void OnInit()
         {
             base.OnInit();
@@ -27,6 +28,8 @@ namespace GFGGame
             viewCom = _ui.target;
             isfullScreen = true;
 
+            _ui.m_btnBg.onClick.Add(OnClickBtnBg);
+            _ui.m_btnChoose.onClick.Add(OnClickBtnChoose);
             _ui.m_btnBack.onClick.Add(OnClickBtnBack);
 
             _ui.m_ComSelect.m_list.itemRenderer = RenderListItem;
@@ -41,7 +44,7 @@ namespace GFGGame
         {
             base.OnShown();
             Input.multiTouchEnabled = true;
-
+            equipDataCache = EquipDataCache.cacher;
 
             if (_sceneObject == null)
             {
@@ -49,16 +52,16 @@ namespace GFGGame
                 EquipDataCache.cacher.setSceneObj(_sceneObject);
             }
 
-            equipDataCache = EquipDataCache.cacher;
-
             _ui.m_ComSelect.m_c1.selectedIndex = 0;
+            OnClickBtnChoose();
             RefreshList(EnumPhotographType.BG);
             UpdateEquipData();
 
             UpdateBgOrNpcOrBorder(EnumPhotographType.BG, equipDataCache.bgId);
             UpdateBody();
             UpdateScene();
-            Timers.inst.Add(0.001f, 0, OnTimerListener);
+
+            // Timers.inst.Add(0.001f, 0, OnTimerListener);
         }
         /************************************************************UI界面*********************************************************/
         private void OnContorllerChanged(EventContext context)
@@ -112,12 +115,12 @@ namespace GFGGame
                     break;
 
                 case EnumPhotographType.SCENE:
-                    if (!equipSceneData.ContainsKey(itemID))
+                    if (!_equipSceneData.ContainsKey(itemID))
                     {
-                        equipSceneData.Add(itemID, new List<int>());
+                        _equipSceneData.Add(itemID, new List<int>());
                     }
-                    equipSceneData[itemID].Add(itemID);
-                    AddScene(itemID, equipSceneData[itemID].Count - 1);
+                    _equipSceneData[itemID].Add(itemID);
+                    AddScene(itemID, _equipSceneData[itemID].Count - 1);
 
                     break;
                 case EnumPhotographType.EFFECT:
@@ -129,6 +132,7 @@ namespace GFGGame
 
         private void OnTimerListener(object param)
         {
+            GameObject gameObj = null;
             // Debug.Log("点击鼠标:" + Input.GetMouseButtonDown(0));
             if (Input.GetMouseButtonDown(0))
             {
@@ -142,34 +146,48 @@ namespace GFGGame
                 }
                 //从摄像机发出到点击坐标的射线
                 RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
-                Vector2 pos = Input.mousePosition;
-
+                // Vector2 pos = Input.mousePosition;
+                // Debug.Log("mousePosition:" + 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!");
-                    }
+                    gameObj = hit.collider.gameObject;
+                    Debug.Log("ClickName:" + gameObj.name);
+                    // Debug.Log("ClickName:" + gameObj.name + "   Pos:" + gameObj.transform.position + "   LocalPos:" + gameObj.transform.position);
+                    // Debug.Log("mousePosition:" + Input.mousePosition);
+                    // Debug.Log("boxPos:" + _ui.m_comChecked.target.position);
+                    // //当射线碰撞目标为boot类型的物品,执行拾取操作
+                    // if (gameObj.tag == "boot")
+                    // {
+                    //     Debug.Log("pickup!");
+                    // }
                 }
             }
-            Debug.Log("触摸屏幕的手指个数:" + Input.touchCount);
+            // Vector2 pos = Input.mousePosition;
+            // Debug.Log("mousePosition:" + pos);
+
+            if (gameObj == null) return;
+            GameObject obj = GetMoveObjByHitObj(gameObj);
 
             if (Input.touchCount <= 0) { return; }
+            Debug.Log("触摸屏幕的手指个数:" + Input.touchCount);
             // for (var touch : Touch in Input.touches)
             // {
             if (Input.GetTouch(0).phase == TouchPhase.Began)
             {
                 Debug.Log("触摸:" + "Began");
+
+                Vector3 objScreenPos = Camera.main.WorldToScreenPoint(obj.transform.position);
+                distance = Input.mousePosition - objScreenPos;
+
             }
             if (Input.GetTouch(0).phase == TouchPhase.Moved)
             {
                 Debug.Log("触摸:" + "Moved");
+                // Vector3 distance =
 
+                ControllerObject(obj);
             }
             if (Input.GetTouch(0).phase == TouchPhase.Stationary)
             {
@@ -179,9 +197,54 @@ namespace GFGGame
             if (Input.GetTouch(0).phase == TouchPhase.Ended)
             {
                 Debug.Log("触摸:" + "Ended");
-
+                distance = Vector3.zero;
             }
         }
+        private GameObject GetMoveObjByHitObj(GameObject obj)
+        {
+            // if (obj == null) return null;
+            if (obj.transform.parent == _sceneObject.transform.Find("Bg") || obj.transform.parent == _sceneObject.transform.Find("Npc"))
+            {
+                return obj;//背景和npc拖动物体本身
+            }
+            else
+            {
+                return obj.transform.parent.gameObject;//场景要拖动父物体
+            }
+        }
+        private void ControllerObject(GameObject obj)
+        {
+            if (obj.name == "BgRes")
+            {
+                Vector2 size = obj.GetComponent<SpriteRenderer>().size;
+                Vector2 uiSize = _ui.target.size;
+                float deviationWidth = (size.x - uiSize.x) / 2;
+                float deviationHeigh = (size.y - uiSize.y) / 2;
+                Vector2 pos = obj.transform.position;
+                if (pos.x <= -deviationWidth)
+                {
+                    obj.transform.position = new Vector2(-deviationWidth, obj.transform.position.y);
+                    return;
+                }
+                if (pos.x >= deviationWidth)
+                {
+                    obj.transform.position = new Vector2(deviationWidth, obj.transform.position.y);
+                    return;
+                }
+                if (pos.y <= -deviationHeigh)
+                {
+                    obj.transform.position = new Vector2(obj.transform.position.x, -deviationHeigh);
+                    return;
+                }
+                if (pos.x >= deviationHeigh)
+                {
+                    obj.transform.position = new Vector2(obj.transform.position.x, deviationHeigh);
+                    return;
+                }
+            }
+            // obj.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x - distance.x, Input.mousePosition.y - distance.y));
+            obj.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition - distance);
+        }
 
 
         //背景
@@ -196,7 +259,7 @@ namespace GFGGame
         {
 
             // int[] equipDatas = equipDataCache.equipDatas;
-            SceneController.UpdateRole(equipRoleData.ToArray(), _sceneObject, false, null, false);
+            SceneController.UpdateRole(_equipRoleData.ToArray(), _sceneObject, false, null, false);
             if (equipDataCache.IsSuitPic && equipDataCache.suitId > 0)
             {
                 SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(equipDataCache.suitId);
@@ -210,10 +273,10 @@ namespace GFGGame
         //场景道具
         private void UpdateScene()
         {
-            ICollection keys = equipSceneData.Keys;
+            ICollection keys = _equipSceneData.Keys;
             foreach (int key in keys)
             {
-                for (int i = 0; i < equipSceneData[key].Count; i++)
+                for (int i = 0; i < _equipSceneData[key].Count; i++)
                 {
                     AddScene(key, i);
                 }
@@ -248,20 +311,33 @@ namespace GFGGame
                 ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(equipDataCache.equipDatas[i]);
                 if (itemCfg.subType == ConstDressUpItemType.QIAN_JING || itemCfg.subType == ConstDressUpItemType.BEI_SHI || itemCfg.subType == ConstDressUpItemType.HUAN_JING)
                 {
-                    if (!equipSceneData.ContainsKey(itemCfg.id))
+                    if (!_equipSceneData.ContainsKey(itemCfg.id))
                     {
-                        equipSceneData.Add(itemCfg.id, new List<int>());
+                        _equipSceneData.Add(itemCfg.id, new List<int>());
                     }
-                    equipSceneData[itemCfg.id].Add(itemCfg.id);
+                    _equipSceneData[itemCfg.id].Add(itemCfg.id);
                 }
                 else
                 {
-                    equipRoleData.Add(equipDataCache.equipDatas[i]);
+                    _equipRoleData.Add(equipDataCache.equipDatas[i]);
                 }
             }
 
         }
+        private void OnClickBtnBg()
+        {
+            _ui.m_ComSelect.target.visible = false;
+            Timers.inst.Add(0.001f, 0, OnTimerListener);
+
+            // _ui.target.opaque = false;//false表示可穿透
+        }
+        private void OnClickBtnChoose()
+        {
+            _ui.m_ComSelect.target.visible = true;
+            Timers.inst.Remove(OnTimerListener);
 
+            // _ui.target.opaque = true;
+        }
         private void OnClickBtnBack()
         {
             this.Hide();
@@ -276,7 +352,11 @@ namespace GFGGame
                 GameObject.Destroy(_sceneObject);
                 _sceneObject = null;
             }
+            Timers.inst.Remove(OnTimerListener);
             equipDataCache = null;
+            _equipRoleData.Clear();
+            _equipSceneData.Clear();
+
         }
         public override void Dispose()
         {

BIN
GameClient/Assets/ResIn/UI/DressUp/DressUp_atlas0!a.png


BIN
GameClient/Assets/ResIn/UI/DressUp/DressUp_atlas0.png


BIN
GameClient/Assets/ResIn/UI/DressUp/DressUp_fui.bytes