Ejemplo n.º 1
0
        public void ActivateEffects(GameObject gameObject)
        {
            if (gameObject.GetComponent <UnityEngine.UI.Image>() || gameObject.GetComponent <UnityEngine.UI.Text>())
            {
                if (shadow)
                {
                    ShadowEffect shadowEffect = gameObject.GetComponent <ShadowEffect>();
                    if (!shadowEffect)
                    {
                        shadowEffect = Undo.AddComponent <ShadowEffect>(gameObject);
                    }
                    shadowEffect.effectDistance = shadowDistance;
                    shadowEffect.effectColor    = shadowColor;
                    EditorUtility.SetDirty(gameObject);
                }
                else if (gameObject.GetComponent <ShadowEffect>())
                {
                    Undo.DestroyObjectImmediate(gameObject.GetComponent <ShadowEffect>());
                }
            }

            if (gameObject.GetComponent <UnityEngine.UI.Image>())
            {
                if (gradient)
                {
                    GradientEffect gradientEffect = gameObject.GetComponent <GradientEffect>();
                    if (!gradientEffect)
                    {
                        gradientEffect = Undo.AddComponent <GradientEffect>(gameObject);
                    }
                    gradientEffect.top    = gradientTop;
                    gradientEffect.bottom = gradientBottom;
                    EditorUtility.SetDirty(gameObject);
                }
                else if (gameObject.GetComponent <GradientEffect>())
                {
                    Undo.DestroyObjectImmediate(gameObject.GetComponent <GradientEffect>());
                }
            }

            if (gameObject.transform.childCount > 0) // Recursive search for components
            {
                for (int i = 0; i < gameObject.transform.childCount; i++)
                {
                    ActivateEffects(gameObject.transform.GetChild(i).gameObject);
                }
            }
        }
Ejemplo n.º 2
0
        private void ActivateEffects(GameObject gameObject, EffectSet set)
        {
            if (gameObject.GetComponent <UnityEngine.UI.Image>())
            {
                if (set.gradient)
                {
                    GradientEffect gradientEffect = gameObject.GetComponent <GradientEffect>();
                    if (!gradientEffect)
                    {
                        gradientEffect = gameObject.AddComponent <GradientEffect>();
                    }
                    gradientEffect.top    = set.gradientTop;
                    gradientEffect.bottom = set.gradientBottom;
                }
                else if (gameObject.GetComponent <GradientEffect>())
                {
                    DestroyImmediate(gameObject.GetComponent <GradientEffect>());
                }

                if (set.radialGradient)
                {
                    RadialGradientEffect gradientEffect = gameObject.GetComponent <RadialGradientEffect>();
                    if (!gradientEffect)
                    {
                        gradientEffect = gameObject.AddComponent <RadialGradientEffect>();
                    }
                    gradientEffect.centerColor    = set.radialColor;
                    gradientEffect.centerPosition = set.centerPosition;
                    gradientEffect.radius         = set.radius;
                }
                else if (gameObject.GetComponent <RadialGradientEffect>())
                {
                    DestroyImmediate(gameObject.GetComponent <RadialGradientEffect>());
                }
            }

            if (gameObject.GetComponent <UnityEngine.UI.Image>() || gameObject.GetComponent <UnityEngine.UI.Text>())
            {
                if (set.shadow)
                {
                    ShadowEffect shadowEffect = gameObject.GetComponent <ShadowEffect>();
                    if (!shadowEffect)
                    {
                        shadowEffect = gameObject.AddComponent <ShadowEffect>();
                    }
                    shadowEffect.effectDistance = set.shadowOffset;
                    shadowEffect.effectColor    = set.shadowColor;
                }
                else if (gameObject.GetComponent <ShadowEffect>())
                {
                    DestroyImmediate(gameObject.GetComponent <ShadowEffect>());
                }

                if (set.mirrorEffect)
                {
                    MirrorEffect mirrorEffect = gameObject.GetComponent <MirrorEffect>();
                    if (!mirrorEffect)
                    {
                        mirrorEffect = gameObject.AddComponent <MirrorEffect>();
                    }
                    mirrorEffect.top    = set.mirrorTop;
                    mirrorEffect.bottom = set.mirrorBottom;
                    mirrorEffect.offset = set.mirrorOffset;
                    mirrorEffect.scale  = set.mirrorScale;
                    mirrorEffect.skew   = set.mirrorSkew;
                }
                else if (gameObject.GetComponent <MirrorEffect>())
                {
                    DestroyImmediate(gameObject.GetComponent <MirrorEffect>());
                }

                if (set.skewEffect)
                {
                    SkewEffect skewEffect = gameObject.GetComponent <SkewEffect>();
                    if (!skewEffect)
                    {
                        skewEffect = gameObject.AddComponent <SkewEffect>();
                    }
                    skewEffect.skew        = set.skew;
                    skewEffect.perspective = set.perspective;
                }
                else if (gameObject.GetComponent <SkewEffect>())
                {
                    DestroyImmediate(gameObject.GetComponent <SkewEffect>());
                }
            }

            if (gameObject.transform.childCount > 0) // Recursive search for components
            {
                for (int i = 0; i < gameObject.transform.childCount; i++)
                {
                    ActivateEffects(gameObject.transform.GetChild(i).gameObject, set);
                }
            }
        }