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; } }
public void Clear() { foreach (var ctx in ctxMap.Values) { Destroy(ctx.ctrl.gameObject); } ctxMap.Clear(); currentCtx = null; }
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; } }