Esempio n. 1
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));
     }
 }
Esempio n. 2
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);
            }
        }
    }