|
@@ -33,7 +33,13 @@ namespace GFGGame
|
|
|
|
|
|
// private GameObject hitGameObj;//当前选中的物体
|
|
|
private GameObject hitParentGameObj;//当前选中的父物体(需要进行移动缩放旋转的物体)
|
|
|
+ private GameObject memoryHitParentGameObj;//当前选中的父物体(需要进行移动缩放旋转的物体)
|
|
|
+
|
|
|
private Vector3 distance = Vector3.zero;//点击位置和点击物体原点的距离,用于
|
|
|
+ private Vector2 lastPos = Vector2.zero;//上一次移动后从物体中心到鼠标位置的方向
|
|
|
+
|
|
|
+ private float _startDistance;//从物体中心到缩放按钮的距离
|
|
|
+
|
|
|
|
|
|
private SwipeGesture swipeGesture;
|
|
|
private PinchGesture pinchGesture;
|
|
@@ -52,7 +58,7 @@ namespace GFGGame
|
|
|
|
|
|
_ui.m_ComSelectRes.m_list.itemRenderer = RenderListItem;
|
|
|
_ui.m_ComSelectRes.m_list.onClickItem.Add(OnListItemClick);
|
|
|
- _ui.m_ComSelectRes.m_c1.onChanged.Add(OnContorllerChanged);
|
|
|
+ _ui.m_ComSelectRes.m_comBtnTab.m_c1.onChanged.Add(OnContorllerChanged);
|
|
|
|
|
|
_scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("ScenePhotograph"));
|
|
|
|
|
@@ -60,7 +66,9 @@ namespace GFGGame
|
|
|
_ui.target.onTouchMove.Add(OnClickUIMove);
|
|
|
_ui.target.onTouchEnd.Add(OnClickUIEnd);
|
|
|
|
|
|
-
|
|
|
+ _ui.m_comSelectBox.m_btnSize.onTouchBegin.Add(OnClickBtnSizeBegin);
|
|
|
+ _ui.m_comSelectBox.m_btnSize.onTouchMove.Add(OnClickBtnSizeMove);
|
|
|
+ _ui.m_comSelectBox.m_btnSize.onTouchEnd.Add(OnClickBtnSizeEnd);
|
|
|
}
|
|
|
|
|
|
protected override void OnShown()
|
|
@@ -85,7 +93,7 @@ namespace GFGGame
|
|
|
rotationGesture = new RotationGesture(_ui.target);
|
|
|
rotationGesture.onAction.Add(OnRotate);
|
|
|
|
|
|
- _ui.m_ComSelectRes.m_c1.selectedIndex = 0;
|
|
|
+ _ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex = 0;
|
|
|
OnClickBtnChoose();
|
|
|
RefreshList(EnumPhotographType.BG);
|
|
|
UpdateEquipData();
|
|
@@ -99,7 +107,7 @@ namespace GFGGame
|
|
|
/************************************************************UI界面*********************************************************/
|
|
|
private void OnContorllerChanged(EventContext context)
|
|
|
{
|
|
|
- int index = _ui.m_ComSelectRes.m_c1.selectedIndex;
|
|
|
+ int index = _ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex;
|
|
|
RefreshList((EnumPhotographType)index);
|
|
|
}
|
|
|
private void RefreshList(EnumPhotographType index)
|
|
@@ -129,16 +137,17 @@ namespace GFGGame
|
|
|
private void RenderListItem(int index, GObject obj)
|
|
|
{
|
|
|
ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_listData[index]);
|
|
|
- string resPath = ResPathUtil.GetPhotographFPath(itemCfg.res, ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType));
|
|
|
+ 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);
|
|
|
- EnumPhotographType type = (EnumPhotographType)_ui.m_ComSelectRes.m_c1.selectedIndex;
|
|
|
+ EnumPhotographType type = (EnumPhotographType)_ui.m_ComSelectRes.m_comBtnTab.m_c1.selectedIndex;
|
|
|
switch (type)
|
|
|
{
|
|
|
case EnumPhotographType.BG:
|
|
@@ -161,7 +170,7 @@ namespace GFGGame
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- /************************************************************场景*********************************************************/
|
|
|
+ /************************** **********************************场景*********************************************************/
|
|
|
|
|
|
private void OnClickUIBegin(EventContext context)
|
|
|
{
|
|
@@ -175,11 +184,18 @@ namespace GFGGame
|
|
|
|
|
|
hitParentGameObj = hit.collider.name == "BgRes" ? hit.collider.gameObject : hit.collider.transform.parent.gameObject;
|
|
|
distance = Input.mousePosition - Camera.main.WorldToScreenPoint(hitParentGameObj.transform.position);
|
|
|
- Debug.Log("ClickName:" + hitParentGameObj.name);
|
|
|
|
|
|
_ui.m_comSelectBox.target.visible = hitParentGameObj.transform.parent.gameObject == bgParent ? false : true;
|
|
|
- _ui.m_comSelectBox.target.size = SceneController.GetGameObjectSize(hitParentGameObj);
|
|
|
+ if (_ui.m_comSelectBox.target.data == null || _ui.m_comSelectBox.target.data as GameObject != hitParentGameObj)
|
|
|
+ {
|
|
|
+ lastPos = Vector2.zero;
|
|
|
+ // _ui.m_comSelectBox.target.SetScale(1, 1);
|
|
|
+ _ui.m_comSelectBox.target.rotation = hitParentGameObj.transform.rotation.z;
|
|
|
+ _ui.m_comSelectBox.target.size = SceneController.GetGameObjectSize(hitParentGameObj);
|
|
|
+ _ui.m_comSelectBox.target.SetScale(hitParentGameObj.transform.localScale.x, hitParentGameObj.transform.localScale.y);
|
|
|
+ }
|
|
|
|
|
|
+ _ui.m_comSelectBox.target.data = hitParentGameObj;
|
|
|
|
|
|
ControllerSelectBoxPos(hitParentGameObj);
|
|
|
|
|
@@ -229,38 +245,77 @@ namespace GFGGame
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
//选中框的位置
|
|
|
private void ControllerSelectBoxPos(GameObject hitParentGameObj)
|
|
|
{
|
|
|
SceneController.SetGameObjectCenter(hitParentGameObj);
|
|
|
- Debug.Log("物体世界坐标:" + hitParentGameObj.transform.position);
|
|
|
+
|
|
|
//位置:角色、道具、npc全用对应父物体的位置
|
|
|
Vector2 objScreenPos = Camera.main.WorldToScreenPoint(hitParentGameObj.transform.position);
|
|
|
- this.viewCom.GlobalToLocal(objScreenPos);
|
|
|
-
|
|
|
- Debug.Log("物体屏幕坐标:" + hitParentGameObj.transform.position);
|
|
|
- Debug.Log("屏幕高:" + Screen.height);
|
|
|
- // Vector2 localPos = new Vector2(objScreenPos.x, (Screen.height - objScreenPos.y));
|
|
|
Vector2 localPos = this.viewCom.GlobalToLocal(new Vector2(objScreenPos.x, (Screen.height - objScreenPos.y)));
|
|
|
|
|
|
- Debug.Log("localPos:" + localPos);
|
|
|
- Debug.Log("选框坐标:" + _ui.m_comSelectBox.target.position);
|
|
|
-
|
|
|
_ui.m_comSelectBox.target.position = localPos;//(localPos.x, localPos.y);
|
|
|
- Debug.Log("选框坐标:" + _ui.m_comSelectBox.target.position);
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ private void OnClickBtnSizeBegin(EventContext context)
|
|
|
+ {
|
|
|
+
|
|
|
+ Vector2 size = _ui.m_comSelectBox.m_imgBox.size;
|
|
|
+ _startDistance = Mathf.Sqrt(size.x * size.x + size.y * size.y) / 2;// Vector2.Distance(pt1, pt2);
|
|
|
+ Debug.Log("_startDistance:" + _startDistance);
|
|
|
+ }
|
|
|
+ private void OnClickBtnSizeMove(EventContext context)
|
|
|
+ {
|
|
|
+ GameObject gameObject = _ui.m_comSelectBox.target.data as GameObject;
|
|
|
+ if (gameObject == null) return;
|
|
|
+ InputEvent inputEvent = (InputEvent)context.data;
|
|
|
+ Vector2 pt1 = this.viewCom.GlobalToLocal(new Vector2(inputEvent.x, inputEvent.y));
|
|
|
+ Vector2 pt2 = this.viewCom.GlobalToLocal(_ui.m_comSelectBox.target.position);
|
|
|
+ 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, gameObject);
|
|
|
+ Debug.Log("angle:" + angle);
|
|
|
+
|
|
|
+ // Vector2 pt1 = this.viewCom.GlobalToLocal(new Vector2(inputEvent.x, inputEvent.y));
|
|
|
+ // Vector2 pt2 = this.viewCom.GlobalToLocal(_ui.m_comSelectBox.target.position);
|
|
|
+ float dist = Vector2.Distance(pt1, pt2);
|
|
|
+ float ss = dist / _startDistance;
|
|
|
+ float newValue = Mathf.Clamp(ss, 0.1f, 2);
|
|
|
+ ControllerScale(newValue, gameObject);
|
|
|
+
|
|
|
+ }
|
|
|
+ private void OnClickBtnSizeEnd(EventContext context)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //双指缩放
|
|
|
private void OnPinch(EventContext context)
|
|
|
{
|
|
|
if (hitParentGameObj == null) return;
|
|
|
+
|
|
|
GTween.Kill(hitParentGameObj);
|
|
|
|
|
|
PinchGesture gesture = (PinchGesture)context.sender;
|
|
|
float newValue = Mathf.Clamp(hitParentGameObj.transform.localScale.x + gesture.delta, 0.3f, 2);
|
|
|
- if (newValue > MaxScale || newValue < MinScale) return;
|
|
|
- hitParentGameObj.transform.localScale = new Vector3(newValue, newValue, newValue);
|
|
|
- _ui.m_comSelectBox.target.SetScale(newValue, newValue);
|
|
|
+
|
|
|
+ ControllerScale(newValue, hitParentGameObj);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ControllerScale(float value, GameObject gameObject)
|
|
|
+ {
|
|
|
+ if (value > MaxScale || value < MinScale) return;
|
|
|
+ gameObject.transform.localScale = new Vector3(value, value, value);
|
|
|
+ _ui.m_comSelectBox.target.SetScale(value, value);
|
|
|
}
|
|
|
|
|
|
private void OnRotate(EventContext context)
|
|
@@ -269,8 +324,12 @@ namespace GFGGame
|
|
|
GTween.Kill(hitParentGameObj.transform);
|
|
|
|
|
|
RotationGesture gesture = (RotationGesture)context.sender;
|
|
|
- hitParentGameObj.transform.Rotate(Vector3.forward, -gesture.delta, Space.World);
|
|
|
- _ui.m_comSelectBox.target.rotation += -gesture.delta;
|
|
|
+ ControllerRotate(gesture.delta, hitParentGameObj);
|
|
|
+ }
|
|
|
+ private void ControllerRotate(float value, GameObject gameObject)
|
|
|
+ {
|
|
|
+ gameObject.transform.Rotate(Vector3.forward, -value, Space.World);
|
|
|
+ _ui.m_comSelectBox.target.rotation += value;
|
|
|
}
|
|
|
//背景
|
|
|
private void UpdateBgOrNpcOrBorder(EnumPhotographType type, int itemId)
|
|
@@ -337,6 +396,7 @@ namespace GFGGame
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
private void OnClickBtnBg()
|
|
|
{
|
|
|
_ui.m_ComSelectRes.target.visible = false;
|