Beispiel #1
0
    public static RaycastHit MostRecentNonNullHit;                                   // used so we can do rotation without looking at the thing
    public static void RunStuffPlacing(bool AllowFineRotation = true, bool HideWhenInvalidPlacement = false, bool AllowEdgePlacement = false)
    {
        if (ThingBeingPlaced == null)
        {
            return;
        }

        PollRotationInput(AllowFineRotation);

        RaycastHit hit;

        if (Physics.Raycast(FirstPersonInteraction.Ray(), out hit, Settings.ReachDistance, FirstPersonInteraction.IgnorePlayerLayermask))
        {
            DisableRotation = false;
            MoveThingBeingPlaced(hit, HideWhenInvalidPlacement, AllowEdgePlacement);
        }
        else if (HideWhenInvalidPlacement)
        {
            ThingBeingPlaced.transform.position = new Vector3(0, -10000, 0); CurrentPlacementIsValid = false;
        }

        if (hit.collider != null)
        {
            MostRecentNonNullHit = hit;
        }

        if (Input.GetButtonDown("Place"))
        {
            PlaceThingBeingPlaced();
        }
    }
    private void HighlightLookedAtBoard()
    {
        RaycastHit hit;

        if (Physics.Raycast(FirstPersonInteraction.Ray(), out hit, Settings.ReachDistance, Wire.IgnoreWiresLayermask))
        {
            if (hit.collider.tag == "CircuitBoard")
            {
                GameObject highlightthis = hit.collider.gameObject;
                if (Input.GetButton("Mod"))
                {
                    GameObject RootObject = hit.collider.transform.root.gameObject;
                    if (RootObject.tag == "CircuitBoard") // protection from mounts
                    {
                        highlightthis = hit.collider.transform.root.gameObject;
                    }
                }
                if (highlightthis != highlightedboard)
                {
                    RemoveOutlineFromLookedAtBoard();
                    highlightedboard = highlightthis;
                    StuffPlacer.OutlineObject(highlightedboard, OutlineColor.blue);
                }
            }
            else
            {
                RemoveOutlineFromLookedAtBoard();
            }
        }
        else
        {
            RemoveOutlineFromLookedAtBoard();
        }
    }
    private static bool PlacingGhostWasHiddenBeforeConnecting = ComponentPlacer.ShowPlacingGhost; // necessary to avoid BUGS!

    private static void ConnectionInitial()
    {
        RaycastHit hit;

        if (!Physics.Raycast(FirstPersonInteraction.Ray(), out hit, Settings.ReachDistance, Wire.IgnoreWiresLayermask))
        {
            return;
        }
        if (hit.collider.tag == "Input" || hit.collider.tag == "Output") // if it's an input or output...
        {
            SelectedPeg = hit.collider.gameObject;                       // ..make it the selected peg
            StuffPlacer.OutlineObject(SelectedPeg);

            PegBeingLookedAt = null; // fixes SetPegBeingLookedAt removing the outline

            if (AutoHidePlacingGhostWhileConnecting)
            {
                StuffPlacer.DeleteThingBeingPlaced();
                PlacingGhostWasHiddenBeforeConnecting = ComponentPlacer.ShowPlacingGhost;
                ComponentPlacer.ShowPlacingGhost      = false;
            }
            StuffRotater.AllowedToDoRotation = false; // so you can rotate wires while placing them
            StuffDeleter.AllowedToDoDeleting = false; // prevents a bug with how null is not the same as destroyed

            SoundPlayer.PlaySoundAt(Sounds.ConnectionInitial, SelectedPeg);
        }
        else
        {
            SoundPlayer.PlaySoundGlobal(Sounds.FailDoSomething);

            DoneConnecting();
        }
    }
Beispiel #4
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);
            }
        }
    public static void CloneBoard()
    {
        RaycastHit hit;

        if (Physics.Raycast(FirstPersonInteraction.Ray(), out hit, Settings.ReachDistance, Wire.IgnoreWiresLayermask))
        {
            if (hit.collider.tag == "CircuitBoard")
            {
                GameObject CloneThis = hit.collider.gameObject;
                if (Input.GetButton("Mod"))
                {
                    GameObject RootBoard = hit.collider.transform.root.gameObject;
                    if (RootBoard.tag == "CircuitBoard")
                    {
                        CloneThis = RootBoard;
                    }
                }

                GameObject newboard = Object.Instantiate(CloneThis, new Vector3(0, -2000, 0), Quaternion.identity); // instantiated so far away so that nothing can interfere with connection.findpoints's raycasts
                RecalculateClustersOfBoard(newboard);
                BoardPlacer.NewBoardBeingPlaced(newboard);

                GameplayUIManager.UIState = UIState.BoardBeingPlaced;
                return;
            }
        }

        SoundPlayer.PlaySoundGlobal(References.Sounds.FailDoSomething);
        GameplayUIManager.UIState = UIState.None;
    }
Beispiel #6
0
    public void Initialize()
    {
        RaycastHit hit;

        Physics.Raycast(FirstPersonInteraction.Ray(), out hit, Settings.ReachDistance, Wire.IgnoreWiresLayermask);
        if (hit.collider == null || (hit.collider.tag != "CircuitBoard" && hit.collider.tag != "World" && hit.collider.tag != "PlaceOnlyBoard")) // all valid tags of things to place on
        {
            SoundPlayer.PlaySoundGlobal(References.Sounds.FailDoSomething);
            GameplayUIManager.UIState = UIState.None;
            return;
        }

        GameplayUIManager.UIState = UIState.NewBoardMenu;

        // to make sure there's no disconnect between the UI and the what it represents
        SizeXSlider.value = SizeX;
        SizeYSlider.value = SizeY;
        SizeXInput.text   = SizeX.ToString();
        SizeYInput.text   = SizeY.ToString();

        NewBoardCanvas.enabled = true;

        // select the size x input field so that the user can immediately begin typing
        SizeXInput.ActivateInputField();
    }
Beispiel #7
0
    public static void SaveBoard()
    {
        RaycastHit hit;

        if (Physics.Raycast(FirstPersonInteraction.Ray(), out hit, Settings.ReachDistance, Wire.IgnoreWiresLayermask))
        {
            if (hit.collider.tag == "CircuitBoard")
            {
                GameObject SaveThis = hit.collider.gameObject;
                if (Input.GetButton("Mod"))
                {
                    GameObject RootBoard = hit.collider.transform.root.gameObject;
                    if (RootBoard.tag == "CircuitBoard")
                    {
                        SaveThis = RootBoard;
                    }                                                              // make sure to check for circuitboard in case of mounts
                }

                Instance.SaveBoardAs(SaveThis);
                return;
            }
            else
            {
                SoundPlayer.PlaySoundGlobal(References.Sounds.FailDoSomething);
            }
        }
        else
        {
            SoundPlayer.PlaySoundGlobal(References.Sounds.FailDoSomething);
        }

        GameplayUIManager.UIState = UIState.None;
    }
Beispiel #8
0
    private void HighlightLookedAtBoard()
    {
        RaycastHit hit;

        if (Physics.Raycast(FirstPersonInteraction.Ray(), out hit, Settings.ReachDistance, Wire.IgnoreWiresLayermask))
        {
            if (hit.collider.tag == "CircuitBoard")
            {
                if (hit.collider.gameObject != lookingatboard)
                {
                    RemoveOutlineFromLookedAtBoard();
                    previouscoloroflookedatboard = hit.collider.GetComponent <CircuitBoard>().GetBoardColor;
                    lookingatboard = hit.collider.gameObject;
                    lookingatboard.AddComponent <cakeslice.Outline>().color = 1;
                    lookingatboard.GetComponent <CircuitBoard>().SetBoardColor(Colors[SelectedThing]);
                }
            }
            else
            {
                RemoveOutlineFromLookedAtBoard();
            }
        }
        else
        {
            RemoveOutlineFromLookedAtBoard();
        }
    }
Beispiel #9
0
    static void ButtonDownPre()
    {
        RaycastHit hit;

        Physics.Raycast(FirstPersonInteraction.Ray(), out hit, Settings.ReachDistance);
        VisualButtonBeingPressed = hit.collider.GetComponent <Button>().visualbutton;
        OriginalLocalPositionOfVisualButtonBeingPressed = VisualButtonBeingPressed.transform.localPosition;
    }
Beispiel #10
0
 private void RunToggleSelection()
 {
     if (Input.GetMouseButtonDown(0) &&
         State.CurrentState == States.Selecting &&
         Physics.Raycast(FirstPersonInteraction.Ray(), out var hit, Settings.ReachDistance, Wire.IgnoreWiresLayermask) &&
         (hit.collider.tag == "Input" || hit.collider.tag == "Output"))
     {
         Selection.Instance.Toggle(hit.collider.gameObject);
     }
 }
    private static void RotateThroughBoard()
    {
        RaycastHit hit;

        if (Physics.Raycast(FirstPersonInteraction.Ray(), out hit, Settings.ReachDistance, Wire.IgnoreWiresLayermask))
        {
            if (hit.collider.tag == "World" || hit.collider.tag == "CircuitBoard")
            {
                SoundPlayer.PlaySoundGlobal(Sounds.FailDoSomething); return;
            }
            GameObject component = ComponentPlacer.FullComponent(hit.collider);
            if (component.transform.parent == null)
            {
                return;
            }
            if (!AllowFlippingOneSidedComponents)
            {
                if (!component.GetComponent <IsThroughComponent>())
                {
                    SoundPlayer.PlaySoundGlobal(Sounds.FailDoSomething); return;
                }
            }

            component.transform.localEulerAngles += new Vector3(0, 0, 180);
            component.transform.Translate(Vector3.up * 0.15f, Space.Self);

            BoxCollider[] colliders = component.GetComponentsInChildren <BoxCollider>();
            StuffPlacer.SetStateOfBoxColliders(colliders, false);

            if (StuffPlacer.GameObjectIntersectingStuffOrWouldDestroyWires(component, true))
            {
                component.transform.localEulerAngles += new Vector3(0, 0, 180);
                component.transform.Translate(Vector3.up * 0.15f, Space.Self);
                StuffPlacer.SetStateOfBoxColliders(colliders, true);
                SoundPlayer.PlaySoundGlobal(Sounds.FailDoSomething);
                return;
            }

            FloatingPointRounder.RoundIn(component);

            StuffPlacer.SetStateOfBoxColliders(colliders, true);

            RedrawCircuitGeometryOf(component);
            DestroyIntersectingConnections(component);
            MegaMeshManager.RecalculateGroupsOf(component);

            SoundPlayer.PlaySoundAt(Sounds.RotateSomething, component);
        }
        else
        {
            SoundPlayer.PlaySoundGlobal(Sounds.FailDoSomething);
        }
    }
    public static bool AllowedToDoRotation = true; // for when you're placing wires
    public static void RunGameplayRotation()
    {
        if (!AllowedToDoRotation)
        {
            return;
        }
        if (StuffPlacer.OkayToPlace)
        {
            return;
        }

        if (Input.GetButtonDown("Rotate"))
        {
            RaycastHit hit;
            if (Physics.Raycast(FirstPersonInteraction.Ray(), out hit, Settings.ReachDistance, FirstPersonInteraction.IgnorePlayerLayermask))
            {
                RotateThing(hit.collider.gameObject);
            }
            else
            {
                SoundPlayer.PlaySoundGlobal(Sounds.FailDoSomething);
            }
        }

        // kind of awkward that both this class and StuffPlacer are f*****g with RotationLocked. TODO do it better
        if (Input.GetButtonDown("RotationLock"))
        {
            RaycastHit hit;
            if (Physics.Raycast(FirstPersonInteraction.Ray(), out hit, Settings.ReachDistance, Wire.IgnoreWiresLayermask))
            {
                if (StuffPlacer.GetThingBeingPlaced == null || !StuffPlacer.OkayToPlace) // so that if there's something we're placing we can lock rotation to that and not what's under it
                {
                    if (hit.collider.tag == "World" || hit.collider.tag == "CircuitBoard")
                    {
                        SetRotationLockToFalseIfThingBeingPlacedIsNull(); return;
                    }
                    StuffPlacer.SetRotationLockAngles(ComponentPlacer.FullComponent(hit.collider));
                    StuffPlacer.RotationLocked = true;
                }
            }
            else
            {
                StuffPlacer.RotationLocked = false;
            }

            SelectionMenu.Instance.SetRotationLockText();
        }

        if (Input.GetButtonDown("RotateThroughBoard"))
        {
            RotateThroughBoard();
        }
    }
Beispiel #13
0
        private Vector3 GetScale()
        {
            if (Physics.Raycast(FirstPersonInteraction.Ray(), out var hit))
            {
                IGConsole.Log(hit.transform.localPosition);
                IGConsole.Log(hit.transform.localScale);
                IGConsole.Log(hit.transform.localEulerAngles);

                ModUtilities.Graphics.CreateSphere(hit.point);
            }

            return(Vector3.back);
        }
 public static void Run()
 {
     if (Input.GetButtonDown("LookThroughBoard"))
     {
         RaycastHit hit;
         if (Physics.Raycast(FirstPersonInteraction.Ray(), out hit, Settings.ReachDistance, Wire.IgnoreWiresLayermask))
         {
             Initial(hit);
         }
     }
     else if (Input.GetButtonUp("LookThroughBoard"))
     {
         Final();
     }
 }
Beispiel #15
0
 public static bool AllowedToDoDeleting = true; // for wire placing
 public static void RunGameplayDeleting()
 {
     if (Input.GetButtonDown("Delete"))
     {
         RaycastHit hit;
         if (Physics.Raycast(FirstPersonInteraction.Ray(), out hit, Settings.ReachDistance, FirstPersonInteraction.IgnorePlayerLayermask) && AllowedToDoDeleting)
         {
             DeleteThing(hit.collider.gameObject);
         }
         else
         {
             SoundPlayer.PlaySoundGlobal(Sounds.FailDoSomething);
         }
     }
 }
Beispiel #16
0
    void ColorBoard()
    {
        RemoveOutlineFromLookedAtBoard();

        RaycastHit hit;

        if (Physics.Raycast(FirstPersonInteraction.Ray(), out hit, Settings.ReachDistance, Wire.IgnoreWiresLayermask))
        {
            if (hit.collider.tag == "CircuitBoard")
            {
                hit.collider.GetComponent <CircuitBoard>().SetBoardColor(Colors[SelectedThing]);
            }
        }

        Done();
    }
    // run every frame the button is held down
    private void Update()
    {
        TicksDownFor++;
        if (TicksDownFor <= MinDownTicks)
        {
            return;
        }

        RaycastHit hit;

        Physics.Raycast(FirstPersonInteraction.Ray(), out hit, Settings.ReachDistance, Wire.IgnoreWiresLayermask);
        if (!Input.GetButton("Interact") || hit.collider == null || hit.collider.gameObject != gameObject) // if we let go of the interact key or if the player is no longer lookin here
        {
            ButtonUp();
        }
    }
Beispiel #18
0
        private void RunComponentMoving()
        {
            if (Input.GetMouseButtonDown(1) &&
                Input.GetKey(KeyCode.LeftControl) &&
                State.CurrentState == States.None &&
                Physics.Raycast(FirstPersonInteraction.Ray(), out var hit, Settings.ReachDistance) &&
                hit.collider.tag != "CircuitBoard" &&
                hit.collider.tag != "Wire")
            {
                var comp = ComponentPlacer.FullComponent(hit.collider);

                if (comp.GetComponent <ObjectInfo>() != null)
                {
                    Mover.BeginMove(comp);
                }
            }
        }
Beispiel #19
0
    public void Initialize()
    {
        RaycastHit hit;

        if (Physics.Raycast(FirstPersonInteraction.Ray(), out hit, Settings.ReachDistance, Wire.IgnoreWiresLayermask))
        {
            if (hit.collider.tag == "CircuitBoard")
            {
                GameObject StackThis = hit.collider.gameObject;
                if (Input.GetButton("Mod"))
                {
                    GameObject RootBoard = hit.collider.transform.root.gameObject;
                    if (RootBoard.tag == "CircuitBoard")
                    {
                        StackThis = RootBoard;
                    }                                                               // make sure to check for circuitboard in case of mounts
                }

                BoardBeingStacked             = StackThis;
                BoardBeingStackedCircuitBoard = StackThis.GetComponent <CircuitBoard>();
                AllSubBoardsInvolvedWithStacking.Add(BoardBeingStacked);
                BoardBeingStacked.AddComponent <cakeslice.Outline>(); // added before we get the copy so clones will have it too
                BoardBeingStackedCopy = Instantiate(BoardBeingStacked, new Vector3(-1000, -1000, -1000), BoardBeingStacked.transform.rotation);

                GameplayUIManager.UIState = UIState.StackBoardMenu;
                Canvas.enabled            = true;
                IterationsInput.ActivateInputField();

                StuffPlacer.SetObjectOutlineColor(BoardBeingStacked, OutlineColor.blue);

                // so that you don't accidentally crash your PC when you first stacked on a simple board then you go to stack on a complex board. Don't set iterations directly for
                // the reason outlined below
                TrueIterations = 1;

                // Using Invoke because for some reason this MUST be done a frame later. If it is not, outputs have duplicated geometry
                Invoke("ShittyHackThatShouldntExist", 0.01f);
                return;
            }
        }

        SoundPlayer.PlaySoundGlobal(Sounds.FailDoSomething);
        GameplayUIManager.UIState = UIState.None;
    }
Beispiel #20
0
    public static void PlaceThingBeingPlaced()
    {
        if (!OkayToPlace)
        {
            // shitty hack to prevent the sound playing in specific circumstances that are undesirable
            RaycastHit hit;
            Physics.Raycast(FirstPersonInteraction.Ray(), out hit, Settings.ReachDistance, Wire.IgnoreWiresLayermask);
            if (hit.collider == null || hit.collider.tag != "Interactable")
            {
                SoundPlayer.PlaySoundGlobal(Sounds.FailDoSomething);
            }

            return;
        }

        RemoveOutlineFromObject(ThingBeingPlaced, true); // destoryimmediate used so that if what you place has you looking at a peg, you'll be able to get it highlighted
        SetStateOfAllBoxCollidersFromThingBeingPlaced(true);
        OutlinesOfThingBeingPlaced     = null;
        BoxCollidersOfThingBeingPlaced = null;

        FloatingPointRounder.RoundIn(ThingBeingPlaced, true);

        // mega mesh stuff
        MegaMeshManager.AddComponentsIn(ThingBeingPlaced);
        foreach (VisualUpdaterWithMeshCombining visualboi in ThingBeingPlaced.GetComponentsInChildren <VisualUpdaterWithMeshCombining>())
        {
            visualboi.AllowedToCombineOnStable = true;
        }
        SnappingPeg.TryToSnapIn(ThingBeingPlaced);

        if (MostRecentPlacementWasOnBoard)
        {
            SoundPlayer.PlaySoundAt(Sounds.PlaceOnBoard, ThingBeingPlaced);
        }
        else
        {
            SoundPlayer.PlaySoundAt(Sounds.PlaceOnTerrain, ThingBeingPlaced);
        }

        ThingBeingPlaced = null;
    }
Beispiel #21
0
        public static void ColorBoard(PaintBoardMenu __instance)
        {
            if (Physics.Raycast(FirstPersonInteraction.Ray(), out var raycastHit, Settings.ReachDistance, Wire.IgnoreWiresLayermask) && raycastHit.collider.tag == "CircuitBoard")
            {
                var netObj = raycastHit.collider.GetComponent <NetObject>();
                IGConsole.Log("Hit " + netObj);

                if (netObj == null)
                {
                    return;
                }

                var color = __instance.Colors[__instance.SelectedThing];

                Network.SendPacket(new PaintBoardPacket
                {
                    BoardID = netObj.NetID,
                    Color   = color
                });
            }
        }
    private static bool ShowPreWiringPegOutlines = true; //= Settings.Get("ShowPreWiringPegOutlines", true);
    // if we're looking at a peg, set PegBeingLookedAt to that. Otherwise, set it to null.
    private static void SetPegBeingLookedAt()
    {
        RaycastHit hit;

        if (Physics.Raycast(FirstPersonInteraction.Ray(), out hit, Settings.ReachDistance, Wire.IgnoreWiresLayermask))
        {
            if (hit.collider.gameObject == PegBeingLookedAt || hit.collider.gameObject == SelectedPeg)
            {
                return;
            }

            if (hit.collider.tag == "Input" || hit.collider.tag == "Output")
            {
                StuffPlacer.RemoveOutlineFromObject(PegBeingLookedAt); // in case you look directly from one peg to another peg
                PegBeingLookedAt = hit.collider.gameObject;

                if (SelectedPeg == null && !ShowPreWiringPegOutlines)
                {
                    return;
                }
                StuffPlacer.OutlineObject(PegBeingLookedAt);

                // play the sound only if we're in the middle of making a connection
                if (SelectedPeg != null)
                {
                    SoundPlayer.PlaySoundAt(Sounds.ConnectionInitial, PegBeingLookedAt);
                }
            }
            else
            {
                StuffPlacer.RemoveOutlineFromObject(PegBeingLookedAt);
                PegBeingLookedAt = null;
            }
        }
        else
        {
            StuffPlacer.RemoveOutlineFromObject(PegBeingLookedAt);
            PegBeingLookedAt = null;
        }
    }
Beispiel #23
0
    // TODO move to a better class
    public void PickComponent()
    {
        RaycastHit hit;

        if (Physics.Raycast(FirstPersonInteraction.Ray(), out hit, Settings.ReachDistance, 1 << 0))
        {
            GameObject ThingWeHit = ComponentPlacer.FullComponent(hit.collider);

            ObjectInfo buttcrack = ThingWeHit.GetComponent <ObjectInfo>();
            if (buttcrack != null)
            {
                for (int i = 0; i < PlaceableObjectTypes.Count; i++)
                {
                    if (PlaceableObjectTypes[i] == buttcrack.ComponentType)
                    {
                        SelectedThing = i + 1;
                        UpdateSelectedThing();
                        MenuClosesIn = SelectionMenuOpenTime;
                        return;
                    }
                }
            }
        }
    }
Beispiel #24
0
    public void RunNewBoardMenu()
    {
        // caching system makes sure a new board is only generated on frames where it matters
        if (PreviousSizeX != SizeX || CachedSizeY != SizeY)
        {
            BoardFunctions.CreateNewBoard(SizeX, SizeY);
        }
        PreviousSizeX = SizeX;
        CachedSizeY   = SizeY;

        // create the menu if space or enter or V are pressed
        if (Input.GetButtonDown("Jump") || Input.GetButtonDown("Submit") || Input.GetButtonDown("BoardMenu") || Input.GetButtonDown("Confirm")) // the last check is so you can place the same new board by double tapping v
        {
            Done();
        }

        // cancel if esc is pressed
        if (Input.GetButtonDown("Cancel"))
        {
            Done(true);
        }

        // tab between input fields
        if (Input.GetButtonDown("tab"))
        {
            if (SizeXInput.isFocused)
            {
                SizeYInput.ActivateInputField();
            }
            else
            {
                SizeXInput.ActivateInputField();
            }
        }

        if (GameplayUIManager.ScrollUp(false))
        {
            if (Input.GetButton("Mod"))
            {
                SizeXSlider.value += 1;
            }
            else
            {
                SizeYSlider.value += 1;
            }
        }

        if (GameplayUIManager.ScrollDown(false))
        {
            if (Input.GetButton("Mod"))
            {
                SizeXSlider.value -= 1;
            }
            else
            {
                SizeYSlider.value -= 1;
            }
        }

        // lets you rotate in the new board menu
        StuffPlacer.PollRotationInput();
        BoardPlacer.PollForBoardRotation();
        BoardPlacer.PollForBoardFlatness();

        RaycastHit hit;

        if (Physics.Raycast(FirstPersonInteraction.Ray(), out hit, Settings.ReachDistance))
        {
            StuffPlacer.MoveThingBeingPlaced(hit, false, true);
        }
    }
Beispiel #25
0
        private void RunWireHighlight()
        {
            if (Input.GetMouseButtonDown(0) && Input.GetKey(KeyCode.LeftControl) && State.CurrentState == States.None)
            {
                foreach (var item in Highlighted)
                {
                    Highlighter.StopHighlight(item);
                }
                Highlighted.Clear();

                if (Physics.Raycast(FirstPersonInteraction.Ray(), out var hit, Settings.ReachDistance) &&
                    hit.collider.tag != "CircuitBoard")
                {
                    var wire = hit.collider.GetComponent <Wire>();

                    if (wire != null) //Clicked on wire, highlight it and both ends
                    {
                        HighlightWire(wire);
                    }
                    else
                    {
                        var input  = hit.collider.GetComponent <CircuitInput>();
                        var output = hit.collider.GetComponent <CircuitOutput>();

                        if (input != null) //Clicked on input peg, highlight it and all wires connected to it
                        {
                            foreach (var item in input.IIConnections.Cast <Wire>().Concat(input.IOConnections.Cast <Wire>()))
                            {
                                HighlightWire(item);
                            }
                        }
                        else if (output != null) //Clicked on output peg, highlight it and all wires connected to it
                        {
                            foreach (var item in output.GetIOConnections())
                            {
                                HighlightWire(item);
                            }
                        }
                        else //Clicked on component, highlight inputs and outputs and all wires connected to it
                        {
                            var component = ComponentPlacer.FullComponent(hit.collider);

                            foreach (var item in Mover.GetWires(component))
                            {
                                HighlightWire(item);
                            }
                        }
                    }
                }
            }

            void HighlightWire(Wire wire)
            {
                Highlight(wire.gameObject, 0);

                HighlightComponent(wire.Point1);
                HighlightComponent(wire.Point2);
            }

            void HighlightComponent(Transform wireReference)
            {
                Highlight(wireReference.parent.gameObject, 3);

                if (wireReference.parent.parent?.tag != "CircuitBoard" && wireReference.parent.parent != null)
                {
                    Highlight(wireReference.parent.parent.gameObject, 2);
                }
            }

            void Highlight(GameObject obj, int clr)
            {
                Highlighted.Add(obj);
                Highlighter.Highlight(obj, clr);
            }
        }