|
@@ -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()
|
|
|
{
|