예제 #1
0
 protected void handleGetElementByPos(Command command)
 {
     Logger.d("handleGetElementByPos");
     try
     {
         List <double>     pos          = JsonParser.Deserialization <List <double> >(command);
         float             x            = (float)pos[0];
         float             y            = (float)pos[1];
         List <GameObject> selectedObjs = uiHelper.FindGameObjectsByPoint(new Point(x, y));
         if (selectedObjs == null || selectedObjs.Count == 0)
         {
             command.status  = ResponseStatus.GAMEOBJ_NOT_EXIST;
             command.sendObj = "";
             CommandDispatcher.SendCommand(command);
             return;
         }
         ElementInfo element  = new ElementInfo();
         GameObject  obj      = selectedObjs[0];
         string      name     = GameObjectTool.GenerateNamePath(obj);
         int         instance = GameObjectManager.INSTANCE.AddGameObject(obj);
         element = new ElementInfo(name, instance);
         Logger.d("Element name = " + element.name + " ,instance =" + element.instance);
         command.sendObj = element;
     }
     catch (System.Exception ex)
     {
         Logger.w(ex.Message + " " + ex.StackTrace);
         command.status  = ResponseStatus.UN_KNOW_ERROR;
         command.sendObj = ex.Message + " " + ex.StackTrace;
     }
     CommandDispatcher.SendCommand(command);
 }
예제 #2
0
        protected void handleGetElementsByComponent(Command command)
        {
            Logger.d("handleGetElementsByComponent " + command.recvObj);
            List <string> componentNames = JsonParser.Deserialization <List <string> >(command);

            string componentName = componentNames[0];

            List <GameObject>  objs;
            List <ElementInfo> elements = new List <ElementInfo>();

            command.sendObj = elements;
            try
            {
                objs = GameObjectManager.INSTANCE.FindByComponent(componentName);
                foreach (GameObject obj in objs)
                {
                    string      name     = GameObjectTool.GenerateNamePath(obj);
                    int         instance = GameObjectManager.INSTANCE.AddGameObject(obj);
                    ElementInfo e        = new ElementInfo(name, instance);
                    elements.Add(e);
                    Logger.d("Element name = " + e.name + " ,instance =" + e.instance);
                }
            }
            catch (System.Exception ex)
            {
                Logger.w(ex.Message + " " + ex.StackTrace);
                command.status = ResponseStatus.UN_KNOW_ERROR;
            }
            CommandDispatcher.SendCommand(command);
        }
예제 #3
0
        public List <InteractElement> GetInteractElements(List <String> buttonTypes)
        {
            List <UINode> nodes = NGUITools.GetInteractiveGameobject(buttonTypes);

            List <InteractElement> elements = new List <InteractElement>();

            foreach (UINode node in nodes)
            {
                GameObject gameobject = node.gameobject;
                Rectangle  rect       = node.bound;

                InteractElement element = new InteractElement();
                element.nodetype = AutoTravelNodeType.BUTTON;
                //能够很容易的获取控件上的文字,下同
                String path_name = GameObjectTool.GenerateNamePath(gameobject);
                element.name          = path_name;
                element.instanceid    = gameobject.GetInstanceID();
                element.bound.x       = rect.x;
                element.bound.y       = rect.y;
                element.bound.fWidth  = rect.width;
                element.bound.fHeight = rect.height;
                elements.Add(element);
                GameObjectManager.INSTANCE.AddGameObject(gameobject);
            }

            return(elements);
        }
예제 #4
0
        /// <summary>
        /// 获取GameObject在屏幕上的位置信息
        /// </summary>
        /// <param name="command"></param>
        protected void handleGetElementsBound(Command command)
        {
            Logger.d("handleGetElementsBound" + command.recvObj);
            List <int>       instances  = JsonParser.Deserialization <List <int> >(command);
            List <BoundInfo> boundInfos = new List <BoundInfo>();


            foreach (int instance in instances)
            {
                GameObject obj   = GameObjectManager.INSTANCE.FindGameObjectGlobal(instance);
                BoundInfo  bound = new BoundInfo();
                bound.instance = instance;
                boundInfos.Add(bound);
                try
                {
                    if (obj != null)
                    {
                        Rectangle rc = uiHelper.GetBound(obj);
                        if (rc == null)
                        {
                            bound.visible = false;
                        }
                        else
                        {
                            bound.x       = rc.x;
                            bound.y       = rc.y;
                            bound.width   = rc.width;
                            bound.height  = rc.height;
                            bound.visible = obj.activeInHierarchy;
                        }
                        bound.path = GameObjectTool.GenerateNamePath(obj);
                    }
                    else
                    {
                        bound.existed = false;
                    }
                }
                catch (System.Exception ex)
                {
                    Logger.w(ex.Message + " " + ex.StackTrace);
                    bound.visible = false;
                }
            }

            foreach (BoundInfo b in boundInfos)
            {
                Logger.d("Bound width = " + b.width + " height = " + b.height + " x = " + b.x + " y=" + b.y + " existed = " + b.existed + " visible = " + b.visible);
            }
            command.sendObj = boundInfos;
            CommandDispatcher.SendCommand(command);
        }
예제 #5
0
        public List <InteractElement> GetInteractElements(List <String> buttonTypes)
        {
            List <UINode> nodes = EventSystemTool.GetInteractiveGameobject(buttonTypes);

            List <InteractElement> elements = new List <InteractElement>();

            foreach (UINode node in nodes)
            {
                GameObject gameobject = node.gameobject;
                Rectangle  rect       = node.bound;

                InteractElement element = new InteractElement();
                if (gameobject.GetComponent <Button>() != null)
                {
                    element.nodetype = AutoTravelNodeType.BUTTON;
                    //能够很容易的获取控件上的文字,下同
                }
                else if (gameobject.GetComponent <InputField>() != null)
                {
                    if (gameobject.GetComponent <InputField>().contentType == InputField.ContentType.Password)
                    {
                        element.nodetype = AutoTravelNodeType.INPUTPAS;
                    }
                    else
                    {
                        element.nodetype = AutoTravelNodeType.INPUTXT;
                    }
                }
                else
                {
                    element.nodetype = AutoTravelNodeType.OTHER;
                }
                String path_name = GameObjectTool.GenerateNamePath(gameobject);
                element.name          = path_name;
                element.instanceid    = gameobject.GetInstanceID();
                element.bound.x       = rect.x;
                element.bound.y       = rect.y;
                element.bound.fWidth  = rect.width;
                element.bound.fHeight = rect.height;
                elements.Add(element);
                GameObjectManager.INSTANCE.AddGameObject(gameobject);
            }

            return(elements);
        }
예제 #6
0
 protected void handleDumpTree(Command command)
 {
     Logger.d("handleDumpTree ");
     try
     {
         string   xml      = GameObjectTool.DumpTree();
         string   scene    = Application.loadedLevelName;
         DumpTree dumpTree = new DumpTree();
         dumpTree.scene  = scene;
         dumpTree.xml    = xml;
         command.sendObj = dumpTree;
     }
     catch (System.Exception ex)
     {
         Logger.w(ex.Message + " " + ex.StackTrace);
         command.status  = ResponseStatus.UN_KNOW_ERROR;
         command.sendObj = ex.Message + " " + ex.StackTrace;
     }
     CommandDispatcher.SendCommand(command);
 }
예제 #7
0
        /// <summary>
        /// 获取所有的根节点,不包含未激活的节点
        /// </summary>
        /// <returns></returns>
        public static Transform[] GetRootTransforms()
        {
            Transform[] transforms = UnityEngine.Object.FindObjectsOfType <Transform>();

            //Logger.d("transforms = " + transforms.Length);

            List <Transform> list = new List <Transform>();

            foreach (Transform transform in transforms)
            {
                if (transform == null)
                {
                    continue;
                }

                if (GameObjectTool.IsRoot(transform.gameObject))
                {
                    list.Add(transform);
                    continue;
                }
            }

            return(list.ToArray());
        }
예제 #8
0
        protected void NotifyTouchElement()
        {
            try
            {
                Cmd     cmd       = Cmd.TOUCH_NOTIFY;
                Command command   = new Command(cmd, recordSocket);
                Touch[] touchs    = Input.touches;
                int     fingerNum = touchs.Length;
                if (fingerNum == 0)
                {
                    return;
                }
                bool        finded      = false;
                TouchNotify touchNotify = new TouchNotify();
                string      scene       = Application.loadedLevelName;
                touchNotify.scene = scene;
                for (int i = 0; i < fingerNum && i < 5; ++i)
                {
                    Touch t = touchs[i];
                    Logger.d("Touch delta time = {0},x = {1},y={2} ,fingerId = {3},phase = {4}", t.deltaTime * Time.timeScale, t.position.x, t.position.y, t.fingerId, t.phase);
                    //只考虑,一个点的情况,Begin的时候
                    if (t.phase == TouchPhase.Began && !finded)
                    {
                        GameObject selectedObj = null;
                        try
                        {
                            selectedObj = NGUITools.FindElementByUnityPos(new Point(t.position.x, t.position.y));
                        }
                        catch (System.Exception ex)
                        {
                            Logger.v(ex.StackTrace);
                        }
                        if (selectedObj != null && NGUITools.IsInteraction(selectedObj))
                        {
                            finded = true;
                            String name = GameObjectTool.GenerateNamePath(selectedObj);
                            Logger.d("Touch UI = " + name);
                            touchNotify.name = name;
                        }
                    }
                    if (t.phase == TouchPhase.Canceled || t.phase == TouchPhase.Stationary || t.phase == TouchPhase.Moved)
                    {
                        continue;
                    }
                    TouchData td = new TouchData();
                    td.deltatime = DateTime.Now.Ticks / 10000 - startTime;
                    td.fingerId  = (short)t.fingerId;
                    Point point = CoordinateTool.ConvertUnity2Mobile(t.position);
                    td.x         = point.X;
                    td.y         = point.Y;
                    td.relativeX = t.position.x / Screen.width;
                    td.relativeY = (Screen.height - t.position.y) / Screen.height;
                    switch (t.phase)
                    {
                    case TouchPhase.Began:
                        td.phase = (byte)TouchType.TOUCH_DOWN;
                        break;

                    //case TouchPhase.Moved:
                    //    td.bPhase = (byte)ATTouchType.AT_TOUCH_MOVE;
                    //    break;
                    case TouchPhase.Ended:
                        td.phase = (byte)TouchType.TOUCH_UP;
                        break;
                    }
                    touchNotify.touches.Add(td);
                }
                if (touchNotify.touches.Count > 0)
                {
                    command.sendObj = touchNotify;
                    CommandDispatcher.SendCommand(command);
                }
            }
            catch (System.Exception ex)
            {
                Logger.w(ex.Message + "\n" + ex.StackTrace);
                Cmd     cmd     = Cmd.TOUCH_NOTIFY;
                Command command = new Command(cmd, recordSocket);
                command.sendObj = ex.Message + "\n" + ex.StackTrace;
                command.status  = ResponseStatus.UN_KNOW_ERROR;
                CommandDispatcher.SendCommand(command);
            }
        }