// 从SpriteSleeperManager中找到本Image,所在的atlas
        // 记录其tag
        // 并标记引用此tag
        private void FindTag()
        {
            if (string.IsNullOrEmpty(Tag) && _image != null && _manager != null && !_manager.Equals(null))
            {
                // 获取Image控件的Sprite
                Sprite sprite = _image.sprite;
                if (sprite != null)
                {
                    // 保存自己的sprite名称
                    SpriteName = sprite.name;

                    // sprite对应的texture
                    Texture2D texture = sprite.texture;
                    if (texture != null)
                    {
                        // 从SpriteSleeperManager中,获取texture对应的tag
                        string tag = _manager.GetTag(texture);
                        if (tag != null)
                        {
                            StopListeningForAtlases();
                            Tag = tag;

                            //
                            _manager.RefTag(Tag);
                        }
                    }
                }
            }
        }
示例#2
0
 private void OnDestroy()
 {
     if (_manager != null && !_manager.Equals(null))
     {
         _manager.RemoveCanvas(this);
     }
 }
示例#3
0
        private void Awake()
        {
            _canvas = GetComponent <Canvas>();
            if (_canvas == null)
            {
                Debug.LogError("SpriteSleeperCanvas is unable to find a Canvas component on the current object. Ensure that this component is added to the GameObject containing the Canvas.");
                return;
            }

            if (!_canvas.isRootCanvas)
            {
                Debug.LogError("SpriteSleeperCanvas should only be used on root canvases.");
                return;
            }

            _hasCanvas = true;
            _manager   = SpriteSleeperManager.Instance();

            if (_manager == null || _manager.Equals(null))
            {
                Debug.LogError("SpriteSleeperCanvas is unable to find a SpriteSleeperManager.");
                return;
            }

            _manager.AddCanvas(this);

            _spriteSleepers = new List <SpriteSleeperImage>();
            RefreshImageList();

            // Allow for canvases that start disabled to unref their images
            Invoke("OnCanvasHierarchyChanged", 0.0001f);
        }
示例#4
0
        private void FindTag()
        {
            if (string.IsNullOrEmpty(Tag) && _image != null && _manager != null && !_manager.Equals(null))
            {
                Sprite sprite = _image.sprite;
                if (sprite != null)
                {
                    SpriteName = sprite.name;

                    Texture2D texture = sprite.texture;
                    if (texture != null)
                    {
                        string tag = _manager.GetTag(texture);
                        if (tag != null)
                        {
                            StopListeningForAtlases();
                            Tag = tag;

                            _manager.RefTag(Tag);
                        }
                    }
                }
            }
        }