public GenericRenderer(SpriteRenderer spriteRenderer = null, ColorGroup colorGroup = null, AlphaGroup alphaGroup = null, Tilemap tilemap = null, Image image = null,
                               RawImage rawImage             = null, Text text = null, TextMeshProUGUI tmProText = null, CanvasGroup canvasGroup = null)
        {
            #region Exceptions
            bool[] list = new bool[] { spriteRenderer, colorGroup, alphaGroup, tilemap, image, rawImage, text, tmProText, canvasGroup };

            int qttOfNull = 0;
            for (int i = 0; i < list.Length; i++) // false == null, true == not null
            {
                if (!list[i])
                {
                    qttOfNull++;
                }
            }

            if (qttOfNull < list.Length - 1) // More than 1 ins't null
            {
                //Debug.LogError("<GenericRenderer> More than one renderer ins't null, conflict.");
            }
            else if (qttOfNull > list.Length - 1) // All is null
            {
                //Debug.LogError("<GenericRenderer> All renderers is null.");
            }
            #endregion

            _spriteRenderer = spriteRenderer;
            _colorGroup     = colorGroup;
            _alphaGroup     = alphaGroup;
            _tilemap        = tilemap;
            _image          = image;
            _rawImage       = rawImage;
            _text           = text;
            _tmProText      = tmProText;
            _canvasGroup    = canvasGroup;

            StartValues();
        }
Beispiel #2
0
        public override void OnInspectorGUI()
        {
            AlphaGroup alphaGroup = (AlphaGroup)target;

            RendererType newRend = (RendererType)EditorGUILayout.EnumFlagsField(new GUIContent("Renderer Type", "Type of renderers accepted."),
                                                                                alphaGroup.rendererType);

            if (newRend != alphaGroup.rendererType)
            {
                Undo.RecordObject(alphaGroup, "Changed renderer type.");
                alphaGroup.rendererType = newRend;
            }

            float newAlpha = EditorGUILayout.Slider(new GUIContent("Alpha", "Atual alpha value of the group."), alphaGroup.alpha, 0, 1);

            if (newAlpha != alphaGroup.alpha)
            {
                Undo.RecordObject(alphaGroup, "Changed alpha.");
                alphaGroup.alpha = newAlpha;
            }

            if (GUILayout.Button(new GUIContent("Reset max alphas")))
            {
                alphaGroup._AtualizeMaxAlphas();
            }

            EditorGUILayout.Separator();
            bool useRemote = EditorGUILayout.Toggle(
                new GUIContent("Use Remote Sprites", "Mark to modify renderers that ins't children of this component. (Only for SpriteRenderers)"),
                alphaGroup.useRemoteObjects);

            if (useRemote != alphaGroup.useRemoteObjects)
            {
                Undo.RecordObject(alphaGroup, "Changed UseRemoteObjects.");
                alphaGroup.useRemoteObjects = useRemote;
            }

            if (alphaGroup.useRemoteObjects)
            {
                List <GameObject> remoteObjects = alphaGroup.remoteObjects;
                bool restartRenderers           = false;

                for (int i = 0; i < remoteObjects.Count; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    remoteObjects[i] = (GameObject)EditorGUILayout.ObjectField(remoteObjects[i], typeof(GameObject), true);

                    bool delete = GUILayout.Button(new GUIContent("Delete", "saas"));
                    if (delete)
                    {
                        remoteObjects.RemoveAt(i);
                        restartRenderers = true;
                    }
                    else if (remoteObjects[i] != null)
                    {
                        if (!RendererGroupUtils.IsValid(remoteObjects[i]))
                        {
                            Debug.LogWarning("That GameObject is not valid for AlphaGroup remoteObjects.");
                            remoteObjects.RemoveAt(i);
                        }
                        else
                        {
                            Undo.RecordObject(alphaGroup, "Added a remote object.");
                            restartRenderers = true;
                        }
                    }

                    EditorGUILayout.EndHorizontal();
                }

                remoteObjects.RemoveAll(x => x == null);
                remoteObjects.Add(null);

                alphaGroup.remoteObjects = remoteObjects;

                if (restartRenderers)
                {
                    Undo.RecordObject(alphaGroup, "Atualized renderers.");
                    Debug.Log("Custom editor restart renderers.");
                    alphaGroup.AtualizeRenderers();
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Get all renderers (recursively) of a gameObject of specific types.
        /// </summary>
        /// <param name="transform"></param>
        /// <param name="rendererTypes"></param>
        /// <returns></returns>
        public static List <GenericRenderer> GetAllRenderers(this Transform transform, RendererType[] rendererTypes)
        {
            bool spriteRend      = rendererTypes.Contains(RendererType.SpriteRenderer);
            bool colorGroupRend  = rendererTypes.Contains(RendererType.ColorGroup);
            bool alphaGroupRend  = rendererTypes.Contains(RendererType.AlphaGroup);
            bool tilemapRend     = rendererTypes.Contains(RendererType.Tilemap);
            bool imageRend       = rendererTypes.Contains(RendererType.Image);
            bool rawImageRend    = rendererTypes.Contains(RendererType.RawImage);
            bool textRend        = rendererTypes.Contains(RendererType.Text);
            bool tmTextRend      = rendererTypes.Contains(RendererType.TmProText);
            bool canvasGroupRend = rendererTypes.Contains(RendererType.CanvasGroup);

            List <GenericRenderer> genericRenders = new List <GenericRenderer>();

            SpriteRenderer  spriteRenderer = spriteRend ? transform.GetComponent <SpriteRenderer>() : null;
            ColorGroup      colorGroup     = colorGroupRend ? transform.GetComponent <ColorGroup>() : null;
            AlphaGroup      alphaGroup     = alphaGroupRend ? transform.GetComponent <AlphaGroup>() : null;
            Tilemap         tilemap        = tilemapRend ? transform.GetComponent <Tilemap>() : null;
            Image           image          = imageRend ? transform.GetComponent <Image>() : null;
            RawImage        rawImage       = rawImageRend ? transform.GetComponent <RawImage>() : null;
            Text            text           = textRend ? transform.GetComponent <Text>() : null;
            TextMeshProUGUI tmText         = tmTextRend ? transform.GetComponent <TextMeshProUGUI>() : null;
            CanvasGroup     canvasGroup    = canvasGroupRend ? transform.GetComponent <CanvasGroup>() : null;

            genericRenders.Add(new GenericRenderer(
                                   spriteRenderer,
                                   colorGroup,
                                   alphaGroup,
                                   tilemap,
                                   image,
                                   rawImage,
                                   text,
                                   tmText,
                                   canvasGroup));

            for (int i = 0; i < transform.childCount; i++)
            {
                SpriteRenderer  spriteRenderer2 = spriteRend ? transform.GetComponent <SpriteRenderer>() : null;
                ColorGroup      colorGroup2     = colorGroupRend ? transform.GetComponent <ColorGroup>() : null;
                AlphaGroup      alphaGroup2     = alphaGroupRend ? transform.GetComponent <AlphaGroup>() : null;
                Tilemap         tilemap2        = tilemapRend ? transform.GetComponent <Tilemap>() : null;
                Image           image2          = imageRend ? transform.GetComponent <Image>() : null;
                RawImage        rawImage2       = rawImageRend ? transform.GetComponent <RawImage>() : null;
                Text            text2           = textRend ? transform.GetComponent <Text>() : null;
                TextMeshProUGUI tmText2         = tmTextRend ? transform.GetComponent <TextMeshProUGUI>() : null;
                CanvasGroup     canvasGroup2    = canvasGroupRend ? transform.GetComponent <CanvasGroup>() : null;

                Transform child = transform.GetChild(i);

                genericRenders.Add(new GenericRenderer(
                                       spriteRenderer2,
                                       colorGroup2,
                                       alphaGroup2,
                                       tilemap2,
                                       image2,
                                       rawImage2,
                                       text2,
                                       tmText2,
                                       canvasGroup2
                                       ));

                if (child.childCount > 0)
                {
                    List <GenericRenderer> childComponents = child.GetAllRenderers(rendererTypes);

                    genericRenders.AddRange(childComponents);
                }
            }


            return(genericRenders);
        }