Esempio n. 1
0
    //------------------------------------------------------------------------------------------------------------
    // ignoreInactive表示是否忽略未启用的节点,当includeSelf为true时orderInParent才会生效
    protected void setUIDepth(myUIObject window, int orderInParent, bool includeSelf = true, bool ignoreInactive = false)
    {
        // 先设置当前窗口的深度
        if (includeSelf)
        {
            UIDepth parentDepth = null;
            if (window != mRoot)
            {
                parentDepth = window.getParent().getDepth();
            }
            window.getDepth().setDepthValue(parentDepth, orderInParent, window.isDepthOverAllChild());
            mGlobalTouchSystem.notifyWindowDepthChanged(window);
        }
        if (ignoreInactive && !window.isActive())
        {
            return;
        }

        // 再设置子窗口的深度,子节点在父节点中的下标从1开始,如果从0开始,则会与默认值的0混淆
        var children   = window.getChildList();
        int childCount = children.Count;

        for (int i = 0; i < childCount; ++i)
        {
            setUIDepth(children[i], i + 1, true, ignoreInactive);
        }
    }
Esempio n. 2
0
 // 注册碰撞器,只有注册了的碰撞器才会进行检测
 public void registeBoxCollider(txUIObject button, UIClickCallback clickCallback = null,
                                UIPressCallback pressCallback = null, UIHoverCallback hoverCallback = null)
 {
     if (mUseGlobalTouch)
     {
         button.setClickCallback(clickCallback);
         button.setPressCallback(pressCallback);
         button.setHoverCallback(hoverCallback);
         if (!mButtonCallbackList.Contains(button))
         {
             mButtonCallbackList.Add(button);
             UIDepth depth = new UIDepth(button.getLayout().getRenderOrder(), button.getDepth());
             if (!mButtonOrderList.ContainsKey(depth))
             {
                 mButtonOrderList.Add(depth, new List <txUIObject>());
             }
             mButtonOrderList[depth].Add(button);
         }
     }
     // 如果不使用
     else
     {
         logError("Not Active Global Touch! use public void registeBoxCollider(txUIObject button, " +
                  "UIEventListener.VoidDelegate clickCallback = null,UIEventListener.BoolDelegate pressCallback = null, " +
                  "UIEventListener.BoolDelegate hoverCallback = null) instead");
     }
 }
Esempio n. 3
0
 // 注册碰撞器,只有注册了的碰撞器才会进行检测
 public void registeBoxCollider(txUIObject button, BoxColliderClickCallback clickCallback = null,
                                BoxColliderPressCallback pressCallback = null, BoxColliderHoverCallback hoverCallback = null)
 {
     if (mUseGlobalTouch)
     {
         if (!mButtonCallbackList.ContainsKey(button))
         {
             ColliderCallBack colliderCallback = new ColliderCallBack();
             colliderCallback.mButton        = button;
             colliderCallback.mClickCallback = clickCallback;
             colliderCallback.mHoverCallback = hoverCallback;
             colliderCallback.mPressCallback = pressCallback;
             mButtonCallbackList.Add(button, colliderCallback);
             UIDepth depth = new UIDepth(button.mLayout.getRenderOrder(), button.getDepth());
             if (!mButtonOrderList.ContainsKey(depth))
             {
                 mButtonOrderList.Add(depth, new List <txUIObject>());
             }
             mButtonOrderList[depth].Add(button);
         }
     }
     // 如果不使用
     else
     {
         logError("Not Active Global Touch! use public void registeBoxCollider(txUIObject button, " +
                  "UIEventListener.VoidDelegate clickCallback = null,UIEventListener.BoolDelegate pressCallback = null, " +
                  "UIEventListener.BoolDelegate hoverCallback = null) instead");
     }
 }
Esempio n. 4
0
	public virtual void keyProcess()
	{
		// F1切换日志等级
		if (FrameBase.getKeyCurrentDown(KeyCode.F1))
		{
			int newLevel = ((int)UnityUtility.getLogLevel() + 1) % (int)LOG_LEVEL.MAX;
			UnityUtility.setLogLevel((LOG_LEVEL)newLevel);
		}
		// F2检测当前鼠标坐标下有哪些窗口
		if (FrameBase.getKeyCurrentDown(KeyCode.F2))
		{
			Vector3 mousePos = FrameBase.getMousePosition();
			var resultList = FrameBase.mGlobalTouchSystem.getAllHoverWindow(ref mousePos, null, true);
			int resultCount = resultList.Count;
			for (int i = 0; i < resultCount; ++i)
			{
				UIDepth depth = resultList[i].getDepth();
				UnityUtility.log("窗口:" + resultList[i].getName() +
										", 深度:layout:" + depth.toDepthString() +
										", priority:" + depth.getPriority(),
										LOG_LEVEL.FORCE);
			}
		}
		// F3启用或禁用用作调试的脚本的更新
		if (FrameBase.getKeyCurrentDown(KeyCode.F3))
		{
			mEnableScriptDebug = !mEnableScriptDebug;
		}
	}
Esempio n. 5
0
 public UIBase(int resId, UILevel uiLevel, UIDepth depth = UIDepth.Normal)
 {
     this.UILevel      = uiLevel;
     ResId             = resId;
     this.uiCreateType = UICreateType.Res;
     this.uiDepthLayer = depth;
     this.Name         = CommonHelper.GetResourceMgr().GetResNameById(resId);
 }
 public void addWindow(UIDepth depth, IMouseEventCollect window)
 {
     if (!mWindowOrderList.ContainsKey(depth))
     {
         mWindowOrderList.Add(depth, new List <IMouseEventCollect>());
     }
     mWindowOrderList[depth].Add(window);
 }
 public bool hasWindow(UIDepth depth, IMouseEventCollect window)
 {
     if (!mWindowOrderList.ContainsKey(depth))
     {
         return(false);
     }
     return(mWindowOrderList[depth].Contains(window));
 }
Esempio n. 8
0
 /// <summary>
 /// 只清空逻辑
 /// </summary>
 public void RemoveAtIndex(int index)
 {
     if (index < childItem.Count)
     {
         UIDepth.Remove(childItem[index]);
         childItem.RemoveAt(index);
     }
 }
Esempio n. 9
0
 // 注销碰撞器
 public void unregisteBoxCollider(txUIObject button)
 {
     if (mButtonCallbackList.ContainsKey(button))
     {
         mButtonCallbackList.Remove(button);
         UIDepth depth = new UIDepth(button.mLayout.getRenderOrder(), button.getDepth());
         mButtonOrderList[depth].Remove(button);
     }
 }
    public void removeWindow(IMouseEventCollect window)
    {
        UIDepth depth = window.getUIDepth();

        mWindowOrderList[depth].Remove(window);
        if (mWindowOrderList[depth].Count == 0)
        {
            mWindowOrderList.Remove(depth);
        }
    }
Esempio n. 11
0
    /// <summary>
    /// 添加父级
    /// </summary>
    /// <param name="order"></param>
    public void ApplyParentItem()
    {
        UIDepth temp = UIDepth.Add(ParentItem);

        if (temp != null)
        {
            temp.IsUI  = true;
            temp.Order = parentOrder;
        }
    }
Esempio n. 12
0
    public void bindPassOnlyParent(myUIObject obj)
    {
        // 设置当前窗口需要调整深度在所有子节点之上,并计算深度调整值
        obj.setDepthOverAllChild(true);
        UIDepth depth = obj.getDepth();

        depth.setDepthValue(obj.getParent().getDepth(), depth.getOrderInParent(), obj.isDepthOverAllChild());
        // 刷新深度
        mGlobalTouchSystem.bindPassOnlyParent(obj);
    }
Esempio n. 13
0
    /// <summary>
    /// 设置子物体UI
    /// </summary>
    /// <param name="index"></param>
    /// <param name="isUI"></param>
    public void SetChildItemIsUI(int index, bool isUI)
    {
        if (index >= childItem.Count)
        {
            return;
        }
        UIDepth temp = UIDepth.Add(childItem[index]);

        temp.IsUI = isUI;
    }
Esempio n. 14
0
 public static int compare(UIDepth depth0, UIDepth depth1)
 {
     for (int i = 0; i < DEPTH_COUNT; ++i)
     {
         if (depth0.mWindowDepth[i] != depth1.mWindowDepth[i])
         {
             return(sign(depth1.mWindowDepth[i], depth0.mWindowDepth[i]));
         }
     }
     return(sign(depth1.mPriority - depth0.mPriority));
 }
Esempio n. 15
0
 public myUIObject()
 {
     mID        = makeID();
     mDepth     = new UIDepth();
     mChildList = new List <myUIObject>();
     mLongPressTimeThreshold   = 1.0f;
     mPressedTime              = -1.0f;
     mLongPressLengthThreshold = -1.0f;
     mLastClickTime            = -1.0f;
     mPassRay = true;
     mEnable  = false;               // 出于效率考虑,窗口默认不启用更新,只有部分窗口和使用组件进行变化时才自动启用更新
 }
    public void windowDepthChanged(UIDepth lastDepth, IMouseEventCollect window)
    {
        // 移除旧的按钮深度
        mWindowOrderList[lastDepth].Remove(window);
        // 添加新的按钮深度
        UIDepth newDepth = window.getUIDepth();

        if (!mWindowOrderList.ContainsKey(newDepth))
        {
            mWindowOrderList.Add(newDepth, new List <IMouseEventCollect>());
        }
        mWindowOrderList[newDepth].Add(window);
    }
Esempio n. 17
0
    public static UIDepth Add(GameObject obj)
    {
        if (obj == null)
        {
            return(null);
        }

        UIDepth temp = obj.GetComponent <UIDepth>();

        if (temp == null)
        {
            temp = obj.AddComponent <UIDepth>();
        }
        return(temp);
    }
Esempio n. 18
0
    /// <summary>
    /// 添加子元素
    /// </summary>
    /// <param name="obj"></param>
    public void ApplyChildItem(int index)
    {
        if (index >= childItem.Count)
        {
            return;
        }
        UIDepth temp = UIDepth.Add(childItem[index]);

        if (temp != null)
        {
            temp.SetIsUI();
            temp.Order = parentOrder + index * 1;
            temp       = null;
        }
    }
Esempio n. 19
0
    public override void OnLoadComplete(Transform obj)
    {
        base.OnLoadComplete(obj);

        //提示特效层级
        UIPanelBase parent_component = GetComponentInParent <UIPanelBase>();

        if (parent_component != null)
        {
            UIDepth effectDepth = gameObject.AddComponent <UIDepth>();
            if (effectDepth != null)
            {
                effectDepth.SetOrder(parent_component.MaxSortingOrder + 1);
                parent_component.MaxSortingOrder++;
            }
        }
    }
Esempio n. 20
0
    public static void Remove(GameObject obj)
    {
        if (obj == null)
        {
            return;
        }
        UIDepth temp = obj.GetComponent <UIDepth>();

        if (temp != null)
        {
            if (temp.GetComponent <Canvas>() != null)
            {
                DestroyImmediate(temp.GetComponent <Canvas>());
            }
            DestroyImmediate(temp);
        }
    }
Esempio n. 21
0
 public void SortRender()
 {
     if (m_WinObj != null)
     {
         Component[] depth = m_WinObj.GetComponentsInChildren(typeof(UIDepth));
         if (depth != null)
         {
             int count = depth.Length;
             for (int i = 0; i < count; ++i)
             {
                 UIDepth d = depth[i] as UIDepth;
                 if (d != null)
                 {
                     d.SetOrder(m_RenderOrder + i);
                 }
             }
         }
     }
 }
Esempio n. 22
0
 // 注册碰撞器,只有注册了的碰撞器才会进行检测
 public void registeBoxCollider(txUIObject button, BoxColliderClickCallback clickCallback = null,
                                BoxColliderHoverCallback hoverCallback = null, BoxColliderPressCallback pressCallback = null)
 {
     if (!mButtonCallbackList.ContainsKey(button))
     {
         ColliderCallBack colliderCallback = new ColliderCallBack();
         colliderCallback.mButton        = button;
         colliderCallback.mClickCallback = clickCallback;
         colliderCallback.mHoverCallback = hoverCallback;
         colliderCallback.mPressCallback = pressCallback;
         mButtonCallbackList.Add(button, colliderCallback);
         UIDepth depth = new UIDepth(button.mLayout.getRenderOrder(), button.getDepth());
         if (!mButtonOrderList.ContainsKey(depth))
         {
             mButtonOrderList.Add(depth, new List <txUIObject>());
         }
         mButtonOrderList[depth].Add(button);
     }
 }
Esempio n. 23
0
    public void notifyButtonDepthChanged(txUIObject button, int lastDepth)
    {
        // 如果之前没有记录过,则不做判断
        UIDepth oldDepth = new UIDepth(button.mLayout.getRenderOrder(), lastDepth);

        if (!mButtonOrderList.ContainsKey(oldDepth) || !mButtonOrderList[oldDepth].Contains(button))
        {
            return;
        }
        // 移除旧的按钮
        mButtonOrderList[oldDepth].Remove(button);
        // 添加新的按钮
        UIDepth newDepth = new UIDepth(button.mLayout.getRenderOrder(), button.getDepth());

        if (!mButtonOrderList.ContainsKey(newDepth))
        {
            mButtonOrderList.Add(newDepth, new List <txUIObject>());
        }
        mButtonOrderList[newDepth].Add(button);
    }
    /// <summary>
    /// 更新深度Point
    /// </summary>
    public void UpdateDepthPoint()
    {
        //更新父级层级
        if (depth != null)
        {
            depth.Order = mainOrder;
        }
        foreach (Transform item in depth.transform)
        {
            UIDepth depth = item.GetComponent <UIDepth>();
            if (depth)
            {
                if (childItem.Find(x => x.depth == depth) == null)
                {
                    UIDepthPoint uIDepth = new UIDepthPoint()
                    {
                        depth = depth
                    };
                    childItem.Add(uIDepth);
                }
            }
        }

        //用于清空 手动删除的NUll
        for (int i = 0; i < childItem.Count; i++)
        {
            if (childItem[i].depth == null)
            {
                childItem.RemoveAt(i);//清除这个空引用
            }
            else
            {
                childItem[i].mainOrder   = mainOrder + mainOrder;//主节点索引
                childItem[i].depth.Order = mainOrder + mainOrder;
                childItem[i].UpdateDepthPoint();
            }
        }
    }
Esempio n. 25
0
    void Awake()
    {
        this.camera    = Camera.main;
        this.resources = this.GetComponentInChildren <PlayerResources>();
        this.canvas    = GameObject.Find("Overlay").GetComponent <Canvas>();

        this.canvas.GetComponent <ScreenSpaceCanvas>().AddToCanvas(this.gameObject);
        this.transform.position = new Vector3(-100, -100, 0); //Render off screen
        this.transform.SetParent(this.canvas.transform);

        //Name & Damage
        TMP_Text[] text = this.GetComponentsInChildren <TMP_Text>();
        this.playerName  = text[0];
        this.damage      = text[1];
        this.freeze      = text[2];
        this.immune      = text[3];
        this.damageOrig  = this.damage.transform.localPosition;
        this.damage.text = "Damage";

        //Bars
        this.depthScript = this.GetComponent <UIDepth>();
        //this.selfRenderer = GetComponent<Renderer>();
    }
Esempio n. 26
0
    public void notifyWindowDepthChanged(IMouseEventCollect button)
    {
        // 只判断UI的深度变化
        if (!(button is txUIObject))
        {
            return;
        }
        // 如果之前没有记录过,则不做判断
        if (!mAllButtonSet.Contains(button))
        {
            return;
        }
        UIDepth lastDepth = mButtonDepthList[button];

        foreach (var item in mMouseCastWindowList)
        {
            if (item.hasWindow(lastDepth, button))
            {
                item.windowDepthChanged(lastDepth, button);
                break;
            }
        }
        mButtonDepthList[button] = button.getUIDepth();
    }
Esempio n. 27
0
 protected UIBase(UIDepth depth = UIDepth.Normal)
 {
     this.ResId        = 0;
     this.uiDepthLayer = depth;
     this.uiCreateType = UICreateType.Go;
 }
Esempio n. 28
0
    // 根据父节点的深度和在父节点中的顺序,更新深度值
    public void setDepthValue(UIDepth parentDepth, int orderInParent, bool depthOverAllChild)
    {
        if (orderInParent < 0 || orderInParent > ushort.MaxValue)
        {
            logError("节点在父节点中的顺序值无效,有效范围是1~" + ushort.MaxValue);
            return;
        }
        if (parentDepth == null)
        {
            mDepthLevel = 0;
            for (int i = 0; i < DEPTH_COUNT; ++i)
            {
                if (i == 0)
                {
                    mWindowDepth[i] = (ulong)orderInParent << ((BYTE_LENGTH - LEVEL_LENGTH) * 8);
                }
                else
                {
                    mWindowDepth[i] = 0;
                }
                mOriginDepth[i] = mWindowDepth[i];
            }
            return;
        }
        // 如果窗口需要调整为深度在所有子节点之上,则计算额外的深度调整
        // 有父节点才允许这么做,没有父节点的是根节点,根节点调整深度基本没意义
        int originOrderInParent = orderInParent;

        if (depthOverAllChild)
        {
            mPriority = -1;
            ++orderInParent;
        }
        else
        {
            mPriority = 0;
        }
        mDepthLevel = parentDepth.mDepthLevel + 1;
        if (mDepthLevel > BYTE_LENGTH * DEPTH_COUNT / LEVEL_LENGTH)
        {
            logError("UI层次超过上限,最多为" + (BYTE_LENGTH * DEPTH_COUNT / LEVEL_LENGTH) + "层");
            return;
        }
        int longIndex         = mDepthLevel / (BYTE_LENGTH / LEVEL_LENGTH);
        int ushortIndexInLong = mDepthLevel % (BYTE_LENGTH / LEVEL_LENGTH);
        int offsetBit         = (BYTE_LENGTH - LEVEL_LENGTH - ushortIndexInLong * LEVEL_LENGTH) * 8;

        for (int i = 0; i < DEPTH_COUNT; ++i)
        {
            if (i < longIndex)
            {
                mWindowDepth[i] = parentDepth.mOriginDepth[i];
                mOriginDepth[i] = mWindowDepth[i];
            }
            else if (i == longIndex)
            {
                mWindowDepth[i] = parentDepth.mOriginDepth[i] | ((ulong)orderInParent << offsetBit);
                mOriginDepth[i] = parentDepth.mOriginDepth[i] | ((ulong)originOrderInParent << offsetBit);
            }
            else
            {
                mWindowDepth[i] = 0;
                mOriginDepth[i] = mWindowDepth[i];
            }
        }
    }
Esempio n. 29
0
 // 注销碰撞器
 public void unregisteBoxCollider(IMouseEventCollect obj)
 {
     if (!mAllButtonSet.Contains(obj))
     {
         return;
     }
     if (mHoverWindow == obj)
     {
         mHoverWindow = null;
     }
     if (obj is txUIObject)
     {
         // 从深度列表中移除
         UIDepth depth = mButtonDepthList[obj];
         mButtonDepthList.Remove(obj);
         UIDepth curDepth = obj.getUIDepth();
         if (depth.mPanelDepth != curDepth.mPanelDepth || !isFloatEqual(depth.mWindowDepth, curDepth.mWindowDepth))
         {
             logError("depth error");
         }
         foreach (var item in mMouseCastWindowList)
         {
             if (item.hasWindow(depth, obj))
             {
                 item.removeWindow(obj);
                 if (item.isEmpty())
                 {
                     mMouseCastWindowList.Remove(item);
                 }
                 break;
             }
         }
         if (WidgetUtility.isNGUI((obj as txUIObject).getObject()))
         {
             --mNGUICount;
         }
         else
         {
             --mUGUICount;
         }
     }
     else if (obj is MovableObject)
     {
         foreach (var item in mMouseCastObjectList)
         {
             if (item.hasObject(obj))
             {
                 item.removeObject(obj);
                 if (item.isEmpty())
                 {
                     mMouseCastObjectList.Remove(item);
                 }
                 break;
             }
         }
         mMovableObjectList.Remove(obj);
     }
     mAllButtonList.Remove(obj);
     mAllButtonSet.Remove(obj);
     mMouseDownWindowList.Remove(obj);
     mMultiTouchWindowList.Remove(obj);
 }
Esempio n. 30
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);
     }
 }