Exemplo n.º 1
0
    public static void UnwirePlug(Plug plug, _Wire wire, bool doNotdestroyWire = false)
    {
        if (wire != null && plug != null)
        {
            if (wire.begin == plug)
            {
                wire.begin      = null;
                wire.beginBlock = null;
                plug.wire       = null;
            }
            else if (wire.end == plug)
            {
                wire.end      = null;
                wire.endBlock = null;
                plug.wire     = null;
            }

            if (!doNotdestroyWire)
            {
                if (wire.end == null || wire.begin == null)
                {
                    wire.DestroyWire();
                }
            }
        }
    }
Exemplo n.º 2
0
    public static bool TryWirePlug(Plug plug, _Wire wire)
    {
        bool result = false;

        if (plug.wire == null)
        {
            if (plug.type == ConnectionType.Output && wire.begin == null)
            {
                plug.wire        = wire;
                plug.timeUnwired = 0.0f;

                wire.begin      = plug;
                wire.beginBlock = plug.block;

                result = true;
            }
            else if (plug.type == ConnectionType.Input && wire.end == null)
            {
                plug.wire        = wire;
                plug.timeUnwired = 0.0f;

                wire.end      = plug;
                wire.endBlock = plug.block;

                result = true;
            }
        }
        return(result);
    }
Exemplo n.º 3
0
    public static _Wire TryCreateWire(Plug begin, Plug end)
    {
        var   manager = GetInstance();
        _Wire wire    = null;

        if (begin.block && end.block && (end.block != begin.block))
        {
            if (CanWirePlugs(begin, end))
            {
                var obj = Instantiate(manager.wirePrefab);
                wire = obj.GetComponent <_Wire>();
                Debug.Assert(wire != null);

                wire.renderer.positionCount = 2;

                bool beginWired = TryWirePlug(begin, wire);
                bool endWired   = TryWirePlug(end, wire);

                Debug.Assert(beginWired);
                Debug.Assert(endWired);
            }
        }
        return(wire);
    }