123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731 |
- using BeinLab.Util;
- using DG.Tweening;
- using LitJson;
- using PublicTools.XMLDataBase;
- using ShadowStudio.Model;
- using ShadowStudio.UI;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- using XRTool.UI;
- using XRTool.Util;
- using XRTool.WorldUI;
- namespace ShadowStudio.Tool
- {
- /// <summary>
- /// 黑板类
- /// </summary>
- [RequireComponent(typeof(WorldDlg))]
- public class BoardDlg : UnitySingleton<BoardDlg>
- {
- public WorldDlg dlg;
- public BoardConf boardConf;
- private RectTransform container;
- /// <summary>
- /// 存储窗口的起点和终点
- /// </summary>
- private Dictionary<Vector2, Vector2> cellMap;
- private List<WorldDlg> dlgMap = new List<WorldDlg>();
- protected override void OnDestroy()
- {
- base.OnDestroy();
- if (cellMap != null)
- {
- cellMap.Clear();
- }
- cellMap = null;
- }
- /// <summary>
- /// 初始化窗口
- /// </summary>
- private void InitConf()
- {
- #if UNITY_EDITOR || !UNITY_ANDROID
- TableInterface table = XSql.Instance.OpenTable(ResourcesManager.LocalPath, typeof(BoardConf).Name, ".xml", true);
- if (!table.Open())
- {
- table.Create(typeof(BoardConf).Name);
- }
- var boards = table.FindAllData<BoardConf>();
- if (boards == null || boards.Count < 1)
- {
- boardConf = new BoardConf();
- table.InsertData(boardConf);
- table.Close();
- }
- else
- {
- boardConf = boards[0];
- }
- #else
- string fullPath = Path.Combine(ResourcesManager.LocalPath, typeof(BoardConf).Name+".xml");
- GameNode.Instance. StartCoroutine( XSql.Instance.ReadServerData(fullPath,(List<BoardConf> boards) => {
- if (boards != null && boards.Count > 0)
- {
- boardConf = boards[0];
- dlg.DlgTrans.sizeDelta = boardConf.Boundary.Trans();
- dlg.SetScale(dlg.DlgTrans.sizeDelta);
- }
- }));
- #endif
- }
- private GameObject blackGroud;
- public GameObject BlackGroud
- {
- get
- {
- /*
- if (!blackGroud)
- {
- var dlg = Resources.Load("BackGround");
- if (dlg)
- {
- blackGroud = GameObject.Instantiate(dlg) as GameObject;
- GameNode.Instance.SetParent(ObjNode.WorldCanvas, blackGroud.transform, blackGroud.transform.localPosition, blackGroud.transform.localEulerAngles, blackGroud.transform.localScale);
-
- }
- }*/
- blackGroud = dlg.GetBreadthChild<Transform>("FrontBG").gameObject;
- return blackGroud;
- }
- }
- protected override void Awake()
- {
- base.Awake();
- InitConf();
- dlg = GetComponent<WorldDlg>();
- }
- private static Vector3 initBoard = Vector3.zero;
- //private Button loginOutBtn;
- private Button outRoomBtn;
- private TextMesh roomName;
- private TextMesh roomType;
- public TextMesh roomNum;
- private TextMesh roomPass;
- private TextMesh roomCreator;
- private TextMesh pubRoomType;
- private TextMesh roomExplain;
- private Button createSenceBtn;
- private Button showInfoBtn;
- private Button heidInfoBtn;
- private Button showUserListBtn;
- private Button heidUserListBtn;
- private GameObject UIRoot;
- private GameObject FullUIRoot;
- public GameObject AllInfoObj;
- public GameObject UserListObj;
- private void Start()
- {
- container = dlg.GetBreadthChild<RectTransform>("Container");
- //loginOutBtn = dlg.GetBreadthChild<Button>("LoginOutBtn");
- outRoomBtn = dlg.GetBreadthChild<Button>("OutRoomBtn");
- showInfoBtn = dlg.GetBreadthChild<Button>("ShowInfoBtn");
- heidInfoBtn = dlg.GetBreadthChild<Button>("HeidInfoBtn");
- showInfoBtn.onClick.AddListener(ShowAllInfo);
- heidInfoBtn.onClick.AddListener(HeidAllInfo);
- roomName = dlg.GetBreadthChild<TextMesh>("RoomName");
- roomType = dlg.GetBreadthChild<TextMesh>("RoomType");
- roomNum = dlg.GetBreadthChild<TextMesh>("RoomNum");
- roomPass = dlg.GetBreadthChild<TextMesh>("RoomPass");
- roomCreator = dlg.GetBreadthChild<TextMesh>("RoomCreator");
- pubRoomType = dlg.GetBreadthChild<TextMesh>("PubRoomType");
- roomExplain = dlg.GetBreadthChild<TextMesh>("RoomExplain");
- createSenceBtn = dlg.GetBreadthChild<Button>("CreateSenceBtn");
- showUserListBtn = dlg.GetBreadthChild<Button>("ShowUserListBtn");
- heidUserListBtn = dlg.GetBreadthChild<Button>("HeidUserListBtn");
- if (CommonMethod.roomConfig != null)
- {
- #if UNITY_EDITOR
- roomName.text = CommonMethod.roomConfig.Room_name + " (" + CommonMethod.roomConfig.Id + ")";
- #else
- roomName.text = CommonMethod.roomConfig.Room_name ;
- #endif
- Debug.Log("房间密码"+CommonMethod.roomConfig.Room_password);
- if (string.IsNullOrEmpty(CommonMethod.roomConfig.Room_password))
- {
- roomPass.text = LanguageMgr.Instance.GetMessage("1090").Message;
- }
- else
- {
- if (!string.IsNullOrEmpty(CommonMethod.roomPassWord))
- {
- roomPass.text = CommonMethod.roomPassWord;
- CommonMethod.roomPassWord = "";
- }
- }
- roomCreator.text = CommonMethod.roomConfig.Nick_name;
- if (CommonMethod.roomConfig.Room_explain == "")
- {
- roomExplain.text = LanguageMgr.Instance.GetMessage("1090").Message;
- }
- else
- {
- roomExplain.text = CommonMethod.roomConfig.Room_explain;
- }
- //roomExplain.text = CommonMethod.roomConfig.Room_explain;
- if (int.Parse(CommonMethod.roomConfig.Max_member) < 1)
- {
- CommonMethod.roomConfig.Max_member = "1";
- }
- switch (CommonMethod.roomConfig.Type)
- {
- case "1":
- roomType.text = LanguageMgr.Instance.GetMessage("1036").Message;
- roomNum.text = "1/1";
- pubRoomType.text = LanguageMgr.Instance.GetMessage("1090").Message;
- break;
- case "2":
- roomType.text = LanguageMgr.Instance.GetMessage("1037").Message;
- roomNum.text = (int.Parse(CommonMethod.roomConfig.Number) + 1) + "/" + CommonMethod.roomConfig.Max_member;
- switch (CommonMethod.roomConfig.Room_type)
- {
- case "1":
- pubRoomType.text = LanguageMgr.Instance.GetMessage("1045").Message;
- break;
- case "2":
- pubRoomType.text = LanguageMgr.Instance.GetMessage("1046").Message;
- break;
- default:
- break;
- }
- break;
- }
- }
- createSenceBtn.onClick.AddListener(OnClickCreateSence);
- outRoomBtn.onClick.AddListener(OnClickOutRoom);
- showUserListBtn.onClick.AddListener(ShowUserList);
- heidUserListBtn.onClick.AddListener(HeidUserList);
- if (boardConf != null)
- {
- dlg.DlgTrans.sizeDelta = boardConf.Boundary.Trans();
- dlg.SetScale(dlg.DlgTrans.sizeDelta);
- }
- if (initBoard == Vector3.zero)
- {
- initBoard = transform.localPosition;
- }
- AllInfoObj.SetActive(false);
- UserListObj.SetActive(true);
- showUserListBtn.gameObject.SetActive(false);
- heidUserListBtn.gameObject.SetActive(true);
- Vector3 realPos = new Vector3(0,0,0);
- //if (CScript.App.AppManager.Instance.isRunHolographic)
- //{
- // realPos = OpenXRCamera.Instance.head.TransformPoint(new Vector3(-initBoard.x, -initBoard.y, -initBoard.z / 3f));
- //}
- //else
- //{
- // realPos = OpenXRCamera.Instance.head.TransformPoint(initBoard);
- //}
- realPos = OpenXRCamera.Instance.head.TransformPoint(initBoard);
- transform.position = realPos;
- Vector3 pos = GameSession.Instance.gameHead.position;
- Vector3 forward = (realPos - pos).normalized;
- forward.y = 0;
- transform.forward = forward;
- GetComponent<TransferCell>().DragTransfer += OnDragTransfer;
- OnDragTransfer();
- //selectTarget.gameObject.SetActive(false);
- BlackGroud.SetActive(true);
- WorldDlgContainer.BackGD = BlackGroud;
- WorldDlgContainer.BackGD.GetComponent<MeshRenderer>().material.SetFloat("_Int", 10);
- UIRoot = UnityUtil.GetBreadthChild(this.transform, "UIRoot");
- // UIRoot.SetActive(false);
- FullUIRoot = UnityUtil.GetBreadthChild(this.transform, "FullUIRoot");
- // FullUIRoot.SetActive(false);
- //被zby替换的代码
- //if (ItemView.itemPos != Vector3.zero)
- if (MenuIcon.itemPos != Vector3.zero)
- {
- GameEffect.setAlpha(FullUIRoot, 0, 0.1f);
- GameEffect.setAlpha(UIRoot, 0, 0.1f);
- initScale = dlg.transform.localScale;
- initPos = dlg.transform.position;
- this.gameObject.SetActive(false);
- TimerMgr.Instance.CreateTimer(() =>
- {
- //被zby替换的代码
- //dlg.transform.position = ItemView.itemPos;
- dlg.transform.position = MenuIcon.itemPos;
- dlg.transform.localScale = dlg.transform.localScale / 35;
- this.gameObject.SetActive(true);
- MeshRenderer mr = WorldDlgContainer.BackGD.GetComponent<MeshRenderer>();
- mr.material.DOTiling(new Vector2(1, 1), "_TextureSample0", 1f);
- mr.material.DOOffset(new Vector2(0, 0), "_TextureSample0", 1f);
- dlg.transform.DOMove(initPos, 1f);
- GameEffect.setAlpha(FullUIRoot, 1, 1);
- GameEffect.setAlpha(UIRoot, 1, 1);
- mr.material.DOFloat(4, "_Int", 1f);
- dlg.transform.DOScale(initScale, 1f).OnComplete(() =>
- {
- });
- /*
- dlg.transform.DOScale(dlg.transform.localScale*4, 0.5f).OnComplete(()=> {
- dlg.transform.DOScale(initScale, 1f).OnComplete(()=> {
- GameEffect.setAlpha(FullUIRoot, 1, 1);
- GameEffect.setAlpha(UIRoot, 1, 1);
- PictrueContainer.BackGD.GetComponent<MeshRenderer>().material.DOFloat(4, "_Int", 1f);
- });
- });*/
- }, 0.2f);
- }
- }
- private void OnClickCreateSence()
- {
- if (ItemSenceList.Instance)
- {
- string scenename = "场景" + ItemSenceList.Instance.GetSceneCount();
- WSHandler.Room.CreateScene(scenename);
- }
- }
- private void HeidUserList()
- {
- UserListObj.SetActive(false);
- heidUserListBtn.gameObject.SetActive(false);
- showUserListBtn.gameObject.SetActive(true);
- }
- private void ShowUserList()
- {
- UserListObj.SetActive(true);
- showUserListBtn.gameObject.SetActive(false);
- heidUserListBtn.gameObject.SetActive(true);
- }
- private void HeidAllInfo()
- {
- AllInfoObj.SetActive(false);
- }
- private void ShowAllInfo()
- {
- AllInfoObj.SetActive(true);
- }
- private void OnClickOutRoom()
- {
- TransferCell.CancelCell();
- if (ConsoleDlg.Instance)
- {
- ConsoleDlg.Instance.CloseScan();
- }
- AgoraRTCManager.Instance.LeaveChannel();
- AgoraRTCManager.Instance.ClearDatas();
- // AppManager.Instance.MeshPoint.SetActive(false);
- Debug.Log("OutRoom 1");
- DestoryARcamera();
- // WSHandler.Room.ExitRoom();
- ShowViewMgr.Instance.SelfLeaveRoom();
- WSHandler.roomCloes();
- Vector3 posRoom = outRoomBtn.transform.position;
- Debug.Log("OutRoom 2");
- //被zby替换的代码
- //ItemView.itemPos = posRoom;
- MenuIcon.itemPos = posRoom;
- if (WorldDlgContainer.BackGD!= null&& WorldDlgContainer.BackGD.GetComponent<MeshRenderer>() == null)
- Debug.Log("Not BackGD");
- Debug.Log("OutRoom 3");
- // SceneManager.LoadSceneAsync("Home", LoadSceneMode.Additive);
- if (posRoom != Vector3.zero)
- {
-
- // MeshRenderer mr = WorldDlgContainer.BackGD.GetComponent<MeshRenderer>();
- MeshRenderer mr = BlackGroud.GetComponent<MeshRenderer>();
- Debug.Log("OutRoom 4");
- mr.material.DOTiling(new Vector2(0.205f, 0.23f), "_TextureSample0", 0.5f).SetDelay<Tween>(0.2f);
- mr.material.DOOffset(new Vector2(0.3F, 0.3F), "_TextureSample0", 0.5f).SetDelay<Tween>(0.2f);
- mr.material.DOFloat(10, "_Int", 0.5f).SetDelay<Tween>(0.2f);
- Debug.Log("OutRoom 5");
- dlg.transform.DOMove(posRoom, 0.5f).SetDelay<Tween>(0.2f).OnComplete<Tween>(() =>
- {
- ShowViewMgr.Instance.LoadHomeSence();
- }).SetDelay<Tween>(0.3f);
- Debug.Log("OutRoom 6");
- dlg.transform.DOScale(initScale / 30, 0.5f).SetDelay<Tween>(0.3f);
- Debug.Log("OutRoom 7");
- if (GameNode.Instance)
- {
- if (GameNode.Instance.GoodsContainerMap != null && GameNode.Instance.GoodsContainerMap.Count > 0)
- {
- foreach (int index in GameNode.Instance.GoodsContainerMap.Keys)
- {
- if (GameNode.Instance.GoodsContainerMap[index] != null&& GameNode.Instance.GoodsContainerMap[index].GetInstace())
- {
- GameNode.Instance.GoodsContainerMap[index].GetInstace().transform.DOMove(posRoom, 0.5f).SetDelay<Tween>(0.2f).OnComplete<Tween>(() =>
- {
- });
- GameNode.Instance.GoodsContainerMap[index].GetInstace().transform.DOScale(initScale / 30, 0.5f);
- }
- }
- Debug.Log("OutRoom 8");
- }
- }
- else
- {
- if (GameNode.Instance.GoodsContainerMap != null && GameNode.Instance.GoodsContainerMap.Count > 0)
- {
- foreach (int index in GameNode.Instance.GoodsContainerMap.Keys)
- {
- if (GameNode.Instance.GoodsContainerMap[index] != null)
- {
- GameNode.Instance.GoodsContainerMap[index].GetInstace().transform.DOMove(posRoom, 0.5f).SetDelay<Tween>(0.2f).OnComplete<Tween>(() =>
- {
- });
- GameNode.Instance.GoodsContainerMap[index].GetInstace().transform.DOScale(initScale / 30, 0.5f);
- }
- }
- Debug.Log("OutRoom 9");
- }
- }
- }
- else
- {
- ShowViewMgr.Instance.LoadHomeSence();
- Debug.Log("OutRoom 10");
- }
- }
- public void DestoryARcamera()
- {
- if (CheckDeviceType.checkIsPhone())
- {
- return;
- }
- if (ConsoleDlg.Instance!=null && ConsoleDlg.Instance.vufora_camera != null)
- {
- if (DeviceType.type == "Phone")
- {
- }
- else
- {
- ConsoleDlg.Instance.vufora_camera.enabled = false;
- }
- }
- if (ConsoleDlg.Instance != null && ConsoleDlg.Instance.vufora_camera != null)
- {
- Destroy(ConsoleDlg.Instance.vufora_camera.gameObject);
- }
- }
- private void OnClickLoginOut()
- {
- TransferCell.CancelCell();
- DestoryARcamera();
- WSHandler.Room.ExitRoom();
- ShowViewMgr.Instance.SelfLeaveRoom();
- WSHandler.roomCloes();
- WSHandler.clientClosed();
- ShowViewMgr.Instance.LoadLoginSence();
- }
- public void OnDragTransfer(TransferState state = TransferState.Doing)
- {
- if (GameNode.Instance)
- {
- GameNode.Instance.transform.position = transform.position;
- GameNode.Instance.transform.rotation = transform.rotation;
- transform.localPosition = Vector3.zero;
- transform.localRotation = Quaternion.identity;
- }
- else
- {
- GameNode.InitComplte += () =>
- {
- OnDragTransfer();
- };
- }
- }
- public void EnterCreatSceneBtn()
- {
- GetComponent<TransferCell>().DragStop();
- }
- /// <summary>
- /// 添加此窗口到黑板的合适位置
- /// 判断是否和已在窗口上的存在交叉
- /// 如果没有任何交叉,则加入
- /// 如果有交叉,移动至合适的位置
- /// Vector2 dis = b.center - a.center;
- /// if (((int) a.width + (int) b.width) / 2 > Math.Abs(dis.x) && ((int) a.height + (int) b.height) / 2 > Math.Abs(dis.y))
- /// </summary>
- /// <param name="dlg"></param>
- public void AddDlg(WorldDlg dlg, Vector3 prefectPos, bool isUser)
- {
- if (!dlgMap.Contains(dlg))
- {
- //dlgMap.Sort((dlg1, dlg2) => { return SortDlg(dlg1, dlg2, prefectPos); });
- bool isNeedMove = false;
- for (int i = dlgMap.Count - 1; i >= 0; i--)
- {
- var oldDlg = dlgMap[i];
- if (!oldDlg)
- {
- dlgMap.RemoveAt(i);
- continue;
- }
- Vector2 offsize = dlg.DlgTrans.anchoredPosition - oldDlg.DlgTrans.anchoredPosition;
- if ((oldDlg.DlgSize.x + dlg.DlgSize.x) / 2 > Math.Abs(offsize.x) &&
- (oldDlg.DlgSize.y + dlg.DlgSize.y) / 2 > Math.Abs(offsize.y))
- {
- isNeedMove = true;
- break;
- }
- }
- //for (int i = 0; i < dlgMap.Count; i++)
- //{
- // var oldDlg = dlgMap[i];
- // Vector2 offsize = dlg.DlgTrans.anchoredPosition - oldDlg.DlgTrans.anchoredPosition;
- // if ((oldDlg.DlgSize.x + dlg.DlgSize.x) / 2 > Math.Abs(offsize.x) &&
- // (oldDlg.DlgSize.y + dlg.DlgSize.y) / 2 > Math.Abs(offsize.y))
- // {
- // isNeedMove = true;
- // break;
- // }
- //}
- ///如果存在重叠的情况,需要移动
- ///计算合适的空余位置,并移动至合适的位置中去
- if (isNeedMove)
- {
- prefectPos.z = -(boardConf.Adsorption - boardConf.ShowDis) / 2;
- dlg.ContainerState = ContainerState.Free;
- }
- else
- {
- prefectPos.z = boardConf.ShowDis;
- dlgMap.Add(dlg);
- dlg.isOnBoard = true;
- }
- dlg.DlgTrans.DOKill();
- dlg.DlgTrans.DOAnchorPos3D(prefectPos, 0.3f).OnComplete(() =>
- {
- if (isUser && dlg.Transfer)
- {
- dlg.Transfer.DisActiveCell();
- }
- });
- }
- }
- private Vector3 initScale;
- private Vector3 initPos;
- /// <summary>
- /// 对窗口进行排序,排序规则:按照距离center点的远近进行排序
- /// </summary>
- /// <param name="dlg1"></param>
- /// <param name="dlg2"></param>
- /// <returns></returns>
- private int SortDlg(WorldDlg dlg1, WorldDlg dlg2, Vector2 center)
- {
- float dis1 = Vector2.Distance(dlg1.DlgTrans.anchoredPosition, center);
- float dis2 = Vector2.Distance(dlg2.DlgTrans.anchoredPosition, center);
- return dis1 > dis2 ? 1 : dis1 < dis2 ? -1 : 0;
- }
- public void RemoveDlg(WorldDlg dlg)
- {
- if (dlgMap.Contains(dlg))
- {
- dlgMap.Remove(dlg);
- dlg.isOnBoard = false;
- }
- }
- /// <summary>
- /// 尝试申请一个空间
- /// </summary>
- /// <param name="startPos"></param>
- /// <param name="endPos"></param>
- /// <param name="offset"></param>
- /// <returns></returns>
- public bool TryGetSpace(Vector2 startPos, Vector2 endPos, out Vector2 offset)
- {
- offset = Vector2.zero;
- if ((endPos.x - startPos.x) > container.rect.size.x || (endPos.y - startPos.y) > container.rect.size.y)
- {
- UnityLog.Instance.LogError("图片尺寸超过黑板大小!" + startPos.ToString() + "_" + endPos.ToString());
- return false;
- }
- if (cellMap == null)
- {
- cellMap = new Dictionary<Vector2, Vector2>();
- Vector2 tmpStart = startPos;
- while (tmpStart.x < 0)
- {
- tmpStart.x += boardConf.CellSize.x / 2;
- }
- while (tmpStart.y > 0)
- {
- tmpStart.y -= boardConf.CellSize.y / 2;
- }
- tmpStart.x = UnityUtil.GetNearst(tmpStart.x, boardConf.CellSize.x);
- tmpStart.y = UnityUtil.GetNearst(tmpStart.y, boardConf.CellSize.y);
- offset = tmpStart - startPos;
- return true;
- }
- else
- {
- Vector2 tmpStart = startPos;
- while (tmpStart.x < 0)
- {
- tmpStart.x += boardConf.CellSize.x / 2;
- }
- while (tmpStart.x > container.rect.size.x - (endPos.x - startPos.x))
- {
- tmpStart.x -= boardConf.CellSize.x / 2;
- }
- while (tmpStart.y > 0)
- {
- tmpStart.y -= boardConf.CellSize.y / 2;
- }
- while (tmpStart.y < (endPos.y - startPos.y) - container.rect.size.y)
- {
- tmpStart.y += boardConf.CellSize.y / 2;
- }
- tmpStart.x = UnityUtil.GetNearst(tmpStart.x, boardConf.CellSize.x);
- tmpStart.y = UnityUtil.GetNearst(tmpStart.y, boardConf.CellSize.y);
- if (cellMap.ContainsKey(tmpStart))
- {
- return false;
- }
- foreach (var item in cellMap)
- {
- Rect a = new Rect(item.Key, item.Value - item.Key);
- Rect b = new Rect(tmpStart, endPos - startPos);
- if (UnityUtil.IsCrossLine(a, b))
- {
- //UnityLog.Instance.Log("相交:" + a.ToString() + b.ToString(), 3);
- return false;
- }
- }
- offset = tmpStart - startPos;
- return true;
- }
- }
- /// <summary>
- /// 处理一个窗口是否可以放置到黑板上
- /// </summary>
- /// <param name="pic"></param>
- /// <param name="v"></param>
- public void ExecutePicture(WorldDlg pic, bool isDraging, bool isUser)
- {
- if (boardConf == null)
- {
- return;
- }
- ///相对位置
- Vector3 anchor3D = pic.DlgTrans.anchoredPosition3D;
- Vector3 rpos = anchor3D;
- if (pic.ContainerState == ContainerState.BoardMove)
- {
- pic.transform.forward = Vector3.Lerp(pic.transform.forward, transform.forward, Time.deltaTime * 6.66f);
- Vector3 pos = pic.DlgTrans.anchoredPosition3D;
- if (pos.z > boardConf.PressPonit)
- {
- pos.z = boardConf.PressPonit;
- }
- rpos = pos;
- pic.DlgTrans.anchoredPosition3D = pos;
- }
- if ((Math.Abs(rpos.z) <= boardConf.Adsorption && Vector3.Angle(transform.forward, pic.transform.forward) < boardConf.Angle) ||
- dlg.IsIntersect(pic))
- {
- if (isDraging)
- {
- pic.ContainerState = ContainerState.BoardMove;
- }
- else
- {
- pic.ContainerState = ContainerState.OnBoard;
- }
- }
- else if (dlg.IsIntersect(pic))
- {
- if (isDraging)
- {
- pic.transform.forward = Vector3.Lerp(pic.transform.forward, transform.forward, Time.deltaTime * 6.66f);
- }
- else
- {
- pic.ContainerState = ContainerState.OnBoard;
- }
- }
- else
- {
- if (!isDraging)
- {
- pic.ContainerState = ContainerState.Free;
- }
- else
- {
- pic.ContainerState = ContainerState.FreeMove;
- }
- }
- if (pic.ContainerState == ContainerState.OnBoard)
- {
- pic.transform.DORotate(transform.eulerAngles, 0.3f);
- if (!pic.isOnBoard)
- {
- AddDlg(pic, pic.DlgTrans.anchoredPosition3D, isUser);
- }
- else
- {
- pic.DlgTrans.DOKill();
- Vector3 pos = pic.DlgTrans.anchoredPosition3D;
- pos.z = boardConf.ShowDis;
- pic.DlgTrans.DOAnchorPos3D(pos, 0.3f).OnComplete(() =>
- {
- if (isUser&& pic.Transfer)
- {
- pic.Transfer.DisActiveCell();
- }
- });
- }
- }
- else
- {
- if (pic.isOnBoard)
- {
- RemoveDlg(pic);
- }
- }
- }
- }
- }
|