Пример #1
0
    public void Init(float dissapearTimer, float startingAlpha, Sprite sprite, int sortingId, int sortingOrder,
                     Transform referencedTransform, Vector3 offset, Color desiredColor)
    {
        _startingAlpha = startingAlpha;

        /*    Color color = SpriteRenderer.color;
         * color.a = _startingAlpha;
         * SpriteRenderer.color = color;*/
        _desiredColor   = desiredColor;
        _desiredColor.a = _startingAlpha;
        GhostMaterial.SetColor("_Color", _desiredColor);

        SpriteRenderer.color          = desiredColor;
        _dissapearTimer               = dissapearTimer;
        SpriteRenderer.sortingLayerID = sortingId;
        SpriteRenderer.sortingOrder   = sortingOrder;
        _sprite = sprite;
        Debug.Log(sprite);
        SpriteRenderer.sprite = sprite;

        _offset            = offset;
        _originalPosition  = referencedTransform.position;
        transform.position = _originalPosition;

        _originalScaling     = referencedTransform.localScale;
        transform.localScale = _originalScaling;
        _hasBeenInitiated    = true;

        gameObject.SetActive(true);
        _useTint           = true;
        _startDissapearing = StartDissapearing(_useTint);
        StartCoroutine(_startDissapearing);
    }
Пример #2
0
    /// <summary>
    /// From the class field, dissapear timer, slowly disspear the sprite renderer . Pass in a bool to use the provided ghost shader which
    /// behaves
    /// </summary>
    /// <returns></returns>
    private IEnumerator StartDissapearing(bool changeColor)
    {
        bool  finishedLerping    = false;
        float startLerpTime      = Time.time;
        Color color              = SpriteRenderer.color;
        Color blackWithZeroAlpha = Color.black;
        Color startColor         = GhostMaterial.color;

        blackWithZeroAlpha.a = 0;
        if (!changeColor)
        {
            GhostMaterial.shader = Shader.Find("Sprites/Default");
        }
        else
        {
            GhostMaterial.shader = Shader.Find("Spine/SkeletonGhost");
            GhostMaterial.SetFloat("_TextureFade", 0.25f);
        }
        while (!finishedLerping)
        {
            float timeSinceLerpStart = Time.time - startLerpTime;
            float percentComplete    = timeSinceLerpStart / _dissapearTimer;
            if (percentComplete >= 1)
            {
                finishedLerping = true;
                if (!changeColor)
                {
                    color.a             = 0;
                    GhostMaterial.color = color;
                }
                else
                {
                    GhostMaterial.SetColor("_Color", blackWithZeroAlpha);
                }
            }
            if (!changeColor)
            {
                float newAlphaValue = Mathf.Lerp(_startingAlpha, 0, percentComplete);
                color.a             = newAlphaValue;
                GhostMaterial.color = color;
            }
            else
            {
                Color newColor = Color.Lerp(startColor, blackWithZeroAlpha, percentComplete);
                GhostMaterial.SetColor("_Color", newColor);
            }

            yield return(null);
        }

        _canBeReused = true;
        gameObject.SetActive(false);
        _hasBeenInitiated = false;
    }