public SnappingPeg GetPegToSnapTo()
    {
        Vector3    origin = Wire.GetWireReference(gameObject).position;
        RaycastHit hit;

        if (Physics.Raycast(origin, -Wire.GetWireReference(gameObject).forward, out hit, 0.20f, Wire.IgnoreWiresLayermask)) // snapped connections will be about 18cm long; we cast for 20, just to be safe
        {
            if (hit.collider.tag == "Input")
            {
                SnappingPeg OtherSnappyPeg = hit.collider.GetComponent <SnappingPeg>();
                if (OtherSnappyPeg != null)
                {
                    if (StuffConnector.CanConnect(gameObject, OtherSnappyPeg.gameObject) && !WirePlacer.ConnectionExists(gameObject, OtherSnappyPeg.gameObject) &&
                        hit.transform.InverseTransformPoint(hit.point).z < -0.49f // make sure it hits the right face of the other peg
                        &&

                        // make sure it's rotated approximately correctly
                        // use the wire reference instead of the peg itself so the same code works for vertical and horizontal pegs
                        ((Wire.GetWireReference(hit).eulerAngles.y + 180 > Wire.GetWireReference(transform).eulerAngles.y - 2 &&
                          Wire.GetWireReference(hit).eulerAngles.y + 180 < Wire.GetWireReference(transform).eulerAngles.y + 2)

                         || (Wire.GetWireReference(hit).eulerAngles.y - 180 > Wire.GetWireReference(transform).eulerAngles.y - 2 &&
                             Wire.GetWireReference(hit).eulerAngles.y - 180 < Wire.GetWireReference(transform).eulerAngles.y + 2)))
                    {
                        return(OtherSnappyPeg);
                    }
                }
            }
        }

        return(null);
    }
Beispiel #2
0
    public void Place()
    {
        if (!CurrentPlacementIsValid)
        {
            SoundPlayer.PlaySoundGlobal(Sounds.FailDoSomething);
            return;
        }

        StuffPlacer.RemoveOutlineFromObject(BoardBeingStacked);
        StuffPlacer.SetStateOfAllBoxCollidersIn(BoardBeingStacked, true);

        FloatingPointRounder.RoundIn(BoardBeingStacked, true);
        SnappingPeg.TryToSnapIn(BoardBeingStacked);

        MegaMeshManager.AddComponentsIn(StackedBoard);
        foreach (VisualUpdaterWithMeshCombining visualboi in StackedBoard.GetComponentsInChildren <VisualUpdaterWithMeshCombining>())
        {
            visualboi.AllowedToCombineOnStable = true;
        }

        SoundPlayer.PlaySoundAt(Sounds.PlaceOnBoard, BoardBeingStacked);

        BoardBeingStacked             = null;
        BoardBeingStackedCircuitBoard = null;

        AllSubBoardsInvolvedWithStacking = new List <GameObject>();

        Done();
    }
Beispiel #3
0
        public override bool Execute(IEnumerable <string> arguments)
        {
            GetScale();

            var clone = CreatePrefabFromCode();

            clone.transform.position = GetPosition();

            clone.AddComponent <ObjectInfo>().ComponentType = ComponentType.Delayer;

            clone.transform.position = new Vector3(clone.transform.position.x + 10, clone.transform.position.y, clone.transform.position.z + 10);

            ModUtilities.ExecuteStaticMethod(typeof(StuffPlacer), "SetStateOfAllBoxCollidersFromThingBeingPlaced", true);
            StuffPlacer.OutlinesOfThingBeingPlaced = null;

            ModUtilities.SetStaticFieldValue(typeof(StuffPlacer), "BoxCollidersOfThingBeingPlaced", null);

            FloatingPointRounder.RoundIn(clone, true);

            MegaMeshManager.AddComponentsIn(clone);

            foreach (VisualUpdaterWithMeshCombining visualUpdaterWithMeshCombining in clone.GetComponentsInChildren <VisualUpdaterWithMeshCombining>())
            {
                visualUpdaterWithMeshCombining.AllowedToCombineOnStable = true;
            }
            SnappingPeg.TryToSnapIn(clone);

            return(true);
        }
    public void SetThisAsSnappedConnectionOfPegs()
    {
        // man, all this casting is real annoying
        SnappingPeg SnapInput1 = (SnappingPeg)Input1;
        SnappingPeg SnapInput2 = (SnappingPeg)Input2;

        SnapInput1.SnappedConnection = this;
        SnapInput2.SnappedConnection = this;
    }
Beispiel #5
0
        public override void Do()
        {
            var RotateThis = NetObject.GetByNetId(Packet.ComponentID)?.gameObject;

            if (RotateThis != null)
            {
                BoxCollider[] componentsInChildren = RotateThis.GetComponentsInChildren <BoxCollider>();
                SoundPlayer.PlaySoundAt(Sounds.RotateSomething, RotateThis);

                RotateThis.transform.localEulerAngles = Packet.EulerAngles;

                FloatingPointRounder.RoundIn(RotateThis, false);
                StuffRotater.RedrawCircuitGeometryOf(RotateThis);
                StuffRotater.DestroyIntersectingConnections(RotateThis);
                SnappingPeg.TryToSnapIn(RotateThis);
                MegaMeshManager.RecalculateGroupsOf(RotateThis);
            }
        }
    public static void RecalculateAllClustersEverywhere()
    {
        // we used to destroy all existing clusters, but I took this out to make through pegs work in 0.2. I sure hope this wasn't necessary!
        //WireCluster[] existingclusters = UnityEngine.Object.FindObjectsOfType<WireCluster>();
        //foreach (WireCluster oldcluster in existingclusters) { UnityEngine.Object.Destroy(oldcluster.gameObject); }

        Wire[] wires = UnityEngine.Object.FindObjectsOfType <Wire>();

        foreach (Wire wire in wires)
        {
            wire.FindPoints();
            StuffConnector.LinkConnection(wire);
        }

        SnappingPeg.SnapEverywhere();
        MegaMeshManager.AddComponentsEverywhere();

        // and FINALLY, allow circuitry updates again
        BehaviorManager.AllowedToUpdate = true;
    }
Beispiel #7
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;
    }
    public void TryToConnect()
    {
        DestroySnappedConnection();
        SnappingPeg OtherSnappyPeg = GetPegToSnapTo();                         // I quite like the prefix "snappy"

        if (OtherSnappyPeg != null && OtherSnappyPeg.GetPegToSnapTo() == this) // make sure the snapping can occur both ways
        {
            SnappedConnection SnappyConnection = Instantiate(References.Prefabs.Wire).AddComponent <SnappedConnection>();
            SnappyConnection.Input1 = this;
            SnappyConnection.Input2 = OtherSnappyPeg;
            SnappyConnection.DrawWire();
            SnappyConnection.Initialize();

            StuffConnector.LinkInputs(SnappyConnection);

            if (BehaviorManager.AllowedToUpdate)
            {
                SoundPlayer.PlaySoundAt(References.Sounds.ConnectionFinal, transform);
            }                                                                                                               // the check is so it doesn't play on loaded pegs
        }
    }
Beispiel #9
0
        public override void Do()
        {
            NetObject         parentBoard = NetObject.GetByNetId(Packet.ParentBoardID);
            SavedCircuitBoard savedBoard;

            using (var mem = new MemoryStream(Packet.SavedBoard))
            {
                savedBoard = (SavedCircuitBoard)BinFormatter.Deserialize(mem);
            }

            var boardObj = SavedObjectUtilities.LoadSavedObject(savedBoard, parentBoard?.transform);

            boardObj.transform.position    = Packet.Position;
            boardObj.transform.eulerAngles = Packet.EulerAngles;

            foreach (var item in boardObj.GetComponentsInChildren <CircuitOutput>())
            {
                item.On = item.On; //It works 100% of the times most of the time
            }

            BoardFunctions.RecalculateClustersOfBoard(boardObj);
            SnappingPeg.TryToSnapIn(boardObj);
        }
    public static bool CurrentWirePlacementIsValid()
    {
        // below: some invalid placement conditions. We must do CanConnect as well as CanFindPoints because each can sometimes return true while the other returns false; sorry, future me, but I'm too lazy to type out exactly what those scenarios are. Figure it out yourself you ungrateful piece of shit
        if (ConnectionExists(SelectedPeg, PegBeingLookedAt) || !WireBeingPlaced.GetComponent <Wire>().CanFindPoints())
        {
            return(false);
        }

        InputInputConnection IIconnection = WireBeingPlaced.GetComponent <InputInputConnection>();

        if (IIconnection != null)
        {
            // for the edge case of color displays
            if (ComponentPlacer.FullComponent(IIconnection.Point1) == ComponentPlacer.FullComponent(IIconnection.Point2))
            {
                return(false);
            }
        }

        // a snapping peg may only have one non-snapped connection
        SnappingPeg TheSnappyPeg = SelectedPeg.GetComponent <SnappingPeg>();

        if (TheSnappyPeg == null)
        {
            TheSnappyPeg = PegBeingLookedAt.GetComponent <SnappingPeg>();
        }
        if (TheSnappyPeg != null)
        {
            int MaxConnections = TheSnappyPeg.SnappedConnection == null ? 1 : 2;
            if (TheSnappyPeg.IIConnections.Count + TheSnappyPeg.IOConnections.Count >= MaxConnections)
            {
                return(false);
            }
        }

        return(true);
    }
    public static void RotateThing(GameObject RotateThis)
    {
        // determines which direction to rotate
        // TODO: use camera.main.transform to rotate stuff left and right rather than clockwise & ccw

        if (RotateThis.tag == "World")
        {
            SoundPlayer.PlaySoundGlobal(Sounds.FailDoSomething);
            return;
        }

        if (RotateThis.tag == "CircuitBoard" || RotateThis.tag == "PlaceOnlyCircuitBoard")
        {
            SoundPlayer.PlaySoundGlobal(Sounds.FailDoSomething);
            return;
        }

        // rotate the full object, not part of it
        // the last check is so that rotating child boards doesn't rotate their parent
        RotateThis = ComponentPlacer.FullComponent(RotateThis);

        Quaternion BeforeRotation     = Quaternion.identity;
        Vector3    AxisToRotateAround = RotateThis.transform.up;

        // everything but wires should rotate around transform.up
        if (RotateThis.tag == "Wire")
        {
            if (RotateThis.GetComponent <SnappedConnection>()) // you cannot rotate snapped connections
            {
                SoundPlayer.PlaySoundGlobal(Sounds.FailDoSomething);
                return;
            }

            AxisToRotateAround = RotateThis.transform.forward;
            StuffConnector.QueueWireMeshRecalculation(RotateThis);

            SoundPlayer.PlaySoundAt(Sounds.RotateSomething, RotateThis);
        }
        else
        {
            BeforeRotation = RotateThis.transform.rotation; // non-wires might be rotated into invalid positions, in which case they should be reverted to their original rotations
        }

        int direction = 1;

        if (Input.GetAxis("Rotate") < 0)
        {
            direction = -1;
        }
        else
        {
            direction = 1;
        }

        if (Input.GetButton("Mod")) // rotate by 22.5 degrees if the mod key is held down
        {
            RotateThis.transform.RotateAround(RotateThis.transform.position, AxisToRotateAround, direction * 22.5f);
        }
        else // ...but normally rotate by 90 degrees
        {
            RotateThis.transform.RotateAround(RotateThis.transform.position, AxisToRotateAround, direction * 90f);
        }

        // the validity of wire placement is never affected when rotating them, but if it's an object, check if it can actually be placed there. If not, revert to original rotation
        if (RotateThis.tag != "Wire")
        {
            BoxCollider[] colliders = RotateThis.GetComponentsInChildren <BoxCollider>();
            StuffPlacer.SetStateOfBoxColliders(colliders, false);

            if (StuffPlacer.GameObjectIntersectingStuffOrWouldDestroyWires(RotateThis, true, true)) // ignore wires
            {
                RotateThis.transform.rotation = BeforeRotation;
                StuffPlacer.SetStateOfBoxColliders(colliders, true);

                SoundPlayer.PlaySoundGlobal(Sounds.FailDoSomething);
                return;
            }

            SoundPlayer.PlaySoundAt(Sounds.RotateSomething, RotateThis);
            StuffPlacer.SetStateOfBoxColliders(colliders, true);
        }

        FloatingPointRounder.RoundIn(RotateThis);

        RedrawCircuitGeometryOf(RotateThis);
        DestroyIntersectingConnections(RotateThis);

        SnappingPeg.TryToSnapIn(RotateThis);

        MegaMeshManager.RecalculateGroupsOf(RotateThis);
    }