//------------------------------------------------------------------------------------------------------------------ void UpdateZoneButtons() { int num = m_SpawnButtons != null ? m_SpawnButtons.Length : 0; while (num-- > 0) { SpawnZoneButton btn = m_SpawnButtons[num]; if (btn != null) { btn.Update(m_SelectedTeam, m_SpawnZoneIndex); } } }
//------------------------------------------------------------------------------------------------------------------ SpawnZoneButton GetSpawnZoneButton(int inSpawnZoneIndex) { int num = m_SpawnButtons != null ? m_SpawnButtons.Length : 0; while (num-- > 0) { SpawnZoneButton btn = m_SpawnButtons[num]; if ((btn != null) && (btn.ZoneIndex == inSpawnZoneIndex)) { return(btn); } } return(null); }
//------------------------------------------------------------------------------------------------------------------ SpawnZoneButton GetSpawnZoneButton(ZoneControlFlag inSpawnZone) { int num = m_SpawnButtons != null ? m_SpawnButtons.Length : 0; while (num-- > 0) { SpawnZoneButton btn = m_SpawnButtons[num]; if ((btn != null) && (btn.Zone == inSpawnZone)) { return(btn); } } return(null); }
//------------------------------------------------------------------------------------------------------------------ int GetNearestZoneToEnemy() { int bestZone = -1; float bestDist = float.MaxValue; GameZoneZoneControl gzc = Mission.Instance.GameZone as GameZoneZoneControl; if ((m_SelectedTeam != E_Team.None) && (gzc != null) && (m_SpawnButtons != null)) { for (int i = 0; i < m_SpawnButtons.Length; ++i) { SpawnZoneButton iBtn = m_SpawnButtons[i]; if ((iBtn == null) || (iBtn.Zone == null) || (iBtn.Zone.FlagOwner != m_SelectedTeam)) { continue; } if (bestZone == -1) { bestZone = iBtn.ZoneIndex; // there is at least one available zone } for (int j = 0; j < m_SpawnButtons.Length; ++j) { SpawnZoneButton jBtn = m_SpawnButtons[j]; if ((jBtn == null) || (jBtn.Zone.FlagOwner == m_SelectedTeam)) { continue; } float dist = (iBtn.Zone.gameObject.transform.position - jBtn.Zone.gameObject.transform.position).sqrMagnitude; dist -= 1.0e6f * (int)jBtn.Zone.FlagOwner; // prefer zones taken by enemy over the unoccupied ones if (dist < bestDist) { bestDist = dist; bestZone = iBtn.ZoneIndex; } } } } return(bestZone); }
//------------------------------------------------------------------------------------------------------------------ int GetPreferredZone() { int idx = PPIManager.Instance.GetLocalPPI().ZoneIndex; SpawnZoneButton btn = GetSpawnZoneButton(idx); if ((m_SpawnZoneAutoselected == true) || (btn == null) || (btn.Zone.FlagOwner != m_SelectedTeam)) { idx = GetNearestZoneToEnemy(); m_SpawnZoneAutoselected = true; // if ( idx != -1 ) // nearest to previous one // { // idx = GetNearestZone( idx ); // } // else // random if previous one is uknown // { // idx = GetNextZone( Random.Range(0,999), Random.value < 0.5f ? -1 : +1 ); // } } return(idx); }
//------------------------------------------------------------------------------------------------------------------ void InitZoneButtons() { // find death-match-map definition... GameZoneZoneControl gzc = null; if (Mission.Instance != null) { gzc = Mission.Instance.GameZone as GameZoneZoneControl; } if ((gzc == null) || (gzc.Zones == null)) { return; } DominationMapDefinition def = m_Def.GetComponentInChildren <DominationMapDefinition>(); if ((def == null) || (def.m_SpawnZones == null) || (def.m_SpawnZones.Length == 0)) { return; } // init on mini-map buttons... int bNum = 0; m_SpawnButtons = new SpawnZoneButton[def.m_SpawnZones.Length]; for (int i = 0; i < def.m_SpawnZones.Length; ++i) { DominationMapDefinition.SpawnZoneData zoneDef = def.m_SpawnZones[i]; if ((zoneDef.m_SpawnZone == null) || (zoneDef.m_MiniMapButton == null)) { Debug.LogWarning("MiniMapDefinition : Record #" + i + " in 'Spawn Zones' is invalid!"); continue; } int zoneIndex = gzc.Zones.FindIndex(sz => sz == zoneDef.m_SpawnZone); if (zoneIndex == -1) { Debug.LogWarning("MiniMapDefinition : Record #" + i + " in 'Spawn Zones' is referencing 'unknown' zone!"); continue; } m_SpawnButtons[i] = new SpawnZoneButton(zoneDef.m_MiniMapButton, zoneDef.m_SpawnZone, zoneIndex, OnZoneSelected); bNum++; } // Debug.LogInfo( "Successfully created " + bNum + " spawn-zone buttons." ); // init prev/next buttons... Transform child = m_MapParent.transform.FindChildByName("SpawnPoint_Enum"); if (child != null) { GUIBase_Button prev = child.GetChildComponent <GUIBase_Button>("GUI_enum_left"); GUIBase_Button next = child.GetChildComponent <GUIBase_Button>("GUI_enum_right"); if (prev != null) { prev.RegisterTouchDelegate2(SelectPrevZone); prev.SetDisabled(bNum == 0); } if (next != null) { next.RegisterTouchDelegate2(SelectNextZone); next.SetDisabled(bNum == 0); } m_SpawnZoneLabel = child.GetChildComponent <GUIBase_Label>("Spawn_Label"); if (m_SpawnZoneLabel != null) { m_SpawnZoneLabel.SetNewText(string.Empty); } } }