Browse Source

打开详情界面时在UI前10厘米,增加自定义ScrollView

蓝色星空 1 year ago
parent
commit
0441e14ec9

+ 6 - 2
Assets/Game/Blue/Command/DeviceDetailsUpdataDataCommand.cs

@@ -1,20 +1,24 @@
 using Blue;
+using UnityEngine;
 
 namespace GHZLangChao
 {
     public class DeviceDetailsUpdataDataCommand : ICommand
     {
         private DeviceParameters DeviceParameter;
-        public DeviceDetailsUpdataDataCommand(DeviceParameters DeviceParameter)
+        private Vector3 currentPos;
+        public DeviceDetailsUpdataDataCommand(DeviceParameters DeviceParameter,Vector3 currentPos)
         {
             this.DeviceParameter = DeviceParameter;
+            this.currentPos = currentPos;
         }
 
         public void OnExcute()
         {
             this.SendEvent(new DeviceDetailsUpdataDataEvent()
             {
-                DeviceParameter = this.DeviceParameter
+                DeviceParameter = this.DeviceParameter,
+                currentPos = this.currentPos
             });
         }
     }

+ 4 - 1
Assets/Game/Blue/Controller/Item/DeviceInfo_Item.cs

@@ -24,7 +24,10 @@ namespace GHZLangChao
         private void ClickDetails()
         {
             DeviceParameter.deviceModel = "NetView400"+i;
-            this.SendCommand(new DeviceDetailsUpdataDataCommand(DeviceParameter)); // 触发事件,打开面板,更新数据
+
+            Vector3 currentPos = transform.position; // 为了将详情面板移动到面前
+
+            this.SendCommand(new DeviceDetailsUpdataDataCommand(DeviceParameter,currentPos)); // 触发事件,打开面板,更新数据
         }
     }
 }

+ 2 - 0
Assets/Game/Blue/Event/DeviceDetailsUpdataDataEvent.cs

@@ -1,9 +1,11 @@
 using Blue;
+using UnityEngine;
 
 namespace GHZLangChao
 {
     public struct DeviceDetailsUpdataDataEvent : IEvent
     {
         public DeviceParameters DeviceParameter;
+        public Vector3 currentPos;
     }
 }

+ 206 - 0
Assets/Game/Blue/Other/CustomVerticleScrollView.cs

@@ -0,0 +1,206 @@
+using System;
+using System.Collections.Generic;
+using SC.XR.Unity.Module_InputSystem;
+using UnityEngine;
+using UnityEngine.EventSystems;
+using UnityEngine.UI;
+
+namespace GHZLangChao
+{
+    public class CustomVerticleScrollView : MonoBehaviour, IPointerDownHandler
+    {
+        public List<string> data = new List<string>();
+
+        public RectTransform content;
+        public List<RoomName_Item> itemList = new List<RoomName_Item>();
+        private Vector3 lastPosition;
+        private float offset;
+
+        public int startIndex = 0;
+        public int endIndex = 0;
+
+        private float size;
+        private float index0Y;
+
+        private bool isMoveItem; // 标记当前的Item是否需要挪动
+        private bool sliderUp;
+        private bool isDrag;
+
+        public float moveSpeed = 2000;
+
+        private void Awake()
+        {
+            for (int i = 0; i < 20; i++) // 添加10个数据
+            {
+                data.Add("4A-"+i.ToString()+"机房");
+            }
+            //data = MachineRoomManager.Instance.listRoomName;
+
+            size = itemList[0].GetComponent<RectTransform>().rect.size.y;
+            index0Y = itemList[0].transform.localPosition.y;
+
+            for (int i = 0; i < itemList.Count; i++) // 显示几个数据(这里为5个)
+            {
+                itemList[i].GetComponentInChildren<Text>().text = data[i];
+            }
+
+            startIndex = 0;
+            endIndex = itemList.Count - 2;
+            DispatcherBase.KeyDownDelegateRegister(downEvent);
+        }
+
+        private void downEvent(InputKeyCode keyCode, InputDevicePartBase part)
+        {
+            if (part.inputDataBase.SCPointEventData.pointerCurrentRaycast.gameObject != null)
+            {
+                checkMoveDown(part.inputDataBase.SCPointEventData.pointerCurrentRaycast.gameObject, part);
+            }
+        }
+
+        public void checkMoveDown(GameObject obj, InputDevicePartBase part)
+        {
+            if (obj)
+            {
+                if (obj.name==this.gameObject.name)
+                {
+                    Debug.Log("OnPointerDown");
+                    isDrag = true;
+                    lastPosition = part.inputDataBase.SCPointEventData.position;
+                }
+                else
+                {
+                    if (obj.transform.parent != null)
+                        checkMoveDown(obj.transform.parent.gameObject, part);
+                }
+            }
+        }
+
+        private void UpdateList(Vector2 position)
+        {
+            offset = position.y - lastPosition.y;
+            offset = Mathf.Clamp(offset, -75, 75); // Item高/2
+            lastPosition = position;
+            for (int i = 0; i < itemList.Count; i++)
+            {
+                itemList[i].transform.localPosition += Vector3.up * offset;
+            }
+
+            if (offset > 0) // 往上滑动
+            {
+                if (!sliderUp && isMoveItem)
+                {
+                    startIndex++;
+                    if (startIndex > data.Count - 1)
+                        startIndex = 0;
+                    isMoveItem = false;
+                }
+                sliderUp = true;
+
+                if (itemList[0].transform.localPosition.y >= index0Y && !isMoveItem)
+                {
+                    isMoveItem = true;
+                    Debug.Log("添加一个Item到末尾");
+                    itemList[itemList.Count - 1].transform.localPosition = itemList[itemList.Count - 2].transform.localPosition - Vector3.up * size;
+                    endIndex++;
+                    if (endIndex > data.Count - 1)
+                        endIndex = 0;
+
+                    itemList[itemList.Count - 1].GetComponentInChildren<Text>().text = data[endIndex];
+                }
+                else
+                {
+                    if (itemList[0].transform.localPosition.y >= index0Y + size)
+                    {
+                        isMoveItem = false;
+                        Debug.Log("将第一个Item放到末尾");
+                        RoomName_Item temp = itemList[0];
+                        temp.transform.localPosition = itemList[itemList.Count - 1].transform.localPosition - Vector3.up * size;
+                        for (int i = 1; i < itemList.Count; i++)
+                        {
+                            itemList[i - 1] = itemList[i];
+                        }
+                        itemList[itemList.Count - 1] = temp;
+
+                        startIndex++;
+                        if (startIndex > data.Count - 1)
+                            startIndex = 0;
+                    }
+                }
+
+            }
+            else if (offset < 0)// 往下滑动
+            {
+                if (sliderUp && isMoveItem)
+                {
+                    endIndex--;
+                    if (endIndex < 0)
+                        endIndex = data.Count - 1;
+                    isMoveItem = false;
+                }
+                sliderUp = false;
+
+                if (itemList[0].transform.localPosition.y <= index0Y && !isMoveItem)
+                {
+                    isMoveItem = true;
+                    Debug.Log("添加一个Item到顶部");
+                    itemList[itemList.Count - 1].transform.localPosition = itemList[0].transform.localPosition + Vector3.up * size;
+                    startIndex--;
+                    if (startIndex < 0)
+                        startIndex = data.Count - 1;
+
+                    itemList[itemList.Count - 1].GetComponentInChildren<Text>().text = data[startIndex];
+                }
+                else
+                {
+                    if (itemList[0].transform.localPosition.y <= index0Y - size)
+                    {
+                        Debug.Log("将最后一个Item放到顶部");
+                        RoomName_Item temp = itemList[itemList.Count - 1];
+                        temp.transform.localPosition = itemList[0].transform.localPosition + Vector3.up * size;
+                        isMoveItem = false;
+                        for (int i = itemList.Count - 1; i >= 1; i--)
+                        {
+                            itemList[i] = itemList[i - 1];
+                        }
+                        itemList[0] = temp;
+
+                        endIndex--;
+                        if (endIndex < 0)
+                            endIndex = data.Count - 1;
+                    }
+                }
+
+            }
+        }
+
+        private Vector3 targetPos;
+        private Vector3 currentPos;
+        private void Update()
+        {
+            if (isDrag)
+            {
+                if (Input.GetMouseButtonUp(0))
+                {
+                    isDrag = false;
+                    targetPos = Input.mousePosition + Vector3.Project(Input.mousePosition - currentPos, Vector3.up) * moveSpeed;
+                }
+                else
+                {
+                    currentPos = Input.mousePosition;
+                    UpdateList(currentPos);
+                }
+            }
+            else
+            {
+                currentPos = Vector3.Lerp(currentPos, targetPos, Time.deltaTime);
+                UpdateList(currentPos);
+            }
+        }
+
+        public void OnPointerDown(PointerEventData eventData)
+        {
+            isDrag = true;
+            lastPosition = eventData.position;
+        }
+    }
+}

+ 11 - 0
Assets/Game/Blue/Other/CustomVerticleScrollView.cs.meta

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

File diff suppressed because it is too large
+ 833 - 93
Assets/Game/ShowChoose/ShowChoose.prefab


+ 2 - 0
Assets/Game/ShowChoose/ShowChoosePanelSelect.cs

@@ -13,6 +13,7 @@ namespace GHZLangChao
         {
             currentRoom_Text.text = UICallManager.Instance.GetMachineRoomList()[0];
 
+            /*
             // 实例化 item
             for (int i = 0;i< UICallManager.Instance.GetMachineRoomList().Count;i++)
             {
@@ -21,6 +22,7 @@ namespace GHZLangChao
                 item.RoomName_Text.text = MachineRoomManager.Instance.listRoomName[i];
                 go.name = UICallManager.Instance.GetMachineRoomList()[i];
             }
+            */
         }
     }
 }

+ 9 - 1
Assets/Game/ShowDevice/ShowDevice.cs

@@ -1,6 +1,7 @@
 using SC.XR.Unity;
 using Blue;
 using GHZLangChao;
+using UnityEngine;
 
 public class ShowDevice : RemoteSingleton<ShowDevice>,IController
 {
@@ -18,8 +19,15 @@ public class ShowDevice : RemoteSingleton<ShowDevice>,IController
             ShowDevice.Instance.gotoWindow(ScenesManager.SceneType.DeviceDetails);
             if(DeviceDetailsControl==null)
                 DeviceDetailsControl = GetComponentInChildren<DeviceDetailsControl>();
+
+            // 更新数据
             DeviceDetailsControl.UpdateData(e.DeviceParameter);
+            // 更新位置
+            DeviceDetailsControl.transform.position = new Vector3(
+                DeviceDetailsControl.transform.position.x,
+                DeviceDetailsControl.transform.position.y,
+                e.currentPos.z-0.1f);
         }).UnRegisterWhenGameObjectDestroyed(gameObject);
     }
-    DeviceDetailsControl DeviceDetailsControl;
+    private DeviceDetailsControl DeviceDetailsControl;
 }

Some files were not shown because too many files changed in this diff