예제 #1
0
    //new simple event manager test. untested as of now.
    public void CallEvent(string eventName, object eventData)
    {
        //   Debug.LogWarning("!"+eventName+":"+eventData);

        //modifys a single instance of the event so that an event can be created without the "new" keyword *(unless the objecty is null of course...)*
        if (QuickEventCall == null)
        {
            QuickEventCall = new EventBPA();
        }
        QuickEventCall.eventName = eventName;
        QuickEventCall.eventData = eventData;
        CallEvent(QuickEventCall);
    }
예제 #2
0
 public void CallEvent(EventBPA eventCall)
 {
     for (int i = 0; i < eventsList.Count; i++)
     {
         if (eventsList [i].eventName == eventCall.eventName)
         {
             for (int e = 0; e < eventsList[i].eventListeners.Count; e++)
             {
                 eventsList [i].eventListeners [e].TriggerEvent(eventCall);
                 if (eventsList [i].eventListeners [e].GetRemoveIfEventTriggered())
                 {
                     //remove event if required
                     eventsList [i].eventListeners.Remove(eventsList [i].eventListeners [e]);
                     e--;
                 }
             }
             //as found a matching event, so register and return.
             return;
         }
     }
 }
    public void TriggerEvent(EventBPA eventRecieved)
    {
        string objectDataString = (string)eventRecieved.eventData as string;

        string[] dataInArray = objectDataString.Split(":,".ToCharArray());
        int      addValue    = 0;

        int defaultValue = 0;

        if (dataInArray.Length < 1)
        {
            return;
        }
        if (dataInArray.Length > 2)
        {
            TryParseOrGetFromKey(dataInArray[2], out addValue, -1);
        }
        if (dataInArray.Length > 3)
        {
            TryParseOrGetFromKey(dataInArray[3], out defaultValue, -1);
        }
        //CLEAR GROUP FUNCTION (NOT MATH)
        if (eventRecieved.eventName.ToUpper() == "CLEAR")
        {
            //add 1 value to a key, and set the default value.
            IniGameMemory.instance.ClearGroup(dataInArray[0]);
            Debug.Log("Attempt to clear:" + dataInArray[0]);
        }
        //ADD FUNCTION
        if (eventRecieved.eventName.ToUpper() == "ADD")
        {
            //add 1 value to a key, and set the default value.
            IniGameMemory.instance.IncrementKeyValue(dataInArray[0], dataInArray[1], addValue, defaultValue);
        }

        //SUB FUNCTION
        if (eventRecieved.eventName.ToUpper() == "SUB")
        {
            IniGameMemory.instance.IncrementKeyValue(dataInArray[0], dataInArray[1], addValue * -1, defaultValue);
        }
        //SET FUNCTION
        if (eventRecieved.eventName.ToUpper() == "SET")
        {
            //  IniGameMemory.instance.WriteData(dataInArray[0], dataInArray[1], addValue);
            //Use a string instead of an int, so that this can also be used for non numaric data setting.
            IniGameMemory.instance.WriteData(dataInArray[0], dataInArray[1], dataInArray[2]);
        }
        //MULT
        if (eventRecieved.eventName.ToUpper() == "MULT")
        {
            IniGameMemory.instance.MultiplyKeyValue(dataInArray[0], dataInArray[1], addValue, defaultValue);
        }
        //DIV
        if (eventRecieved.eventName.ToUpper() == "DIV")
        {
            /*
             * Division example:
             *  SET(v,a,               32)
             *  SET(v,b,                2)
             *  DIV(output,a,     v/a,v/b)
             *  --------------------------
             *  Can also be written as:
             *      SET(v,a:32)
             *      SET(v,b:2)
             *      DIV(output,a:v/a,v/b)
             * Or like this:
             *      SET(Var,a: 32)
             *      SET(Var,b:  2)
             *      DIV(Output,c: Var\a,Var\b)
             * */
            if (defaultValue != 0)
            {
                IniGameMemory.instance.WriteData(dataInArray[0], dataInArray[1], addValue / defaultValue);
            }
        }
    }