private static void PlaceNewWire()
    {
        WireBeingPlaced = Object.Instantiate(Prefabs.Wire);
        StuffPlacer.OutlineObject(WireBeingPlaced);
        Wire addedwire = null;

        if (SelectedPeg.tag == "Input" && PegBeingLookedAt.tag == "Input")
        {
            addedwire = WireBeingPlaced.AddComponent <InputInputConnection>();

            addedwire.Point1 = Wire.GetWireReference(SelectedPeg);
            addedwire.Point2 = Wire.GetWireReference(PegBeingLookedAt);
        }
        else
        {
            addedwire = WireBeingPlaced.AddComponent <InputOutputConnection>();

            if (SelectedPeg.tag == "Input")
            {
                addedwire.Point1 = Wire.GetWireReference(SelectedPeg);
                addedwire.Point2 = Wire.GetWireReference(PegBeingLookedAt);
            }
            else
            {
                addedwire.Point2 = Wire.GetWireReference(SelectedPeg);
                addedwire.Point1 = Wire.GetWireReference(PegBeingLookedAt);
            }
        }

        addedwire.DrawWire();
        addedwire.GetComponent <BoxCollider>().enabled = false;
        RotateWireBeingPlaced(PersistentDegrees); // so if you want to place many wires in a row with custom rotation you don't have to keep giving them that custom rotation
    }
    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();
        }
    }
    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();
        }
    }
예제 #4
0
        protected override IEnumerable <GameObject> CreateGhosts()
        {
            foreach (var item in GetWires())
            {
                StuffPlacer.OutlineObject(item.gameObject, OutlineColor.red);
            }

            yield break;
        }
예제 #5
0
파일: Editor.cs 프로젝트: pipe01/WireEdit
        protected GameObject CreateWire(Transform a, Transform b, bool ghost = true)
        {
            if (WirePlacer.ConnectionExists(a.parent.gameObject, b.parent.gameObject))
            {
                return(null);
            }

            GameObject obj = GameObject.Instantiate(Prefabs.Wire);
            Wire       w;

            if (a.parent.tag == "Input" && b.parent.tag == "Input")
            {
                w        = obj.AddComponent <InputInputConnection>();
                w.Point1 = a;
                w.Point2 = b;
            }
            else
            {
                w = obj.AddComponent <InputOutputConnection>();

                if (a.parent.tag == "Input")
                {
                    w.Point1 = a;
                    w.Point2 = b;
                }
                else
                {
                    w.Point1 = b;
                    w.Point2 = a;
                }
            }

            if (!WirePlacer.CanConnect(w))
            {
                GameObject.Destroy(obj);
                return(null);
            }

            w.DrawWire();

            if (ghost)
            {
                obj.GetComponent <BoxCollider>().enabled = false;
                StuffPlacer.OutlineObject(obj, OutlineColor.blue);
            }
            else
            {
                w.SetPegsBasedOnPoints();
                StuffConnector.LinkConnection(w);
                StuffConnector.SetAppropriateConnectionParent(w);
                obj.AddComponent <ObjectInfo>().ComponentType = ComponentType.Wire;
                obj.GetComponent <BoxCollider>().enabled      = true;
            }

            return(obj);
        }
    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;
        }
    }
    public static void RunWirePlacing()
    {
        if (Input.GetButtonDown("ToggleConnectionMode"))
        {
            // this is a really gross hacky way of doing it but whatever yolo am i right
            if (ConnectionMode == ConnectionMode.HoldDown)
            {
                ConnectionMode = ConnectionMode.MultiPhase;
            }
            else if (ConnectionMode == ConnectionMode.MultiPhase)
            {
                ConnectionMode = ConnectionMode.Chained;
            }
            else
            {
                ConnectionMode = ConnectionMode.HoldDown;
            }
        }

        // do the proper placing methods depending on the user's settings
        if (ConnectionMode == ConnectionMode.HoldDown)
        {
            HoldDownPlacing();
        }
        else if (ConnectionMode == ConnectionMode.MultiPhase)
        {
            MultiphasePlacing();
        }
        else if (ConnectionMode == ConnectionMode.Chained)
        {
            ChainedPlacing();
        }

        if (Input.GetButtonDown("TogglePlacingGhost") && Input.GetButton("Mod"))
        {
            ShowPreWiringPegOutlines = !ShowPreWiringPegOutlines;
            // Settings.Save("ShowPreWiringPegOutlines", ShowPreWiringPegOutlines);
            if (ShowPreWiringPegOutlines)
            {
                StuffPlacer.OutlineObject(PegBeingLookedAt);
            }
            else
            {
                StuffPlacer.RemoveOutlineFromObject(PegBeingLookedAt);
            }
        }

        PollRotationInput();
        SetPegBeingLookedAt();

        // don't do all the outlining stuff if nothing's changed. A small optimization. (also it makes some code more convenient)
        if (PreviousPegBeingLookedAt == PegBeingLookedAt && PreviousSelectedPeg == SelectedPeg)
        {
            return;
        }
        else
        {
            PreviousPegBeingLookedAt = PegBeingLookedAt; PreviousSelectedPeg = SelectedPeg;
        }                                                                                        // keep these values updated

        // if the above things changed, odds are we need a new WireBeingPlaced
        if (WireBeingPlaced != null)
        {
            Object.Destroy(WireBeingPlaced);
        }

        if ((SelectedPeg == null || PegBeingLookedAt == null) || // if we have less than two pegs
            (SelectedPeg.tag == "Output" && PegBeingLookedAt.tag == "Output"))    // or if our pegs are both outputs
        {
            OutlineColor color;
            if (SelectedPeg == null && PegBeingLookedAt != null)
            {
                color = OutlineColor.blue;
            }                                                                                   // if we're not in the process of placing and just looking at a peg, make it blue
            else
            {
                color = OutlineColor.red;
            }                                  // otherwise - since the other possibilities of the above if statement are all invalid placements - make it red
            SetOutlineColorOfObjectsInvolvedWithPlacing(color);
            return;
        }

        PlaceNewWire();

        if (CurrentWirePlacementIsValid())
        {
            SetOutlineColorOfObjectsInvolvedWithPlacing(OutlineColor.green);
        }
        else
        {
            SetOutlineColorOfObjectsInvolvedWithPlacing(OutlineColor.red);
        }
    }