示例#1
0
        public void RemoveObject(sBehaviour obj, bool tryReconnect)
        {
            var node = obj as Node;

            if (node != null)
            {
                if (!Nodes.Remove(node))
                {
                    Debug.LogWarning("Removed node but was not in list: " + node.name, node);
                    return;
                }

                if (tryReconnect && node.InConnections.Count == 1 && node.OutConnections.Count == 1)
                {
                    // In a simple case of <x>--<y>--<z> where we are removing <y>, we can connect <x> and <z>
                    ConnectNodes(node.InConnections[0].ThisNode, node.OutConnections[0].NextNode, node.InConnections[0].Configuration);
                }

                node.Destroy();
                var go = node.gameObject;
                DestroyImmediate(node);
                if (go.transform.childCount == 0 && go.GetComponents <Component>().Length == 1)
                {
                    DestroyImmediate(go);
                }
            }
            var connection = obj as NodeConnection;

            if (connection != null)
            {
                DisconnectNodes(connection.ThisNode, connection.NextNode);
            }
            //Think();
        }
示例#2
0
        private sBehaviour DoConnectOrCreateNodes(Event myEvent, Vector3 hitPoint, Vector3 hitNormal)
        {
            if (!myEvent.control)
            {
                return(null);
            }

            var  currentSelection      = GetCurrentlySelectedNodes();
            Node currentlySelectedNode = null;

            if (!currentSelection.IsNullOrEmpty() && currentSelection.Count == 1)
            {
                currentlySelectedNode = currentSelection[0];
            }

            int selectionMouseNum = 2;

            if (_placementKey.Value == ENodePlacementKey.RightMouse)
            {
                selectionMouseNum = 1;
            }
            sBehaviour createdObject = null;

            if (myEvent.type == EventType.MouseDown)
            {
                if (myEvent.button != selectionMouseNum)
                {
                    return(null);
                }
                if (_currentHoverNode == null)
                {
                    // Create a new node and set the selection to it
                    createdObject = FocusedRoadNetwork.CreateNewNode(hitPoint, Vector3.up, currentlySelectedNode, _currentConfiguration, FocusedRoadNetwork.CurrentNodeConfiguration);
                    SetCurrentlySelectedNodes((Node)createdObject);
                    myEvent.Use();
                    FocusedRoadNetwork.ForceThink();
                }
                else if (_currentHoverNode != null)
                {
                    // Connect two nodes
                    var currentSelectedNode = currentlySelectedNode;
                    if (currentSelectedNode != null)
                    {
                        if (myEvent.button == selectionMouseNum && myEvent.control)
                        {
                            createdObject = FocusedRoadNetwork.ConnectNodes(currentSelectedNode, _currentHoverNode,
                                                                            _currentConfiguration);
                        }
                    }
                    myEvent.Use();
                    SetCurrentlySelectedNodes(_currentHoverNode);
                    FocusedRoadNetwork.ForceThink();
                }
            }
            return(createdObject);
        }
示例#3
0
 public static bool IsHovering(sBehaviour obj)
 {
     return(obj == _currentHoverNode);
 }
示例#4
0
 public static bool IsSelected(sBehaviour obj)
 {
     return(Selection.objects.Contains(obj) || Selection.objects.Contains(obj.gameObject));
 }