Пример #1
0
        public static void initializeAnAnyUi(AnyUiMesh anyui)
        {
            DestroyImmediate(anyui.GetComponent <Collider>());
            anyui.gameObject.AddComponent <MeshCollider>();

            createCameraAndRendertextureFor(anyui);
            createMaterialInMaterialsList(anyui);
        }
Пример #2
0
        public static void deleteMaterialListEntry(AnyUiMesh tTarget, Material toDelete)
        {
            Material[] newMaterialsList = new Material[tTarget.GetComponent <Renderer>().sharedMaterials.Length - 1];
            var        renderer         = tTarget.GetComponent <Renderer>();

            int i = 0;
            int j = 0;

            while (j < newMaterialsList.Length && i < renderer.sharedMaterials.Length)
            {
                if (renderer.sharedMaterials[i] != toDelete)
                {
                    newMaterialsList[j] = renderer.sharedMaterials[i];
                    j++;
                }
                i++; //go through the old materials
            }
            renderer.sharedMaterials = newMaterialsList;
        }
Пример #3
0
        public static Material createMaterialInMaterialsList(AnyUiMesh tTarget)
        {
            Material mat;
            var      renderer = tTarget.GetComponent <Renderer>();

            if (tTarget.UseMaterial == null)
            {
                //new Material
                mat             = new Material(Shader.Find("Unlit/Transparent"));
                mat.mainTexture = tTarget.CanvasToProject.worldCamera.targetTexture;
                mat.SetFloat("_Mode", 2);
                mat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
                mat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                mat.SetInt("_ZWrite", 0);
                mat.DisableKeyword("_ALPHATEST_ON");
                mat.EnableKeyword("_ALPHABLEND_ON");
                mat.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                mat.renderQueue     = 3000;
                mat.name            = "AnyUI_Material" + tTarget.gameObject.name + System.Guid.NewGuid().ToString();
                tTarget.UseMaterial = mat;
                if (!AssetDatabase.IsValidFolder("Assets/AnyUI/AnyUIRenderTexturesAndMaterials"))
                {
                    AssetDatabase.CreateFolder("Assets/AnyUI", "AnyUIRenderTexturesAndMaterials");
                }
                AssetDatabase.CreateAsset(mat, "Assets/AnyUI/AnyUIRenderTexturesAndMaterials/" + mat.name + ".mat");
            }
            else
            {
                mat = tTarget.UseMaterial;
            }

            //new materials array

            if (tTarget.UseMaterialLayering)
            {
                Material[] tNewMaterials;
                //search for already existent rendertexture material, assign updated material, else add as new material
                bool isAlreadyAdded = false;
                int  j = 0;
                foreach (var t in renderer.sharedMaterials)
                {
                    if (t == mat)
                    {
                        //Debug.Log("already added render texture");
                        isAlreadyAdded = true;
                        break;
                    }
                    j++;
                }
                if (isAlreadyAdded)
                {
                    tNewMaterials    = renderer.sharedMaterials;
                    tNewMaterials[j] = mat;
                }
                else
                {
                    tNewMaterials = new Material[renderer.sharedMaterials.Length + 1];
                    int i = 0;
                    foreach (var t in renderer.sharedMaterials)
                    {
                        tNewMaterials[i] = t;
                        i++;
                    }
                    tNewMaterials[i] = mat;
                }
                //assign new materials array
                renderer.sharedMaterials = tNewMaterials;
            }
            else
            {
                Material[] tNewMaterials = new Material[1];
                tNewMaterials[0]         = mat;
                renderer.sharedMaterials = tNewMaterials;
            }

            return(mat);
        }