Beispiel #1
0
    public static void RegistMultiCommand(string commandName, OnCommandHandlerDelegate onCommandHandler)
    {
        if (string.IsNullOrEmpty(commandName) || onCommandHandler == null)
        {
                        #if UNITY_EDITOR
            throw new Exception("argument is bad!");
                        #endif
        }

        List <ItemCommandEntity> listTmp = null;
        if (mMultiDictMapCommandHandler.ContainsKey(commandName))
        {
            listTmp = mMultiDictMapCommandHandler[commandName];

            // push it
            ItemCommandEntity ic = new ItemCommandEntity();
            ic.commandName = commandName;
            ic.handler     = onCommandHandler;

            listTmp.Add(ic);
        }
        else
        {
            listTmp = new List <ItemCommandEntity>();

            ItemCommandEntity ic = new ItemCommandEntity();
            ic.commandName = commandName;
            ic.handler     = onCommandHandler;

            listTmp.Add(ic);
            mMultiDictMapCommandHandler.Add(commandName, listTmp);
        }
    }
Beispiel #2
0
    private static void RemoveCommand(string command)
    {
        if (mSingleDictMapCommandHandler.ContainsKey(command))
        {
            ItemCommandEntity ic = mSingleDictMapCommandHandler[command];
            if (ic != null)
            {
                ic.Clear();
            }

            mSingleDictMapCommandHandler.Remove(command);
        }

        if (mMultiDictMapCommandHandler.ContainsKey(command))
        {
            List <ItemCommandEntity> listTmp = mMultiDictMapCommandHandler[command];
            if (listTmp != null)
            {
                foreach (ItemCommandEntity ic in listTmp)
                {
                    ic.Clear();
                }
            }

            mMultiDictMapCommandHandler.Remove(command);
        }
    }
Beispiel #3
0
    public static void RegistCommand(string commandName, OnCommandHandlerDelegate onCommandHandler)
    {
        if (string.IsNullOrEmpty(commandName) || onCommandHandler == null)
        {
#if UNITY_EDITOR
            throw new Exception("argument is bad!");
#endif
        }

        if (mSingleDictMapCommandHandler.ContainsKey(commandName))
        {
            ItemCommandEntity ic = mSingleDictMapCommandHandler[commandName];
            ic.handler = onCommandHandler;
        }
        else
        {
            ItemCommandEntity ic = new ItemCommandEntity();
            ic.commandName = commandName;
            ic.handler     = onCommandHandler;
            mSingleDictMapCommandHandler.Add(commandName, ic);
        }
    }
Beispiel #4
0
    //
    // Process command
    //
    //
    private static void ProcessCommand(string expression)
    {
        string[] arrayCommand = expression.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
        string   commandName  = arrayCommand[0];

        commandName = commandName.Trim();

        List <System.Object> arrayParamsList = new List <System.Object>();
        int nums = arrayCommand.Length - 1;

        if (nums > 0)
        {
            for (int k = 1; k <= nums; k++)
            {
                string paramKey = arrayCommand[k];
                paramKey = paramKey.Trim();// clear it
                if (paramKey.Substring(0, 1) == "-")
                {
                    if (paramKey.Length >= 2)
                    {
                        paramKey = paramKey.Substring(1);
                    }
                }
                arrayParamsList.Add(paramKey);// gather params
            }
        }

        // search command
        List <ItemCommandEntity> listTmp = new List <ItemCommandEntity>();

        if (mSingleDictMapCommandHandler.ContainsKey(commandName))
        {
            ItemCommandEntity ic = mSingleDictMapCommandHandler[commandName];
            if (ic != null)
            {
                listTmp.Add(ic);
            }
        }
        if (mMultiDictMapCommandHandler.ContainsKey(commandName))
        {
            List <ItemCommandEntity> listTmp2 = mMultiDictMapCommandHandler[commandName];
            if (listTmp2 != null)
            {
                listTmp.AddRange(listTmp2);
            }
        }

        //
        if (arrayParamsList.Count > 0)
        {
            foreach (ItemCommandEntity ic in listTmp)
            {
                ic.Excute(arrayParamsList.ToArray());
            }
        }
        else
        {
            // not any params for  function
            foreach (ItemCommandEntity ic in listTmp)
            {
                ic.Excute();
            }
        }
    }