Exemple #1
0
    void UpdateParam()
    {
        if (Material == null)
        {
            Debug.LogWarning("Metarial is miss");
            return;
        }

        if (mGraphic == null)
        {
            mGraphic = GetComponent <MaskableGraphic>();
        }

        if (mGraphic is Text)
        {
            Debug.LogError("FlashEffec need component type of Image、RawImage");
            return;
        }

        if (mDynaMaterial == null)
        {
            mDynaMaterial           = new Material(Material);
            mDynaMaterial.name      = mDynaMaterial.name + "(Copy)";
            mDynaMaterial.hideFlags = HideFlags.DontSave | HideFlags.NotEditable;
        }

        if (mDynaMaterial == null)
        {
            return;
        }

        mDynaMaterial.mainTexture = null;
        if (OverrideTexture != null)
        {
            mDynaMaterial.mainTexture = OverrideTexture;

            if (mGraphic is RawImage)
            {
                RawImage img = mGraphic as RawImage;
                img.texture = null;
            }
            else if (mGraphic is Image)
            {
                Image img = mGraphic as Image;
                img.sprite = null;
            }
        }
        else
        {
            mDynaMaterial.mainTexture = mGraphic.mainTexture;
        }

        if (Duration > Interval)
        {
            Debug.LogWarning("ImageFlashEffect.UpdateParam:Duration need less Interval");
            Interval = Duration + 0.5f;
        }

        mDynaMaterial.SetColor("_LightColor", Color);
        mDynaMaterial.SetFloat("_LightPower", Power);
        mDynaMaterial.SetFloat("_LightScale", Scale);
        mDynaMaterial.SetFloat("_LightAngle", Angle);
        mDynaMaterial.SetFloat("_LightDuration", Duration);
        mDynaMaterial.SetFloat("_LightInterval", Interval);
        mDynaMaterial.SetFloat("_LightOffSetX", OffSet);
        mGraphic.material = mDynaMaterial;
        mGraphic.SetMaterialDirty();
    }