/// <summary> /// Initializes crates /// </summary> /// <param name="contents">Contents.</param> public void SetupCrate(TankDecorationDefinition contents) { cratePrize = contents; m_StickerRenderer.material.mainTexture = cratePrize.crateDecal; m_CachedRigidbody = GetComponent <Rigidbody>(); // Work out material ID int prizeIndex = TankDecorationLibrary.s_Instance.GetIndexForDecoration(cratePrize); List <int> colourIndexList = new List <int>(); PlayerDataManager playerdata = PlayerDataManager.s_Instance; for (int i = 0; i < contents.availableMaterials.Length; i++) { if (!playerdata.IsColourUnlockedForDecoration(prizeIndex, i)) { colourIndexList.Add(i); } } decorationMaterialIndex = colourIndexList[Random.Range(0, colourIndexList.Count)]; m_PaintRenderer.material.color = cratePrize.availableMaterials[decorationMaterialIndex].color; }
public void SetTankDecoration(int newDecorationId, int newMaterialIndex, bool destroyDecorations = true) { //Get decoration data TankDecorationDefinition itemData = TankDecorationLibrary.s_Instance.GetDecorationForIndex(newDecorationId); //Iterate through all decoration points and clear them if (destroyDecorations) { for (int i = 0; i < m_AttachedDecorations.Count; i++) { Decoration decoration = m_AttachedDecorations[i]; if (decoration != null) { Destroy(decoration.gameObject); } } } //Instantiate and place the relevant object. Since a decorationType value of 0 equates to "no items", we subtract 1 from the enum to get the intended location transform array index if (itemData.id != "none") { Transform positionTransform = m_DecorationPoints[newDecorationId - 1]; Decoration newDecoration = (Decoration)Instantiate(itemData.decorationPrefab, positionTransform.position, positionTransform.rotation, positionTransform); if (TankDecorationLibrary.s_Instance.GetMaterialQuantityForIndex(newDecorationId) > 0) { newDecoration.SetMaterial(TankDecorationLibrary.s_Instance.GetMaterialForDecoration(newDecorationId, newMaterialIndex)); } newDecoration.Attach(m_TankManager); m_AttachedDecorations.Add(newDecoration); } }
//Used for temporarily unlocking an item private void UnlockTempItem() { TankDecorationDefinition prizeItem = TankDecorationLibrary.s_Instance.GetDecorationForIndex(m_PrizeIndex); //If no colour index was specified for this item unlock, we select one at random. if (m_PrizeColourIndex < 0) { m_PrizeColourIndex = Random.Range(0, prizeItem.availableMaterials.Length); } DailyUnlockManager.s_Instance.SetDailyUnlock(prizeItem.id, m_PrizeColourIndex); ApplyChangesAndClose(); }
/// <summary> /// Set up this tank with the correct properties /// </summary> private void Initialize(TanksNetworkPlayer player) { if (initialized) { return; } initialized = true; this.player = player; playerTankType = TankLibrary.s_Instance.GetTankDataForIndex(player.tankType); // Create visual tank GameObject tankDisplay = (GameObject)Instantiate(playerTankType.displayPrefab, transform.position, transform.rotation); tankDisplay.transform.SetParent(transform, true); // Analytics messages on server if (isServer) { AnalyticsHelper.PlayerUsedTankInGame(playerTankType.id); TankDecorationDefinition itemData = TankDecorationLibrary.s_Instance.GetDecorationForIndex(player.tankDecoration); if (itemData.id != "none") { AnalyticsHelper.PlayerUsedDecorationInGame(itemData.id); } } // Get references to the components. display = tankDisplay.GetComponent <TankDisplay>(); movement = GetComponent <TankMovement>(); shooting = GetComponent <TankShooting>(); health = GetComponent <TankHealth>(); // Initialize components movement.Init(this); shooting.Init(this); health.Init(this); display.Init(this); GameManager.AddTank(this); if (player.hasAuthority) { DisableShooting(); player.CmdSetReady(); } }
// Win the game, and remember the first crate we destroy public override void DestroyNpc(Npc npc) { Crate crate = npc as Crate; if (!m_MatchOver && crate != null) { m_EarnedDecoration = crate.cratePrize; m_DecorationMaterialId = crate.decorationMaterialIndex; m_MatchOver = true; LazyLoadPlayerTank(); m_Winner = m_PlayerTank; m_MissionFailed = false; } }
public override void Show() { base.Show(); MusicManager.s_Instance.StopMusic(); //play victory fanfare UIAudioManager.s_Instance.PlayVictorySound(); //safely casts the rulesProcessor to ShootingRangeRulesProcessor ShootingRangeRulesProcessor rules = m_RulesProcessor as ShootingRangeRulesProcessor; if (rules != null) { if (m_RetryButton != null) { //Update reroll cost m_CostMessageLabel.text = m_RerollCost.ToString(); // Enable if a reroll is applicable m_RetryButton.interactable = !rules.hasReset && PlayerDataManager.s_Instance.CanPlayerAffordPurchase(m_RerollCost); } //Get the prize from rules processor TankDecorationDefinition prize = rules.prize; int prizeColour = rules.prizeColourId; // Populate decoration you've earned m_ColourSwatch.color = prize.availableMaterials[prizeColour].color; m_Label.text = prize.name; m_PreviewImage.sprite = prize.preview; m_PreviewImage.transform.localScale = Vector3.zero; //Play reward effects m_Animator.Play("Reward"); int count = m_ConfettiParticleSystems.Length; for (int i = 0; i < count; i++) { m_ConfettiParticleSystems[i].Play(); } } }
//Clears current UI items and adds new UI items public void RegenerateItems() { m_RouletteButton.gameObject.SetActive(!PlayerDataManager.s_Instance.AreAllDecorationsUnlocked()); Clear(); int length = TankDecorationLibrary.s_Instance.GetNumberOfDefinitions(); for (int i = 0; i < length; i++) { TankDecorationDefinition decoration = TankDecorationLibrary.s_Instance.GetDecorationForIndex(i); GameObject skinObject = Instantiate <GameObject>(m_SkinPrefab.gameObject); skinObject.transform.SetParent(gameObject.transform, false); Skin skin = skinObject.GetComponent <Skin>(); skin.SetPreview(decoration.preview); if (decoration.preview == null) { skin.SetNameText(decoration.name); } //Checks if the Decoration is unlocked, either permanently or temporarily (by an add) bool isUnlocked = false; if (PlayerDataManager.s_InstanceExists) { isUnlocked |= PlayerDataManager.s_Instance.IsDecorationUnlocked(i); } if (DailyUnlockManager.s_InstanceExists) { isUnlocked |= DailyUnlockManager.s_Instance.IsItemTempUnlocked(decoration.id); } skin.SetUnlockedStatus(isUnlocked); skin.SetupSkinSelect(this); skin.SetupSkin(i, decoration); } }
//Make the Skin have knowledge of its index and definition public void SetupSkin(int index, TankDecorationDefinition definition) { this.m_Index = index; }