Exemplo 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);
     }
 }
Exemplo n.º 2
0
 // 注册碰撞器,只有注册了的碰撞器才会进行检测
 public void registeCollider(IMouseEventCollect obj, GameCamera camera = null)
 {
     if (!mUseGlobalTouch)
     {
         logError("Not Active Global Touch!");
         return;
     }
     if (obj.getCollider() == null)
     {
         logError("window must has collider that can registeCollider! " + obj.getName());
         return;
     }
     if (mAllObjectSet.Contains(obj))
     {
         logError("不能重复注册窗口碰撞体: " + obj.getName());
         return;
     }
     if (obj is myUIObject)
     {
         // 寻找窗口对应的摄像机
         ++mUGUICount;
         if (camera == null)
         {
             camera = mCameraManager.getUICamera();
         }
         if (camera == null)
         {
             logError("can not find ui camera for raycast!");
         }
         // 将窗口加入到鼠标射线检测列表中
         MouseCastWindowSet mouseCastSet = null;
         int count = mMouseCastWindowList.Count;
         for (int i = 0; i < count; ++i)
         {
             MouseCastWindowSet item = mMouseCastWindowList[i];
             if (item.getCamera() == camera)
             {
                 mouseCastSet = item;
                 break;
             }
         }
         if (mouseCastSet == null)
         {
             mouseCastSet = new MouseCastWindowSet(camera);
             mMouseCastWindowList.Add(mouseCastSet);
         }
         mouseCastSet.addWindow(obj);
     }
     else if (obj is MovableObject)
     {
         MouseCastObjectSet mouseCastSet = null;
         int count = mMouseCastObjectList.Count;
         for (int i = 0; i < count; ++i)
         {
             MouseCastObjectSet item = mMouseCastObjectList[i];
             if (item.mCamera == camera)
             {
                 mouseCastSet = item;
                 break;
             }
         }
         if (mouseCastSet == null)
         {
             mouseCastSet = new MouseCastObjectSet(camera);
             mMouseCastObjectList.Add(mouseCastSet);
         }
         mouseCastSet.addObject(obj);
         mMovableObjectList.Add(obj);
     }
     mAllObjectSet.Add(obj);
 }