コード例 #1
0
    public void Init(Controller control)
    {
        cl = control;
        if (!partsHolder)
        {
            partsHolder = transform;
        }

        for (int i = 0; i < healthPartsInBar; i++)
        {
            GameObject       part = Instantiate(healthPartPrefab, partsHolder);
            HealthPartScript hps  = part.GetComponent <HealthPartScript>();
            hps.img.gameObject.SetActive(false);
            healthParts.Add(hps);
        }
        StartCoroutine(ShowPartsOverTime(null));
    }
コード例 #2
0
    public IEnumerator ShowPartsOverTime(Health health)
    {
        if (cl)
        {
            if (!cl.playerView.devView)
            {
                cl.canMove = false;
            }
        }

        for (int i = 0; i < healthParts.Count; i++)
        {
            yield return(new WaitForSeconds(partSpawnTimer));

            HealthPartScript hp  = healthParts[i];
            Image            img = hp.img;
            img.gameObject.SetActive(true);
            img.color              = Color.white;
            img.fillAmount         = 1f;
            hp.outline.effectColor = hp.outlineColor;
        }

        if (cl)
        {
            if (!cl.playerView.devView)
            {
                cl.canMove = true;
            }
        }
        if (health)
        {
            health.StopRespawning();
        }
        if (!isActive)
        {
            Controller cl = Controller.single_CLocal;
            if (cl)
            {
                cl.Init();
            }
            isActive = true;
        }
    }
コード例 #3
0
    public void ChangeHealth(int currentHealth, int maxHealth)
    {
        int   partAmount = currentHealth / healthPartsInBar;
        int   remain = currentHealth % healthPartsInBar;
        float H, S, V;

        for (int i = 0; i < healthParts.Count; i++)
        {
            HealthPartScript hp = healthParts[i];
            float            fill;
            Color            imgColor     = Color.white;
            Color            outlineColor = hp.outlineColor;
            if (i < partAmount)
            {
                fill = 1f;
            }
            else
            {
                if (i == partAmount)
                {
                    fill       = (float)remain / healthPartsInBar;
                    imgColor   = Color.HSVToRGB(0, 1 - fill, 1);
                    imgColor.a = 1;
                    Color.RGBToHSV(outlineColor, out H, out S, out V);
                    outlineColor = Color.HSVToRGB(0, 1 - fill, V);
                }
                else
                {
                    fill = 0;
                }
            }
            Image image = healthParts[i].img;
            image.fillAmount       = fill;
            image.color            = imgColor;
            hp.outline.effectColor = outlineColor;
        }
    }