Ejemplo n.º 1
0
 // Use this for initialization
 void OnEnable()
 {
     foreach (var e in EventMap)
     {
         VRsqr_EventsManager.StartListening(e.eventIn, eventHandler_In);
     }
 }
Ejemplo n.º 2
0
        private void eventHandlerFunc(int EventContext)
        {
            //eventInTimeStamp = VRsqr_EventsManager.getEventInTime(EventContext);
            //eventOutTimeStamp = VRsqr_EventsManager.getEventOutTime(EventContext);

            VRsqrUtil.Debug.LogInfo("eventHandlerFunc: EventContext = " + EventContext);
            int eventParamInd = 0;

            // use reflection mechanisms to collect the EventParam fields, as added in the definition of the current sub-class, which is inheriting EventIn
            foreach (EventParamsField epf in this.eventParamFields)
            {
                VRsqrUtil.Debug.Log(LogLevel.Debug, "eventHandlerFunc:  epf.paramName = " + epf.paramName + "  , epf.paramType = " + epf.paramType);
                EventParam ep = VRsqr_EventsManager.GetEventParam(EventContext, epf.paramName);
                if (ep != null) // data was set in this event for this param
                {
                    VRsqrUtil.Debug.Log(LogLevel.Debug, "eventHandlerFunc: ep.paramType = " + ep.paramType + " , ep.paramObjVal = " + ep.paramObjVal);
                    if (ep.paramObjVal != null)                             //  ep.Val() == null)
                    {
                        epf.fiEventParamObj.SetValue(this, ep.paramObjVal); // TODO: save the setter function one time, at init
                    }
                    else
                    {
                        if (ep.paramType == null)
                        {
                            ep.paramType = epf.paramType; // interpret the received parameter based on the receiving-end expected input
                        }
                        VRsqrUtil.Debug.Log(LogLevel.Debug, "eventHandlerFunc: ep.StringToObjVal() = " + ep.StringToObjVal());
                        epf.fiEventParamObj.SetValue(this, ep.StringToObjVal()); // TODO: make this mode, of string-based setting, deprecate
                    }
                    eventParams[eventParamInd++] = ep;
                }
            }
        }
Ejemplo n.º 3
0
        public void StartListening(GameObject listeningObj, UnityAction <int> customEventHandler = null)
        {
            VRsqrUtil.Debug.Log("StartListening");
            this.basicEventHandler = eventHandlerFunc;

            VRsqrUtil.Debug.Log("StartListening: listeningObj.name = " + listeningObj.name);
            string gameObjName = listeningObj.name;

            Type   tempType   = this.GetType();
            String typeString = tempType.ToString();

            string[] splitArray = typeString.Split("+"[0]);
            string   scriptName = splitArray[0];

            VRsqrUtil.Debug.Log("StartListening: scriptName = " + scriptName);

            Component script = listeningObj.GetComponent(scriptName);

            FieldInfo[] scriptFields = script.GetType().GetFields();

            string eventName = gameObjName;

            foreach (FieldInfo field in scriptFields)
            {
                VRsqrUtil.Debug.Log("StartListening: field = " + field.Name);
                if (System.Object.ReferenceEquals(field.GetValue(script), this))
                {
                    VRsqrUtil.Debug.Log("=== StartListening: field.GetValue(script) = " + field.GetValue(script));
                    eventName += "." + field.Name;
                }
            }
            this.eventName = eventName;

            VRsqr_EventsManager.StartListening(eventName, this.basicEventHandler);
            if (customEventHandler != null)
            {
                this.customEventHandler = customEventHandler;
                VRsqr_EventsManager.StartListening(eventName, this.customEventHandler);
            }

            FieldInfo[] eventParamFieldInfo = this.GetType().GetFields();
            foreach (FieldInfo pfi in eventParamFieldInfo)
            {
                if (pfi.FieldType != typeof(EventParam)) // TEMP
                {
                    string varName = pfi.Name;
                    VRsqrUtil.Debug.Log("StartListening: varName = " + varName);

                    this.eventParamFields.Add(new EventParamsField {
                        fiEventParamObj = pfi, paramName = varName
                    });
                }
            }
        }
Ejemplo n.º 4
0
 public void eventHandlerFunc(int EventContext)
 {
     VRsqrUtil.Debug.Log("eventHandlerFunc: EventContext = " + EventContext);
     // use reflection mechanisms to collect the EventParam fields, as added in the definition of the current sub-class, which is inheriting EventIn
     foreach (EventParamsField epf in this.eventParamFields)
     {
         VRsqrUtil.Debug.Log("eventHandlerFunc:  epf.paramName = " + epf.paramName);
         EventParam ep = VRsqr_EventsManager.GetEventParam(EventContext, epf.paramName);
         VRsqrUtil.Debug.Log("eventHandlerFunc:  ep.Val() = " + ep.Val());
         epf.fiEventParamObj.SetValue(this, ep.Val());
     }
 }
Ejemplo n.º 5
0
 public void eventHandlerFunc(int EventContext)
 {
     VRsqrUtil.Debug.LogInfo("eventHandlerFunc: EventContext = " + EventContext);
     // use reflection mechanisms to collect the EventParam fields, as added in the definition of the current sub-class, which is inheriting EventIn
     foreach (EventParamsField epf in this.eventParamFields)
     {
         string nameFieldVal = (string)epf.fiParamName.GetValue(epf.fiEventParamObj.GetValue(this));
         //VRsqrUtil.Debug.Log(LogLevel.Debug, "eventHandlerFunc: nameFieldVal = " + nameFieldVal);
         EventParam ep = VRsqr_EventsManager.GetEventParam(EventContext, nameFieldVal);
         epf.fiEventParamObj.SetValue(this, ep);
     }
 }
Ejemplo n.º 6
0
        public void sendData(GameObject sendingObj)
        {
            if (initialized == false)
            {
                Init(sendingObj);
                initialized = true;
            }

            eventParams = new EventParam[eventParamFields.Count];
            VRsqrUtil.Debug.Log(LogLevel.Debug, "TTTTTTTTTTTTTTT  sendData: eventParamFields.Count = " + eventParamFields.Count);

            buildEventParamArray();

            VRsqrUtil.Debug.Log(LogLevel.Debug, "TTTTTTTTTTTTTTT  sendData: TriggerDataEvent - eventParams.Length = " + eventParams.Length);
            VRsqr_EventsManager.TriggerDataEvent(this.eventName, this.eventParams, this.persistent);
        }
Ejemplo n.º 7
0
        public static void TriggerDataEvent(UnityEventData unityEventData)
        {
            if (unityEventData == null || unityEventData.eventName == "")
            {
                VRsqrUtil.Debug.Log(LogLevel.Error, "TriggerDataEvent: Illegal unityEventData argument");
                return;
            }

            UnityEventInt thisEvent      = null;
            bool          listenerExists = instance.NameToListenedEventDictionary.TryGetValue(unityEventData.eventName, out thisEvent);

            VRsqrUtil.Debug.LogInfo("TriggerDataEvent: eventName = " + unityEventData.eventName + "    listenerExists = " + listenerExists);
            if (unityEventData.presistentData || listenerExists) // there is at least one listerner to this event
            {
                int eventContextInd = GetFreeEventDataInd();
                int dataBufferInd   = eventContextInd % numDataBuffers;
                eventDataBuffers[dataBufferInd] = unityEventData;
                eventDataBuffers[dataBufferInd].eventContextInd = eventContextInd;

                // keep the index of the most recent triggering of this event - to support getting values of past events (e.g. in case of persistent events with no listener)
                //instance.NameToLastEventIndDictionary.Add(unityEventData.eventName.ToLower(), dataBufferInd);
                instance.NameToLastEventIndDictionary[unityEventData.eventName] = dataBufferInd;

                unityEventData.varInd = new Dictionary <string, int>();
                if (unityEventData.eventParams != null)
                {
                    for (int i = 0; i < unityEventData.eventParams.Length; i++)
                    {
                        //unityEventData.varInd.Add(unityEventData.eventParams[i].NameString.ToLower(), i);
                        //unityEventData.varInd[unityEventData.eventParams[i].NameString.ToLower()] = i;
                        unityEventData.eventParams[i].NameString = VRsqr_EventsManager.StandardizeString(unityEventData.eventParams[i].NameString);
                        unityEventData.varInd[unityEventData.eventParams[i].NameString] = i;
                        VRsqrUtil.Debug.Log(LogLevel.Debug, "---------- TriggerDataEvent: NameString = " + unityEventData.eventParams[i].NameString +
                                            " , ValString = " + unityEventData.eventParams[i].ValString +
                                            " , paramObjVal = " + unityEventData.eventParams[i].paramObjVal);
                    }
                }

                if (listenerExists)
                {
                    thisEvent.Invoke(eventContextInd);
                }
            }
        }
Ejemplo n.º 8
0
        public void StartListening(GameObject listeningObj, UnityAction <int> customEventHandler = null)
        {
            VRsqrUtil.Debug.LogInfo("StartListening");

            if (initialized == false)
            {
                Init(listeningObj);
                eventParams = new EventParam[eventParamFields.Count];

                initialized = true;
            }

            this.basicEventHandler = eventHandlerFunc;

            VRsqr_EventsManager.StartListening(this.eventName, this.basicEventHandler);
            if (customEventHandler != null)
            {
                this.customEventHandler = customEventHandler;
                VRsqr_EventsManager.StartListening(this.eventName, this.customEventHandler);
            }
        }
Ejemplo n.º 9
0
        public void StartListening(UnityAction <int> customEventHandler = null)
        {
            VRsqrUtil.Debug.Log(LogLevel.Warning, "StartListening: customEventHandler = " + customEventHandler);
            this.basicEventHandler = eventHandlerFunc;

            Type tempType = this.GetType();

            VRsqrUtil.Debug.Log(LogLevel.Warning, "StartListening: tempType = " + tempType);
            FieldInfo tempInfo = tempType.GetField("eventName");

            VRsqrUtil.Debug.Log(LogLevel.Warning, "StartListening: tempInfo = " + tempInfo);
            string eventName = (string)this.GetType().GetField("eventName").GetValue(this);

            VRsqrUtil.Debug.Log(LogLevel.Warning, "StartListening: eventName = " + eventName);
            VRsqr_EventsManager.StartListening(eventName, this.basicEventHandler);
            if (customEventHandler != null)
            {
                this.customEventHandler = customEventHandler;
                VRsqr_EventsManager.StartListening(eventName, this.customEventHandler);
            }

            eventParamFields = new List <EventParamsField>();
            FieldInfo[] eventParamFieldInfo = this.GetType().GetFields();
            foreach (FieldInfo pfi in eventParamFieldInfo)
            {
                if (pfi.FieldType == typeof(EventParam))
                {
                    //string nameFieldVal = (string)typeof(EventParam).GetField("NameString").GetValue(pfi.GetValue(eventListenerData));
                    FieldInfo fiParamName = typeof(EventParam).GetField("NameString");
                    this.eventParamFields.Add(new EventIn.EventParamsField {
                        fiEventParamObj = pfi, fiParamName = fiParamName
                    });
                    VRsqrUtil.Debug.Log(LogLevel.Warning, "StartListening: fiParamName.Name = " + fiParamName.Name);
                    //EventParam ep = VRsqr_EventsManager.GetEventParam(EventContext, nameFieldVal);
                    //pfi.SetValue(eventListenerData, ep);
                }
            }
        }
Ejemplo n.º 10
0
        void eventHandler_In(int EventContextInd)
        {
            UnityEventData eventData = VRsqr_EventsManager.GetEventData(EventContextInd);

            VRsqr_EventsManager.TriggerDataEvent(eventData);
        }
Ejemplo n.º 11
0
 public void trigger()
 {
     eventName = VRsqr_EventsManager.StandardizeString(eventName);
     VRsqr_EventsManager.TriggerDataEvent(eventName, eventParams);
     VRsqrUtil.Debug.LogInfo("------------ EventOut - trigger: eventName = " + eventName);
 }