Esempio n. 1
0
 public CodeLine(BaseDrone drone)
 {
     _drone = drone;
     Cmd = Instruction.NO_OP;
 }
Esempio n. 2
0
    public void SelectDrone(BaseDrone drone)
    {
        // unset last
        if (Drone)
        {
            foreach (var oldRegister in Drone.Registers)
            {
                oldRegister.Setup(null);
            }
            foreach (var oldLines in _lines)
            {
                oldLines.gameObject.SetActive(false);
            }
        }

        foreach (var visual in _registers)
        {
            visual.gameObject.SetActive(false);
        }
        foreach (var line in _lines)
        {
            line.gameObject.SetActive(false);
        }

        Drone = drone;

        if (!Drone)
        {
            GetComponent<Canvas>().enabled = false;

            return;
        }

        GetComponent<Canvas>().enabled = true;

        DroneName.text = Drone.name;
        DroneStory.text = Drone.Story;

        var outputs = _registers.Where(r => r.Type == RegisterType.OUTPUT).GetEnumerator();
        var registers = _registers.Where(r => r.Type == RegisterType.REGISTER).GetEnumerator();
        var sensors = _registers.Where(r => r.Type == RegisterType.SENSOR).GetEnumerator();

        foreach (var register in drone.Registers)
        {
            RegisterVisualizer visual = null;
            switch (register.Type)
            {
                case RegisterType.OUTPUT:
                    outputs.MoveNext();
                    visual = outputs.Current;
                    break;
                case RegisterType.SENSOR:
                    sensors.MoveNext();
                    visual = sensors.Current;
                    break;
                case RegisterType.REGISTER:
                    registers.MoveNext();
                    visual = registers.Current;
                    break;
            }

            if (visual != null)
            {
                visual.Label.text = register.Label;
                register.Setup(visual.Content);
                visual.gameObject.SetActive(true);
            }
        }

        for (int i = 0; i < Drone.Lines.Count; i++)
        {
            if (_lines.Count == i)
            {
                var next = Instantiate(_lines[0]);
                next.transform.SetParent(_lines[0].transform.parent, false);
                _lines.Add(next);
            }
            _lines[i].Setup(Drone.Lines[i], i);
        }
    }