Exemple #1
0
    private void CreatePhysicalPorts()
    {
        int num = Grid.PosToCell(base.transform.GetPosition());

        if (num != cell)
        {
            cell = num;
            DestroyVisualizers();
            if (outputPortInfo != null)
            {
                outputPorts = new List <ILogicUIElement>();
                for (int i = 0; i < outputPortInfo.Length; i++)
                {
                    Port             info             = outputPortInfo[i];
                    LogicEventSender logicEventSender = new LogicEventSender(info.id, GetActualCell(info.cellOffset), delegate(int new_value)
                    {
                        if ((UnityEngine.Object) this != (UnityEngine.Object)null)
                        {
                            OnLogicValueChanged(info.id, new_value);
                        }
                    }, OnLogicNetworkConnectionChanged, info.spriteType);
                    outputPorts.Add(logicEventSender);
                    Game.Instance.logicCircuitManager.AddVisElem(logicEventSender);
                    Game.Instance.logicCircuitSystem.AddToNetworks(logicEventSender.GetLogicUICell(), logicEventSender, true);
                }
                if (serializedOutputValues != null && serializedOutputValues.Length == outputPorts.Count)
                {
                    for (int j = 0; j < outputPorts.Count; j++)
                    {
                        LogicEventSender logicEventSender2 = outputPorts[j] as LogicEventSender;
                        logicEventSender2.SetValue(serializedOutputValues[j]);
                    }
                }
            }
            serializedOutputValues = null;
            if (inputPortInfo != null)
            {
                inputPorts = new List <ILogicUIElement>();
                for (int k = 0; k < inputPortInfo.Length; k++)
                {
                    Port info2 = inputPortInfo[k];
                    LogicEventHandler logicEventHandler = new LogicEventHandler(GetActualCell(info2.cellOffset), delegate(int new_value)
                    {
                        if ((UnityEngine.Object) this != (UnityEngine.Object)null)
                        {
                            OnLogicValueChanged(info2.id, new_value);
                        }
                    }, OnLogicNetworkConnectionChanged, info2.spriteType);
                    inputPorts.Add(logicEventHandler);
                    Game.Instance.logicCircuitManager.AddVisElem(logicEventHandler);
                    Game.Instance.logicCircuitSystem.AddToNetworks(logicEventHandler.GetLogicUICell(), logicEventHandler, true);
                }
            }
        }
    }
Exemple #2
0
 private void OnSerializing()
 {
     if (isPhysical && outputPorts != null)
     {
         serializedOutputValues = new int[outputPorts.Count];
         for (int i = 0; i < outputPorts.Count; i++)
         {
             LogicEventSender logicEventSender = outputPorts[i] as LogicEventSender;
             serializedOutputValues[i] = logicEventSender.GetLogicValue();
         }
     }
 }
Exemple #3
0
 public int GetOutputValue(HashedString port_id)
 {
     for (int i = 0; i < outputPorts.Count; i++)
     {
         LogicEventSender logicEventSender = outputPorts[i] as LogicEventSender;
         if (logicEventSender == null)
         {
             return(0);
         }
         if (logicEventSender.ID == port_id)
         {
             return(logicEventSender.GetLogicValue());
         }
     }
     return(0);
 }