Exemplo n.º 1
0
        private void NoticeTargetPos(string connectItemName)
        {
            var elements = ElementController.Instence.GetElements <ConnectItem>(connectItemName, true);

            Debug.Assert(elements != null);
            foreach (var item in elements)
            {
                if (!ConnectUtil.HaveConnected(item, firstItem))
                {
                    firstItem.Notice(item.transform);

                    if (!noticed.Contains(item.transform))
                    {
                        noticed.Add(item.transform);
                    }
                }
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
        public void TryComplete()
        {
            var list = new ConnectItem[elements.Length];

            //找到所有的组合,并判断是否已经连接
            for (int i = 0; i < connectGroup.Length; i++)
            {
                var groupi    = connectGroup[i];
                var itemAName = groupi.p1;
                var itemBName = groupi.p2;
                var itemAID   = Array.IndexOf(elements, itemAName);
                var itemBID   = Array.IndexOf(elements, itemBName);

                ConnectItem itemA = collectNodeFeature.elementPool.Find(x => x.Name == itemAName && x is ConnectItem) as ConnectItem;
                ConnectItem itemB = collectNodeFeature.elementPool.Find(x => x.Name == itemBName && x is ConnectItem) as ConnectItem;

                if (itemA != null && itemB != null)
                {
                    if (!ConnectUtil.HaveConnected(itemA, itemB))
                    {
                        return;
                    }
                    else
                    {
                        list[itemAID] = itemA;
                        list[itemBID] = itemB;
                    }
                }
                else
                {
                    return;
                }
            }

            OnConnectOK(list);
            OnEndExecute(false);
        }