浏览代码

拍照边框大小

zhaoyang 3 年之前
父节点
当前提交
adb5e16a40

+ 36 - 3
GameClient/Assets/Game/HotUpdate/DressUp/SceneController.cs

@@ -94,7 +94,7 @@ namespace GFGGame
             {
             {
                 void UpdateDialogPicAlpha(object param)
                 void UpdateDialogPicAlpha(object param)
                 {
                 {
-                    if(spr != null)
+                    if (spr != null)
                     {
                     {
                         Color c = spr.color;
                         Color c = spr.color;
                         if (spr.enabled && c.a < 1f)
                         if (spr.enabled && c.a < 1f)
@@ -111,7 +111,7 @@ namespace GFGGame
                     {
                     {
                         FairyGUI.Timers.inst.Remove(UpdateDialogPicAlpha);
                         FairyGUI.Timers.inst.Remove(UpdateDialogPicAlpha);
                     }
                     }
-                    
+
                 }
                 }
                 var resPath = ResPathUtil.GetNpcPicSPath(value);
                 var resPath = ResPathUtil.GetNpcPicSPath(value);
                 Sprite sp = GFGAsset.Load<Sprite>(resPath);
                 Sprite sp = GFGAsset.Load<Sprite>(resPath);
@@ -232,11 +232,44 @@ namespace GFGGame
                 BoxCollider2D boxCollider2D = childGameObj.GetComponent<BoxCollider2D>();
                 BoxCollider2D boxCollider2D = childGameObj.GetComponent<BoxCollider2D>();
                 if (boxCollider2D != null)
                 if (boxCollider2D != null)
                 {
                 {
-                    return boxCollider2D.size * childGameObj.transform.localScale * parentObj.transform.localScale * 100;
+                    size = GetGameObjectSize1(parentObj);
+                    // boxCollider2D.size = size * childGameObj.transform.localScale * parentObj.transform.localScale;
+                    size = size * childGameObj.transform.localScale * parentObj.transform.localScale * 100;
+                    return size;
                 }
                 }
             }
             }
             return Vector2.zero;
             return Vector2.zero;
         }
         }
+        private static Vector2 GetGameObjectSize1(GameObject parentObj)
+        {
+            float right = int.MinValue;
+            float left = int.MaxValue;
+            float top = int.MinValue;
+            float bottom = int.MaxValue;
+            for (int i = 0; i < parentObj.transform.childCount; i++)
+            {
+                Transform transform = parentObj.transform.GetChild(i);
+                SpriteRenderer sr = transform.GetComponent<SpriteRenderer>();
+
+                if (sr != null)
+                {
+                    Vector2 pos = transform.localPosition;
+                    Vector2 size = sr.bounds.size / parentObj.transform.localScale.x;
+                    Debug.Log("size:" + size + "     pos:" + pos);
+
+                    right = Math.Max(size.x / 2 + pos.x, right);
+                    left = Math.Min(pos.x - size.x / 2, left);
+                    top = Math.Max(size.y / 2 + pos.y, top);
+                    bottom = Math.Min(pos.y - size.y / 2, bottom);
+                }
+            }
+            Vector2 bounds = new Vector2(right - left, top - bottom);
+            Debug.Log("size:" + bounds);
+
+            return bounds;
+        }
+
+
         //设置物体中心点
         //设置物体中心点
         public static void SetGameObjectCenter(GameObject parentObj)
         public static void SetGameObjectCenter(GameObject parentObj)
         {
         {

+ 116 - 7
GameClient/Assets/Game/HotUpdate/Views/DressUp/PhotographView.cs

@@ -2,7 +2,9 @@ using FairyGUI;
 using System;
 using System;
 using System.Collections;
 using System.Collections;
 using System.Collections.Generic;
 using System.Collections.Generic;
+using System.Drawing;
 using UI.DressUp;
 using UI.DressUp;
+using UnityEditor;
 using UnityEngine;
 using UnityEngine;
 using UnityEngine.EventSystems;
 using UnityEngine.EventSystems;
 
 
@@ -45,6 +47,7 @@ namespace GFGGame
 
 
         private Vector3 distance = Vector3.zero;//点击位置和点击物体原点的距离,用于
         private Vector3 distance = Vector3.zero;//点击位置和点击物体原点的距离,用于
         private Vector2 lastPos = Vector2.zero;//上一次移动后从物体中心到鼠标位置的方向
         private Vector2 lastPos = Vector2.zero;//上一次移动后从物体中心到鼠标位置的方向
+        private float lastDistance = 0;//上一次移动后从物体中心到鼠标位置的方向
 
 
         // private float _startDistance;//从物体中心到缩放按钮的距离
         // private float _startDistance;//从物体中心到缩放按钮的距离
 
 
@@ -132,6 +135,7 @@ namespace GFGGame
                 _ui.m_loaGuide.enabled = true;
                 _ui.m_loaGuide.enabled = true;
                 _ui.m_loaGuide1.enabled = false;
                 _ui.m_loaGuide1.enabled = false;
             }
             }
+            // CreatTex();
             Timers.inst.AddUpdate(UpdateToCheckGuide);
             Timers.inst.AddUpdate(UpdateToCheckGuide);
         }
         }
         /************************************************************UI界面*********************************************************/
         /************************************************************UI界面*********************************************************/
@@ -300,13 +304,16 @@ namespace GFGGame
         private void OnTouchBtnSizeBegin(EventContext context)
         private void OnTouchBtnSizeBegin(EventContext context)
         {
         {
             InputEvent inputEvent = (InputEvent)context.data;
             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 screenPos = this.viewCom.GlobalToLocal(_ui.m_comSelectBox.m_btnSize.LocalToGlobal(Vector2.zero));
-            Vector2 pt = new Vector2(screenPos.x, screenPos.y);
+            Vector2 pt1 = new Vector2(screenPos.x, screenPos.y);
             Vector2 pt2 = new Vector2(_ui.m_comSelectBox.target.x, _ui.m_comSelectBox.target.y);
             Vector2 pt2 = new Vector2(_ui.m_comSelectBox.target.x, _ui.m_comSelectBox.target.y);
-
+            lastDistance = Vector2.Distance(pt0, pt2);
             if (!_equipDistance.ContainsKey(memoryHitGameObj))
             if (!_equipDistance.ContainsKey(memoryHitGameObj))
             {
             {
-                float distance = Vector2.Distance(pt, pt2) / memoryHitGameObj.transform.localScale.x;
+                float distance = Vector2.Distance(pt1, pt2) / memoryHitGameObj.transform.localScale.x;
+                Debug.Log("distance:" + distance + "    pt1:" + pt1 + "   pt2:" + pt2);
                 _equipDistance.Add(memoryHitGameObj, distance);
                 _equipDistance.Add(memoryHitGameObj, distance);
             }
             }
         }
         }
@@ -314,6 +321,7 @@ namespace GFGGame
         {
         {
             if (memoryHitGameObj == null) return;
             if (memoryHitGameObj == null) return;
             InputEvent inputEvent = (InputEvent)context.data;
             InputEvent inputEvent = (InputEvent)context.data;
+
             Vector2 pt1 = this.viewCom.GlobalToLocal(new Vector2(inputEvent.x, inputEvent.y));
             Vector2 pt1 = this.viewCom.GlobalToLocal(new Vector2(inputEvent.x, inputEvent.y));
             Vector2 pt2 = new Vector2(_ui.m_comSelectBox.target.x, _ui.m_comSelectBox.target.y);
             Vector2 pt2 = new Vector2(_ui.m_comSelectBox.target.x, _ui.m_comSelectBox.target.y);
             Vector2 curPos = pt1 - pt2;
             Vector2 curPos = pt1 - pt2;
@@ -324,12 +332,21 @@ namespace GFGGame
             lastPos = curPos;
             lastPos = curPos;
             ControllerRotate(angle, memoryHitGameObj);
             ControllerRotate(angle, memoryHitGameObj);
 
 
-
             float dist = Vector2.Distance(pt1, pt2);
             float dist = Vector2.Distance(pt1, pt2);
-            float ss = dist / _equipDistance[memoryHitGameObj];
-            float newValue = Mathf.Clamp(ss, 0.1f, 2);
+
+            float ss = dist / lastDistance;
+            Debug.Log("dist:" + dist + "   lastDistance:" + lastDistance + "  ss:" + ss);
+            float newValue = Mathf.Clamp(ss * memoryHitGameObj.transform.localScale.x, 0.1f, 2);
             ControllerScale(newValue, memoryHitGameObj);
             ControllerScale(newValue, memoryHitGameObj);
 
 
+            if (newValue <= 0.1f) return;
+            Debug.Log("ss:" + ss + "    newValue:" + newValue);
+            lastDistance = dist;
+            Debug.Log("newValue:" + newValue);
+
+
+
+
         }
         }
         private void OnTouchBtnSizeEnd(EventContext context)
         private void OnTouchBtnSizeEnd(EventContext context)
         {
         {
@@ -373,7 +390,8 @@ namespace GFGGame
             if (value > MaxScale || value < MinScale) return;
             if (value > MaxScale || value < MinScale) return;
             gameObject.transform.localScale = new Vector3(value, value, 1);
             gameObject.transform.localScale = new Vector3(value, value, 1);
             Vector2 size = SceneController.GetGameObjectSize(gameObject);
             Vector2 size = SceneController.GetGameObjectSize(gameObject);
-            _ui.m_comSelectBox.target.SetSize(size.x, size.y);
+            _ui.m_comSelectBox.target.size = size;
+            // _ui.m_comSelectBox.target.SetSize(size.x, size.y);
         }
         }
         private void ControllerRotate(float value, GameObject gameObject)
         private void ControllerRotate(float value, GameObject gameObject)
         {
         {
@@ -623,6 +641,97 @@ namespace GFGGame
             GuideController.TryCompleteGuide(ConstGuideId.PHOTOGRAPH, 7);
             GuideController.TryCompleteGuide(ConstGuideId.PHOTOGRAPH, 7);
         }
         }
 
 
+
+
+        private void CreatTex()
+        {
+            Rect rect = new Rect(-(UnityEngine.Screen.width / 2), -(UnityEngine.Screen.height / 2), UnityEngine.Screen.width, UnityEngine.Screen.height);
+            Texture2D tex = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.ARGB32, false);//新建一个Texture2D对象
+            Transform transform = _sceneObject.transform.Find("Scene/Role");
+            Dictionary<SpriteRenderer, int> data = new Dictionary<SpriteRenderer, int>();
+
+            float width = 0;
+            float height = 0;
+            for (int i = 0; i < transform.childCount; i++)
+            {
+                SpriteRenderer sr = transform.GetChild(i).GetComponent<SpriteRenderer>();
+                if (sr != null)
+                {
+                    width = Math.Max(sr.bounds.size.x + sr.transform.position.x, width);
+                    height = Math.Max(sr.bounds.size.x + sr.transform.position.x, width);
+
+                    data.Add(sr, sr.sortingOrder);
+                }
+            }
+            List<KeyValuePair<SpriteRenderer, int>> lst = new List<KeyValuePair<SpriteRenderer, int>>(data);
+            lst.Sort(delegate (KeyValuePair<SpriteRenderer, int> s1, KeyValuePair<SpriteRenderer, int> s2) { return s2.Value.CompareTo(s1.Value); });
+            data.Clear();
+
+            for (int i = lst.Count - 1; i >= 0; i--)
+            {
+                SpriteRenderer sr = lst[i].Key;
+                if (sr != null)
+                {
+                    // Sprite sprite1 = sr.GetComponent<Sprite>();
+                    Texture2D texture2D = sr.sprite.texture;
+                    for (int j = 0; j < texture2D.width; j++)
+                    {
+                        for (int k = 0; k < texture2D.height; k++)
+                        {
+                            var color = texture2D.GetPixel(j, k);
+                            tex.SetPixel(j, k, color);
+                            tex.Apply();
+                            Debug.Log("color:" + color + "     " + j + "   " + k);
+                        }
+                    }
+                    // var color = texture2D.GetPixel(0, 0);
+
+                    // tex.SetPixel(0, 0, color);
+                    // tex.Apply();//保存像素信息
+                }
+            }
+            Sprite sprite = Sprite.Create(tex, rect, new Vector2(-(UnityEngine.Screen.width / 2), -(UnityEngine.Screen.height / 2)));
+            GameObject gameObject = _sceneObject.transform.Find("Scene/Role/BodyRes").gameObject;
+            gameObject.AddComponent<SpriteRenderer>();
+            gameObject.GetComponent<SpriteRenderer>().sprite = sprite;
+
+            // // Dictionary<string, int> data = new Dictionary<string, int>();
+            // // for (int i = 0; i < _equipRoleData.Count; i++)
+            // // {
+            // //     ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_equipRoleData[i]);
+            // //     ItemTypeCfg typeCfg = ItemTypeCfgArray.Instance.GetCfg(itemCfg.subType);
+
+            // //     if (itemCfg.resLayer1 > 0)
+            // //     {
+            // //         data.Add(itemCfg.res, typeCfg.defaultLayer);
+            // //     }
+            // //     if (itemCfg.resLayer2 > 0)
+            // //     {
+            // //         data.Add(string.Format("{0}_t", itemCfg.res), typeCfg.defaultLayer);
+            // //     }
+            // // }
+            // // List<KeyValuePair<string, int>> lst = new List<KeyValuePair<string, int>>(data);
+            // // lst.Sort(delegate (KeyValuePair<string, int> s1, KeyValuePair<string, int> s2) { return s2.Value.CompareTo(s1.Value); });
+            // // data.Clear();
+            // // for (int i = lst.Count - 1; i >= 0; i--)
+            // // {
+            // //     string res = lst[i].Key;
+            // //     int sortingOrder = lst[i].Value;
+
+            // //     float tx, ty;
+            // //     DressUpUtil.LoadSpritePos(res, out tx, out ty);
+            // //     string resPath = ResPathUtil.GetDressUpPath(res);
+            // //     Bitmap bmp = new Bitmap(resPath);
+
+            // //     tex.SetPixel(0, 0, );//读取像素,屏幕左下角为0点
+            // //     tex.Apply();//保存像素信息
+            // // }
+            // tex.SetPixel(0, 0, );//读取像素,屏幕左下角为0点
+
+            // tex.Apply();//保存像素信息
+            // return tex;
+        }
+
     }
     }
 }
 }