Exemplo n.º 1
0
    public void Display(Machine machine)
    {
        currentMachine = machine;
        if(machine == null)
        {
            gameObject.SetActive(false);
        }
        else
        {
            gameObject.SetActive (true);
            //Get correct display for rule
            MachineRuleDisplay properDisplayPrefab = MachineRuleDisplayUtil.GetDisplayPrefabForRule(machine.Rule);
            //If rule has no display, nuke current
            if(properDisplayPrefab == null && ruleDisplay != null)
            {
                DestroyCurrentDisplay();
            }
            //Else nuke current and instantiate correct
            else if(properDisplayPrefab != null && (ruleDisplay == null || ruleDisplay.GetType() != properDisplayPrefab.GetType()))
            {
                MachineRuleDisplay properDisplay = Instantiate(properDisplayPrefab, Vector3.zero, Quaternion.identity) as MachineRuleDisplay;
                properDisplay.transform.SetParent(RuleDisplayAnchor, false);
                if(ruleDisplay != null)
                {
                    DestroyCurrentDisplay();
                }
                ruleDisplay = properDisplay;
            }
            if(ruleDisplay != null)
            {
                ruleDisplay.Display(machine);
            }

            MiniLayout.Display (machine);

            Background.sprite = machine == SimulationView.Instance.CarriedMachine ? BackgroundDown : BackgroundUp;
        }
    }
Exemplo n.º 2
0
    public void Init(Machine mach)
    {
        if(machine != mach)
        {
            Cleanup();
        }
        machine = mach;

        if(machine == null)
        {
            return;
        }

        foreach(var part in mach.Parts)
        {
            var display = Object.Instantiate(PrefabManager.MachinePartDisplay);
            display.Part = part;
            display.transform.SetParent(transform);
            display.transform.localPosition = FloorView.FloorToWorldVector(part.Offset);
            display.UpdateSubrenderers();
            machinePartDisplays.Add (display);
        }

        foreach(var port in mach.Ports)
        {
            var display = Object.Instantiate(PrefabManager.DockDisplay);
            display.Dock = port;
            display.transform.SetParent(transform);
            display.transform.localPosition = (Vector3)FloorView.FloorToWorldVector(port.Offset) + new Vector3(0, 0, ZLayer.DockOffset);
            portDisplays.Add (display);
        }

        ruleDisplay = Object.Instantiate(MachineRuleDisplayUtil.GetDisplayPrefabForRule(mach.Rule)) as MachineRuleDisplay; //TODO: Kind of broken (?)
        ruleDisplay.transform.SetParent(transform);
        ruleDisplay.transform.localPosition = (Vector3)FloorView.FloorToWorldVector(mach.Parts[0].Offset) + new Vector3(0, 0, ZLayer.RuleOffset);
    }
Exemplo n.º 3
0
 private void Cleanup()
 {
     foreach(var partDisplay in machinePartDisplays)
     {
         Destroy(partDisplay.gameObject);
     }
     machinePartDisplays.Clear();
     foreach(var portDisplay in portDisplays)
     {
         Destroy(portDisplay.gameObject);
     }
     portDisplays.Clear();
     if (ruleDisplay)
     {
         Destroy(ruleDisplay.gameObject);
         ruleDisplay = null;
     }
     machine = null;
 }