public static void DestroyIntersectingConnections(GameObject PlacedObject)
    {
        BoxCollider[]     boxes          = PlacedObject.GetComponentsInChildren <BoxCollider>();
        List <GameObject> WiresDestroyed = new List <GameObject>();

        foreach (BoxCollider box in boxes)
        {
            Vector3    center      = box.transform.TransformPoint(box.center);
            Vector3    halfextents = Vector3.Scale(box.size, box.transform.lossyScale) / 2;
            Vector3    direction   = box.transform.up;
            Quaternion orientation = box.transform.rotation;

            RaycastHit[] hits = Physics.BoxCastAll(center, halfextents, direction, orientation, 1); // not sure why maxdistance needs to be 1 here but 0 doesn't register ANY wire collisions. Possibly something to do with how thin their colliders are?
            foreach (RaycastHit hit in hits)
            {
                if (hit.collider.tag == "Wire")
                {
                    // manually check connections, just in case the boxcast hits a false positive
                    if (!hit.collider.GetComponent <Wire>().CanFindPoints())
                    {
                        if (!WiresDestroyed.Contains(hit.collider.gameObject))
                        {
                            WiresDestroyed.Add(hit.collider.gameObject);
                            StuffDeleter.DestroyWire(hit.collider.gameObject);
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 2
0
        private void DeleteBoard()
        {
            if (Physics.Raycast(FirstPersonInteraction.Ray(), out var raycastHit, Settings.ReachDistance, 769) && StuffDeleter.AllowedToDoDeleting && raycastHit.collider.gameObject.tag == "CircuitBoard")
            {
                var board = raycastHit.collider.gameObject;

                BoardFunctions.SetMostRecentlyDeletedBoard(board);

                BoardFunctions.DestroyAllWiresConnectedToBoardButNotPartOfIt(board);
                MegaMeshManager.RemoveComponentsImmediatelyIn(board);

                CircuitInput[]  componentsInChildren  = board.GetComponentsInChildren <CircuitInput>();
                CircuitOutput[] componentsInChildren2 = board.GetComponentsInChildren <CircuitOutput>();

                foreach (CircuitInput input in componentsInChildren)
                {
                    StuffDeleter.DestroyInput(input);
                }

                foreach (CircuitOutput output in componentsInChildren2)
                {
                    StuffDeleter.DestroyOutput(output);
                }

                GameObject.Destroy(board);

                SoundPlayer.PlaySoundGlobal(Sounds.DeleteSomething);
            }
        }
Ejemplo n.º 3
0
        public void Do()
        {
            var board = NetObject.GetByNetId(BoardID);

            if (board == null)
            {
                return;
            }

            BoardFunctions.DestroyAllWiresConnectedToBoardButNotPartOfIt(board.gameObject);
            MegaMeshManager.RemoveComponentsImmediatelyIn(board.gameObject);

            CircuitInput[]  componentsInChildren  = board.GetComponentsInChildren <CircuitInput>();
            CircuitOutput[] componentsInChildren2 = board.GetComponentsInChildren <CircuitOutput>();

            foreach (CircuitInput input in componentsInChildren)
            {
                StuffDeleter.DestroyInput(input);
            }

            foreach (CircuitOutput output in componentsInChildren2)
            {
                StuffDeleter.DestroyOutput(output);
            }

            GameObject.Destroy(board.gameObject);
        }
    public static void DestroyBoardBeingPlaced()
    {
        ReferenceObject.transform.parent = null; // without this line the referenceobject is left on the board and you are unable to delete it without move board
        if (BoardBeingPlaced == null)
        {
            return;
        }

        // so that we don't end up with empty clusters when deleting boards.
        // this code is from stuffdeleter.cs. TODO: merge in a nice way
        CircuitInput[]  inputs  = BoardBeingPlaced.GetComponentsInChildren <CircuitInput>();
        CircuitOutput[] outputs = BoardBeingPlaced.GetComponentsInChildren <CircuitOutput>();
        foreach (CircuitInput input in inputs)
        {
            StuffDeleter.DestroyInput(input);
        }
        foreach (CircuitOutput output in outputs)
        {
            StuffDeleter.DestroyOutput(output);
        }

        BoardBeingPlaced.transform.parent = null; // this is done so that when StuffPlacer sets the BoxCollidersOfThingBeingPlaced it doesn't get the box collider from the old board. Maybe a better way would be DestroyImmediate but the documentation is really insistant that you don't use that so IDK. Man... the extent to which stuff in this codebase is interdependant on other stuff in unintuitive ways really bothers me. I'll need to refactor the refactor at this rate...

        Object.Destroy(BoardBeingPlaced);
        StuffPlacer.ResetReferences();
    }
Ejemplo n.º 5
0
    // called once per frame
    public static void DoInteraction()
    {
        if (Input.GetButtonDown("BoardMenu"))
        {
            BoardMenu.Instance.InitializeBoardMenu();
            Done();
            return;
        }

        if (Input.GetButtonDown("PickComponent"))
        {
            SelectionMenu.Instance.PickComponent();
        }

        if (Input.GetButtonDown("Interact"))
        {
            RaycastHit hit;
            if (Physics.Raycast(Ray(), out hit, Settings.ReachDistance, IgnorePlayerLayermask))
            {
                if (hit.collider.tag == "Interactable") // if the cast hits an interactable such as a button or lever, interact with it
                {
                    hit.collider.GetComponent <Interactable>().Interact();
                    return; // so we can't place stuff too, as they are bound to the same key
                }
            }
        }

        if (Input.GetButtonDown("Zoom"))
        {
            FirstPersonCamera.fieldOfView = 10;
            FirstPersonController.Instance.m_MouseLook.XSensitivity /= 3;
            FirstPersonController.Instance.m_MouseLook.YSensitivity /= 3;
        }
        if (Input.GetButtonUp("Zoom"))
        {
            SettingsApplier.Instance.LoadFOV();
            SettingsApplier.Instance.LoadXSensitivity();
            SettingsApplier.Instance.LoadYSensitivity();
        }

        if (Input.GetButtonDown("Cancel"))
        {
            PauseMenu.Instance.PauseGame();
        }

        if (Input.GetButtonDown("UndoBoardDelete"))
        {
            BoardFunctions.RestoreMostRecentlyDeletedBoard();
            return;
        }

        ComponentPlacer.RunComponentPlacing();
        WirePlacer.RunWirePlacing();
        StuffDeleter.RunGameplayDeleting();
        StuffRotater.RunGameplayRotation();
        SelectionMenu.Instance.RunBuildMenu();
        LookThroughBoard.Run();
    }
 private void DestroySnappedConnection()
 {
     if (SnappedConnection == null)
     {
         return;
     }
     StuffDeleter.DestroyWire(SnappedConnection);
     DestroyImmediate(SnappedConnection.gameObject); // without this, rotating a snapping peg will make its wire get drawn with the new geometry for a frame
 }
Ejemplo n.º 7
0
        protected override void ApplyInner()
        {
            foreach (var wire in GetWires())
            {
                DeletedWires.Add(new DeletedWire(wire.Point1, wire.Point2));
                StuffDeleter.DestroyWire(wire);
            }

            SoundPlayer.PlaySoundGlobal(Sounds.DeleteSomething);
        }
Ejemplo n.º 8
0
        public override void Do()
        {
            var wire = NetObject.GetByNetId(Packet.WireNetID)?.gameObject;

            if (wire == null)
            {
                return;
            }

            StuffDeleter.DestroyWire(wire);
        }
Ejemplo n.º 9
0
        public virtual void Undo()
        {
            if (Created != null)
            {
                foreach (var item in Created)
                {
                    StuffDeleter.DestroyWire(item);
                }

                SoundPlayer.PlaySoundGlobal(Sounds.DeleteSomething);
            }
        }
    // finds all connections connected to an input or output which is a child of BoardBeingPlaced. If that connection does not have BoardBeingPlaced above it in the heirarchy, destroy it
    public static void DestroyAllWiresConnectedToBoardButNotPartOfIt(GameObject board)
    {
        CircuitInput[]  Inputs  = board.GetComponentsInChildren <CircuitInput>();
        CircuitOutput[] Outputs = board.GetComponentsInChildren <CircuitOutput>();

        // annoying InvalidOperationException protection
        List <InputInputConnection>  IIConnectionsToDestroy = new List <InputInputConnection>();
        List <InputOutputConnection> IOConnectionsToDestroy = new List <InputOutputConnection>();

        foreach (CircuitInput input in Inputs)
        {
            foreach (InputInputConnection connection in input.IIConnections)
            {
                if (!StuffConnector.IsChildOf(connection.transform, board.transform))
                {
                    IIConnectionsToDestroy.Add(connection);
                }
            }

            foreach (InputOutputConnection connection in input.IOConnections)
            {
                if (!StuffConnector.IsChildOf(connection.transform, board.transform))
                {
                    IOConnectionsToDestroy.Add(connection);
                }
            }
        }

        foreach (CircuitOutput output in Outputs)
        {
            foreach (InputOutputConnection connection in output.GetIOConnections())
            {
                if (!StuffConnector.IsChildOf(connection.transform, board.transform))
                {
                    IOConnectionsToDestroy.Add(connection);
                }
            }
        }

        foreach (InputInputConnection connection in IIConnectionsToDestroy)
        {
            StuffDeleter.DestroyIIConnection(connection);
        }
        foreach (InputOutputConnection connection in IOConnectionsToDestroy)
        {
            StuffDeleter.DestroyIOConnection(connection);
        }
    }
Ejemplo n.º 11
0
        private void DestroyInvalidWiresOnBoard(GameObject board)
        {
            foreach (var iiCon in board.GetComponents <InputInputConnection>())
            {
                if (!StuffConnecter.CanConnect(iiCon.gameObject))
                {
                    StuffDeleter.DestroyIIConnection(iiCon);
                }
            }

            foreach (var ioCon in board.GetComponents <InputOutputConnection>())
            {
                if (!StuffConnecter.CanConnect(ioCon.gameObject))
                {
                    StuffDeleter.DestroyIOConnection(ioCon);
                }
            }
        }
Ejemplo n.º 12
0
        protected override void CircuitLogicUpdate()
        {
            var ChildInputs = GetComponentsInChildren <CircuitInput>();

            if (!this.Inputs[2].On && IIC != null)
            {
                StuffDeleter.DestroyIIConnection(IIC);
                IIC = null;
            }

            if (GetComponentsInChildren <Wire>().Length < 1 && this.Inputs[2].On)
            {
                InputInputConnection inputInputConnection = Instantiate(Prefabs.Wire, base.transform).AddComponent <InputInputConnection>();
                inputInputConnection.Input1 = ChildInputs[0];
                inputInputConnection.Input2 = ChildInputs[1];
                inputInputConnection.DrawWire();
                inputInputConnection.unbreakable = true;
                StuffConnector.LinkConnection(inputInputConnection);
                IIC = inputInputConnection;
            }
        }
    public static void RecalculateClustersOfBoard(GameObject board)
    {
        foreach (WireCluster cluster in board.GetComponentsInChildren <WireCluster>())
        {
            cluster.transform.parent = null;
            Object.Destroy(cluster.gameObject);
        }

        // get all the stuff that needs to have its clusters recalculated
        CircuitInput[]  inputs  = board.GetComponentsInChildren <CircuitInput>();
        CircuitOutput[] outputs = board.GetComponentsInChildren <CircuitOutput>();
        Wire[]          Wires   = board.GetComponentsInChildren <Wire>();

        // clear the connections of each input and output, since they'll still have stuff from their cloned boards
        foreach (CircuitInput input in inputs)
        {
            input.IIConnections.Clear();
            input.IOConnections.Clear();
        }
        foreach (CircuitOutput output in outputs)
        {
            output.ClearIOConnections();
        }

        // have the connections find their new points, since they'll still have their points set as the boards they were cloned from
        foreach (Wire wire in Wires)
        {
            wire.FindPoints();
        }

        // this needs to be done because SnappingPeg.SnappedConnection is not serialized, and cloning it can cause bugs because of this.
        SnappedConnection[] SnappedConnections = board.GetComponentsInChildren <SnappedConnection>();
        foreach (SnappedConnection connection in SnappedConnections)
        {
            connection.SetThisAsSnappedConnectionOfPegs();
        }

        StuffDeleter.RecalculateClustersFromInputs(inputs); // todo: since we've already gotten the lists of wires, it would be more efficient to pass them to this function instead of letting it re-find them
    }
Ejemplo n.º 14
0
        public override void Do()
        {
            var obj = NetObject.GetByNetId(Packet.ComponentNetID).gameObject;

            var interactable = obj.GetComponentInChildren <Interactable>();

            if (interactable is DisplayInteractable)
            {
                EditDisplayColorMenu.Instance.DoneMenu();
            }

            CircuitInput[]  componentsInChildren  = obj.GetComponentsInChildren <CircuitInput>();
            CircuitOutput[] componentsInChildren2 = obj.GetComponentsInChildren <CircuitOutput>();
            foreach (CircuitInput input in componentsInChildren)
            {
                StuffDeleter.DestroyInput(input);
            }
            foreach (CircuitOutput output in componentsInChildren2)
            {
                StuffDeleter.DestroyOutput(output);
            }

            GameObject.Destroy(obj);
        }