コード例 #1
0
        public void AddSprite(
            SpriteRecord record
            )
        {
            if (spritePrefab == null)
            {
                return;
            }
            // instantiate sprite prefab
            var spriteGO = UnityEngine.Object.Instantiate(spritePrefab, contentTransform);
            // grab controller
            var spriteCtrl = spriteGO.GetComponent <UxAvailSpriteCtrl>();

            if (spriteCtrl != null)
            {
                // create ctx
                var ctx = new AvailSpriteCtx(record, spriteCtrl);
                // assign sprite image
                spriteCtrl.AssignSprite(record.sprite);
                // wire handlers
                // -- select button
                spriteCtrl.selectButton.onClick.AddListener(() => {
                    if (currentCtx != null)
                    {
                        currentCtx.ctrl.Select(false);
                    }
                    spriteCtrl.Select(true);
                    mgrCtx.selectSpriteFcn(record);
                    currentCtx = ctx;
                });
                // add to ctx map
                ctxMap[record.id] = ctx;
            }
        }
コード例 #2
0
 public void Clear()
 {
     foreach (var ctx in ctxMap.Values)
     {
         Destroy(ctx.ctrl.gameObject);
     }
     ctxMap.Clear();
     currentCtx = null;
 }
コード例 #3
0
        public void SelectSprite(
            SpriteRecord record
            )
        {
            AvailSpriteCtx ctx;

            if (ctxMap.TryGetValue(record.id, out ctx))
            {
                if (currentCtx != null)
                {
                    currentCtx.ctrl.Select(false);
                }
                ctx.ctrl.Select(true);
                currentCtx = ctx;
            }
        }