Пример #1
0
        public void SetActiveItem(IPortParent item)
        {
            this.pickedUpItem = item;
            List <IPortItem> olditems = new List <IPortItem>();

            if (connectedNodes.ContainsKey(item))
            {
                List <IPortItem> needClear = new List <IPortItem>();
                for (int i = 0; i < connectedNodes[item].Count; i++)
                {
                    IPortItem nodeItem = connectedNodes[item][i];
                    needClear.Add(nodeItem);

                    IPortItem target = nodeItem.ConnectedNode;
                    connectedNodes[target.Body].Remove(target);
                    Debug.Log(connectedNodes[item][i].Detach());

                    olditems.Add(nodeItem);
                    olditems.Add(target);
                }

                for (int i = 0; i < needClear.Count; i++)
                {
                    connectedNodes[item].Remove(needClear[i]);
                }
                if (onDisconnected != null)
                {
                    onDisconnected.Invoke(needClear.ToArray());
                }
            }
        }
 public bool Attach(IPortItem item)
 {
     item.ConnectedNode = this;
     ConnectedNode      = item;
     _render.enabled    = _renderActive;
     return(true);
 }
 private bool FindInstallableNode(IPortItem item, out IPortItem node)
 {
     Collider[] colliders = Physics.OverlapSphere(item.Pos, sphereRange, 1 << LayerConst.nodeLayer);
     if (colliders != null && colliders.Length > 0)
     {
         foreach (var collider in colliders)
         {
             IPortItem tempNode = collider.GetComponent <IPortItem>();
             if (tempNode == null)
             {
                 //Debug.Log(collider + " have no iportItem");
                 continue;
             }
             //主被动动连接点,非自身点,相同名,没有建立连接
             if (tempNode.Body != item.Body && tempNode.ConnectedNode == null)
             {
                 if (tempNode.connectAble.Find((x) => x.itemName == item.Body.Name && x.nodeId == item.NodeID) != null)
                 {
                     node = tempNode;
                     return(true);
                 }
             }
         }
     }
     node = null;
     return(false);
 }
        public void TryConnect()
        {
            if (activeNode != null && activeNode != null)
            {
                if (targetNode.Attach(activeNode))
                {
                    activeNode.ResetTransform();

                    if (!connectedNodes.ContainsKey(pickedUpItem))
                    {
                        connectedNodes[pickedUpItem] = new List <IPortItem>();
                    }

                    connectedNodes[pickedUpItem].Add(activeNode);

                    if (!connectedNodes.ContainsKey(targetNode.Body))
                    {
                        connectedNodes[targetNode.Body] = new List <IPortItem>();
                    }

                    connectedNodes[targetNode.Body].Add(targetNode);

                    if (onConnected != null)
                    {
                        onConnected.Invoke(new IPortItem[] { activeNode, targetNode });
                    }
                    activeNode = null;
                    targetNode = null;
                }
            }
        }
Пример #5
0
        public IPortItem Detach()
        {
            IPortItem outItem = ConnectedNode;

            if (ConnectedNode != null)
            {
                ConnectedNode.ConnectedNode = null;
                ConnectedNode = null;
            }
            return(outItem);
        }
        public IPortItem Detach()
        {
            _render.enabled = false;
            IPortItem outItem = ConnectedNode;

            if (ConnectedNode != null)
            {
                ConnectedNode.ConnectedNode = null;
                ConnectedNode = null;
            }
            return(outItem);
        }
Пример #7
0
 public bool FindConnectableObject()
 {
     if (pickedUpItem != null)
     {
         IPortItem tempNode;
         foreach (var item in pickedUpItem.ChildNodes)
         {
             if (FindInstallableNode(item, out tempNode))
             {
                 activeNode = item;
                 targetNode = tempNode;
                 return(true);
             }
         }
     }
     activeNode = null;
     targetNode = null;
     return(false);
 }
        public void Update()
        {
            timeSpan += Time.deltaTime;
            if (pickedUpItem != null && timeSpan > spanTime)
            {
                timeSpan = 0f;

                if (!FindConnectableObject())
                {
                    if (targetNode != null)
                    {
                        onDisMatch.Invoke(targetNode);
                    }
                    if (activeNode != null)
                    {
                        onDisMatch.Invoke(activeNode);
                    }
                    activeNode = null;
                    targetNode = null;
                }
            }
        }
Пример #9
0
 public void SetDisableItem(IPortParent item)
 {
     pickedUpItem = null;
     targetNode   = null;
     activeNode   = null;
 }
Пример #10
0
 void OnDisMath(IPortItem item)
 {
     onDisMatch.Invoke(item.Render);
 }
Пример #11
0
 void OnMatch(IPortItem item)
 {
     onMatch.Invoke(item.Render);
 }
Пример #12
0
 public bool Attach(IPortItem item)
 {
     item.ConnectedNode = this;
     ConnectedNode      = item;
     return(true);
 }
 void OnDisMath(IPortItem item)
 {
     item.Render.enabled = false;
     onDisMatch.Invoke(item.Render.gameObject);
 }
 void OnMatch(IPortItem item)
 {
     item.Render.enabled = true;
     onMatch.Invoke(item.Render.gameObject);
 }