Exemple #1
0
        public void FilteredEventHandlerOfCustomType_FiltersEventsLocally()
        {
            // prepare event handler
            var firstArgument  = 0;
            var secondArgument = string.Empty;
            var handled        = false;
            var handler        = new CustomEventType((first, second) =>
            {
                firstArgument  = first;
                secondArgument = second;
                handled        = true;
            });

            // attach client-side event filter
            var sample = new SampleServer();

            sample.CustomEvent += FilteredEventHandler.Create(handler, new CustomEventFilter("3.14"));

            // raise events, check results
            sample.RaiseCustomEvent(1, string.Empty);             // filtered out
            Assert.IsFalse(handled);

            sample.RaiseCustomEvent(3, ".14");
            Assert.IsTrue(handled);
            Assert.AreEqual(3, firstArgument);
            Assert.AreEqual(".14", secondArgument);

            handled = false;
            sample.RaiseCustomEvent();             // filtered out
            Assert.IsFalse(handled);
        }
Exemple #2
0
        public void FilteredEventHandlerOfCustomType_FiltersEventsRemotely()
        {
            // prepare event handler
            var firstArgument  = 0;
            var secondArgument = string.Empty;
            var handled        = false;
            var handler        = new CustomEventType((first, second) =>
            {
                firstArgument  = first;
                secondArgument = second;
                handled        = true;
            });

            // attach server-side event filter
            var proxy = ZyanConnection.CreateProxy <ISampleServer>();

            proxy.CustomEvent += FilteredEventHandler.Create(handler, new CustomEventFilter("2.71828"), false);

            // raise events, check results
            proxy.RaiseCustomEvent(1, string.Empty);             // filtered out
            Assert.IsFalse(handled);

            proxy.RaiseCustomEvent(2, ".71828");
            Assert.IsTrue(handled);
            Assert.AreEqual(2, firstArgument);
            Assert.AreEqual(".71828", secondArgument);

            handled = false;
            proxy.RaiseCustomEvent();             // filtered out
            Assert.IsFalse(handled);
        }
Exemple #3
0
        public void FilteredCustomHandlerUsingCombinedFilter_FiltersEventsRemotely()
        {
            // prepare event handler
            var firstArgument  = 0;
            var secondArgument = string.Empty;
            var handled        = false;
            var handler        = new CustomEventType((first, second) =>
            {
                firstArgument  = first;
                secondArgument = second;
                handled        = true;
            });

            // initialize event filter
            handler = FilteredEventHandler.Create(handler, new CustomEventFilter("2.718", "1.618"), false);
            handler = FilteredEventHandler.Create(handler, new CustomEventFilter("3.14", "2.718"), false);

            // attach client-side event filter
            var proxy = ZyanConnection.CreateProxy <ISampleServer>();

            proxy.CustomEvent += handler;

            // raise events, check results
            proxy.RaiseCustomEvent(3, ".14");             // filtered out
            Assert.IsFalse(handled);

            proxy.RaiseCustomEvent(2, ".718");
            Assert.IsTrue(handled);
            Assert.AreEqual(2, firstArgument);
            Assert.AreEqual(".718", secondArgument);

            handled = false;
            proxy.RaiseCustomEvent(1, ".618");             // filtered out
            Assert.IsFalse(handled);
        }
Exemple #4
0
 private static void OnRemovedListener(CustomEventType eventType)
 {
     if (_eventTable[eventType] == null)
     {
         _eventTable.Remove(eventType);
     }
 }
Exemple #5
0
 public static void RegisterHandler(CustomEventType eventType, Action <object> eventHandler)
 {
     if (!_subscriptions.ContainsKey(eventType))
     {
         _subscriptions.Add(eventType, new List <Action <object> >());
     }
     _subscriptions[eventType].Add(eventHandler);
 }
Exemple #6
0
 public static void UnregisterHandler(CustomEventType eventType, Action <object> eventHandler)
 {
     if (!_subscriptions.ContainsKey(eventType))
     {
         Debug.LogError("Trying to unregister a event that is not subscribed!");
         return;
     }
     _subscriptions[eventType].Remove(eventHandler);
 }
    /// <summary>
    /// Customs the event call.
    /// </summary>
    /// <param name='type'>
    /// Type.
    /// </param>
    /// <param name='param'>
    /// Parameter.
    /// </param>
    public void CustomEventCall(CustomEventType type, params object[] param)
    {
        return;

        try{
            Globals.Instance.MConnectManager.PutFlurryEvent(type.ToString(), param);

            ProcessTalkingDataPurchaseEvent(type, param);
        }catch {};
    }
        public void RegisterCustomEventType(XmlNode node)
        {
            var attr = node.Attributes;

            if (attr != null)
            {
                CustomEventType o = new CustomEventType(attr["id"].Value, attr["color"].Value, attr["label"].Value);
                AuditLogger.Current.RegisterEventType(o);
            }
        }
 public static void TriggerEvent(CustomEventType eventType, Object actionObject)
 {
     if (!isApplicationQuitting)
     {
         CustomUnityEvent unityEvent = null;
         if (Instance.eventDictionary.TryGetValue(eventType, out unityEvent))
         {
             unityEvent.Invoke(actionObject);
         }
     }
 }
    public static void StartListening(CustomEventType eventType, UnityAction <Object> listener)
    {
        CustomUnityEvent unityEvent = null;

        if (!Instance.eventDictionary.TryGetValue(eventType, out unityEvent))
        {
            unityEvent = new CustomUnityEvent();
            Instance.eventDictionary.Add(eventType, unityEvent);
        }

        unityEvent.AddListener(listener);
    }
Exemple #11
0
 public static void Raise(CustomEventType eventType, object eventArg = null)
 {
     if (!_subscriptions.ContainsKey(eventType))
     {
         Debug.LogWarning($"Trying to raise {eventType} event which has no subscriptions");
         return;
     }
     foreach (var action in _subscriptions[eventType])
     {
         action.Invoke(eventArg);
     }
 }
    public static void StopListening(CustomEventType eventType, UnityAction <Object> listener)
    {
        if (eventManager == null)
        {
            return;
        }

        CustomUnityEvent unityEvent = null;

        if (Instance.eventDictionary.TryGetValue(eventType, out unityEvent))
        {
            unityEvent.RemoveListener(listener);
        }
    }
Exemple #13
0
        private static void OnAddListenering(CustomEventType eventType, Delegate callBack)
        {
            if (!_eventTable.ContainsKey(eventType))
            {
                _eventTable.Add(eventType, null);
            }

            Delegate d = _eventTable[eventType];

            if (d != null && d.GetType() != callBack.GetType())
            {
                throw new Exception(string.Format("尝试为事件{0}添加不同的类型的委托, 当前事件所对应的委托是{1}, 要添加的委托是{2}", eventType, d.GetType(), callBack.GetType()));
            }
        }
Exemple #14
0
        /// <summary>
        /// 广播事件 4个参数
        /// </summary>
        /// <param name="eventType"></param>
        public static void BroadcastEvent <T1, T2, T3, T4>(CustomEventType eventType, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
        {
            Delegate d;

            if (_eventTable.TryGetValue(eventType, out d))
            {
                Action <T1, T2, T3, T4> callback = d as Action <T1, T2, T3, T4>;
                if (callback == null)
                {
                    throw new Exception(string.Format("广播事件错误,事件{0}具有不同的类型"));
                }
                else
                {
                    callback(arg1, arg2, arg3, arg4);
                }
            }
        }
Exemple #15
0
        /// <summary>
        /// 广播事件 0个参数
        /// </summary>
        /// <param name="eventType"></param>
        public static void BroadcastEvent(CustomEventType eventType)
        {
            Delegate d;

            if (_eventTable.TryGetValue(eventType, out d))
            {
                Action callback = d as Action;
                if (callback == null)
                {
                    throw new Exception(string.Format("广播事件错误,事件{0}具有不同的类型"));
                }
                else
                {
                    callback();
                }
            }
        }
Exemple #16
0
    // Function to be called when something occurs.
    public void AddEvent(CustomEventType type)
    {
        switch (type)
        {
        case CustomEventType.NONE:
            break;

        case CustomEventType.STEPPED_IN_FIRE:
        {
            onSteppedOnFire.Invoke();         // Invokes all callbacks stored in that event.
        }
        break;

        default:
            break;
        }
    }
Exemple #17
0
        private static void OnRemoveListenering(CustomEventType eventType, Delegate callBack)
        {
            if (!_eventTable.ContainsKey(eventType))
            {
                throw new Exception(string.Format("当前不存在事件{0}, 移除失败", eventType));
            }

            Delegate d = _eventTable[eventType];

            if (d == null)
            {
                throw new Exception(string.Format("事件{0}没有对应的委托", eventType));
            }
            else if (d.GetType() != callBack.GetType())
            {
                throw new Exception(string.Format("尝试为事件{0}移除不同的类型的委托, 当前事件所对应的委托是{1}, 要移除的委托是{2}", eventType, d.GetType(), callBack.GetType()));
            }
        }
	public override void OnInspectorGUI () 
	{
		UniStormEventSystem self = (UniStormEventSystem)target;

		EditorGUILayout.LabelField("UniStorm Event System", EditorStyles.boldLabel);
		EditorGUILayout.LabelField("By: Black Horizon Studios", EditorStyles.label);
		EditorGUILayout.Space();


		editorVariableToAlter = (VariableToAlter)self.intToString;
		editorVariableToAlter = (VariableToAlter)EditorGUILayout.EnumPopup("Variable", editorVariableToAlter);
		self.intToString = (int)editorVariableToAlter;

		EditorGUILayout.Space();

		if (self.intToString == 0)
		{
			EditorGUILayout.LabelField("Type (int)", EditorStyles.label);

			EditorGUILayout.Space();

			self.intToAlter = EditorGUILayout.IntField ("Weather", self.intToAlter);
		}

		if (self.intToString == 1)
		{
			//EditorGUILayout.LabelField("Variable Type: int", EditorStyles.boldLabel);
			self.intToAlter = EditorGUILayout.IntField ("Temperature", self.intToAlter);
		}

		EditorGUILayout.Space();

		editorCustomEventType = (CustomEventType)self.eventType;
		editorCustomEventType = (CustomEventType)EditorGUILayout.EnumPopup("Event Type", editorCustomEventType);
		self.eventType = (int)editorCustomEventType;

		EditorGUILayout.Space();

		if (self.eventType == 0 || self.eventType == 1)
		{
			self.tagName = EditorGUILayout.TextField("Tag Name", self.tagName);
		}
	}
Exemple #19
0
 /// <summary>
 /// 移除监听事件, 0个参数
 /// </summary>
 /// <param name="eventType"></param>
 /// <param name="callBack"></param>
 public static void RemoveListener(CustomEventType eventType, Action callBack)
 {
     OnRemoveListenering(eventType, callBack);
     _eventTable[eventType] = (Action)_eventTable[eventType] - callBack;
     OnRemovedListener(eventType);
 }
    /// <summary>
    /// Draws the editor for the events.
    /// </summary>
    public void DrawEvents(SerializedProperty _events, ref bool[] _foldouts)
    {
        // Button to add a new event
        GUI.backgroundColor = TDS_EditorUtility.BoxLightColor;
        GUI.color           = Color.green;

        if (TDS_EditorUtility.Button("+", "Add a new event", EditorStyles.miniButton))
        {
            _events.InsertArrayElementAtIndex(0);
            _events.GetArrayElementAtIndex(0).FindPropertyRelative("Name").stringValue = "New Event";

            bool[] _newFoldouts = new bool[_foldouts.Length + 1];
            Array.Copy(_foldouts, 0, _newFoldouts, 1, _foldouts.Length);
            _foldouts = _newFoldouts;
        }

        GUI.color           = Color.white;
        GUI.backgroundColor = TDS_EditorUtility.BoxDarkColor;

        for (int _i = 0; _i < _events.arraySize; _i++)
        {
            GUILayout.Space(5);

            GUI.backgroundColor = TDS_EditorUtility.BoxLightColor;
            EditorGUILayout.BeginVertical("Box");

            SerializedProperty _event     = _events.GetArrayElementAtIndex(_i);
            SerializedProperty _eventName = _event.FindPropertyRelative("Name");

            EditorGUILayout.BeginHorizontal();

            // Button to show or not this event
            if (TDS_EditorUtility.Button(_eventName.stringValue, "Wrap / unwrap this event", TDS_EditorUtility.HeaderStyle))
            {
                _foldouts[_i] = !_foldouts[_i];
            }

            GUILayout.FlexibleSpace();

            // BUttons to change the event position in the list
            if ((_i > 0) && TDS_EditorUtility.Button("▲", "Move this element up", EditorStyles.miniButton))
            {
                _events.MoveArrayElement(_i, _i - 1);
            }
            if ((_i < _events.arraySize - 1) && TDS_EditorUtility.Button("▼", "Move this element down", EditorStyles.miniButton))
            {
                _events.MoveArrayElement(_i, _i + 1);
            }

            // Button to delete this event
            GUI.color = Color.red;
            if (TDS_EditorUtility.Button("X", "Delete this event", EditorStyles.miniButton))
            {
                _events.DeleteArrayElementAtIndex(_i);

                bool[] _newFoldouts = new bool[_foldouts.Length - 1];
                Array.Copy(_foldouts, 0, _newFoldouts, 0, _i);
                Array.Copy(_foldouts, _i + 1, _newFoldouts, _i, _foldouts.Length - (_i + 1));
                _foldouts = _newFoldouts;
                break;
            }

            GUI.color = Color.white;
            EditorGUILayout.EndHorizontal();

            // If unfolded, draws this event
            if (_foldouts[_i])
            {
                SerializedProperty _eventType     = _event.FindPropertyRelative("eventType");
                SerializedProperty _doRequireType = _event.FindPropertyRelative("doRequireSpecificPlayerType");

                TDS_EditorUtility.TextField("Name", "Name of this event", _eventName);

                GUILayout.Space(3);

                TDS_EditorUtility.PropertyField("Event Type", "Type of this event", _eventType);
                CustomEventType _eventTypeValue = (CustomEventType)_eventType.enumValueIndex;
                if (_eventType.enumValueIndex > 7)
                {
                    _eventTypeValue += 13;
                }

                TDS_EditorUtility.FloatField("Delay", "Delay before starting this event", _event.FindPropertyRelative("delay"));

                GUILayout.Space(3);

                TDS_EditorUtility.Toggle("Require specific Player type", "Should this event require a specific player type to be triggered", _doRequireType);
                if (_doRequireType.boolValue)
                {
                    TDS_EditorUtility.PropertyField("Required type of Player", "Required type of player to trigger this event", _event.FindPropertyRelative("playerType"));
                }

                GUILayout.Space(5);

                switch (_eventTypeValue)
                {
                case CustomEventType.CameraMovement:
                    TDS_EditorUtility.PropertyField("Target", "Target to make the camera look ", _event.FindPropertyRelative("eventTransform"));

                    TDS_EditorUtility.FloatField("Duration", "Time to look at the target", _event.FindPropertyRelative("cameraWaitTime"));

                    TDS_EditorUtility.FloatField("Speed Coef", "Coefficient applied to the speed of the camera.", _event.FindPropertyRelative("eventFloat"));
                    break;

                case CustomEventType.DesactiveInfoBox:
                    break;

                case CustomEventType.DisplayInfoBox:
                    TDS_EditorUtility.TextField("Text ID", "ID of the text to use for the Info Box", _event.FindPropertyRelative("eventString"));
                    break;

                case CustomEventType.Instantiate:
                    TDS_EditorUtility.PropertyField("Prefab", "Prefab to instantiate", _event.FindPropertyRelative("prefab"));

                    TDS_EditorUtility.PropertyField("Instantiation transform reference", "Transform to use as reference for position & rotation for the transform of the instantiated object", _event.FindPropertyRelative("eventTransform"));
                    break;

                case CustomEventType.InstantiatePhoton:
                    TDS_EditorUtility.PropertyField("Prefab", "Prefab to instantiate", _event.FindPropertyRelative("prefab"));

                    TDS_EditorUtility.PropertyField("Instantiation transform reference", "Transform to use as reference for position & rotation for the transform of the instantiated object", _event.FindPropertyRelative("eventTransform"));
                    break;

                case CustomEventType.MovePlayerAroundPoint:
                    TDS_EditorUtility.PropertyField("Position", "Where to move te player around", _event.FindPropertyRelative("eventTransform"));
                    break;

                case CustomEventType.Narrator:
                    TDS_EditorUtility.PropertyField("Quote", "Narrator quote to play", _event.FindPropertyRelative("quote"));

                    GUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();

                    Color _originalColor = GUI.color;
                    GUI.color = new Color(.7f, .35f, .75f);
                    if (GUILayout.Button(new GUIContent("Load Quote", "Loads the quote with the ID entered as Text ID"), GUILayout.Width(150)))
                    {
                        FieldInfo _fieldInfo = typeof(TDS_Event).GetField("quote", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                        if (_fieldInfo != null)
                        {
                            TDS_NarratorQuote _quote = ((TDS_NarratorManager)Resources.Load(TDS_NarratorManager.FILE_PATH)).Quotes.FirstOrDefault(q => q.Name == _event.FindPropertyRelative("quote").FindPropertyRelative("Name").stringValue);

                            if (_quote != null)
                            {
                                TDS_Event[] _objectEvents = (TDS_Event[])typeof(TDS_EventsSystem).GetField(_events.name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(target);

                                typeof(TDS_Event).GetField("quote", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).SetValue(_objectEvents[_i], _quote);
                            }
                        }
                    }

                    GUI.color = _originalColor;
                    GUILayout.EndHorizontal();
                    break;

                case CustomEventType.PlayMusic:
                    _event.FindPropertyRelative("eventInt").intValue = EditorGUILayout.IntPopup("Music", _event.FindPropertyRelative("eventInt").intValue, Enum.GetNames(typeof(Music)), (int[])Enum.GetValues(typeof(Music)));

                    TDS_EditorUtility.FloatField("Fade Duration", "Time during which the previous music will fade out before the new one starts.", _event.FindPropertyRelative("eventFloat"));
                    break;

                case CustomEventType.WaitForObjectDeath:
                    TDS_EditorUtility.PropertyField("Object Tag", "Tag waiting for an object with dies", _event.FindPropertyRelative("eventString"));
                    TDS_EditorUtility.PropertyField("Amount", "Amount of object with this tag to wait for death", _event.FindPropertyRelative("eventInt"));
                    break;

                case CustomEventType.WaitForSpawnAreaDesactivation:
                    TDS_EditorUtility.PropertyField("Amount", "Amount of spawn area to wait for desactivation", _event.FindPropertyRelative("eventInt"));
                    break;

                case CustomEventType.UnityEventLocal:
                    TDS_EditorUtility.PropertyField("Unity Event", "Associated Unity Event to this event", _event.FindPropertyRelative("unityEvent"));
                    break;

                case CustomEventType.UnityEventOnline:
                    TDS_EditorUtility.PropertyField("Unity Event", "Associated Unity Event to this event", _event.FindPropertyRelative("unityEvent"));
                    break;

                case CustomEventType.WaitForAction:
                    TDS_EditorUtility.PropertyField("Action to wait", "Action to wait the player to perform", _event.FindPropertyRelative("actionType"));
                    break;

                case CustomEventType.WaitForEveryone:
                    TDS_EditorUtility.PropertyField("Bound min X", "Transform to use for minimum bound X value to wait", _event.FindPropertyRelative("eventTransform"));
                    break;

                default:
                    // Mhmm...
                    break;
                }

                // Button to add a new event
                GUI.color = Color.green;

                if (TDS_EditorUtility.Button("+", "Add a new event", EditorStyles.miniButton))
                {
                    _events.InsertArrayElementAtIndex(_i);

                    bool[] _newFoldouts = new bool[_foldouts.Length + 1];
                    Array.Copy(_foldouts, 0, _newFoldouts, 0, _i + 1);
                    Array.Copy(_foldouts, _i + 1, _newFoldouts, _i + 2, _foldouts.Length - (_i + 1));
                    _foldouts = _newFoldouts;
                }

                GUI.color = Color.white;
            }

            EditorGUILayout.EndVertical();
        }
    }
Exemple #21
0
 /// <summary>
 /// 移除监听事件, 4个参数
 /// </summary>
 public static void RemoveListener <T1, T2, T3, T4>(CustomEventType eventType, Action <T1, T2, T3, T4> callBack)
 {
     OnRemoveListenering(eventType, callBack);
     _eventTable[eventType] = (Action <T1, T2, T3, T4>)_eventTable[eventType] - callBack;
     OnRemovedListener(eventType);
 }
Exemple #22
0
 public CustomEventBuilder Type(CustomEventType eventType)
 {
     this.eventType = eventType;
     return(this);
 }
    /// <summary>
    /// Processes the talking data purchase event.
    /// </summary>
    /// <param name='type'>
    /// Type.
    /// </param>
    /// <param name='param'>
    /// Parameter.
    /// </param>
    private void ProcessTalkingDataPurchaseEvent(CustomEventType type, params object[] param)
    {
        switch (type)
        {
        case CustomEventType.BlueprintCompose:
            if ((bool)param[1])
            {
                UploadTalkingDataPurchaseEvent(type.ToString(), 100);
            }
            break;

        case CustomEventType.TechSpeedUp:
            if ((int)param[3] == 2)
            {
                UploadTalkingDataPurchaseEvent(type.ToString(), (int)param[5]);
            }
            break;

        case CustomEventType.IngotExchange:
            UploadTalkingDataPurchaseEvent(type.ToString(), (int)param[1]);
            break;

        case CustomEventType.AddShipBlood:
            UploadMoneyConsumeEvent(type.ToString(), (int)param[1]);
            break;

        case CustomEventType.BuyTreasureMap:
            UploadMoneyConsumeEvent(type.ToString(), (int)param[1]);
            break;

        default:
            // upload the purchase talkingdata event
            //
            for (int idx = 0; idx < param.Length; idx++)
            {
                object p = param[idx];

                // has
                if (p is string && p.ToString() == "price" && idx < param.Length - 1)
                {
                    bool tUploadIngot = true;

                    for (int i = 0; i < param.Length; i++)
                    {
                        if (param[i] is string && param[i].ToString() == "useIngot")
                        {
                            if (!(bool)(param[i + 1]))
                            {
                                tUploadIngot = false;
                            }
                        }
                    }

                    int priceOrMoney = int.Parse(param[idx + 1].ToString());

                    if (tUploadIngot)
                    {
                        UploadTalkingDataPurchaseEvent(type.ToString(), priceOrMoney);
                    }
                    else
                    {
                        UploadMoneyConsumeEvent(type.ToString(), priceOrMoney);
                    }

                    break;
                }
            }

            break;
        }
    }
Exemple #24
0
 /// <summary>
 /// 添加监听事件 0个参数
 /// </summary>
 /// <param name="eventType"></param>
 /// <param name="callBack"></param>
 public static void AddListener(CustomEventType eventType, Action callBack)
 {
     OnAddListenering(eventType, callBack);
     _eventTable[eventType] = (Action)_eventTable[eventType] + callBack;
 }
Exemple #25
0
 /// <summary>
 /// 添加监听事件 4个参数
 /// </summary>
 public static void AddListener <T1, T2, T3, T4>(CustomEventType eventType, Action <T1, T2, T3, T4> callBack)
 {
     OnAddListenering(eventType, callBack);
     _eventTable[eventType] = (Action <T1, T2, T3, T4>)_eventTable[eventType] + callBack;
 }