private RunnerItem ItemFactory(Type inItemType, LevelGroup.eLevelGroupID levelGroupID) { RunnerItem spawnedItem = null; if (inItemType == typeof(HazardItem)) { List <HazardItem> hazardItems = levelHazardItems[levelGroupID]; HazardItem randomHazard = hazardItems[Random.Range(0, hazardItems.Count)]; spawnedItem = (HazardItem)Instantiate(randomHazard); } else if (inItemType == typeof(CoinItem)) { CoinItem randomCoin = CoinItems[Random.Range(0, CoinItems.Count)]; spawnedItem = (CoinItem)Instantiate(randomCoin); } else if (inItemType == typeof(RunnerItem)) { RunnerItem randomItem = ItemPrefabs[Random.Range(0, ItemPrefabs.Count)]; spawnedItem = (RunnerItem)Instantiate(randomItem); } else { Debug.LogError("No spawn logic set for item type " + inItemType); } spawnedItem.transform.parent = runnerItemsParent.transform; return(spawnedItem); }
public void InitCoinItems() { Debug.Log("金币总量为:" + PlayerDataManager.GetCoins()); for (int i = 0; i != coinItems.Length; i++) { CoinItem item = coinItems[i]; item.coinAmountText.text = item.coinAmount.ToString(); if (item.dealValue > 0) { item.dealValueText.GetComponent <LocalizationParamsManager>().SetParameterValue("AMOUNT", $"+{item.dealValue.ToString()}"); item.dealValueText.text = "<color=#9806FD>" + item.dealValue.ToString() + "%" + "额外赠送!"; } item.priceText.text = item.gemPrice.ToString(); item.button.onClick.AddListener(delegate { TryPurchase(item.gemPrice, CurrencyType.Gems, delegate { AnimatedCurrencyController.AnimateCoins(item.coinAmount, MenuController.UICamera.WorldToViewportPoint(item.graphicButton.transform.position), MenuController.TotalCoinsPositionViewport, 1, null, delegate(int tc) { }); MenuController.instance.topTotalGemsText.Tick(-item.gemPrice); //宝石扣除 PlayerDataManager.AddCoins(item.coinAmount, sync: true, cloudSync: false); //金币添加 MenuController.UpdateTopMenu(); Debug.Log("金币总量为:" + PlayerDataManager.GetCoins()); Debug.Log("钻石总量为:" + PlayerDataManager.GetGems()); }); }); } }
private void SpawnCoinStrip(LevelComponent inLevelComponent, PointGroup inSpawnGroup) { RunnerItemManager runnerItemManager = RunnerItemManager.Instance; switch (inSpawnGroup.mCurveType) { case eCurveType.Point: case eCurveType.Linear: { float interpolationLeftovers = 0; for (int pointIndex = 0; pointIndex < inSpawnGroup.mPoints.Count - 1; pointIndex++) { Vector3 currentLineBegin = inSpawnGroup.mPoints[pointIndex].mPosition; Vector3 currentLineEnd = inSpawnGroup.mPoints[pointIndex + 1].mPosition; float currentLineDistance = Vector3.Distance(currentLineBegin, currentLineEnd); // Interpolate along our current line int coinNum = 1; //Number of coins we have spawned on this line CoinItem lastCoin = null; for (float currentInterpolation = interpolationLeftovers; currentInterpolation < currentLineDistance; currentInterpolation += CoinSpawnDistance) { // Find our new spawn point Vector3 newCoinPosition = Vector3.Lerp(currentLineBegin, currentLineEnd, (currentInterpolation / currentLineDistance)); // But wait, that's on the prefab. Add in our real world clones position. newCoinPosition += inLevelComponent.transform.localPosition; CoinItem newCoin = (CoinItem)runnerItemManager.GetRandomItemOfType(typeof(CoinItem), mCurrentLevelGroup.LevelGroupID); newCoin.transform.position = newCoinPosition; newCoin.CoinValue = coinNum; inLevelComponent.AddLevelItem(newCoin); if (coinNum == 1) { newCoin.NextToCollect = true; } else { lastCoin.NextCoin = newCoin; //The coin after the one before us, is us } coinNum++; lastCoin = newCoin; interpolationLeftovers = currentInterpolation - currentLineDistance; } lastCoin.LastCoin = true; } } break; case eCurveType.Quadratic: case eCurveType.Cubic: { float lineLength = CalculateCurveLength(inSpawnGroup); if (lineLength > 0f) { // Set up some variables. Vector3 ptA = inSpawnGroup.mPoints[0].mPosition; Vector3 ptB = inSpawnGroup.mPoints[1].mPosition; Vector3 ptC = inSpawnGroup.mPoints[2].mPosition; Vector3 ptD = Vector3.zero; if (inSpawnGroup.mPoints.Count > 3) { ptD = inSpawnGroup.mPoints[3].mPosition; } // Iterate the line length. int coinNum = 1; //Number of coins we have spawned on this line CoinItem lastCoin = null; CoinSpawnDistance += .75f; //When we are a curve, we need a little bit more spin in between our stars for (float currentPosition = 0f; currentPosition < lineLength; currentPosition += CoinSpawnDistance) { // Determine current t float currentT = currentPosition / lineLength; // Get the new position Vector3 coinSpawnLocation; if (inSpawnGroup.mCurveType == eCurveType.Quadratic) { coinSpawnLocation = CalculateQuadtraticPoint(currentT, ptA, ptB, ptC); } else { coinSpawnLocation = CalculateBezierPoint(currentT, ptA, ptB, ptC, ptD); } coinSpawnLocation += inLevelComponent.transform.position; // And spawn CoinItem newCoin = (CoinItem)runnerItemManager.GetRandomItemOfType(typeof(CoinItem), mCurrentLevelGroup.LevelGroupID); newCoin.transform.position = coinSpawnLocation; newCoin.CoinValue = coinNum; inLevelComponent.AddLevelItem(newCoin); if (coinNum == 1) { newCoin.NextToCollect = true; } else { lastCoin.NextCoin = newCoin; //The coin after the one before us, is us } coinNum++; lastCoin = newCoin; inLevelComponent.AddLevelItem(newCoin); } } } break; } }
public override decimal Resolve(CoinItem source, Coin destination, decimal destMember, ResolutionContext context) { return(Resolve(source?.MarketData.PriceChangePercentage24HInCurrency)); }
public override decimal Resolve(CoinItem source, Coin destination, decimal destMember, ResolutionContext context) { return(Resolve(source?.MarketData.CurrentPrice)); }