Inheritance: MonoBehaviour
Ejemplo n.º 1
0
 public static void Initialize(
     DisplayedDevice displayedDeviceScript
     , Device device
     , DevicesDisplayer devicesDisplayer
     , DevicesDisplayer.DeviceType deviceType
     )
 {
     if (device == null)
     {
         Logger.Log("DisplayedDevice::Initialize device==null", Logger.Level.WARN);
     }
     Logger.Log("DisplayedDevice::Initialize(" + displayedDeviceScript + ", " + device + ", " + devicesDisplayer + ", " + deviceType + ") starts", Logger.Level.DEBUG);
     displayedDeviceScript._device = Device.buildDevice(device);
     if (displayedDeviceScript._device == null)
     {
         Logger.Log("DisplayedDevice::Initialize _device==null", Logger.Level.WARN);
     }
     Logger.Log("DisplayedDevice::Create built device " + displayedDeviceScript._device + " from " + device, Logger.Level.TRACE);
     if (_devicesDisplayer == null)
     {
         _devicesDisplayer = DevicesDisplayer.get();
     }
     displayedDeviceScript._deviceType = deviceType;
     Logger.Log("DisplayedDevice::Initialize ends", Logger.Level.TRACE);
 }
Ejemplo n.º 2
0
    public void addEquipedDevice(Device device)
    {
        Logger.Log("addEquipedDevice(" + device.ToString() + ")", Logger.Level.TRACE);
        if (device == null)
        {
            Logger.Log("DevicesDisplayer::addEquipedDevice device == null", Logger.Level.WARN);
        }
        bool newEquiped = (!_equipedDevices.Exists(equiped => equiped._device == device));

        if (newEquiped)
        {
            Vector3 localPosition        = getNewPosition(DeviceType.Equiped);
            UnityEngine.Transform parent = equipPanel.transform;

            DisplayedDevice newDevice =
                EquipedDisplayedDevice.Create(
                    parent,
                    localPosition,
                    null,
                    device,
                    this,
                    DevicesDisplayer.DeviceType.Equiped
                    );
            _equipedDevices.Add(newDevice);

            graphMoleculeList.addDeviceAndMoleculesComponent(newDevice);
        }
        else
        {
            Logger.Log("addDevice failed: alreadyEquiped=" + newEquiped, Logger.Level.TRACE);
        }
    }
Ejemplo n.º 3
0
    public static DisplayedDevice Create(
        Transform parentTransform
        , Vector3 localPosition
        , string spriteName
        , Device device
        , DevicesDisplayer devicesDisplayer
        , DevicesDisplayer.DeviceType deviceType
        )
    {
        if (device == null)
        {
            Logger.Log("DisplayedDevice::Create device==null", Logger.Level.WARN);
        }

        string nullSpriteName = (spriteName != null)?"":"(null)";
        Object prefab;

        if (deviceType == DevicesDisplayer.DeviceType.Equiped)
        {
            Logger.Log("DisplayedDevice: will create Equiped " + equipedPrefabURI, Logger.Level.DEBUG);
            prefab = Resources.Load(equipedPrefabURI);
        }
        else if (deviceType == DevicesDisplayer.DeviceType.Inventoried)
        {
            Logger.Log("DisplayedDevice: will create Inventoried " + inventoriedPrefabURI, Logger.Level.DEBUG);
            prefab = Resources.Load(inventoriedPrefabURI);
        }
        else if (deviceType == DevicesDisplayer.DeviceType.Listed)
        {
            Logger.Log("DisplayedDevice: will create Listed " + listedPrefabURI, Logger.Level.DEBUG);
            prefab = Resources.Load(listedPrefabURI);
        }
        else
        {
            Logger.Log("DisplayedDevice::Create : unmanaged device type " + deviceType, Logger.Level.WARN);
            return(null);
        }

        Logger.Log("DisplayedDevice::Create(type=" + deviceType
                   + ", parentTransform=" + parentTransform
                   + ", localPosition=" + localPosition
                   + ", device=" + device
                   + ", devicesDisplayer=" + devicesDisplayer
                   + ", spriteName=" + spriteName + nullSpriteName
                   , Logger.Level.DEBUG
                   );

        DisplayedDevice result = (DisplayedDevice)DisplayedElement.Create(
            parentTransform
            , localPosition
            , getTextureName(device)
            , prefab
            );

        Initialize(result, device, devicesDisplayer, deviceType);

        return(result);
    }
Ejemplo n.º 4
0
    public void removeDevice(int deviceID)
    {
        DisplayedDevice        toRemove   = _equipedDevices.Find(device => device.getID() == deviceID);
        List <DisplayedDevice> devices    = _equipedDevices;
        DeviceType             deviceType = DeviceType.Equiped;

        if (toRemove == null)
        {
            toRemove   = _inventoriedDevices.Find(device => device.getID() == deviceID);
            devices    = _inventoriedDevices;
            deviceType = DeviceType.Inventoried;
        }
        else
        {
        }

        removeDevice(toRemove, devices, deviceType);
    }
Ejemplo n.º 5
0
    private void removeDevice(DisplayedDevice toRemove, List <DisplayedDevice> devices, DeviceType deviceType)
    {
        if (toRemove != null)
        {
            int startIndex = devices.IndexOf(toRemove);

            //debug
            int    count  = deviceType == DeviceType.Equiped ? _equipedDevices.Count : (deviceType == DeviceType.Inventoried ? _inventoriedDevices.Count : _listedInventoriedDevices.Count);
            string source = deviceType == DeviceType.Equiped ? "equipment" : (deviceType == DeviceType.Inventoried ? "inventory" : "listed");
            Logger.Log("removeDevice(" + toRemove + ", devices, " + deviceType + ") of index " + startIndex + " from " + source + " of count " + count, Logger.Level.TRACE);

            devices.Remove(toRemove);
            toRemove.Remove();

            //debug
            count = deviceType == DeviceType.Equiped ? _equipedDevices.Count : (deviceType == DeviceType.Inventoried ? _inventoriedDevices.Count : _listedInventoriedDevices.Count);
            Logger.Log("removeDevice(" + toRemove + ", devices, " + deviceType + ") from " + source + " of count " + count + " done", Logger.Level.TRACE);

            redraw(devices, deviceType, startIndex);
        }
    }
    public void setDisplayedDevice(
        Device device
        , string status = _defaultStatus
        , string infos  = _defaultInfo
        , string name   = _defaultName
        )
    {
        Logger.Log("FinalizationInfoPanelManager::setDisplayedDevice(" + device + ")"
                   + "with status=" + status
                   + ", infos=" + infos
                   + ", name=" + name
                   + ", _device=" + _device
                   , Logger.Level.DEBUG
                   );

        _device = device;
        craftResultDevice._device = device;

        finalizationIconSprite.spriteName = DisplayedDevice.getTextureName(device);
        finalizationIconSprite.gameObject.SetActive(null != device);

        //string displayedInfo = _device!=null?_lengthPrefix+_device.getSize().ToString()+_lengthPostfix:infos;
        //finalizationInfoLabel.text = displayedInfo;
        //Logger.Log("FinalizationInfoPanelManager::setDisplayedDevice: finalizationInfoLabel.text="+finalizationInfoLabel.text, Logger.Level.TRACE);

        //string displayedName = _device!=null?_device.getName():name;
        //finalizationNameLabel.text = displayedName;
        //Logger.Log("FinalizationInfoPanelManager::setDisplayedDevice: finalizationNameLabel.text="+finalizationNameLabel.text, Logger.Level.TRACE);

        if (null != finalizationStatusLabel)
        {
            finalizationStatusLabel.key = status;
            finalizationStatusLabel.Localize();
            //Logger.Log("FinalizationInfoPanelManager::setDisplayedDevice: finalizationStatusLabel.text="+finalizationStatusLabel.text, Logger.Level.TRACE);
        }
    }
Ejemplo n.º 7
0
    private void removeDevice (DisplayedDevice toRemove, List<DisplayedDevice> devices, DeviceType deviceType)
    {
        if (toRemove != null) {
            int startIndex = devices.IndexOf (toRemove);

            //debug
            int count = deviceType == DeviceType.Equiped ? _equipedDevices.Count : (deviceType == DeviceType.Inventoried ? _inventoriedDevices.Count : _listedInventoriedDevices.Count);
            string source = deviceType == DeviceType.Equiped ? "equipment" : (deviceType == DeviceType.Inventoried ? "inventory" : "listed");
            Logger.Log ("removeDevice(" + toRemove + ", devices, " + deviceType + ") of index " + startIndex + " from " + source + " of count " + count, Logger.Level.TRACE);

            devices.Remove (toRemove);
            toRemove.Remove ();

            //debug
            count = deviceType == DeviceType.Equiped ? _equipedDevices.Count : (deviceType == DeviceType.Inventoried ? _inventoriedDevices.Count : _listedInventoriedDevices.Count);
            Logger.Log ("removeDevice(" + toRemove + ", devices, " + deviceType + ") from "+source+" of count " + count + " done", Logger.Level.TRACE);

            redraw (devices, deviceType, startIndex);
        }
    }
Ejemplo n.º 8
0
  public void addDeviceAndMoleculesComponent(DisplayedDevice equipedDeviceScript)
  {
    if(equipedDeviceScript == null)
    {
      Logger.Log ("GraphMoleculeList::addDeviceAndMoleculesComponent device == null", Logger.Level.WARN);
    }
    else
    {
      //equipedDevice is "EquipedDevicePrefabPos" object
      GameObject equipedDevice = equipedDeviceScript.gameObject;

      bool newEquiped = (!_equipedDevices.Exists(equiped => equiped.device == equipedDeviceScript._device)); 
      if(newEquiped) { 

        //EquipedDisplayedDeviceWithMolecules
        GameObject prefab = Resources.Load(DisplayedDevice.equipedWithMoleculesPrefabURI) as GameObject;        
        //deviceWithMoleculesComponent is "EquipedDisplayedDeviceWithMoleculesButtonPrefab" object
        //it needs an EquipmentDevice instance - it has only an EquipmentDeviceDummy object
        GameObject deviceWithMoleculesComponent = Instantiate(prefab, new Vector3(0.0f, 0.0f, 0.0f), Quaternion.identity) as GameObject;
        deviceWithMoleculesComponent.transform.parent = transform;
        deviceWithMoleculesComponent.transform.localScale = new Vector3(1f, 1f, 0);

        EquipedDisplayedDeviceWithMolecules eddwm = deviceWithMoleculesComponent.GetComponent<EquipedDisplayedDeviceWithMolecules>();
        

        //equipmentDevice
        GameObject equipmentDevicePrefab = Resources.Load(DisplayedDevice.equipmentPrefabURI) as GameObject;
        GameObject equipmentDeviceComponent = Instantiate(equipmentDevicePrefab, new Vector3(0.0f, 0.0f, 0.0f), Quaternion.identity) as GameObject;
        eddwm.equipmentDevice = equipmentDeviceComponent;
        EquipmentDevice equipmentD = equipmentDeviceComponent.GetComponent<EquipmentDevice>() as EquipmentDevice;
        eddwm.equipmentDeviceScript = equipmentD;
                
        //equipedDevice
        GameObject equipedDeviceComponent = Instantiate(equipedDevice) as GameObject;
        eddwm.equipedDevice = equipedDeviceComponent;
        EquipedDisplayedDevice edd = equipedDeviceComponent.GetComponent<EquipedDisplayedDevice>() as EquipedDisplayedDevice;
        eddwm.equipedDeviceScript = edd;
        eddwm.device = equipedDeviceScript._device;
        edd._device = equipedDeviceScript._device;

        eddwm.initialize(equipmentDeviceDummy, equipedDeviceDummy);

        _equipedDevices.Add(eddwm);

        //search if there's already in the cell a molecule that this device produces
        foreach(DisplayedMolecule molecule in _displayedMolecules)
        {
          if(molecule.getCodeName() == eddwm.device.getFirstGeneProteinName())
          {
            displayMoleculeInDevice(molecule, eddwm);
          }
        }

        //depends on displayed list of molecules
        //Vector3 localPosition = getNewPosition(previousEquipedDevicesCount);
        //deviceWithMoleculesComponent.transform.localPosition = localPosition;
        positionDeviceAndMoleculeComponents();
                    
      } else {
        Logger.Log("addDevice failed: newEquiped="+newEquiped, Logger.Level.TRACE);
      }
    }
  }
Ejemplo n.º 9
0
  public static void Initialize(
    DisplayedDevice displayedDeviceScript
    , Device device
    , DevicesDisplayer devicesDisplayer
    , DevicesDisplayer.DeviceType deviceType
    ) {

    if(device == null)
    {
      Logger.Log("DisplayedDevice::Initialize device==null", Logger.Level.WARN);
    }
    Logger.Log("DisplayedDevice::Initialize("+displayedDeviceScript+", "+device+", "+devicesDisplayer+", "+deviceType+") starts", Logger.Level.DEBUG);
    displayedDeviceScript._device = Device.buildDevice(device);
    if(displayedDeviceScript._device==null)
    {
      Logger.Log("DisplayedDevice::Initialize _device==null", Logger.Level.WARN);
    }
    Logger.Log("DisplayedDevice::Create built device "+displayedDeviceScript._device+" from "+device, Logger.Level.TRACE);
    if(_devicesDisplayer == null)
    {
      _devicesDisplayer = DevicesDisplayer.get();
    }
    displayedDeviceScript._deviceType = deviceType;
    Logger.Log("DisplayedDevice::Initialize ends", Logger.Level.TRACE);

  }
Ejemplo n.º 10
0
    /*
     *  ADD
     *
     */

    public void addInventoriedDevice(Device device)
    {
        Logger.Log("DevicesDisplayer::addInventoriedDevice(" + device + ")"
                   + " starts with _listedInventoriedDevices=" + Logger.ToString <DisplayedDevice>(_listedInventoriedDevices),
                   Logger.Level.TRACE);

        if (device == null)
        {
            Logger.Log("DevicesDisplayer::addInventoriedDevice device==null", Logger.Level.WARN);
            return;
        }

        bool alreadyInventoried = (_inventoriedDevices.Exists(inventoriedDevice => inventoriedDevice._device == device));

        if (!alreadyInventoried)
        {
            // ADD TO EQUIPABLE DEVICES
            Vector3 localPosition        = getNewPosition(DeviceType.Inventoried);
            UnityEngine.Transform parent = inventoryPanel.transform;

            DisplayedDevice newDevice =
                InventoriedDisplayedDevice.Create(
                    parent,
                    localPosition,
                    null,
                    device,
                    this,
                    DevicesDisplayer.DeviceType.Inventoried
                    );
            _inventoriedDevices.Add(newDevice);
            //TODO
            //redraw (_inventoriedDevices, DeviceType.Inventoried);

            // ADD TO LISTED DEVICES
            Logger.Log("DevicesDisplayer::addInventoriedDevice: adding listed device", Logger.Level.TRACE);
            localPosition = getNewPosition(DeviceType.Listed);
            Logger.Log("DevicesDisplayer::addInventoriedDevice: localPosition=" + localPosition, Logger.Level.TRACE);
            parent = listedInventoryPanel.transform;
            Logger.Log("DevicesDisplayer::addInventoriedDevice: parent=" + parent, Logger.Level.TRACE);
            DisplayedDevice newListedDevice =
                ListedDevice.Create(
                    parent
                    , localPosition
                    , null
                    , device
                    , this
                    , DevicesDisplayer.DeviceType.Listed
                    );
            Logger.Log("DevicesDisplayer::addInventoriedDevice: newListedDevice=" + newListedDevice, Logger.Level.TRACE);
            _listedInventoriedDevices.Add(newListedDevice);

            /*
             * if(_listedInventoriedDevices.Count == 1) {
             * Logger.Log("DevicesDisplayer::addInventoriedDevice: only 1 listed device", Logger.Level.);
             * CraftZoneManager.get().askSetDevice(device);
             * }
             */
        }
        else
        {
            Logger.Log("DevicesDisplayer::addInventoriedDevice failed: alreadyInventoried=" + alreadyInventoried, Logger.Level.WARN);
        }
        Logger.Log("DevicesDisplayer::addInventoriedDevice(" + device + ")"
                   + " end with _listedInventoriedDevices=" + Logger.ToString <DisplayedDevice>(_listedInventoriedDevices),
                   Logger.Level.TRACE);
    }
Ejemplo n.º 11
0
    public void addDeviceAndMoleculesComponent(DisplayedDevice equipedDeviceScript)
    {
        if (equipedDeviceScript == null)
        {
            Logger.Log("GraphMoleculeList::addDeviceAndMoleculesComponent device == null", Logger.Level.WARN);
        }
        else
        {
            //equipedDevice is "EquipedDevicePrefabPos" object
            GameObject equipedDevice = equipedDeviceScript.gameObject;

            bool newEquiped = (!_equipedDevices.Exists(equiped => equiped.device == equipedDeviceScript._device));
            if (newEquiped)
            {
                //EquipedDisplayedDeviceWithMolecules
                GameObject prefab = Resources.Load(DisplayedDevice.equipedWithMoleculesPrefabURI) as GameObject;
                //deviceWithMoleculesComponent is "EquipedDisplayedDeviceWithMoleculesButtonPrefab" object
                //it needs an EquipmentDevice instance - it has only an EquipmentDeviceDummy object
                GameObject deviceWithMoleculesComponent = Instantiate(prefab, new Vector3(0.0f, 0.0f, 0.0f), Quaternion.identity) as GameObject;
                deviceWithMoleculesComponent.transform.parent     = transform;
                deviceWithMoleculesComponent.transform.localScale = new Vector3(1f, 1f, 0);

                EquipedDisplayedDeviceWithMolecules eddwm = deviceWithMoleculesComponent.GetComponent <EquipedDisplayedDeviceWithMolecules>();


                //equipmentDevice
                GameObject equipmentDevicePrefab    = Resources.Load(DisplayedDevice.equipmentPrefabURI) as GameObject;
                GameObject equipmentDeviceComponent = Instantiate(equipmentDevicePrefab, new Vector3(0.0f, 0.0f, 0.0f), Quaternion.identity) as GameObject;
                eddwm.equipmentDevice = equipmentDeviceComponent;
                EquipmentDevice equipmentD = equipmentDeviceComponent.GetComponent <EquipmentDevice>() as EquipmentDevice;
                eddwm.equipmentDeviceScript = equipmentD;

                //equipedDevice
                GameObject equipedDeviceComponent = Instantiate(equipedDevice) as GameObject;
                eddwm.equipedDevice = equipedDeviceComponent;
                EquipedDisplayedDevice edd = equipedDeviceComponent.GetComponent <EquipedDisplayedDevice>() as EquipedDisplayedDevice;
                eddwm.equipedDeviceScript = edd;
                eddwm.device = equipedDeviceScript._device;
                edd._device  = equipedDeviceScript._device;

                eddwm.initialize(equipmentDeviceDummy, equipedDeviceDummy);

                _equipedDevices.Add(eddwm);

                //search if there's already in the cell a molecule that this device produces
                foreach (DisplayedMolecule molecule in _displayedMolecules)
                {
                    if (molecule.getCodeName() == eddwm.device.getFirstGeneProteinName())
                    {
                        displayMoleculeInDevice(molecule, eddwm);
                    }
                }

                //depends on displayed list of molecules
                //Vector3 localPosition = getNewPosition(previousEquipedDevicesCount);
                //deviceWithMoleculesComponent.transform.localPosition = localPosition;
                positionDeviceAndMoleculeComponents();
            }
            else
            {
                Logger.Log("addDevice failed: newEquiped=" + newEquiped, Logger.Level.TRACE);
            }
        }
    }