using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;

public class ModelXuHua : MonoBehaviour
{
    public GameObject teshu;
    public GameObject teshuXs;
    public bool isXS=false;
    public List<Material> mats;
    public GameObject TabGo;
    public GameObject baimo;
    public GameObject texiao;
    // Start is called before the first frame update
    void Start()
    {
    }
    
    public void showModel(bool isshow=true)
    {
        baimo.SetActive(false);
        this.gameObject.SetActive(true);
        if(this.texiao)
        this.texiao.SetActive(true);

        Debug.Log("showModel===>"+isshow);
        if(teshu)
        teshu.SetActive(isshow);

        if(teshuXs&&isshow)
        {
            teshuXs.SetActive(false);
        }
    }
    public void showBaiMo()
    {
        if(teshuXs)
         teshuXs.SetActive(true);
        if(teshu)
        teshu.SetActive(false);
        if(this.texiao)
        this.texiao.SetActive(false);
        if(isXS)
        {
            baimo.SetActive(false);
            this.gameObject.SetActive(false);
            return;
        }
        baimo.SetActive(true);
        this.gameObject.SetActive(false);
        for (int i = 0;i<mats.Count;i++)
        {
            Color c = mats[i].GetColor("_Color");
            mats[i].SetColor("_Color",new Color(c.r,c.g,c.b,1f));
            mats[i].DOColor(new Color(c.r,c.g,c.b,0.3f),0.5f).OnComplete(()=>{ });
        }
    }
    public void show()
    {
        this.gameObject.SetActive(true);
    }

    public void changemode()
    { 
    }
    public void hide()
    {
        if(!baimo.activeSelf)
        {
            baimo.SetActive(true);
            this.gameObject.SetActive(false);
            for (int i = 0;i<mats.Count;i++)
            {
                Color c = mats[i].GetColor("_Color");
                mats[i].SetColor("_Color",new Color(c.r,c.g,c.b,1f));
                mats[i].DOColor(new Color(c.r,c.g,c.b,0f),0.5f).OnComplete(()=>{ baimo.SetActive(false);});
            }
        }
    }
    /// <summary>
    /// 设置材质的 Albedo 颜色
    /// </summary>
    /// <param name="material">目标材质</param>
    /// <param name="color">目标颜色</param>
    public static void SetAlbedoColor(Material material, Color color)
    {
        if (material != null)
        {
            // 设置 _Color 属性
            material.SetColor("_Color", color);
        }
        else
        {
            Debug.LogError("Material is null!");
        }
    }

    public enum RenderingMode
    {
        Opaque,
        Cutout,
        Fade,
        Transparent
    }
    public static void SetMaterialRenderingMode(Material material, RenderingMode mode)
    {
        switch (mode)
        {
            case RenderingMode.Opaque:
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                material.SetInt("_ZWrite", 1);
                material.DisableKeyword("_ALPHATEST_ON");
                material.DisableKeyword("_ALPHABLEND_ON");
                material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                material.renderQueue = -1;
                break;
            case RenderingMode.Cutout:
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                material.SetInt("_ZWrite", 1);
                material.EnableKeyword("_ALPHATEST_ON");
                material.DisableKeyword("_ALPHABLEND_ON");
                material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                material.renderQueue = 2450;
                break;
            case RenderingMode.Fade:
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                material.SetInt("_ZWrite", 0);
                material.DisableKeyword("_ALPHATEST_ON");
                material.EnableKeyword("_ALPHABLEND_ON");
                material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                material.renderQueue = 3000;
                break;
            case RenderingMode.Transparent:
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                material.SetInt("_ZWrite", 0);
                material.DisableKeyword("_ALPHATEST_ON");
                material.DisableKeyword("_ALPHABLEND_ON");
                material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
                material.renderQueue = 3000;
                break;
        }
    }
}