Ejemplo n.º 1
0
    /// <summary>
    /// Automatically find the camera responsible for drawing the widgets under this object.
    /// </summary>

    void Start()
    {
        if (container == null && widgetContainer != null)
        {
            container       = widgetContainer.gameObject;
            widgetContainer = null;
#if UNITY_EDITOR
            NGUITools.SetDirty(this);
#endif
        }

        mRoot = NGUITools.FindInParents <UIRoot>(gameObject);
        if (uiCamera == null)
        {
            uiCamera = NGUITools.FindCameraForLayer(gameObject.layer);
        }

        Update();

        mStarted = true;
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Convert the specified position, making it relative to the specified object's parent.
    /// Useful if you plan on positioning the widget using the specified value (think mouse cursor).
    /// </summary>

    static public Vector2 ScreenToParentPixels(Vector2 pos, Transform relativeTo)
    {
        int layer = relativeTo.gameObject.layer;

        if (relativeTo.parent != null)
        {
            relativeTo = relativeTo.parent;
        }

        Camera cam = NGUITools.FindCameraForLayer(layer);

        if (cam == null)
        {
            Debug.LogWarning("No camera found for layer " + layer);
            return(pos);
        }

        Vector3 wp = cam.ScreenToWorldPoint(pos);

        return((relativeTo != null) ? relativeTo.InverseTransformPoint(wp) : wp);
    }
Ejemplo n.º 3
0
        void Init(StructUIHUD uihuid, Transform parent)
        {
            if (uihuid.FollowObject == null)
            {
                Debug.LogError("followObj==null");
                Destroy(gameObject);
                return;
            }

            if (parent == null)
            {
                Debug.LogError("parent is null");
                return;
            }

            MyStructUIHUD   = uihuid;
            _followedTarget = MyStructUIHUD.FollowObject.transform;

            transform.parent        = parent;
            transform.localPosition = Vector3.zero;
            transform.localRotation = Quaternion.identity;
            transform.localScale    = Vector3.one;

            // 摄像机
            _gameCamera = NGUITools.FindCameraForLayer(MyStructUIHUD.FollowObject.layer);
            _uiCamera   = NGUITools.FindCameraForLayer(parent.gameObject.layer);
            //设置当前hp进度条
            OnEventHPChange(MyStructUIHUD.CurHP, MyStructUIHUD.MaxHP);
            //设置名字
            SetName(MyStructUIHUD);
            //名字颜色
            SetNameColor(MyStructUIHUD.NameColor);
            //hp刻度条
            BaseHPScale = BaseHPScale == 0 ? (int)uihuid.MaxHP / UIHUD.Param_min : BaseHPScale;
            SetHPScale(BaseHPScale, (int)uihuid.MaxHP);
            //类型标识
            SetHeroFeature(uihuid);

            _mpBar.gameObject.SetActive(MyStructUIHUD.IsActiveMP);
        }
Ejemplo n.º 4
0
    //bool mPlayCirculation = false;

    //float mTimer;
    //float mTotalTime;



    //MouseOpMgr.MouseOpCursor mCurState = MouseOpMgr.MouseOpCursor.Null;

    void Start()
    {
        mTrans = transform;
        if (uiCamera == null)
        {
            uiCamera = NGUITools.FindCameraForLayer(gameObject.layer);
        }
        ch      = new CursorHandler();
        ch.Type = CursorState.EType.None;
        //mTimer = 0;
        //mTotalTime = 0.75f;
        m_TipScaleTween.onFinished = TipTweenFinish;

        //mMouseHandBig = "mouse_hand";
        //mMouseHandSmall = "mouse_hand1";
        mBag       = "mouse_get";
        mAxe       = "mouse_axe";
        mNouseTalk = "mouse_talk";
        mHand      = "mouse_help";
        mRide      = "mouse_ride";
        mDefault   = "sighting_3";
    }
Ejemplo n.º 5
0
        public void SetPOI(Transform poi)
        {
            if (mPOI != poi)
            {
                mPOI = poi;

                if (mPOI != null)
                {
                    mPOICam = NGUITools.FindCameraForLayer(mPOI.gameObject.layer);

                    gameObject.SetActive(true);
                }
                else
                {
                    mPOICam = null;

                    gameObject.SetActive(false);

                    pointer.gameObject.SetActive(false);
                }
            }
        }
Ejemplo n.º 6
0
    protected virtual void Start()
    {
        this.SetAlpha(0f);

        if (this.uiCamera == null)
        {
            this.uiCamera = NGUITools.FindCameraForLayer(this.gameObject.layer);
        }
        if (this.uiCamera == null)
        {
            this.uiCamera = Camera.main;
        }

        if (this.uiCamera == null)
        {
            Debug.LogWarning(this.GetType() + " requires a camera in order to work.", this);
            this.enabled = false;
            return;
        }

        if (this.container == null)
        {
            Debug.LogWarning(this.GetType() + " requires a container to be define in order to work.", this);
            this.enabled = false;
            return;
        }

        if (this.background == null)
        {
            Debug.LogWarning(this.GetType() + " requires a background sprite in order to work.", this);
            this.enabled = false;
            return;
        }

        // Clear the title and description labels
        this._SetTitle("");
        this._SetDescription("");
    }
Ejemplo n.º 7
0
 private void Start()
 {
     if (this.target != null)
     {
         if (this.gameCamera == null)
         {
             this.gameCamera = Camera.main;
         }
         if (this.uiCamera == null)
         {
             this.uiCamera = NGUITools.FindCameraForLayer(base.gameObject.layer);
         }
         this.gameCameraTransform         = this.gameCamera.transform;
         this.lastFrameTargetPosition     = this.target.transform.position;
         this.targetTransform             = this.target.transform;
         this.lastFrameGameCameraPosition = this.gameCameraTransform.position;
     }
     else
     {
         Debug.LogError("Expected to have 'target' set to a valid transform", this);
         base.enabled = false;
     }
 }
    void Init()
    {
        if (GameManager.battleType != BattleMode.RandomPvE)
        {
            information.SetActive(true);
        }

        int i      = 0;
        int iRight = 0;

        GameObject[] roleSet = (from hero in GameplayManager.Instance.heroPlayerSet select hero.gameObject).ToArray();


        foreach (GameObject role in roleSet)
        {
            if (role.GetComponent <Controller>().role.Base.Type != DEngine.Common.GameLogic.RoleType.Mob && role.GetComponent <Controller>().role.Base.Type != DEngine.Common.GameLogic.RoleType.Hostage)
            {
                GameObject           go   = NGUITools.AddChild(UIHeroRoot, UIBattleHeroSlotPrefab);
                UIHeroSlotController slot = go.GetComponent <UIHeroSlotController>();
                slot.setRole(role.GetComponent <Controller>());
                go.transform.localPosition = new Vector3((i + iRight) * 140, 0, 0);
                //go.transform.localScale = new Vector3(0.8f, 0.8f, 0.8f);
                i++;
                if (i > 2)
                {
                    iRight = 2;
                }
                Vector3 worldPos = Vector3.zero;

                Vector3 screenPos = NGUITools.FindCameraForLayer(go.layer).WorldToScreenPoint(go.transform.position);

                worldPos = Camera.main.ScreenToWorldPoint(new Vector3(screenPos.x, screenPos.y - 10, 7));

                slot.worldPos = worldPos;
            }
        }
    }
Ejemplo n.º 9
0
    /// <summary>
    /// Ensure that all rect references are set correctly on the anchors.
    /// </summary>

    public void ResetAnchors()
    {
        mAnchorsCached = true;

        leftAnchor.rect   = (leftAnchor.target)   ? leftAnchor.target.GetComponent <UIRect>()       : null;
        bottomAnchor.rect = (bottomAnchor.target) ? bottomAnchor.target.GetComponent <UIRect>() : null;
        rightAnchor.rect  = (rightAnchor.target)  ? rightAnchor.target.GetComponent <UIRect>()      : null;
        topAnchor.rect    = (topAnchor.target)    ? topAnchor.target.GetComponent <UIRect>()        : null;

        var targetLayer = cachedGameObject.layer;
        var uiCams      = UICamera.list;

        for (int i = 0; i < uiCams.size; i++)
        {
            if (uiCams[i].gameObject.scene == cachedGameObject.scene)
            {
                var cam = uiCams[i].cachedCamera;
                if (cam && (cam.cullingMask & 1 << targetLayer) != 0)
                {
                    mCam = cam;
                    break;
                }
            }
        }

        if (mCam == null)
        {
            mCam = NGUITools.FindCameraForLayer(cachedGameObject.layer);
        }

        FindCameraFor(leftAnchor);
        FindCameraFor(bottomAnchor);
        FindCameraFor(rightAnchor);
        FindCameraFor(topAnchor);

        mUpdateAnchors = true;
    }
Ejemplo n.º 10
0
    // Update is called once per frame
    void Update()
    {
        //获得统计数据
        GetStatisticsData();
        //
#if (!UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE))
        CheckTouchEvent();
#endif
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (m_MessageBoxExitGame == null)
            {
                m_MessageBoxExitGame = (GameObject)Instantiate(MessageBoxExitGame);
                if (PopupObjManager.Instance == null)
                {
                    m_MessageBoxExitGame.transform.parent = NGUITools.FindCameraForLayer(25).transform;
                }
                else
                {
                    m_MessageBoxExitGame.transform.parent = PopupObjManager.Instance.UICamera.transform;
                }
                m_MessageBoxExitGame.transform.localPosition = Vector3.zero;
                m_MessageBoxExitGame.transform.localScale    = Vector3.one;
                MsgBoxExitGame msgScript = m_MessageBoxExitGame.GetComponent <MsgBoxExitGame>();
                msgScript.ShowBox(LanguageTextManager.GetString("IDS_D6_509"), OnExitGameHandle, OnCancelHandle);
            }
            //UI.MessageBox.Instance.Show(5, "", LanguageTextManager.GetString("IDS_D6_509"), LanguageTextManager.GetString("IDS_H2_55"),
            //    LanguageTextManager.GetString("IDS_H2_28"), OnExitGameHandle, OnCancelHandle);
        }

        //启动网络消息队列处理

        //if (true)
        {
            ResponseHandleInvoker.Instance.DO();
        }
    }
Ejemplo n.º 11
0
    /// <summary>
    /// Ensure that all rect references are set correctly on the anchors.
    /// </summary>

    public void ResetAnchors()
    {
        mAnchorsCached = true;

        leftAnchor.rect   = (leftAnchor.target)   ? leftAnchor.target.GetComponent <UIRect>()       : null;
        bottomAnchor.rect = (bottomAnchor.target) ? bottomAnchor.target.GetComponent <UIRect>() : null;
        rightAnchor.rect  = (rightAnchor.target)  ? rightAnchor.target.GetComponent <UIRect>()      : null;
        topAnchor.rect    = (topAnchor.target)    ? topAnchor.target.GetComponent <UIRect>()        : null;

        mCam = NGUITools.FindCameraForLayer(cachedGameObject.layer);

        FindCameraFor(leftAnchor);
        FindCameraFor(bottomAnchor);
        FindCameraFor(rightAnchor);
        FindCameraFor(topAnchor);

        mUpdateAnchors = true;

        //这里考虑我们项目如果有则必然leftAnchor有,所以直接以此来判断
        if (leftAnchor.target && leftAnchor.rect)
        {
            hasAnchorTarget = true;
        }
    }
Ejemplo n.º 12
0
    /// <summary>
    /// Automatically find the camera responsible for drawing the widgets under this object.
    /// </summary>

    void Start()
    {
        mRoot = NGUITools.FindInParents <NGUIRoot>(gameObject);
        mNeedsHalfPixelOffset = (Application.platform == RuntimePlatform.WindowsPlayer ||
                                 Application.platform == RuntimePlatform.XBOX360 ||
                                 Application.platform == RuntimePlatform.WindowsWebPlayer ||
                                 Application.platform == RuntimePlatform.WindowsEditor);

        // Only DirectX 9 needs the half-pixel offset
        if (mNeedsHalfPixelOffset)
        {
            mNeedsHalfPixelOffset = (SystemInfo.graphicsShaderLevel < 40);
        }

        if (uiCamera == null)
        {
            uiCamera = NGUITools.FindCameraForLayer(gameObject.layer);
        }
        if (uiCamera == null)
        {
            uiCamera = GameObject.Find("UI/GUI Camera").GetComponent <Camera>();
        }
        Update();
    }
Ejemplo n.º 13
0
    /// <summary>
    /// 设置3D UI 的位置
    /// </summary>
    /// <param name="go"></param>
    /// <param name="tPos">世界坐标</param>
    /// <param name="localPos">go的worldPosition</param>
    public static Vector3 Set3DUIPos(GameObject go, Vector3 tPos)
    {
        if (go == null)
        {
            return(Vector3.zero);
        }

        Camera gameCamera = Camera.main;
        Camera uiCamera   = NGUITools.FindCameraForLayer(go.layer);

        if (gameCamera == null || uiCamera == null)
        {
            return(Vector3.zero);
        }
        Vector3 pos = gameCamera.WorldToViewportPoint(tPos);

        go.transform.position = uiCamera.ViewportToWorldPoint(pos);
        pos   = go.transform.localPosition;
        pos.x = Mathf.FloorToInt(pos.x);
        pos.y = Mathf.FloorToInt(pos.y);
        pos.z = 0f;
        go.transform.localPosition = pos;
        return(pos);
    }
Ejemplo n.º 14
0
	void Start ()
	{
		if (uiCamera == null) uiCamera = NGUITools.FindCameraForLayer(gameObject.layer);
		mRoot = NGUITools.FindInParents<UIRoot>(gameObject);
		Update();
	}
Ejemplo n.º 15
0
    void LateUpdate()
    {
        {
            if (_UnitInfo == null)
            {
                if (_BaseObject == null)
                {
                    Enemy en = this.transform.parent.GetComponent <Enemy>();
                    if (en)
                    {
                        _UnitInfo = en._UnitInfo;
                    }
                    else
                    {
                        wt_PlayerController cont = this.transform.parent.GetComponent <wt_PlayerController>();
                        if (cont)
                        {
                            _UnitInfo = cont._UnitInfo;
                        }
                    }
                }
                else
                {
                    Enemy en = _BaseObject.GetComponent <Enemy>();
                    if (en)
                    {
                        _UnitInfo = en._UnitInfo;
                    }
                    else
                    {
                        wt_PlayerController cont = _BaseObject.GetComponent <wt_PlayerController>();
                        if (cont)
                        {
                            _UnitInfo = cont._UnitInfo;
                        }
                    }
                }
            }
            else
            {
                if (_UnitInfo._DeathFlag == false)
                {
                    if (_HPBar.gameObject.activeInHierarchy == false)
                    {
                        GameWorld.SetActiveRecursively(_HPBar.gameObject, true);
                    }

                    this.transform.rotation = Quaternion.identity;

                    //월드좌표의 카메라객체입니다.
                    if (_AICam == null)
                    {
                        _AICam = NGUITools.FindCameraForLayer(this.gameObject.layer);
                        if (_AICam == null)
                        {
                            return;
                        }
                    }

                    //GUI객체의 카메라 객체입니다.
                    Camera guiCam = UICamera.currentCamera;
                    if (guiCam == null)
                    {
                        return;
                    }

                    //타겟의 포지션을 월드좌표에서 ViewPort좌표로 변환하고 다시 ViewPort좌표를 NGUI월드좌표로 변환합니다.
                    Vector3 targetPos = _UnitInfo.transform.position + targetOffset;
                    Vector3 pos       = guiCam.ViewportToWorldPoint(_AICam.WorldToViewportPoint(targetPos));
                    //Z는 0으로...
                    pos.z = 0f;

                    _HPBar.transform.position = pos;
                    _HPBar.sliderValue        = (float)_UnitInfo._HP / (float)_UnitInfo._HP_Default;

                    if (_Lb_Lv)
                    {
                        _Lb_Lv.transform.position = pos + _lb_LvOffset;
                        _Lb_Lv.text = "Lv" + _UnitInfo._Level.ToString();
                    }

                    return;
                }
                else
                {
                    if (_HPBar.gameObject.activeInHierarchy == true)
                    {
                        GameWorld.SetActiveRecursively(_HPBar.gameObject, false);
                    }
                    if (_Lb_Lv)
                    {
                        if (_Lb_Lv.gameObject.activeInHierarchy == true)
                        {
                            GameWorld.SetActiveRecursively(_Lb_Lv.gameObject, false);
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 16
0
 void Start()
 {
     cursor               = transform;
     uiCamera             = NGUITools.FindCameraForLayer(cursor.gameObject.layer);
     cursorRenderer.depth = 100;
 }
Ejemplo n.º 17
0
    //int mIsVisible = -1;

    /// <summary>
    /// Whether the target is currently visible or not.
    /// </summary>

    //public bool isVisible { get { return mIsVisible == 1; } }

    /// <summary>
    /// Cache the transform;
    /// </summary>

    //void Awake () { mTrans = transform; }

    /// <summary>
    /// Find both the UI camera and the game camera so they can be used for the position calculations
    /// </summary>

    void Start()
    {
        gameCamera = Camera.main;
        uiCamera   = NGUITools.FindCameraForLayer(gameObject.layer);
    }
Ejemplo n.º 18
0
    public void OnTargetToMonster()
    {
        if (GameManager.tutorial.step != TutorialManager.TutorialStep.Control_NPCFinshed)
        {
            return;
        }
        if (tutStep >= TutorialStepForBattle.TargetToMob)
        {
            return;
        }
        if (GameplayManager.Instance.heroEnemySet.Count <= 0)
        {
            Debug.Log("*************NULL");
            return;
        }
        uiTutorial.hand.SetActive(true);

        uiTutorial.startPoint.localPosition = Helper.GetScreenPosOfWorldPos(heroFirst.gameObject.transform.position,
                                                                            uiTutorial.startPoint.transform, NGUITools.FindCameraForLayer(uiTutorial.startPoint.gameObject.layer));

        uiTutorial.endPoint.localPosition = Helper.GetScreenPosOfWorldPos(GameplayManager.Instance.heroEnemySet[0].gameObject.transform.position,
                                                                          uiTutorial.endPoint.transform, NGUITools.FindCameraForLayer(uiTutorial.endPoint.gameObject.layer));

        uiTutorial.arrowTouchHero.SetActive(true);
        uiTutorial.arrowTouchHero.transform.localPosition = Helper.GetScreenPosOfWorldPos(GameplayManager.Instance.heroEnemySet[0].gameObject.transform.position,
                                                                                          uiTutorial.arrowTouchHero.transform, NGUITools.FindCameraForLayer(uiTutorial.arrowTouchHero.layer));

        StartCoroutine(MoveHand());
    }
Ejemplo n.º 19
0
    public void OnTouchHeroFinish()
    {
        if (GameManager.tutorial.step != TutorialManager.TutorialStep.Control_NPCFinshed)
        {
            return;
        }
        if (tutStep >= TutorialStepForBattle.TabToHero)
        {
            return;
        }
        if (heroFirst == null)
        {
            return;
        }
        if (TouchController.instance.controllerGetSkill != heroFirst.controller)
        {
            return;
        }

        tutStep = TutorialStepForBattle.TabToHero;

        uiTutorial.arrowTouchHero.SetActive(false);

        uiTutorial.hand.SetActive(true);

        uiTutorial.startPoint.localPosition = Helper.GetScreenPosOfWorldPos(heroFirst.gameObject.transform.position,
                                                                            uiTutorial.startPoint.transform, NGUITools.FindCameraForLayer(uiTutorial.startPoint.gameObject.layer));

        uiTutorial.endPoint.localPosition = Helper.GetScreenPosOfWorldPos(_tutorial_PosMove,
                                                                          uiTutorial.endPoint.transform, NGUITools.FindCameraForLayer(uiTutorial.endPoint.gameObject.layer));

        StartCoroutine(MoveHand());
    }
Ejemplo n.º 20
0
    public void Tutorial()
    {
        if (GameManager.tutorial.step != TutorialManager.TutorialStep.Control_NPCFinshed)
        {
            return;
        }

        tutStep = TutorialStepForBattle.None;
        uiTutorial.root.gameObject.SetActive(true);
        heroFirst = GameplayManager.Instance.heroPlayerSet.FirstOrDefault(p => p.controller.role.GameRole.Class != (int)RoleClass.Healer);
        if (heroFirst == null)
        {
            return;
        }

        uiTutorial.arrowTouchHero.transform.localPosition = Helper.GetScreenPosOfWorldPos(heroFirst.gameObject.transform.position,
                                                                                          uiTutorial.arrowTouchHero.transform, NGUITools.FindCameraForLayer(uiTutorial.startPoint.gameObject.layer));
        uiTutorial.arrowTouchHero.SetActive(true);

        uiTutorial.hand.SetActive(false);

        uiTutorial.arrowWorldMap.SetActive(true);
    }
Ejemplo n.º 21
0
    /// <summary>
    /// Layer is used to ensure that if it changes, widgets get moved as well.
    /// </summary>

    void Start()
    {
        mLayer = gameObject.layer;
        mCam   = NGUITools.FindCameraForLayer(mLayer);
    }
Ejemplo n.º 22
0
 void Start()
 {
     camera = NGUITools.FindCameraForLayer(gameObject.layer);
     originalCameraDepth = camera.depth;
     camera.depth        = 88;
 }
Ejemplo n.º 23
0
    /// <summary>
    /// Convenience function that figures out the panel's correct change flag by searching the parents.
    /// </summary>

    int GetChangeFlag(UINode start)
    {
        int flag = start.changeFlag;

        if (flag == -1)
        {
            Transform trans = start.trans.parent;
            UINode    sub;

            // Keep going until we find a set flag
            for (;;)
            {
                // Check the parent's flag
#if UNITY_FLASH
                if (trans != null && mChildren.TryGetValue(trans, out sub))
                {
#else
                if (trans != null && mChildren.Contains(trans))
                {
                    sub = (UINode)mChildren[trans];
#endif
                    flag  = sub.changeFlag;
                    trans = trans.parent;

                    // If the flag hasn't been set either, add this child to the hierarchy
                    if (flag == -1)
                    {
                        mHierarchy.Add(sub);
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    flag = 0;
                    break;
                }
            }

            // Update the parent flags
            for (int i = 0, imax = mHierarchy.size; i < imax; ++i)
            {
                UINode pc = mHierarchy.buffer[i];
                pc.changeFlag = flag;
            }
            mHierarchy.Clear();
        }
        return(flag);
    }

    /// <summary>
    /// Update the world-to-local transform matrix as well as clipping bounds.
    /// </summary>

    void UpdateTransformMatrix()
    {
        float time = Time.realtimeSinceStartup;

        if (time == 0f || mMatrixTime != time)
        {
            mMatrixTime   = time;
            mWorldToLocal = cachedTransform.worldToLocalMatrix;

            if (mClipping != UIDrawCall.Clipping.None)
            {
                Vector2 size = new Vector2(mClipRange.z, mClipRange.w);

                if (size.x == 0f)
                {
                    size.x = mScreenSize.x;
                }
                if (size.y == 0f)
                {
                    size.y = mScreenSize.y;
                }

                size *= 0.5f;

                mMin.x = mClipRange.x - size.x;
                mMin.y = mClipRange.y - size.y;
                mMax.x = mClipRange.x + size.x;
                mMax.y = mClipRange.y + size.y;
            }
        }
    }

    /// <summary>
    /// Run through all managed transforms and see if they've changed.
    /// </summary>

    void UpdateTransforms()
    {
        mChangedLastFrame = false;
        bool transformsChanged = false;

#if UNITY_EDITOR
        bool shouldCull = !Application.isPlaying || Time.realtimeSinceStartup > mCullTime;
        if (!Application.isPlaying || !widgetsAreStatic || mWidgetsAdded || shouldCull != mCulled)
#else
        bool shouldCull = Time.realtimeSinceStartup > mCullTime;
        if (!widgetsAreStatic || mWidgetsAdded || shouldCull != mCulled)
#endif
        {
#if UNITY_FLASH
            foreach (KeyValuePair <Transform, UINode> child in mChildren)
            {
                UINode node = child.Value;
#else
            for (int i = 0, imax = mChildren.Count; i < imax; ++i)
            {
                UINode node = (UINode)mChildren[i];
#endif
                if (node.trans == null)
                {
                    mRemoved.Add(node.trans);
                    continue;
                }

                if (node.HasChanged())
                {
                    node.changeFlag   = 1;
                    transformsChanged = true;
                }
                else
                {
                    node.changeFlag = -1;
                }
            }

            // Clean up the deleted transforms
            for (int i = 0, imax = mRemoved.Count; i < imax; ++i)
            {
                mChildren.Remove(mRemoved[i]);
            }
            mRemoved.Clear();
        }

        // If the children weren't culled but should be, check their visibility
        if (!mCulled && shouldCull)
        {
            mCheckVisibility = true;
        }

        // If something has changed, propagate the changes *down* the tree hierarchy (to children).
        // An alternative (but slower) approach would be to do a pc.trans.GetComponentsInChildren<UIWidget>()
        // in the loop above, and mark each one as dirty.

        if (mCheckVisibility || transformsChanged || mRebuildAll)
        {
#if UNITY_FLASH
            foreach (KeyValuePair <Transform, UINode> child in mChildren)
            {
                UINode pc = child.Value;
#else
            for (int i = 0, imax = mChildren.Count; i < imax; ++i)
            {
                UINode pc = (UINode)mChildren[i];
#endif
                if (pc.widget != null)
                {
                    int visibleFlag = 1;

                    // No sense in checking the visibility if we're not culling anything (as the visibility is always 'true')
                    if (shouldCull || transformsChanged)
                    {
                        // If the change flag has not yet been determined...
                        if (pc.changeFlag == -1)
                        {
                            pc.changeFlag = GetChangeFlag(pc);
                        }

                        // Is the widget visible?
                        if (shouldCull)
                        {
                            visibleFlag = (mCheckVisibility || pc.changeFlag == 1) ? (IsVisible(pc.widget) ? 1 : 0) : pc.visibleFlag;
                        }
                    }

                    // If visibility changed, mark the node as changed as well
                    if (pc.visibleFlag != visibleFlag)
                    {
                        pc.changeFlag = 1;
                    }

                    // If the node has changed and the widget is visible (or was visible before)
                    if (pc.changeFlag == 1 && (visibleFlag == 1 || pc.visibleFlag != 0))
                    {
                        // Update the visibility flag
                        pc.visibleFlag = visibleFlag;
                        Material mat = pc.widget.material;

                        // Add this material to the list of changed materials
                        if (!mChanged.Contains(mat))
                        {
                            mChanged.Add(mat);
                            mChangedLastFrame = true;
                        }
                    }
                }
            }
        }
        mCulled          = shouldCull;
        mCheckVisibility = false;
        mWidgetsAdded    = false;
    }

    /// <summary>
    /// Update all widgets and rebuild their geometry if necessary.
    /// </summary>

    void UpdateWidgets()
    {
#if UNITY_FLASH
        foreach (KeyValuePair <Transform, UINode> c in mChildren)
        {
            UINode pc = c.Value;
#else
        for (int i = 0, imax = mChildren.Count; i < imax; ++i)
        {
            UINode pc = (UINode)mChildren[i];
#endif
            UIWidget w = pc.widget;

            // If the widget is visible, update it
            if (pc.visibleFlag == 1 && w != null && w.UpdateGeometry(ref mWorldToLocal, (pc.changeFlag == 1), generateNormals))
            {
                // We will need to refill this buffer
                if (!mChanged.Contains(w.material))
                {
                    mChanged.Add(w.material);
                    mChangedLastFrame = true;
                }
            }
            pc.changeFlag = 0;
        }
    }

    /// <summary>
    /// Update the clipping rect in the shaders and draw calls' positions.
    /// </summary>

    public void UpdateDrawcalls()
    {
        Vector4 range = Vector4.zero;

        if (mClipping != UIDrawCall.Clipping.None)
        {
            range = new Vector4(mClipRange.x, mClipRange.y, mClipRange.z * 0.5f, mClipRange.w * 0.5f);
        }

        if (range.z == 0f)
        {
            range.z = mScreenSize.x * 0.5f;
        }
        if (range.w == 0f)
        {
            range.w = mScreenSize.y * 0.5f;
        }

        RuntimePlatform platform = Application.platform;

        if (platform == RuntimePlatform.WindowsPlayer ||
            platform == RuntimePlatform.WindowsWebPlayer ||
            platform == RuntimePlatform.WindowsEditor)
        {
            range.x -= 0.5f;
            range.y += 0.5f;
        }

        Transform t = cachedTransform;

        for (int i = 0, imax = mDrawCalls.size; i < imax; ++i)
        {
            UIDrawCall dc = mDrawCalls.buffer[i];
            dc.clipping     = mClipping;
            dc.clipRange    = range;
            dc.clipSoftness = mClipSoftness;
            dc.depthPass    = depthPass;

            // Set the draw call's transform to match the panel's.
            // Note that parenting directly to the panel causes unity to crash as soon as you hit Play.
            Transform dt = dc.transform;
            dt.position   = t.position;
            dt.rotation   = t.rotation;
            dt.localScale = t.lossyScale;
        }
    }

    /// <summary>
    /// Set the draw call's geometry responsible for the specified material.
    /// </summary>

    void Fill(Material mat)
    {
        // Cleanup deleted widgets
        for (int i = mWidgets.size; i > 0;)
        {
            if (mWidgets[--i] == null)
            {
                mWidgets.RemoveAt(i);
            }
        }

        // Fill the buffers for the specified material
        for (int i = 0, imax = mWidgets.size; i < imax; ++i)
        {
            UIWidget w = mWidgets.buffer[i];

            if (w.visibleFlag == 1 && w.material == mat)
            {
                UINode node = GetNode(w.cachedTransform);

                if (node != null)
                {
                    if (generateNormals)
                    {
                        w.WriteToBuffers(mVerts, mUvs, mCols, mNorms, mTans);
                    }
                    else
                    {
                        w.WriteToBuffers(mVerts, mUvs, mCols, null, null);
                    }
                }
                else
                {
                    Debug.LogError("No transform found for " + NGUITools.GetHierarchy(w.gameObject), this);
                }
            }
        }

        if (mVerts.size > 0)
        {
            // Rebuild the draw call's mesh
            UIDrawCall dc = GetDrawCall(mat, true);
            dc.depthPass = depthPass;
            dc.Set(mVerts, generateNormals ? mNorms : null, generateNormals ? mTans : null, mUvs, mCols);
        }
        else
        {
            // There is nothing to draw for this material -- eliminate the draw call
            UIDrawCall dc = GetDrawCall(mat, false);

            if (dc != null)
            {
                mDrawCalls.Remove(dc);
                NGUITools.DestroyImmediate(dc.gameObject);
            }
        }

        // Cleanup
        mVerts.Clear();
        mNorms.Clear();
        mTans.Clear();
        mUvs.Clear();
        mCols.Clear();
    }

    /// <summary>
    /// Main update function
    /// </summary>

    void LateUpdate()
    {
        UpdateTransformMatrix();
        UpdateTransforms();

        // Always move widgets to the panel's layer
        if (mLayer != gameObject.layer)
        {
            mLayer = gameObject.layer;
            UICamera uic = UICamera.FindCameraForLayer(mLayer);
            mCam = (uic != null) ? uic.cachedCamera : NGUITools.FindCameraForLayer(mLayer);
            SetChildLayer(cachedTransform, mLayer);
            for (int i = 0, imax = drawCalls.size; i < imax; ++i)
            {
                mDrawCalls.buffer[i].gameObject.layer = mLayer;
            }
        }

        UpdateWidgets();

        // If the depth has changed, we need to re-sort the widgets
        if (mDepthChanged)
        {
            mDepthChanged = false;
            mWidgets.Sort(UIWidget.CompareFunc);
        }

        // Fill the draw calls for all of the changed materials
        for (int i = 0, imax = mChanged.size; i < imax; ++i)
        {
            Fill(mChanged.buffer[i]);
        }

        // Update the clipping rects
        UpdateDrawcalls();
        mChanged.Clear();
        mRebuildAll = false;

#if UNITY_EDITOR
        mScreenSize = new Vector2(Screen.width, Screen.height);

        UIRoot root = NGUITools.FindInParents <UIRoot>(gameObject);
        if (root != null)
        {
            mScreenSize *= root.GetPixelSizeAdjustment(Screen.height);
        }
#endif
    }
Ejemplo n.º 24
0
        // Use this for initialization
        void Start()
        {
            mUICam = NGUITools.FindCameraForLayer(pointer.gameObject.layer);

            mZ = pointer.position.z;
        }
Ejemplo n.º 25
0
        //////////////////////////////////////////////////////////////////////////

        public void CalculatePositionOrder(UAP_BaseElement uiElement, int backupIndex)
        {
            GameObject obj = uiElement.gameObject;

            // If no parent transform is set, use the next higher up group root if possible
            if (uiElement.m_ManualPositionParent == null)
            {
                AccessibleUIGroupRoot groupRoot = uiElement.GetUIGroupContainer();
                uiElement.m_ManualPositionParent = (groupRoot != null ? groupRoot.gameObject : null);
            }

            bool hasManualOrder = uiElement.m_ManualPositionOrder >= 0 && uiElement.m_ManualPositionParent != null;

            if (hasManualOrder)
            {
                obj = uiElement.m_ManualPositionParent;
            }

            Vector2 anchorMin            = new Vector2();
            Vector2 anchorMax            = new Vector2();
            Vector2 centerPos            = new Vector2();
            bool    gotValidValues       = false;
            bool    secondaryOrderNeeded = false;

            // Calculation for Unity UI (uUI)
            RectTransform t = obj.GetComponent <RectTransform>();

            if (t != null)
            {
                // Does this ui element lie inside a scroll rect?
                Transform     pt = (Transform)t;
                RectTransform primaryOrderBase = t;
                while (pt.parent != null)
                {
                    if (pt.parent.gameObject.GetComponent <ScrollRect>() != null)
                    {
                        primaryOrderBase     = pt.parent.gameObject.GetComponent <RectTransform>();
                        secondaryOrderNeeded = true;
                        break;
                    }
                    pt = pt.parent;
                }

                // Calculate up until the Canvas is found. Otherwise nested objects won't be correctly sorted
                GetAbsoluteAnchors(primaryOrderBase, out anchorMin, out anchorMax, out centerPos);
                gotValidValues = true;
            }

#if ACCESS_NGUI
            UIWidget widget = obj.GetComponent <UIWidget>();
            if (widget == null)
            {
                widget = obj.GetComponentInChildren <UIWidget>();
            }

            Camera uiCam = (widget != null) ? NGUITools.FindCameraForLayer(widget.gameObject.layer) : null;
            if (widget != null && uiCam != null)
            {
                // Transform from world to screen coordinates, if there is a main camera?
                centerPos = uiCam.WorldToScreenPoint(widget.transform.position);
                anchorMin = uiCam.WorldToScreenPoint(widget.worldCorners[0]);
                anchorMax = uiCam.WorldToScreenPoint(widget.worldCorners[1]);


                gotValidValues = true;
            }
#endif


            if (gotValidValues)
            {
                /*
                 * m_Pos = anchorMin + 0.5f * (anchorMax - anchorMin);
                 * m_PositionOrder = (int)(10.0f * (m_Pos.x + (1000.0f * (1.0f - m_Pos.y))));
                 * if (hasManualOrder)
                 *      m_PositionOrder += uiElement.m_ManualPositionOrder;
                 */

                Vector3 wPos = centerPos;
                m_Pos.x = wPos.x;
                m_Pos.y = wPos.y;
                m_Pos.Scale(new Vector2(1.0f / (float)Screen.width, 1.0f / (float)Screen.height));
                m_PositionOrder = (int)(10.0f * (m_Pos.x + (1000.0f * (1.0f - m_Pos.y))));
                if (hasManualOrder)
                {
                    m_PositionOrder += uiElement.m_ManualPositionOrder;
                }

                // For 2D Navigation this is needed to adjust for the aspect ratio!
                m_Pos.Scale(new Vector2(Screen.width, Screen.height));

                // For the secondary order always use the actual game object (regardless of manual order parent reference)
                obj = uiElement.gameObject;

                // Do we need a secondary order?
                if (secondaryOrderNeeded)
                {
                    // TODO: This might need a different calculation in NGUI

                    Vector2 pos = obj.transform.TransformPoint(new Vector3(0.5f, 0.5f, 0.0f));
                    m_SecondaryOrder = (int)(10.0f * (pos.x + (1000.0f * (1.0f - pos.y))));
                }
            }
            else
            {
                // 3D Objects obviously wouldn't have any UI transforms
                if (uiElement is UAP_BaseElement_3D)
                {
                    if (uiElement.m_ManualPositionOrder >= 0)
                    {
                        m_PositionOrder = uiElement.m_ManualPositionOrder;
                    }
                    else
                    {
                        m_PositionOrder = backupIndex;
                    }
                    m_Pos = obj.transform.position;
                }
                else
                {
                    Debug.LogWarning("[Accessibility] Could not find any UI transforms on UI element " + obj.name + " that the accessibility plugin can understand - ordering UI elements by manual position index (if present) or order of initialization.");
                    if (uiElement.m_ManualPositionOrder >= 0)
                    {
                        m_PositionOrder = uiElement.m_ManualPositionOrder;
                    }
                    else
                    {
                        m_PositionOrder = backupIndex;
                    }
                    m_Pos = obj.transform.position;
                }
            }
        }
Ejemplo n.º 26
0
	/// <summary>
	/// Layer is used to ensure that if it changes, widgets get moved as well.
	/// </summary>

	protected override void OnStart ()
	{
		mLayer = mGo.layer;
		UICamera uic = UICamera.FindCameraForLayer(mLayer);
		mCam = (uic != null) ? uic.cachedCamera : NGUITools.FindCameraForLayer(mLayer);
	}
Ejemplo n.º 27
0
    /// <summary>
    /// Convenience function that figures out the panel's correct change flag by searching the parents.
    /// </summary>

    int GetChangeFlag(UINode start)
    {
        int flag = start.changeFlag;

        if (flag == -1)
        {
            Transform trans = start.trans.parent;
            UINode    sub;

            // Keep going until we find a set flag
            for (;;)
            {
                // Check the parent's flag
#if USE_SIMPLE_DICTIONARY
                if (trans != null && mChildren.TryGetValue(trans, out sub))
                {
#else
                if (trans != null && mChildren.Contains(trans))
                {
                    sub = (UINode)mChildren[trans];
#endif
                    flag  = sub.changeFlag;
                    trans = trans.parent;

                    // If the flag hasn't been set either, add this child to the hierarchy
                    if (flag == -1)
                    {
                        mHierarchy.Add(sub);
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    flag = 0;
                    break;
                }
            }

            // Update the parent flags
            for (int i = 0, imax = mHierarchy.size; i < imax; ++i)
            {
                UINode pc = mHierarchy.buffer[i];
                pc.changeFlag = flag;
            }
            mHierarchy.Clear();
        }
        return(flag);
    }

    /// <summary>
    /// Run through all managed transforms and see if they've changed.
    /// </summary>

    void UpdateTransforms()
    {
        bool transformsChanged = false;
        bool shouldCull        = false;

#if UNITY_EDITOR
        shouldCull = (clipping != UIDrawCall.Clipping.None) && (!Application.isPlaying || (cullWhileDragging || mUpdateTime > mCullTime));
        if (!Application.isPlaying || !widgetsAreStatic || mWidgetsAdded || shouldCull != mCulled)
#else
        shouldCull = (clipping != UIDrawCall.Clipping.None) && (mUpdateTime > mCullTime);
        if (!widgetsAreStatic || mWidgetsAdded || shouldCull != mCulled)
#endif
        {
#if USE_SIMPLE_DICTIONARY
            foreach (KeyValuePair <Transform, UINode> child in mChildren)
            {
                UINode node = child.Value;
#else
            for (int i = 0, imax = mChildren.Count; i < imax; ++i)
            {
                UINode node = (UINode)mChildren[i];
#endif
                if (node.trans == null)
                {
                    mRemoved.Add(node.trans);
                    continue;
                }

                if (node.HasChanged())
                {
                    node.changeFlag   = 1;
                    transformsChanged = true;
#if UNITY_EDITOR
                    Vector3 s   = node.trans.lossyScale;
                    float   min = Mathf.Abs(Mathf.Min(s.x, s.y));

                    if (min == 0f)
                    {
                        Debug.LogError("Scale of 0 is invalid! Zero cannot be divided by, which causes problems. Use a small value instead, such as 0.01\n" +
                                       node.trans.lossyScale, node.trans);
                    }
#endif
                }
                else
                {
                    node.changeFlag = -1;
                }
            }

            // Clean up the deleted transforms
            for (int i = 0, imax = mRemoved.Count; i < imax; ++i)
            {
                mChildren.Remove(mRemoved[i]);
            }
            mRemoved.Clear();
        }

        // If the children weren't culled but should be, check their visibility
        if (!mCulled && shouldCull)
        {
            mCheckVisibility = true;
        }

        // If something has changed, propagate the changes *down* the tree hierarchy (to children).
        // An alternative (but slower) approach would be to do a pc.trans.GetComponentsInChildren<UIWidget>()
        // in the loop above, and mark each one as dirty.

        if (mCheckVisibility || transformsChanged || mRebuildAll)
        {
#if USE_SIMPLE_DICTIONARY
            foreach (KeyValuePair <Transform, UINode> child in mChildren)
            {
                UINode pc = child.Value;
#else
            for (int i = 0, imax = mChildren.Count; i < imax; ++i)
            {
                UINode pc = (UINode)mChildren[i];
#endif
                if (pc.widget != null)
                {
                    int visibleFlag = 1;

                    // No sense in checking the visibility if we're not culling anything (as the visibility is always 'true')
                    if (shouldCull || transformsChanged)
                    {
                        // If the change flag has not yet been determined...
                        if (pc.changeFlag == -1)
                        {
                            pc.changeFlag = GetChangeFlag(pc);
                        }

                        // Is the widget visible?
                        if (shouldCull)
                        {
                            visibleFlag = (mCheckVisibility || pc.changeFlag == 1) ? (IsVisible(pc.widget) ? 1 : 0) : pc.visibleFlag;
                        }
                    }

                    // If visibility changed, mark the node as changed as well
                    if (pc.visibleFlag != visibleFlag)
                    {
                        pc.changeFlag = 1;
                    }

                    // If the node has changed and the widget is visible (or was visible before)
                    if (pc.changeFlag == 1 && (visibleFlag == 1 || pc.visibleFlag != 0))
                    {
                        // Update the visibility flag
                        pc.visibleFlag = visibleFlag;
                        Material mat = pc.widget.material;

                        // Add this material to the list of changed materials
                        if (!mChanged.Contains(mat))
                        {
                            mChanged.Add(mat);
                        }
                    }
                }
            }
        }
        mCulled          = shouldCull;
        mCheckVisibility = false;
        mWidgetsAdded    = false;
    }

    /// <summary>
    /// Update all widgets and rebuild their geometry if necessary.
    /// </summary>

    void UpdateWidgets()
    {
#if USE_SIMPLE_DICTIONARY
        foreach (KeyValuePair <Transform, UINode> c in mChildren)
        {
            UINode pc = c.Value;
#else
        for (int i = 0, imax = mChildren.Count; i < imax; ++i)
        {
            UINode pc = (UINode)mChildren[i];
#endif
            UIWidget w = pc.widget;

            // If the widget is visible, update it
            if (pc.visibleFlag == 1 && w != null && w.UpdateGeometry(this, ref worldToLocal, (pc.changeFlag == 1), generateNormals))
            {
                // We will need to refill this buffer
                if (!mChanged.Contains(w.material))
                {
                    mChanged.Add(w.material);
                }
            }
            pc.changeFlag = 0;
        }
    }
#endif

    /// <summary>
    /// Update the clipping rect in the shaders and draw calls' positions.
    /// </summary>

    public void UpdateDrawcalls()
    {
        Vector4 range = Vector4.zero;

        if (mClipping != UIDrawCall.Clipping.None)
        {
            range = new Vector4(mClipRange.x, mClipRange.y, mClipRange.z * 0.5f, mClipRange.w * 0.5f);
        }

        if (range.z == 0f)
        {
            range.z = Screen.width * 0.5f;
        }
        if (range.w == 0f)
        {
            range.w = Screen.height * 0.5f;
        }

        RuntimePlatform platform = Application.platform;

        if (platform == RuntimePlatform.WindowsPlayer ||
            platform == RuntimePlatform.WindowsWebPlayer ||
            platform == RuntimePlatform.WindowsEditor)
        {
            range.x -= 0.5f;
            range.y += 0.5f;
        }

        Transform  t = cachedTransform;
        UIDrawCall dc;
        Transform  dt;

        for (int i = 0, imax = mDrawCalls.size; i < imax; ++i)
        {
            dc              = mDrawCalls.buffer[i];
            dc.clipping     = mClipping;
            dc.clipRange    = range;
            dc.clipSoftness = mClipSoftness;
            dc.depthPass    = depthPass && mClipping == UIDrawCall.Clipping.None;

            // Set the draw call's transform to match the panel's.
            // Note that parenting directly to the panel causes unity to crash as soon as you hit Play.
            dt            = dc.transform;
            dt.position   = t.position;
            dt.rotation   = t.rotation;
            dt.localScale = t.lossyScale;
        }
    }

    /// <summary>
    /// Set the draw call's geometry responsible for the specified material.
    /// </summary>

    void Fill(Material mat)
    {
        int highest = -100;

        // Fill the buffers for the specified material
        for (int i = 0; i < mWidgets.size;)
        {
            UIWidget w = mWidgets.buffer[i];

            if (w == null)
            {
                mWidgets.RemoveAt(i);
                continue;
            }
#if OLD_UNITY
            else if (w.visibleFlag == 1 && w.material == mat)
#else
            else if (w.material == mat && w.isVisible)
#endif
            {
                if (w.panel == this)
                {
                    int depth = w.depth;
                    if (depth > highest)
                    {
                        highest = depth;
                    }
                    if (generateNormals)
                    {
                        w.WriteToBuffers(mVerts, mUvs, mCols, mNorms, mTans);
                    }
                    else
                    {
                        w.WriteToBuffers(mVerts, mUvs, mCols, null, null);
                    }
                }
                else
                {
                    mWidgets.RemoveAt(i);
                    continue;
                }
            }
            ++i;
        }

        if (mVerts.size > 0)
        {
            // Rebuild the draw call's mesh
            UIDrawCall dc = GetDrawCall(mat, true);
            dc.depthPass = depthPass && mClipping == UIDrawCall.Clipping.None;
            dc.depth     = sortByDepth ? highest : 0;
            dc.Set(mVerts, generateNormals ? mNorms : null, generateNormals ? mTans : null, mUvs, mCols);
            dc.mainTexture = mat.mainTexture;
        }
        else
        {
            // There is nothing to draw for this material -- eliminate the draw call
            UIDrawCall dc = GetDrawCall(mat, false);

            if (dc != null)
            {
                mDrawCalls.Remove(dc);
                NGUITools.DestroyImmediate(dc.gameObject);
            }
        }

        // Cleanup
        mVerts.Clear();
        mNorms.Clear();
        mTans.Clear();
        mUvs.Clear();
        mCols.Clear();
    }

    /// <summary>
    /// Main update function
    /// </summary>

    void LateUpdate()
    {
        mUpdateTime = Time.realtimeSinceStartup;
        UpdateTransformMatrix();
#if OLD_UNITY
        UpdateTransforms();
#endif
        // Always move widgets to the panel's layer
        if (mLayer != cachedGameObject.layer)
        {
            mLayer = mGo.layer;
            UICamera uic = UICamera.FindCameraForLayer(mLayer);
            mCam = (uic != null) ? uic.cachedCamera : NGUITools.FindCameraForLayer(mLayer);
            SetChildLayer(cachedTransform, mLayer);
            for (int i = 0, imax = drawCalls.size; i < imax; ++i)
            {
                mDrawCalls.buffer[i].gameObject.layer = mLayer;
            }
        }

#if OLD_UNITY
        UpdateWidgets();
#else
#if UNITY_EDITOR
        bool forceVisible = cullWhileDragging ? false : (clipping == UIDrawCall.Clipping.None) || (Application.isPlaying && mCullTime > mUpdateTime);
#else
        bool forceVisible = cullWhileDragging ? false : (clipping == UIDrawCall.Clipping.None) || (mCullTime > mUpdateTime);
#endif
        // Update all widgets
        for (int i = 0, imax = mWidgets.size; i < imax; ++i)
        {
            UIWidget w = mWidgets[i];

            // If the widget is visible, update it
            if (w.UpdateGeometry(this, forceVisible))
            {
                // We will need to refill this buffer
                if (!mChanged.Contains(w.material))
                {
                    mChanged.Add(w.material);
                }
            }
        }
#endif
        // Inform the changed event listeners
        if (mChanged.size != 0 && onChange != null)
        {
            onChange();
        }

        // If the depth has changed, we need to re-sort the widgets
        if (mDepthChanged)
        {
            mDepthChanged = false;
            mWidgets.Sort(UIWidget.CompareFunc);
        }

        // Fill the draw calls for all of the changed materials
        for (int i = 0, imax = mChanged.size; i < imax; ++i)
        {
            Fill(mChanged.buffer[i]);
        }

        // Update the clipping rects
        UpdateDrawcalls();
        mChanged.Clear();
#if OLD_UNITY
        mRebuildAll = false;
#endif
#if UNITY_EDITOR
        mScreenSize = new Vector2(Screen.width, Screen.height);
#endif
    }
Ejemplo n.º 28
0
    //获得游戏对象
    void GetBallAndTable()
    {
        //获得相机
        m_cMainCam = Camera.main;
        GameObject uiroot = GameObject.Find("UI Root");

        m_cUICam = NGUITools.FindCameraForLayer(uiroot.layer);
        //获得母球
        WhiteBall = GlobalHelper.g_GlobalLevel.WhiteBall;
        //获得球桌
        Table = GlobalHelper.g_GlobalLevel.Table.transform;
        if (null == Right)
        {
            for (int i = 0; i < Table.childCount; i++)
            {
                if ("Right" == Table.GetChild(i).name)
                {
                    Right = Table.GetChild(i).transform;
                }
            }
        }
        if (null == Top)
        {
            for (int i = 0; i < Table.childCount; i++)
            {
                if ("Top" == Table.GetChild(i).name)
                {
                    Top = Table.GetChild(i).transform;
                }
            }
        }
        if (null == Down)
        {
            for (int i = 0; i < Table.childCount; i++)
            {
                if ("Down" == Table.GetChild(i).name)
                {
                    Down = Table.GetChild(i).transform;
                }
            }
        }
        if (null == Left)
        {
            for (int i = 0; i < Table.childCount; i++)
            {
                if ("Left" == Table.GetChild(i).name)
                {
                    Left = Table.GetChild(i).transform;
                }
            }
        }
        //获得UI
        //if(null == HandUI)
        //{
        //    for(int i=0;i<gameObject.transform.childCount;i++)
        //    {
        //        if("Hand" == gameObject.transform.GetChild(i).name)
        //        {
        //            HandUI = gameObject.transform.GetChild(i).gameObject;
        //        }
        //    }
        //}
        UIMgr = GameObject.Find("UIManager");
        UIM   = UIMgr.GetComponent <UIManager>();
        UIh   = UIM.UI <UIHand>(false);
        if (DP == null)
        {
            for (int i = 0; i < UIh.gameObject.transform.childCount; i++)
            {
                if (UIh.gameObject.transform.GetChild(i).name == "DontPush")
                {
                    DP = UIh.gameObject.transform.GetChild(i).gameObject;
                }
            }
        }
        if (HandUI == null)
        {
            for (int i = 0; i < UIh.gameObject.transform.childCount; i++)
            {
                if (UIh.gameObject.transform.GetChild(i).name == "Hand")
                {
                    HandUI = UIh.gameObject.transform.GetChild(i).gameObject;
                }
            }
        }
    }
    public void Start()
    {
        _instance = this;

        uiCamera = NGUITools.FindCameraForLayer(label.gameObject.layer);
    }
Ejemplo n.º 30
0
    /// <summary>
    /// Creates a temporary icon.
    /// </summary>
    /// <returns>The temporary.</returns>
    protected virtual GameObject CreateTemporary()
    {
        // Create temporary icon
        GameObject icon = (GameObject)Instantiate(this.iconSprite.gameObject);

        icon.layer = this.gameObject.layer;

        // Check if the icon has tweens on it
        TweenColor cTween = icon.GetComponent <TweenColor>();

        if (cTween != null)
        {
            cTween.enabled = false;
            NGUITools.Destroy(cTween);
        }

        // Apply normal color to the clone icon
        UITexture tex = icon.GetComponent <UITexture>();

        if (tex != null)
        {
            tex.color = Color.white;
        }

        // Re-parent the item
        if (UIDragDropRoot.root != null)
        {
            icon.transform.parent = UIDragDropRoot.root;
        }
        else
        {
            // Create temporary panel
            GameObject panelObj = new GameObject("_TemporaryPanel");
            panelObj.layer                   = this.gameObject.layer;
            panelObj.transform.parent        = NGUITools.GetRoot(this.gameObject).transform;
            panelObj.transform.localScale    = Vector3.one;
            panelObj.transform.localRotation = Quaternion.identity;
            panelObj.transform.localPosition = Vector3.one;

            // Save the panel so we can destroy it
            this.mTemporaryDraggingPanel = panelObj;

            // Apply depth
            UIPanel panel = panelObj.AddComponent <UIPanel>();
            panel.depth           = UIPanel.nextUnusedDepth;
            icon.transform.parent = panelObj.transform;
        }

        // Fix it's position
        icon.transform.position   = NGUITools.FindCameraForLayer(this.gameObject.layer).ScreenToWorldPoint(Input.mousePosition);
        icon.transform.rotation   = this.transform.rotation;
        icon.transform.localScale = this.transform.localScale;

        // Make sure the icon is at the center on the pointer
        UIWidget widget = icon.GetComponent <UIWidget>();

        if (widget != null)
        {
            if (widget.pivot != UIWidget.Pivot.Center)
            {
                Vector3 centerOffset = Vector3.zero;

                switch (widget.pivot)
                {
                case UIWidget.Pivot.TopLeft:
                    centerOffset = new Vector3(-widget.width / 2f, widget.height / 2f);
                    break;

                case UIWidget.Pivot.Top:
                    centerOffset = new Vector3(0f, widget.height / 2f);
                    break;

                case UIWidget.Pivot.TopRight:
                    centerOffset = new Vector3(widget.width / 2f, widget.height / 2f);
                    break;

                case UIWidget.Pivot.Right:
                    centerOffset = new Vector3(widget.width / 2f, 0f);
                    break;

                case UIWidget.Pivot.BottomRight:
                    centerOffset = new Vector3(widget.width / 2f, -widget.height / 2f);
                    break;

                case UIWidget.Pivot.Bottom:
                    centerOffset = new Vector3(0f, -widget.height / 2f);
                    break;

                case UIWidget.Pivot.BottomLeft:
                    centerOffset = new Vector3(-widget.width / 2f, -widget.height / 2f);
                    break;

                case UIWidget.Pivot.Left:
                    centerOffset = new Vector3(-widget.width / 2f, 0f);
                    break;
                }

                icon.transform.localPosition += centerOffset;
            }
        }

        return(icon);
    }