Beispiel #1
0
        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);
        }
Beispiel #2
0
        public static void EndMove(GameObject newObj)
        {
            var inputs  = newObj.GetComponentsInChildren <CircuitInput>();
            var outputs = newObj.GetComponentsInChildren <CircuitOutput>();

            foreach (var item in Connections)
            {
                GameObject obj = GameObject.Instantiate(Prefabs.Wire);

                var wire = item.InputInput ? (Wire)obj.AddComponent <InputInputConnection>() : obj.AddComponent <InputOutputConnection>();

                var a = (item.OutputIsMoved ? outputs[item.Index].transform : inputs[item.Index].transform).Find("WireReference");
                var b = item.Point;

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

                if (!WirePlacer.CanConnect(wire))
                {
                    GameObject.Destroy(obj);
                    continue;
                }

                wire.DrawWire();
                wire.SetPegsBasedOnPoints();
                StuffConnector.LinkConnection(wire);
                StuffConnector.SetAppropriateConnectionParent(wire);
                obj.AddComponent <ObjectInfo>().ComponentType = ComponentType.Wire;
                obj.GetComponent <BoxCollider>().enabled      = true;
            }

            IsMoving = false;
        }