コード例 #1
0
    public static void ShowImageAlert(string texturePath_, string title_, string message_, string confirmButtonTitle_, string confirmButtonIconPath_, string[] otherButtonTitles_, GameObject alertCallbackTarget_, string alertCallbackMethod_, bool showTitleIcon_ = false)
    {
        PrepareToShow_();

        //CREATE TEXTURE ATLAS
        Texture2DAtlas atlas_ = null;
        Dictionary <string, Texture2D> texturesDictionary_ = new Dictionary <string, Texture2D> ();

        if (!string.IsNullOrEmpty(texturePath_))
        {
            texturesDictionary_[texturePath_] = Resources.Load(texturePath_) as Texture2D;
        }
        if (!string.IsNullOrEmpty(confirmButtonIconPath_))
        {
            texturesDictionary_[confirmButtonIconPath_] = Resources.Load(confirmButtonIconPath_) as Texture2D;
        }

        atlas_ = new Texture2DAtlas(texturesDictionary_, Texture2DAtlas.defaultScale);

        Rect imageUv_      = string.IsNullOrEmpty(texturePath_) ? new Rect() : atlas_.GetRect(texturePath_);
        Rect confirmBtnUv_ = string.IsNullOrEmpty(confirmButtonIconPath_) ? new Rect(0f, 0f, 0f, 0f) : atlas_.GetRect(confirmButtonIconPath_);

        object[] alertPresentParams_ = new object[] { atlas_, imageUv_, title_, message_, confirmButtonTitle_, confirmBtnUv_, otherButtonTitles_, showTitleIcon_ };
        Instance.ShowAlertGeneric <UIImageAlertViewController>(alertPresentParams_, alertCallbackTarget_, alertCallbackMethod_, "Prefabs/UI/AlertViews/UIImageAlertView");
    }
コード例 #2
0
    public void InitializeTextureWithRectAndAtlasSafely(UITexture texture, Texture2DAtlas atlas, Rect uv)
    {
        //INITIALIZE CAFE TEXTURE
        if (atlas == null && texture != null)
        {
            NGUITools.SetActive(texture.gameObject, false);
        }
        else if (texture != null)
        {
            NGUITools.SetActive(texture.gameObject, true);

            texture.mainTexture = null;
            texture.material    = atlas.AtlasMaterial;
            texture.uvRect      = uv;
            texture.ScaleToFit();
        }
    }
コード例 #3
0
 public static void SetTextureImageWithName(this UITexture texture, Texture2DAtlas atlas, string imageName)
 {
     if (imageName == null)
     {
         return;
     }
     if (atlas == null)
     {
         return;
     }
     if (atlas.AtlasMaterial != texture.material)
     {
         texture.mainTexture = null;
         texture.material    = atlas.AtlasMaterial;
     }
     texture.uvRect = atlas.GetRect(imageName);
 }
コード例 #4
0
    public void InitializeGridWithAtlasAndRectsSafely(UIGridExt grid_, Texture2DAtlas atlas_, List <Rect> uvs_, Rect bgUv_)
    {
        if (uvs_ == null)
        {
            uvs_ = new List <Rect>();
        }

        int countOfItemsForDisplay_ = uvs_.Count;

        if (countOfItemsForDisplay_ == 0 && grid_ != null)
        {
            NGUITools.SetActive(grid_.gameObject, false);
        }
        else if (grid_ != null)
        {
            NGUITools.SetActive(grid_.gameObject, true);
            grid_.hideInactive = false;
            List <GameObject> existedItemCells_ = grid_.GetSortedCells();

            if (existedItemCells_.Count > 0)
            {
                //instantiate required cells
                for (int i = existedItemCells_.Count; i < countOfItemsForDisplay_; i++)
                {
                    grid_.AddCell(existedItemCells_[0]);
                }

                //destory unwanted cells
                for (int i = countOfItemsForDisplay_; i < existedItemCells_.Count; i++)
                {
                    grid_.RemoveCell(existedItemCells_[i]);
                }

                //setup all cells
                existedItemCells_ = grid_.GetSortedCells();
                for (int i = 0; i < countOfItemsForDisplay_; i++)
                {
                    GameObject cellGo_ = existedItemCells_[i];
                    NGUITools.SetActive(cellGo_, true);
                    UICountableItemCell cell_ = cellGo_.GetComponent <UICountableItemCell>();
                    if (cell_ != null)
                    {
                        if (atlas_ != null && i < uvs_.Count && cell_.iconTexture != null)
                        {
                            cell_.iconTexture.mainTexture = null;
                            cell_.iconTexture.material    = atlas_.AtlasMaterial;
                            cell_.iconTexture.uvRect      = uvs_[i];
                            cell_.iconTexture.ScaleToFit();
                        }
                        else if (cell_.iconTexture != null)
                        {
                            NGUITools.SetActive(cell_.iconTexture.gameObject, false);
                        }

                        if (atlas_ != null && cell_.backgroundTexture != null & bgUv_.width != 0f && bgUv_.height != 0f)
                        {
                            cell_.backgroundTexture.mainTexture = null;
                            cell_.backgroundTexture.material    = atlas_.AtlasMaterial;
                            cell_.backgroundTexture.uvRect      = bgUv_;
                            cell_.backgroundTexture.ScaleToFit();
                        }
                        else if (cell_.backgroundTexture != null)
                        {
                            NGUITools.SetActive(cell_.backgroundTexture.gameObject, false);
                        }

                        //deactive cell count label, because it is not required
                        if (cell_.countLabel != null)
                        {
                            NGUITools.SetActive(cell_.countLabel.gameObject, false);
                        }
                    }
                }
            }
        }
    }