Esempio n. 1
0
 // 注册碰撞器,只有注册了的碰撞器才会进行检测
 public void registeBoxCollider(IMouseEventCollect button,
                                ObjectClickCallback clickCallback = null,
                                ObjectPressCallback pressCallback = null,
                                ObjectHoverCallback hoverCallback = null,
                                GameCamera camera = null)
 {
     if (!mUseGlobalTouch)
     {
         logError("Not Active Global Touch!");
         return;
     }
     if (button.getCollider() == null)
     {
         logError("window must has collider that can registeBoxCollider! " + button.getName());
         return;
     }
     button.setClickCallback(clickCallback);
     button.setPressCallback(pressCallback);
     button.setHoverCallback(hoverCallback);
     if (!mAllButtonSet.Contains(button))
     {
         if (button is txUIObject)
         {
             // 寻找窗口对应的摄像机
             if (WidgetUtility.isNGUI((button as txUIObject).getObject()))
             {
                 ++mNGUICount;
                 if (camera == null)
                 {
                     camera = mCameraManager.getUICamera(true);
                 }
             }
             else
             {
                 ++mUGUICount;
                 if (camera == null)
                 {
                     camera = mCameraManager.getUICamera(false);
                 }
             }
             if (camera == null)
             {
                 logError("can not find ui camera for raycast!");
             }
             // 将窗口加入到鼠标射线检测列表中
             UIDepth            depth        = button.getUIDepth();
             MouseCastWindowSet mouseCastSet = null;
             foreach (var item in mMouseCastWindowList)
             {
                 if (item.mCamera == camera)
                 {
                     mouseCastSet = item;
                     break;
                 }
             }
             if (mouseCastSet == null)
             {
                 mouseCastSet = new MouseCastWindowSet(camera);
                 mMouseCastWindowList.Add(mouseCastSet);
             }
             mouseCastSet.addWindow(depth, button);
             mButtonDepthList.Add(button, depth);
         }
         else if (button is MovableObject)
         {
             MouseCastObjectSet mouseCastSet = null;
             foreach (var item in mMouseCastObjectList)
             {
                 if (item.mCamera == camera)
                 {
                     mouseCastSet = item;
                     break;
                 }
             }
             if (mouseCastSet == null)
             {
                 mouseCastSet = new MouseCastObjectSet(camera);
                 mMouseCastObjectList.Add(mouseCastSet);
             }
             mouseCastSet.addObject(button);
             mMovableObjectList.Add(button);
         }
         mAllButtonList.Add(button);
         mAllButtonSet.Add(button);
     }
 }