using FairyGUI; using System; using System.Collections; using System.Collections.Generic; using System.Drawing; using UI.DressUp; using UnityEditor; using UnityEngine; using UnityEngine.EventSystems; namespace GFGGame { public class PhotographView : BaseView { private UI_PhotographUI _ui; private GameObject _scenePrefab; private GameObject _sceneObject; // private DressUpObjDataCache equipDataCache; // private const string MOVE = "MOVE"; // private const string SCALE = "SCALE"; // private const string ROTATION = "ROTATION"; 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 NpcPath = "Scene/Npc"; private const string BgResName = "BgRes"; // private const string BorderResName = "BorderRes"; // private GameObject bodyParent; // private GameObject bgParent; // private GameObject npcParent; // private GameObject borderParent; // private GameObject sceneParent; private List _listData = null;//当前选择的资源数据 public List _equipRoleData = new List();//当前穿戴的角色数据 public Dictionary> _equipSceneData = new Dictionary>();//当前穿戴的场景数据 private Dictionary _equipDistance = new Dictionary(); 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 bool isTwoTouchPoint = false; private int maxLayer = int.MinValue;//最上层的层级数 protected override void OnInit() { base.OnInit(); packageName = UI_PhotographUI.PACKAGE_NAME; _ui = UI_PhotographUI.Create(); viewCom = _ui.target; isfullScreen = true; _ui.m_btnBg.onClick.Add(OnClickBtnBg); _ui.m_loaGuide.onClick.Add(OnClickLoaGuide); _ui.m_loaGuide1.onClick.Add(OnClickLoaGuide1); _ui.m_btnChoose.onClick.Add(SetUIView); _ui.m_btnBack.onClick.Add(OnClickBtnBack); _ui.m_btnPhotograph.onClick.Add(OnClickBtnPhotograph); _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); _scenePrefab = GFGAsset.Load(ResPathUtil.GetPrefabPath("ScenePhotograph")); _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_comSelectBox.m_btnDelete.onTouchEnd.Add(OnTouchBtnDeleteEnd); } protected override void OnShown() { base.OnShown(); Input.multiTouchEnabled = true; // equipDataCache = EquipDataCache.cacher; PhotographDataManager.Instance.ClassifyEquipData(); _equipRoleData = PhotographDataManager.Instance._equipRoleData; _equipSceneData = PhotographDataManager.Instance._equipSceneData; if (_sceneObject == null) { _sceneObject = GameObject.Instantiate(_scenePrefab); EquipDataCache.cacher.setSceneObj(_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; RefreshList(EnumPhotographType.BG); SetUIView(); UpdateBg(ItemCfgArray.Instance.GetCfg(EquipDataCache.cacher.bgId)); UpdateBody(); UpdateScene(); GuideController.TryGuideDressUpViewMenuPart1(_ui.m_ComSelectRes.m_comBtnTab.m_btn2); // GuideController.TryGuideBtnPhotograph(_ui.m_btnPhotograph); if (GuideDataManager.GetGuideCount(ConstGuideId.PHOTOGRAPH_GUIDE) > 0 && GuideDataManager.GetGuideCountCopy(ConstGuideId.PHOTOGRAPH) > 0) { _ui.m_loaGuide.enabled = false; _ui.m_loaGuide1.enabled = false; } else { _ui.m_loaGuide.enabled = true; _ui.m_loaGuide1.enabled = false; } // CreatTex(); Timers.inst.AddUpdate(UpdateToCheckGuide); } /************************************************************UI界面*********************************************************/ private void OnContorllerChanged(EventContext context) { int index = _ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex; RefreshList((EnumPhotographType)index); GuideController.TryGuideBtnPhotograph(_ui.m_loaGuide); } 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; } private void RenderListItem(int index, GObject obj) { ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_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; } private void OnListItemClick(EventContext context) { int itemID = (int)((context.data as GObject).data); ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemID); EnumPhotographType type = (EnumPhotographType)_ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex; switch (type) { case EnumPhotographType.BG: UpdateBg(itemCfg); break; case EnumPhotographType.BORDER: if (_listData.IndexOf(itemID) == 0) { Transform tf = _sceneObject.transform.Find(BorderResPath); SpriteRenderer spr = tf.GetComponent(); if (spr != null) { GameObject.Destroy(spr); } return; } UpdateBorder(itemCfg); break; case EnumPhotographType.NPC: UpdateNpc(itemCfg); break; case EnumPhotographType.SCENE: AddSceneItem(itemCfg, false); break; case EnumPhotographType.EFFECT: break; } } /************************************************************场景*********************************************************/ 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 (PhotographDataManager.Instance.IsTouchUI(this.viewCom)) return; RaycastHit2D[] hit2Ds = Physics2D.RaycastAll(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (hit2Ds.Length > 0) { // maxLayer++; lastPos = Vector2.zero; hitGameObj = SceneController.GetFirstHitObj(hit2Ds); _ui.m_comSelectBox.m_btnDelete.visible = true; if (hitGameObj.name == "Body")//主角不可删除 { _ui.m_comSelectBox.m_btnDelete.visible = false; } _ui.m_comSelectBox.target.visible = false; if (hitGameObj.name != BgResName)//背景不可改动层级 { hitGameObj = hitGameObj.transform.parent.gameObject; PhotographDataManager.Instance.SetItemLayer(hitGameObj, maxLayer); maxLayer = PhotographDataManager.Instance.GetMaxLayer(hitGameObj, maxLayer) + 1; _ui.m_comSelectBox.target.visible = true; if (!_equipDistance.ContainsKey(hitGameObj)) { SceneController.SetGameObjectCenter(hitGameObj); } } 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;// localEulerAngles.y != 0 ? hitGameObj.transform.localEulerAngles.z : -hitGameObj.transform.localEulerAngles.z; Debug.Log("rotation:" + _ui.m_comSelectBox.target.rotation + " " + _ui.m_comSelectBox.target.rotationX + " " + _ui.m_comSelectBox.target.rotationY); _ui.m_comSelectBox.target.size = SceneController.GetGameObjectSize(hitGameObj); ControllerSelectBoxPos(); } } private void OnTouchUIMove(EventContext context) { if (hitGameObj == null) return;//未选中任何物体 if (Stage.inst.touchCount > 1) return; //只监听1根手指 if (PhotographDataManager.Instance.IsTouchUI(this.viewCom)) return; Debug.Log("拖动"); ControllerObjectPos(); ControllerSelectBoxPos(); } private void OnTouchUIEnd(EventContext context) { // if (Stage.inst.touchCount > 1 || context.inputEvent.touchId != 0) return; //只监听1根手指 hitGameObj = null; } //选中物体的位置 private void ControllerObjectPos() { hitGameObj.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition - distance); if (hitGameObj.name == BgResName) { PhotographDataManager.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(new Vector2(inputEvent.x, inputEvent.y)); Vector2 pt2 = new Vector2(_ui.m_comSelectBox.target.x, _ui.m_comSelectBox.target.y); 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; Debug.Log("dist:" + dist + " lastDistance:" + lastDistance + " ss:" + ss); float newValue = Mathf.Clamp(ss * memoryHitGameObj.transform.localScale.x, 0.1f, 2); 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) { 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); } //双指旋转 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) { if (value > MaxScale || value < MinScale) return; gameObject.transform.localScale = new Vector3(value, value, 1); Vector2 size = SceneController.GetGameObjectSize(gameObject); _ui.m_comSelectBox.target.size = size; // _ui.m_comSelectBox.target.SetSize(size.x, size.y); } private void ControllerRotate(float value, GameObject gameObject) { gameObject.transform.Rotate(Vector3.forward, -value, Space.World); _ui.m_comSelectBox.target.rotation += value; } private void UpdateBg(ItemCfg itemCfg) { Transform tf = _sceneObject.transform.Find(BgResPath); string resPath = ResPathUtil.GetDressUpPath(itemCfg.res, ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType)); SceneController.SetSpriteRendererToTransform(tf, resPath); SpriteRenderer spr = tf.GetComponent(); spr.sortingOrder = ItemTypeCfgArray.Instance.GetCfg(ConstDressUpItemType.BEI_JING).defaultLayer; SceneController.SetBoxCollider2DToGameObject(tf.gameObject); } //主角 private void UpdateBody() { GameObject bodyParent = _sceneObject.transform.Find(RolePath).gameObject; SceneController.UpdatePhotographBody(_equipRoleData.ToArray(), _sceneObject, bodyParent); maxLayer = PhotographDataManager.Instance.GetMaxLayer(bodyParent, maxLayer) + 1; } //添加初始场景道具 private void UpdateScene() { ICollection keys = _equipSceneData.Keys; foreach (int key in keys) { for (int i = 0; i < _equipSceneData[key].Count; i++) { ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(key); int defaultLayer = ItemTypeCfgArray.Instance.GetCfg(itemCfg.subType).defaultLayer; AddSceneItem(itemCfg, true); } } } private void UpdateNpc(ItemCfg itemCfg) { maxLayer++; Transform tf = _sceneObject.transform.Find(NpcResPath); string resPath = ResPathUtil.GetNpcPicFPath(itemCfg.res); SceneController.SetSpriteRendererToTransform(tf, resPath); SpriteRenderer spr = tf.GetComponent(); spr.sortingOrder = maxLayer; tf.localPosition = new Vector2(-spr.bounds.center.x, -spr.bounds.center.y); SceneController.SetBoxCollider2DToGameObject(tf.gameObject); } private void UpdateBorder(ItemCfg itemCfg) { Transform tf = _sceneObject.transform.Find(BorderResPath); string resPath = ResPathUtil.GetPhotographFPath(itemCfg.res, ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType)); SceneController.SetSpriteRendererToTransform(tf, resPath); SpriteRenderer spr = tf.GetComponent(); spr.sortingOrder = 10000;//边框在所有道具的上边 } private void UpdateEffect() { } private void AddSceneItem(ItemCfg itemCfg, bool isDefaultLayer) { int index = 0; GameObject parentGameObj; if (itemCfg.resLayer2 > 0) { if (!isDefaultLayer) { PhotographDataManager.Instance.AddEquipItem(_equipSceneData, itemCfg.id, out _equipSceneData); } index = _equipSceneData[itemCfg.id].Count - 1; parentGameObj = new GameObject(string.Format("{0}_{1}_{2}", itemCfg.id, index, 1)); SceneController.AddItemToScene(_sceneObject, parentGameObj, itemCfg.id, 2, itemCfg.resLayer2); maxLayer = PhotographDataManager.Instance.GetMaxLayer(parentGameObj, maxLayer) + 1; if (!isDefaultLayer) { PhotographDataManager.Instance.SetItemLayer(parentGameObj, maxLayer); } } if (itemCfg.resLayer1 > 0) { if (!isDefaultLayer) { PhotographDataManager.Instance.AddEquipItem(_equipSceneData, itemCfg.id, out _equipSceneData); } index = _equipSceneData[itemCfg.id].Count - 1; parentGameObj = new GameObject(string.Format("{0}_{1}_{2}", itemCfg.id, index, 0)); SceneController.AddItemToScene(_sceneObject, parentGameObj, itemCfg.id, 1, itemCfg.resLayer1); maxLayer = PhotographDataManager.Instance.GetMaxLayer(parentGameObj, maxLayer) + 1; if (!isDefaultLayer) { PhotographDataManager.Instance.SetItemLayer(parentGameObj, maxLayer); } } } private void OnClickBtnBg() { _ui.m_ComSelectRes.target.visible = false; // GuideController.TryGuideOpenPhotographView(null); } private void OnClickLoaGuide() { _ui.m_loaGuide1.enabled = true; _ui.m_loaGuide.enabled = false; _ui.m_ComSelectRes.target.visible = false; GuideController.TryGuideOpenPhotographView(_ui.m_loaGuide1); } private void OnClickLoaGuide1() { _ui.m_loaGuide1.enabled = false; _ui.m_ComSelectRes.target.visible = false; GuideController.TryGuideBtnSave(_ui.m_btnPhotograph); } private void OnTouchBtnFlipBegin()//翻转 { Transform transform = memoryHitGameObj.transform; if (memoryHitGameObj.name == RoleName) { transform.Rotate(Vector3.up, 180, Space.Self); return; } for (int i = 0; i < transform.childCount; i++) { transform.GetChild(i).Rotate(Vector3.up, 180, Space.Self); } } private void OnTouchBtnFlipEnd() { } private void OnTouchBtnDeleteBegin()//删除 { if (memoryHitGameObj.transform.name == RolePath) { return; } else if (memoryHitGameObj.transform.name == NpcPath) { SpriteRenderer spriteRenderer = memoryHitGameObj.transform.GetChild(0).GetComponent(); if (spriteRenderer != null) { GameObject.Destroy(spriteRenderer); } } else { GameObject.DestroyImmediate(memoryHitGameObj); } _ui.m_comSelectBox.target.visible = false; } private void OnTouchBtnDeleteEnd() { } private void SetUIView() { _ui.m_ComSelectRes.target.visible = true; _ui.m_comSelectBox.target.visible = false; hitGameObj = null; memoryHitGameObj = null; } private void OnClickBtnPhotograph() { GuideController.HideGuide(); GuideController.TryCompleteGuide(ConstGuideId.PHOTOGRAPH_GUIDE); _ui.target.visible = false; Timers.inst.StartCoroutine(ScreenShotTex());// (); } private IEnumerator ScreenShotTex() { _ui.target.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();//保存像素信息 ViewManager.Show(tex); _ui.target.visible = true; } 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; _equipRoleData.Clear(); _equipSceneData.Clear(); hitGameObj = null; memoryHitGameObj = null; pinchGesture.onAction.Remove(OnPinch); rotationGesture.onAction.Remove(OnRotate); pinchGesture = null; rotationGesture = null; Timers.inst.Remove(UpdateToCheckGuide); } public override void Dispose() { if (_scenePrefab != null) { GameObject.Destroy(_scenePrefab); _scenePrefab = null; } base.Dispose(); } private void UpdateToCheckGuide(object param) { if (!ViewManager.CheckIsTopView(this.viewCom)) return; GuideController.TryGuide(_ui.m_ComSelectRes.m_comBtnTab.m_btn2, ConstGuideId.PHOTOGRAPH, 4, "可以自由添加已有道具"); GuideController.TryGuide(_ui.m_loaGuide, ConstGuideId.PHOTOGRAPH, 5, "点击空白处查看整体效果"); GuideController.TryGuide(_ui.m_loaGuide1, ConstGuideId.PHOTOGRAPH, 6, "双指可控制放大缩小,或点击边框上的按键控制"); GuideController.TryGuide(_ui.m_btnPhotograph, 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 data = new Dictionary(); float width = 0; float height = 0; for (int i = 0; i < transform.childCount; i++) { SpriteRenderer sr = transform.GetChild(i).GetComponent(); 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> lst = new List>(data); lst.Sort(delegate (KeyValuePair s1, KeyValuePair 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(); 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(); gameObject.GetComponent().sprite = sprite; // // Dictionary data = new Dictionary(); // // 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> lst = new List>(data); // // lst.Sort(delegate (KeyValuePair s1, KeyValuePair 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; } } }