Пример #1
0
        private void TryConnect(ConnectItem otherItem)
        {
            if (!Input.GetMouseButtonDown(0))
            {
                return;
            }
            ConnectItem element1   = firstItem;
            ConnectItem element2   = otherItem;
            bool        canConnect = false;

            ConnectNode.PointGroup groupInfo = null;
            var node = SuarchOneNode(element1.Name, element2.Name, out groupInfo);

            if (node != null)
            {
                canConnect = ConnectUtil.TryConnect(element1, element2, groupInfo);
                node.TryComplete();
            }
            ClearStarteds();

            if (!canConnect && onError != null)
            {
                onError.Invoke(string.Format("{0}和{1}两点不需要连接", element1, element2));
            }
        }
Пример #2
0
        private void QuickConnectItems()
        {
            ConnectItem[] list = null;
            if (collectNodeFeature.finalGroup != null)
            {
                list = Array.ConvertAll(collectNodeFeature.finalGroup, x => x as ConnectItem);
            }
            else
            {
                list = new ConnectItem[elements.Length];
            }

            //找到所有的组合,并判断是否已经连接
            for (int i = 0; i < connectGroup.Length; i++)
            {
                var groupi = connectGroup[i];
                var idA    = Array.IndexOf(elements, groupi.p1);
                var idB    = Array.IndexOf(elements, groupi.p2);
                var itemA  = list[idA] as ConnectItem;
                var itemB  = list[idB] as ConnectItem;

                if (ConnectUtil.HaveConnected(itemA, itemB))
                {
                    continue;
                }

                var itemAName = groupi.p1;
                var itemBName = groupi.p2;

                itemA = itemA != null ? itemA : collectNodeFeature.elementPool.Find(x => x.Name == itemAName && x is ConnectItem && x.OperateAble) as ConnectItem;
                itemB = itemB != null ? itemB : collectNodeFeature.elementPool.Find(x => x.Name == itemBName && x is ConnectItem && x.OperateAble) as ConnectItem;

                Debug.Assert(itemA != null && itemB != null);

                var connected = ConnectUtil.TryConnect(itemA, itemB, groupi);

                Debug.Assert(connected);

                list[idA] = itemA;
                list[idB] = itemB;
            }

            OnConnectOK(list);
        }
Пример #3
0
        private IEnumerator AutoConnectItems()
        {
            ConnectItem[] list = new ConnectItem[elements.Length];
            Debug.Log("自动连接未完成部分");
            for (int i = 0; i < connectGroup.Length; i++)
            {
                var groupi = connectGroup[i];
                var idA    = Array.IndexOf(elements, groupi.p1);
                var idB    = Array.IndexOf(elements, groupi.p2);
                var itemA  = list[idA] as ConnectItem;
                var itemB  = list[idB] as ConnectItem;

                if (ConnectUtil.HaveConnected(itemA, itemB))
                {
                    continue;
                }

                var itemAName = groupi.p1;
                var itemBName = groupi.p2;

                itemA = itemA != null ? itemA : collectNodeFeature.elementPool.Find(x => x.Name == itemAName && x is ConnectItem && x.OperateAble) as ConnectItem;
                itemB = itemB != null ? itemB : collectNodeFeature.elementPool.Find(x => x.Name == itemBName && x is ConnectItem && x.OperateAble) as ConnectItem;

                Debug.Assert(itemA != null && itemB != null);

                var parent = itemA.GetInstanceID() > itemB.GetInstanceID() ? itemA : itemB;

                var lineRender = ConnectUtil.TryConnect(itemA, itemB, groupi);
                for (float timer = 0; timer < autoTime; timer += Time.deltaTime)
                {
                    var pos = Vector3.Lerp(itemA.transform.position, itemB.transform.position, timer / autoTime);
                    lineRender.SetPositions(new Vector3[] { itemA.transform.position, pos });
                    yield return(null);
                }

                list[idA] = itemA;
                list[idB] = itemB;
            }
            OnConnectOK(list);
            OnEndExecute(false);
        }