Пример #1
0
        private void _bindIngredients <TTarget>(IngredientBuilder <TTarget> builder, ShopProduct product,
                                                ShopIngredient ingredient)
            where TTarget : class
        {
            var ingredientBuilder = builder
                                    .Cost(ingredient.Price)
                                    .Tweakable(ingredient.Tweakable)
                                    .DisplayName(ingredient.Name)
                                    .DefaultAmount(ingredient.Amount)
                                    .Id(product.Guid + "_" + ingredient.Name);

            foreach (var effect in ingredient.Effects)
            {
                ingredientBuilder.Effect(ProductShopUtility.ConvertEffectType(effect.Type), effect.Amount);
            }
        }
Пример #2
0
        private void _loadShop(Asset asset)
        {
            GameObject go = AssetPackUtilities.LoadAsset <GameObject>(_bundle, asset.Guid);

            if (go == null)
            {
                throw new Exception("Can't find Object:" + asset.Guid);
            }

            var builder = Parkitility.CreateProductShop <ProductShop>(go)
                          .DisplayName(asset.Name)
                          .Id(asset.Guid)
                          .Price(asset.Price)
                          .WalkableFlag(Asset.ConvertWalkable(asset.Walkable));

            foreach (var box in AssetPackUtilities.ConvertBoundingBox(asset.BoundingBoxes.ToArray()))
            {
                builder.AddBoundingBox(box);
            }

            foreach (var product in asset.Products)
            {
                GameObject productGo = AssetPackUtilities.LoadAsset <GameObject>(_bundle, product.Guid);
                if (productGo == null)
                {
                    Debug.Log("Can't find product game object for:" + product.Name);
                    continue;
                }

                switch (product.ProductType)
                {
                case ProductType.ON_GOING:
                    var ongoingProductBuilder = Parkitility
                                                .CreateOnGoingProduct <OngoingEffectProduct>(productGo)
                                                .Id(product.Guid)
                                                .DisplayName(product.Name)
                                                .Duration(product.Duration)
                                                .DestroyWhenDepleted(product.DestroyWhenDepleted)
                                                .RemoveFromInventoryWhenDepleted(product.RemoveWhenDepleted)
                                                .TwoHanded(product.IsTwoHanded)
                                                .InterestingToLookAt(product.IsInterestingToLookAt)
                                                .DefaultPrice(product.Price)
                                                .HandSide(ProductShopUtility.ConvertToSide(product.HandSide));

                    foreach (var shopIngredient in product.Ingredients)
                    {
                        _bindIngredients(ongoingProductBuilder.AddIngredient(_assetManagerLoader),
                                         product, shopIngredient);
                    }

                    builder.AddProduct(_assetManagerLoader, ongoingProductBuilder);
                    break;

                case ProductType.BALLOON:
                    Debug.Log(product.Name);
                    var balloonBuilder = Parkitility
                                         .CreateBalloonProduct <Balloon>(productGo)
                                         .Id(product.Guid)
                                         .DisplayName(product.Name)
                                         .DestroyWhenDepleted(false)
                                         .Duration(180)
                                         .DefaultPrice(product.Price)
                                         .DefaultMass(product.DefaultMass)
                                         .DefaultDrag(product.DefaultDrag)
                                         .DefaultAngularDrag(product.DefaultAngularDrag)
                                         .RemoveFromInventoryWhenDepleted(true);

                    if (product.HasCustomColors)
                    {
                        balloonBuilder.CustomColor(
                            AssetPackUtilities.ConvertColors(product.CustomColors, product.ColorCount));
                    }

                    foreach (var shopIngredient in product.Ingredients)
                    {
                        _bindIngredients(balloonBuilder.AddIngredient(_assetManagerLoader),
                                         product, shopIngredient);
                    }

                    builder.AddProduct(_assetManagerLoader, balloonBuilder);
                    break;

                case ProductType.WEARABLE:
                    var wearableProductBuilder = Parkitility
                                                 .CreateWearableProduct <WearableProduct>(productGo)
                                                 .Id(product.Guid)
                                                 .DisplayName(product.Name)
                                                 .TwoHanded(product.IsTwoHanded)
                                                 .InterestingToLookAt(product.IsInterestingToLookAt)
                                                 .DefaultPrice(product.Price)
                                                 .HandSide(ProductShopUtility.ConvertToSide(product.HandSide))
                                                 .TemperaturePreference(
                        ProductShopUtility.ConvertTemperaturePreference(
                            product.TemperaturePreference))
                                                 .SeasonalPreference(
                        ProductShopUtility.ConvertSeasonalPreference(
                            product.SeasonalPreference))
                                                 .BodyLocation(ProductShopUtility.ConvertBodyLocation(product.BodyLocation))
                                                 .HideHair(product.HideHair)
                                                 .HideOnRide(product.HideOnRide);

                    if (product.HasCustomColors)
                    {
                        wearableProductBuilder.CustomColor(
                            AssetPackUtilities.ConvertColors(product.CustomColors, product.ColorCount));
                    }


                    foreach (var shopIngredient in product.Ingredients)
                    {
                        _bindIngredients(wearableProductBuilder.AddIngredient(_assetManagerLoader),
                                         product, shopIngredient);
                    }

                    builder.AddProduct(_assetManagerLoader, wearableProductBuilder);
                    break;

                case ProductType.CONSUMABLE:
                    var consumableBuilder = Parkitility
                                            .CreateConsumableProduct <ConsumableProduct>(productGo)
                                            .Id(product.Guid)
                                            .DisplayName(product.Name)
                                            .TwoHanded(product.IsTwoHanded)
                                            .InterestingToLookAt(product.IsInterestingToLookAt)
                                            .TemperaturePreference(
                        ProductShopUtility.ConvertTemperaturePreference(
                            product.TemperaturePreference))
                                            .ConsumeAnimation(
                        ProductShopUtility.ConvertConsumeAnimation(product.ConsumeAnimation))
                                            .DefaultPrice(product.Price)
                                            .HandSide(ProductShopUtility.ConvertToSide(product.HandSide));

                    GameObject trashGo = AssetPackUtilities.LoadAsset <GameObject>(_bundle, product.TrashGuid);
                    if (trashGo != null)
                    {
                        consumableBuilder.Trash <Trash>(trashGo, _assetManagerLoader)
                        .Id(product.TrashGuid)
                        .Disgust(product.DisgustFactor)
                        .Volume(product.Volume)
                        .CanWiggle(product.CanWiggle);
                    }

                    foreach (var shopIngredient in product.Ingredients)
                    {
                        _bindIngredients(consumableBuilder.AddIngredient(_assetManagerLoader),
                                         product,
                                         shopIngredient);
                    }

                    builder.AddProduct(_assetManagerLoader, consumableBuilder);
                    break;
                }
            }

            builder.Build(_assetManagerLoader);
        }