コード例 #1
0
 /// <summary>
 /// Create a new argument from original,
 /// copy all callbacks but use new data
 /// </summary>
 /// <param name="original">Original argument to copy callbacks from</param>
 /// <param name="data">new data</param>
 public EventAssetArgument(EventAssetArgument original, object data = null)
 {
     this.data            = data ?? original.data;
     this.successCallback = original.successCallback;
     this.failCallback    = original.failCallback;
     this.updateCallback  = original.updateCallback;
 }
コード例 #2
0
    public void CallbackTestHandler(object data)
    {
        if (data is EventAssetArgument)
        {
            EventAssetArgument arg = (EventAssetArgument)data;

            StartCoroutine(DelayedAction(() =>
            {
                arg.successCallback?.Invoke("Success data arrived after 1 second");
            }, 1));
            StartCoroutine(DelayedAction(() =>
            {
                arg.failCallback?.Invoke("successfully failed after 2 second :)");
            }));
        }
    }
コード例 #3
0
    void CallbackTests()
    {
        EventAssetArgument arg = new EventAssetArgument
        {
            data            = "Hello",
            successCallback = data =>
            {
                Debug.Log(data);
            },
            failCallback = error =>
            {
                Debug.Log(error);
            }
        };

        eventWithCallbacks.Raise(arg);
    }
コード例 #4
0
    public void Raise(EventAssetArgument arg)
    {
#if EVENTS_LOG
        object data = arg.data;
        Debug.Log($"<color=blue>EventAsset</color> raised: <color=yellow>{name}</color>, " +
                  $"\n parameter: <color=green>{data}</color>", this);
#endif

        for (int i = _listeners.Count - 1; i >= 0; i--)
        {
            _listeners[i].OnEventRaised(arg);
        }

        foreach (var ec in chainedEvents)
        {
            if (ec.var == null)
            {
                /// if a chained event has a converter,
                /// it will be used to convert and/or modify passed parameter
                if (ec.converter != null)
                {
                    ec._event.Raise(new EventAssetArgument(arg, ec.converter.Convert(arg.data)));
                }
                else
                {
                    ec._event.Raise(arg);
                }
            }
            else
            {
                /// if a chained event has its own VarAsset,
                /// it will override the parameter
                ec._event.Raise(new EventAssetArgument(arg, ec.var.GetValue()));
            }
        }
    }
コード例 #5
0
 public void OnEventRaised(EventAssetArgument argument)
 {
     argResponse?.Invoke(argument);
     objectResponce?.Invoke(argument.data);
     CastedHandler(argument.data);
 }