Пример #1
0
        public ScreenTag CreateScreenTag(GameObject varRelativeObj, Vector3 varOffset, GameObject varView)
        {
            if (mCameraObject == null)
            {
                Helper.LogError("Please set a Camera for translating!");
                return(null);
            }
            if (varRelativeObj == null)
            {
                Helper.LogError("CreateScreenTag fail caused by null varRelativeObj");
                return(null);
            }
            if (varView == null)
            {
                Helper.LogError("CreateScreenTag fail caused by null varView");
                return(null);
            }
            //            GameObject tmpObj = new GameObject("SceneTag " + varView.GetHashCode());
            //            tmpObj.transform.SetParent (mTransform);
            varView.name = "SceneTag " + varView.GetHashCode();
            varView.transform.SetParent(mTransform);
            varView.transform.localScale = Vector3.one;
            ScreenTag tmpTag = varView.AddComponent <ScreenTag>();

            tmpTag.pOffset      = varOffset;
            tmpTag.pRelativeObj = varRelativeObj;
            tmpTag.pView        = varView;
            tmpTag.pCameraObj   = mCameraObject;
            if (mScreenTags == null)
            {
                mScreenTags = new List <ScreenTag>();
            }
            mScreenTags.Add(tmpTag);
            return(tmpTag);
        }
Пример #2
0
 public void RemoveAllScreenTags()
 {
     if (mScreenTags != null && mScreenTags.Count > 0)
     {
         for (int i = 0; i < mScreenTags.Count; i++)
         {
             ScreenTag tmpTag = mScreenTags[i];
             DestroyImmediate(tmpTag.gameObject);
         }
         mScreenTags.Clear();
     }
 }
Пример #3
0
 public void RemoveScreenTag(ScreenTag varScreenTag)
 {
     if (varScreenTag == null)
     {
         return;
     }
     if (mScreenTags == null || mScreenTags.Count == 0)
     {
         return;
     }
     mScreenTags.Remove(varScreenTag);
 }
Пример #4
0
 private void Update()
 {
     if (mCamera == null && mCameraObject != null)
     {
         mCamera = mCameraObject.GetComponentInChildren <Camera>();
     }
     if (mScreenTags != null && mScreenTags.Count > 0)
     {
         for (int i = 0; i < mScreenTags.Count; i++)
         {
             ScreenTag tmpTag = mScreenTags[i];
             if (tmpTag == null || tmpTag.mRelativeObj == null)
             {
                 continue;
             }
             if (tmpTag.mRelativeObj == null || tmpTag.mRelativeObj.transform == null)
             {
                 Destroy(tmpTag.gameObject);
                 mScreenTags.Remove(tmpTag);
             }
             Vector3 tmpWorldPos = tmpTag.mRelativeObj.transform.position;
             tmpWorldPos += tmpTag.mOffset;
             if (Helper.IsInViewPort(mCamera, tmpWorldPos) == false)
             {
                 tmpTag.gameObject.SetActive(false);
             }
             else
             {
                 if (tmpTag.gameObject.activeSelf == false)
                 {
                     tmpTag.gameObject.SetActive(true);
                 }
             }
         }
     }
 }