Beispiel #1
0
    public void SetHUDForEntity(EntityBase entityBase)
    {
        HUDBase newHud = ObjectPool.Spawn(hudPrefab, Vector3.zero, Quaternion.identity, hudContainer);

        entityHUDS.Add(entityBase, newHud);

        entityBase.OnDeath += EntityBaseOnDeath;
    }
Beispiel #2
0
 public void SetHUDForGridCells()
 {
     gridCellHUDS = new HUDBase[GridManager.gridWidth, GridManager.gridHeight];
     for (int x = 0; x < GridManager.gridWidth; x++)
     {
         for (int y = 0; y < GridManager.gridHeight; y++)
         {
             HUDBase newHud = ObjectPool.Spawn(hudPrefab, Vector3.zero, Quaternion.identity, hudContainer);
             gridCellHUDS[x, y] = newHud;
         }
     }
 }
Beispiel #3
0
 private void Init()
 {
     this.m_CanvasGameObject = GameObject.Find("HUD");
     DebugUtils.Assert(this.m_CanvasGameObject, true);
     this.m_CanvasGameObject.SetActive(this.m_Active);
     this.m_HUDList = new HUDBase[this.m_CanvasGameObject.transform.childCount];
     for (int i = 0; i < this.m_CanvasGameObject.transform.childCount; i++)
     {
         GameObject gameObject = this.m_CanvasGameObject.transform.GetChild(i).gameObject;
         HUDBase    component  = gameObject.GetComponent <HUDBase>();
         this.m_HUDList[i] = component;
     }
     DebugUtils.Assert(this.m_HUDList.Length > 0, true);
     this.m_Initialized = true;
     this.m_AudioSource = base.gameObject.AddComponent <AudioSource>();
     this.m_AudioSource.outputAudioMixerGroup = GreenHellGame.Instance.GetAudioMixerGroup(AudioMixerGroupGame.Player);
 }
    public void ShowHUDInfos(List <SystemHUDInfo.HUDInfo> hudInfos)
    {
        int delta = activeHUDS.Count - hudInfos.Count;

        bool shouldRemoveExcess = delta > 0;
        bool shouldAquireMore   = delta < 0;

        if (shouldRemoveExcess)
        {
            for (int i = activeHUDS.Count - 1; i >= activeHUDS.Count - delta; i--)
            {
                ObjectPool.Despawn(activeHUDS[i]);
            }

            activeHUDS.RemoveRange(activeHUDS.Count - delta, delta);
        }
        else if (shouldAquireMore)
        {
            for (int i = 0; i < Mathf.Abs(delta); i++)
            {
                HUDBase newHud = ObjectPool.Spawn(hudPrefab, Vector3.zero, Quaternion.identity, hudContainer);
                activeHUDS.Add(newHud);
            }
        }

        for (int hudInfoIdx = 0; hudInfoIdx < hudInfos.Count; hudInfoIdx++)
        {
            var hudInfo = hudInfos[hudInfoIdx];

            Vector2 screenPoint = Root.CameraController.WorldToScreenPoint(hudInfo.position + Vector3.up);
            Vector2 localPoint;
            if (RectTransformUtility.ScreenPointToLocalPointInRectangle(hudContainer, screenPoint, null, out localPoint))
            {
                activeHUDS[hudInfoIdx].transform.localPosition = localPoint;
                activeHUDS[hudInfoIdx].SetText(hudInfo.infoString);
            }
        }
    }