Ejemplo n.º 1
0
 public void ConnectWire()
 {
     Debug.Log("Connect wire: " + transform.parent.transform.parent.name + "." + name);
     // If no wire is currently being connected
     if (connectingWire == null)
     {
         //Create new wire
         wire = Instantiate(wirePrefab, wirePrefab.transform.position, Quaternion.identity).GetComponent <WireController>();
         //Create a static reference to new wire
         connectingWire = wire.GetComponent <WireController>();
         // Connect wire and reserve this pin from further connections
         wire = connectingWire.SetConnection(this);
     }
     // If a wire is being connected
     else if (connectingWire != null)
     {
         // Connect this wire to the second pin
         wire = connectingWire.SetConnection(this);
         // If connection was made
         if (wire != null)
         {
             // Remove static reference to wire, so a new wire can be created
             connectingWire = null;
         }
     }
 }
Ejemplo n.º 2
0
 public void MoveWire()
 {
     if (wire.RemoveConnection(this))
     {
         connectingWire = wire;
         wire           = null;
     }
 }
Ejemplo n.º 3
0
    void OnTriggerExit(Collider other)
    {
        WireController comp = other.gameObject.GetComponent <WireController>();

        if (comp != null && touchedControls.Contains(comp))
        {
            touchedControls.Remove(comp);
        }
    }
Ejemplo n.º 4
0
 // Update is called once per frame
 void Update()
 {
     if (!Application.isPlaying)
     {
         if (wire == null)
         {
             wire = GetComponent <WireController>();
         }
         wire.InitConnections();
         wire.Updater(Camera.main.ScreenToWorldPoint(Input.mousePosition));
         // wire.UpdatePosition(Camera.main.ScreenToWorldPoint(Input.mousePosition));
     }
 }
Ejemplo n.º 5
0
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Floor"))
        {
            return;
        }
        WireController comp = other.gameObject.GetComponent <WireController>();

        if (comp != null)
        {
            touchedControls.Add(comp);

            CheckIsElectrified();
        }
    }
Ejemplo n.º 6
0
        protected override void onRemoveCallback(UnityEditorInternal.ReorderableList list)
        {
            if (EditorUtility.DisplayDialog("Warning!", "Are you sure you want to delete this pin? " + list.index, "Yes", "No"))
            {
                var data   = _node.Weights[list.index];
                var output = _node.PinCollection.Get(data.OutputName);
                if (output != null)
                {
                    WireController.Disconnect(output);
                }

                _node.Variables.RemoveByName(data.VariableName);
                _node.PinCollection.Remove(data.OutputName);
                _node.Weights.Remove(data);

                _node.HasChanges = true;
            }
        }
Ejemplo n.º 7
0
        protected override void onRemoveCallback(UnityEditorInternal.ReorderableList list)
        {
            if (EditorUtility.DisplayDialog("Warning!", "Are you sure you want to delete this answer?", "Yes", "No"))
            {
                var element = _node.Answers[list.index];
                var input   = _node.PinCollection.Get(element.InputName);
                var output  = _node.PinCollection.Get(element.OutputName);

                if (input != null)
                {
                    WireController.Disconnect(input);
                }
                if (output != null)
                {
                    WireController.Disconnect(output);
                }

                _node.PinCollection.Remove(element.InputName);
                _node.PinCollection.Remove(element.OutputName);
                _node.Variables.RemoveByName(element.VariableName);
                ReorderableList.defaultBehaviours.DoRemoveButton(list);
            }
        }
Ejemplo n.º 8
0
 private void Start()
 {
     wireController = this.transform.parent.GetComponent <WireController>();
 }
Ejemplo n.º 9
0
    void OnSceneGUI(SceneView scene)
    {
        if (Tools.current != oldTool)
        {
            toolEnabled = false;
            Repaint();
        }

        oldTool = Tools.current;
        Event e = Event.current;

        if (toolEnabled && !Application.isPlaying)
        {
            ToolController.SelectedTool = ToolController.ToolType.WIRE;
            if (e.type == EventType.MouseDown && e.button == 0)
            {
                Debug.Log("Click");
                LayerMask      mask  = LayerMask.GetMask("Connector");
                Ray            ray   = HandleUtility.GUIPointToWorldRay(e.mousePosition);
                RaycastHit2D[] hit2d = Physics2D.RaycastAll(ray.origin, ray.direction, 10000, mask);
                foreach (var hit in hit2d)
                {
                    Debug.Log("Ray hit: " + hit.collider.name);
                    if (wire == null)
                    {
                        PinController pin = hit.collider.GetComponent <PinController>();
                        Undo.RecordObject(pin, "ConnectedWire");
                        pin.ConnectWire();
                        EditorUtility.SetDirty(pin);
                        wire = PinController.connectingWire;
                        Undo.FlushUndoRecordObjects();
                        // GameObject clone  = PrefabUtility.InstantiatePrefab(wirePrefab as GameObject) as GameObject;
                        // wire = clone.GetComponent<WireController>();
                        // PinController pin = hit.collider.GetComponent<PinController>();
                        // wire.SetConnection(pin);
                    }
                    else
                    {
                        PinController pin = hit.collider.GetComponent <PinController>();
                        Undo.RecordObject(pin, "ConnectedWire");
                        pin.ConnectWire();
                        EditorUtility.SetDirty(pin);
                        wire = PinController.connectingWire;
                        Undo.FlushUndoRecordObjects();
                    }
                }
                e.Use();
            }
            if (wire != null)
            {
                wire.Updater(HandleUtility.GUIPointToWorldRay(e.mousePosition).origin);
            }
        }
        else
        {
            if (wire != null)
            {
                DestroyImmediate(wire.gameObject);
            }
        }
    }