Ejemplo n.º 1
0
    public void OnEndDrag(PointerEventData data)
    {
        ConstantHandler.Instance.ComponentDragged = false;
        if (ConstantHandler.Instance.ComponentAdded)
        {
            IVector3 pos = ConstantHandler.Instance.PositionComponentAdded;

            if ((_typeOfItem == GridHandler.SpotType.OR_CENTRE || _typeOfItem == GridHandler.SpotType.AND_CENTRE) && _grid.isOnGrid(pos.x, pos.y, pos.z - 1) && _grid.isOnGrid(pos.x, pos.y, pos.z + 1))
            {
                sib1 = _grid.GetGridSpot(pos.x, pos.y, pos.z - 1);
                sib2 = _grid.GetGridSpot(pos.x, pos.y, pos.z + 1);
                _sib.Add(sib1);
                _sib.Add(sib2);

                GridHandler.GridSpot eld;
                eld = _grid.GetGridSpot(pos.x, pos.y, pos.z);
                _grid.SetSpotToType(_typeOfItem, pos.x, pos.y, pos.z);
                _grid.AttachComponent(pos.x, pos.y, pos.z);
                _grid.SetSiblingsForComponent(pos.x, pos.y, pos.z, _sib, GridHandler.ComponentDirection.FRONT, GridHandler.ComponentDirection.BACK);
                _grid.SetEldest(sib1.Position.x, sib1.Position.y, sib1.Position.z, eld.Position);
                _grid.SetEldest(sib2.Position.x, sib2.Position.y, sib2.Position.z, eld.Position);
            }
            else if (_typeOfItem != GridHandler.SpotType.OR_CENTRE && _typeOfItem != GridHandler.SpotType.AND_CENTRE)
            {
                if (_grid.GetComponentType(pos.x, pos.y, pos.z) == GridHandler.SpotType.OR_CENTRE || _grid.GetComponentType(pos.x, pos.y, pos.z) == GridHandler.SpotType.AND_CENTRE)
                {
                    List <GridHandler.GridSpot> sib = _grid.GetSiblings(pos.x, pos.y, pos.z);
                    foreach (GridHandler.GridSpot s in sib)
                    {
                        _grid.SetSpotToType(GridHandler.SpotType.EMPTY, s.Position.x, s.Position.y, s.Position.z);
                        _grid.AttachComponent(s.Position.x, s.Position.y, s.Position.z);
                    }
                }
                else if (_grid.GetComponentType(pos.x, pos.y, pos.z) == GridHandler.SpotType.OR_LEFT || _grid.GetComponentType(pos.x, pos.y, pos.z) == GridHandler.SpotType.OR_RIGHT || _grid.GetComponentType(pos.x, pos.y, pos.z) == GridHandler.SpotType.AND_LEFT || _grid.GetComponentType(pos.x, pos.y, pos.z) == GridHandler.SpotType.AND_RIGHT)
                {
                    eldest = _grid.GetEldest(pos.x, pos.y, pos.z);
                    List <GridHandler.GridSpot> sib = _grid.GetSiblings(eldest.x, eldest.y, eldest.z);
                    foreach (GridHandler.GridSpot s in sib)
                    {
                        _grid.SetSpotToType(GridHandler.SpotType.EMPTY, s.Position.x, s.Position.y, s.Position.z);
                        _grid.AttachComponent(s.Position.x, s.Position.y, s.Position.z);
                    }
                    _grid.SetSpotToType(GridHandler.SpotType.EMPTY, eldest.x, eldest.y, eldest.z);
                    _grid.AttachComponent(eldest.x, eldest.y, eldest.z);
                }
                _grid.SetSpotToType(_typeOfItem, pos.x, pos.y, pos.z);
                _grid.AttachComponent(pos.x, pos.y, pos.z);
            }

            ConstantHandler.Instance.PositionComponentAdded = IVector3.zero;
            ConstantHandler.Instance.ComponentAdded         = false;
        }
        Destroy(gameObject);
    }
Ejemplo n.º 2
0
    private void FindAllComponents()
    {
        input       = new List <InputComponent> ();
        wires       = new List <WireComponent> ();
        not         = new List <NOTComponent> ();
        or          = new List <ORComponent> ();
        splitter    = new List <SplitterComponent> ();
        and         = new List <ANDComponent> ();
        output      = null;
        electronPos = new List <IVector3> ();
        _logicVals  = new List <bool> ();
        int val = 0;

        for (int i = 0; i < ConstantHandler.Instance.GridLength; i++)
        {
            for (int j = 0; j < ConstantHandler.Instance.GridWidth; j++)
            {
                for (int k = 0; k < ConstantHandler.Instance.GridHeight; k++)
                {
                    GameObject spot;
                    if (_grid.GetComponentObject(new IVector3(i, j, k), out spot))
                    {
                        GridHandler.SpotType _type = _grid.GetComponentType(i, j, k);
                        switch (_type)
                        {
                        case GridHandler.SpotType.INPUT_A:
                        {
                            GridHandler.ComponentDirection dir = spot.GetComponent <RotateOnClick> ().Direction;
                            input.Add(new InputComponent(new IVector3(i, j, k), dir, _logicInput[0]));
                            _logicVals.Add(_logicInput [0]);
                            electronPos.Add(new IVector3(i, j, k));
                            break;
                        }

                        case GridHandler.SpotType.INPUT_B:
                        {
                            GridHandler.ComponentDirection dir = spot.GetComponent <RotateOnClick> ().Direction;
                            input.Add(new InputComponent(new IVector3(i, j, k), dir, _logicInput[1]));
                            _logicVals.Add(_logicInput [1]);
                            electronPos.Add(new IVector3(i, j, k));
                            break;
                        }

                        case GridHandler.SpotType.INPUT_C:
                        {
                            GridHandler.ComponentDirection dir = spot.GetComponent <RotateOnClick> ().Direction;
                            input.Add(new InputComponent(new IVector3(i, j, k), dir, _logicInput[2]));
                            _logicVals.Add(_logicInput [2]);
                            electronPos.Add(new IVector3(i, j, k));
                            break;
                        }

                        case GridHandler.SpotType.WIRE:
                        {
                            GridHandler.ComponentDirection dir = spot.GetComponent <RotateOnClick> ().Direction;
                            wires.Add(new WireComponent(new IVector3(i, j, k), dir));
                            break;
                        }

                        case GridHandler.SpotType.OUTPUT:
                        {
                            GridHandler.ComponentDirection dir = spot.GetComponent <RotateOnClick> ().Direction;
                            output = new OutputComponent(new IVector3(i, j, k), dir);
                            break;
                        }

                        case GridHandler.SpotType.NOT:
                        {
                            GridHandler.ComponentDirection dir = spot.GetComponent <RotateOnClick> ().Direction;
                            not.Add(new NOTComponent(new IVector3(i, j, k), dir));
                            break;
                        }

                        case GridHandler.SpotType.OR_LEFT:
                        {
                            GridHandler.ComponentDirection dir = spot.GetComponent <SiblingsDir> ().Direction;
                            wires.Add(new WireComponent(new IVector3(i, j, k), dir));
                            break;
                        }

                        case GridHandler.SpotType.OR_RIGHT:
                        {
                            GridHandler.ComponentDirection dir = spot.GetComponent <SiblingsDir> ().Direction;
                            wires.Add(new WireComponent(new IVector3(i, j, k), dir));
                            break;
                        }

                        case GridHandler.SpotType.OR_CENTRE:
                        {
                            GridHandler.ComponentDirection dir = spot.GetComponent <RotAndSiblingPosChange>().Direction;
                            or.Add(new ORComponent(new IVector3(i, j, k), dir));
                            break;
                        }

                        case GridHandler.SpotType.SPLITTER:
                        {
                            GridHandler.ComponentDirection dir = spot.GetComponent <SplitterRotateOnClick> ().Direction;
                            GridHandler.ComponentDirection sec = spot.GetComponent <SplitterRotateOnClick> ().SecondaryDirection;
                            splitter.Add(new SplitterComponent(new IVector3(i, j, k), dir, sec));
                            break;
                        }

                        case GridHandler.SpotType.AND_CENTRE:
                        {
                            GridHandler.ComponentDirection dir = spot.GetComponent <RotAndSiblingPosChange>().Direction;
                            and.Add(new ANDComponent(new IVector3(i, j, k), dir));
                            break;
                        }

                        case GridHandler.SpotType.AND_LEFT:
                        {
                            GridHandler.ComponentDirection dir = spot.GetComponent <SiblingsDir> ().Direction;
                            wires.Add(new WireComponent(new IVector3(i, j, k), dir));
                            break;
                        }

                        case GridHandler.SpotType.AND_RIGHT:
                        {
                            GridHandler.ComponentDirection dir = spot.GetComponent <SiblingsDir> ().Direction;
                            wires.Add(new WireComponent(new IVector3(i, j, k), dir));
                            break;
                        }
                        }
                    }
                }
            }
        }
        if (input.Count < 1)
        {
            Debug.LogError("No inputs detected");
            return;
        }
        if (output == null)
        {
            Debug.LogError("No output detected");
            return;
        }
        MoveElectron();
    }