示例#1
0
    private void DefautKittySelection()
    {
        var        kitties       = KittyService.GetAll();
        bool       kittySelected = false;
        KittyModel kittyUnlocked = null;

        foreach (var kitty in kitties)
        {
            if (kitty.isSelected)
            {
                kittySelected = true;
            }
            if (kittyUnlocked == null && kitty.isUnlocked)
            {
                kittyUnlocked = kitty;
            }
        }
        if (!kittySelected)
        {
            if (kittyUnlocked != null)
            {
                // set first kitty found that's unlocked to selected status
                kittyUnlocked.isSelected = true;
            }
            else
            {
                // set random kitty to unlocked and selected
                int randomKittyIndex = Random.Range(0, kitties.Count);
                var randomKitty      = kitties[randomKittyIndex];
                randomKitty.isUnlocked = true;
                randomKitty.isSelected = true;
            }
        }
        KittyService.SaveMultiple(kitties);
    }
    public static void Save(KittyModel model)
    {
        var modelsToSave = new List <KittyModel>()
        {
            model
        };

        KittyService.SaveMultiple(modelsToSave);
    }
示例#3
0
    // IMPLEMENTATION METHODS

    private void KittyStartupProcesses()
    {
        List <Sprite> kittySprites =
            Resources.LoadAll("Kitty", typeof(Sprite))
            .Cast <Sprite>()
            .ToList();
        var kittiesToSave = new List <KittyModel>();

        foreach (var kittySprite in kittySprites)
        {
            // create kitty model if it doesn't yet exist
            var kittyModel = KittyService.GetModelByAssetName(kittySprite.name);
            if (kittyModel == null)
            {
                kittyModel = new KittyModel(
                    System.Guid.NewGuid().ToString(),
                    kittySprite.name,
                    KittyService.GetFormattedAssetAddress(kittySprite.name),
                    KittyService.GetFormattedThumbAssetAddress(kittySprite.name),
                    false,
                    false
                    );
                kittiesToSave.Add(kittyModel);
            }
            // register assets
            AssetService.SetSprite(
                KittyService.GetFormattedAssetAddress(kittySprite.name),
                kittySprite
                );
        }
        // save thumb kitty sprites to Asset service
        List <Sprite> kittyThumbSprites =
            Resources.LoadAll("KittyThumb", typeof(Sprite))
            .Cast <Sprite>()
            .ToList();

        foreach (var kittyThumbSprite in kittyThumbSprites)
        {
            string thumbAddress = KittyService.GetFormattedThumbAssetAddress(
                kittyThumbSprite.name,
                true
                );
            AssetService.SetSprite(
                thumbAddress,
                kittyThumbSprite
                );
        }
        // insert kitties to be saved
        KittyService.SaveMultiple(kittiesToSave);
    }
    public static void SetSelected(KittyModel model)
    {
        // deselect currently selected
        var previouslySelectedKitty = KittyService.GetSelected();

        if (model.id == previouslySelectedKitty.id)
        {
            // Debug.Log("attempting to select already selected kitty: " + model.primaryAssetAddress);
            return;
        }
        previouslySelectedKitty.isSelected = false;
        // set selected
        model.isSelected = true;
        // batch save models
        KittyService.SaveMultiple(
            new List <KittyModel>()
        {
            previouslySelectedKitty, model
        }
            );
    }