Example #1
0
        public void DoEvent(int nEventID, System.Object vars = null)
        {
            ArrayList events;

            if (!mhtEvent.TryGetValue(nEventID, out events))
            {
                return;
            }
            List <object> readyForDelete = new List <object>();

            for (int i = 0; i < events.Count; i++)
            {
                LogicEventHandler handler = events[i] as LogicEventHandler;
                if (handler.Target.Equals(null))
                {
                    Debug.Log("handler.Target.Equals(null)");
                    readyForDelete.Add(events[i]);

                    continue;
                }


                if (!handler(vars))
                {
                    break;
                }
            }
            if (readyForDelete.Count != 0)
            {
                for (int j = 0; j < readyForDelete.Count; j++)
                {
                    events.Remove(readyForDelete[j]);
                }
            }
        }
Example #2
0
 private void Disconnect()
 {
     if (connected)
     {
         LogicCircuitManager logicCircuitManager = Game.Instance.logicCircuitManager;
         UtilityNetworkManager <LogicCircuitNetwork, LogicWire> logicCircuitSystem = Game.Instance.logicCircuitSystem;
         connected = false;
         int outputCell = base.OutputCell;
         logicCircuitSystem.RemoveFromNetworks(outputCell, this, true);
         logicCircuitManager.RemoveVisElem(output);
         output = null;
         int inputCellOne = base.InputCellOne;
         logicCircuitSystem.RemoveFromNetworks(inputCellOne, inputOne, true);
         logicCircuitManager.RemoveVisElem(inputOne);
         inputOne = null;
         if (base.RequiresTwoInputs)
         {
             int inputCellTwo = base.InputCellTwo;
             logicCircuitSystem.RemoveFromNetworks(inputCellTwo, inputTwo, true);
             logicCircuitManager.RemoveVisElem(inputTwo);
             inputTwo = null;
         }
         RefreshAnimation();
     }
 }
Example #3
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);
                }
            }
        }
    }
Example #4
0
        public void RegisterCallback(int nEventID, LogicEventHandler handler)
        {
            ArrayList events;

            if (!mhtEvent.TryGetValue(nEventID, out events))
            {
                events = new ArrayList();
                mhtEvent.Add(nEventID, events);
            }
            events.Add(handler);
        }
Example #5
0
 /// <summary>
 /// Convenient method for linking the events of this <see cref="Story"/> to another
 /// <see cref="Procedure"/>. Also optionally add event handlers to
 /// <see cref="Procedure.Started"/> and <see cref="Procedure.Completed"/>.
 /// </summary>
 /// <param name="pro">The <see cref="Procedure"/> to link to.</param>
 /// <param name="started">Event handler for <see cref="Procedure.Started"/>.</param>
 /// <param name="completed">
 /// Event handler for <see cref="Procedure.Completed"/>.
 /// </param>
 public void Link(Procedure pro, LogicEventHandler started = null,
     LogicEventHandler completed = null)
 {
     Event.Register(this, Started, (sender, e) => pro.Start());
     Event.Register(this, Skipped, (sender, e) => pro.Skip());
     Event.Register(this, Stopping, (sender, e) => pro.Stop());
     Event.Register(pro, Completed, (sender, e) => Complete());
     if (started != null)
         Event.Register(this, Started, started);
     if (completed != null)
         Event.Register(this, Completed, completed);
 }
Example #6
0
    protected override void OnSpawn()
    {
        inputOne = new LogicEventHandler(base.InputCellOne, UpdateState, null, LogicPortSpriteType.Input);
        if (base.RequiresTwoInputs)
        {
            inputTwo = new LogicEventHandler(base.InputCellTwo, UpdateState, null, LogicPortSpriteType.Input);
        }
        Subscribe(774203113, OnBuildingBrokenDelegate);
        Subscribe(-1735440190, OnBuildingFullyRepairedDelegate);
        BuildingHP component = GetComponent <BuildingHP>();

        if ((Object)component == (Object)null || !component.IsBroken)
        {
            Connect();
        }
    }
Example #7
0
 private void DestroyPhysicalPorts()
 {
     if (outputPorts != null)
     {
         foreach (ILogicEventSender outputPort in outputPorts)
         {
             Game.Instance.logicCircuitSystem.RemoveFromNetworks(outputPort.GetLogicCell(), outputPort, true);
         }
     }
     if (inputPorts != null)
     {
         for (int i = 0; i < inputPorts.Count; i++)
         {
             LogicEventHandler logicEventHandler = inputPorts[i] as LogicEventHandler;
             if (logicEventHandler != null)
             {
                 Game.Instance.logicCircuitSystem.RemoveFromNetworks(logicEventHandler.GetLogicCell(), logicEventHandler, true);
             }
         }
     }
 }
Example #8
0
 public static void Register(Type type, string name, LogicEventHandler handler)
 {
     Register((object)type, name, handler);
 }
Example #9
0
 public static void Register(object target, string name, LogicEventHandler handler)
 {
     units.GetOrNew(target).GetOrNew(name).Register(handler);
 }
Example #10
0
 public static void Override(object target, string name, LogicEventHandler handler)
 {
     units.GetOrNew(target).GetOrNew(name).Override(handler);
 }
Example #11
0
 public static void Once(Type type, string name, LogicEventHandler handler)
 {
     Once((object)type, name, handler);
 }
Example #12
0
 public void Register(LogicEventHandler handler)
 {
     handlers.Add(handler);
 }
Example #13
0
 public void Override(LogicEventHandler handler)
 {
     handlers.Clear();
     handlers.Add(handler);
 }
Example #14
0
 public void Once(LogicEventHandler handler)
 {
     handlers.Add(handler);
     onces.Add(handler);
 }