コード例 #1
0
    private void SetImageSprite(Sprite value)
    {
        if (spriteRenderer != null)
        {
            spriteRenderer.enabled = true;
            spriteRenderer.sprite  = value;

            if (isPaletteSet == false)
            {
                SetPaletteOnSpriteRenderer();
            }
        }
        else if (image != null)
        {
            image.sprite = value;

            if (isPaletteSet == false)
            {
                SetPaletteOnImage();
            }

            if (value == null)
            {
                image.enabled = false;
            }
            else
            {
                image.enabled = true;
            }
        }

        OnSpriteChanged?.Invoke(value);
    }
コード例 #2
0
    private void SetImageSprite(Sprite value)
    {
        if (spriteRenderer != null)
        {
            spriteRenderer.sprite = value;
            MaterialPropertyBlock block = new MaterialPropertyBlock();
            spriteRenderer.GetPropertyBlock(block);
            var palette = getPaletteOrNull();
            if (palette != null && palette.Count == 8)
            {
                List <Vector4> pal = palette.ConvertAll <Vector4>((Color c) => new Vector4(c.r, c.g, c.b, c.a));
                block.SetVectorArray("_ColorPalette", pal);
                block.SetInt("_IsPaletted", 1);
            }
            else
            {
                block.SetInt("_IsPaletted", 0);
            }

            spriteRenderer.SetPropertyBlock(block);
        }
        else if (image != null)
        {
            image.sprite = value;
            if (value == null)
            {
                image.enabled = false;
            }
        }

        OnSpriteChanged?.Invoke(value);
    }
コード例 #3
0
    private void OnEnable()
    {
        if (Application.isPlaying && NetworkThis)
        {
            NetworkIdentity = SpriteHandlerManager.GetRecursivelyANetworkBehaviour(this.gameObject)?.netIdentity;
            SpriteHandlerManager.RegisterHandler(this.NetworkIdentity, this);
        }

        GetImageComponent();
        OnSpriteChanged?.Invoke(CurrentSprite);
    }
コード例 #4
0
ファイル: SpriteHandler.cs プロジェクト: ewy0/unitystation
    private void OnEnable()
    {
        if (Application.isPlaying && NetworkThis)
        {
            NetworkIdentity = SpriteHandlerManager.GetRecursivelyANetworkBehaviour(this.gameObject);
            SpriteHandlerManager.RegisterHandler(this.NetworkIdentity, this);
        }

        GetImageComponent();
        OnSpriteChanged?.Invoke(CurrentSprite);

        PushTexture(false);         // TODO: animations don't resume when sprite object is disabled and re-enabled, this is a workaround
    }
コード例 #5
0
    private void SetImageSprite(Sprite value)
    {
#if  UNITY_EDITOR
        if (Application.isPlaying == false)
        {
            if (spriteRenderer == null)
            {
                spriteRenderer = GetComponent <SpriteRenderer>();
            }
        }
#endif

        if (spriteRenderer != null)
        {
            spriteRenderer.enabled = true;
            spriteRenderer.sprite  = value;

            if (isPaletteSet == false)
            {
                SetPaletteOnSpriteRenderer();
            }
        }
        else if (image != null)
        {
            image.sprite = value;

            if (isPaletteSet == false)
            {
                SetPaletteOnImage();
            }

            if (value == null)
            {
                image.enabled = false;
            }
            else
            {
                image.enabled = true;
            }
        }

        OnSpriteChanged?.Invoke(value);
    }
コード例 #6
0
 private void OnDisable()
 {
     TryToggleAnimationState(false);
     OnSpriteChanged?.Invoke(null);
 }