private static RuntimeShaderProfilesAsset Create()
        {
            RuntimeShaderProfilesAsset asset = ScriptableObject.CreateInstance <RuntimeShaderProfilesAsset>();

            asset.ShaderInfo = new List <RuntimeShaderInfo>();

            ShaderInfo[]     allShaderInfo = ShaderUtil.GetAllShaderInfo().OrderBy(si => si.name).ToArray();
            HashSet <string> shaderNames   = new HashSet <string>();

            for (int i = 0; i < allShaderInfo.Length; ++i)
            {
                ShaderInfo shaderInfo = allShaderInfo[i];
                Shader     shader     = Shader.Find(shaderInfo.name);

                RuntimeShaderInfo profile = Create(shader);
                asset.ShaderInfo.Add(profile);

                if (shaderNames.Contains(shaderInfo.name))
                {
                    Debug.LogWarning("Shader with same name already exists. Consider renaming " + shaderInfo.name + " shader. File: " + AssetDatabase.GetAssetPath(shader));
                }
                else
                {
                    shaderNames.Add(shaderInfo.name);
                }
            }
            return(asset);
        }
Esempio n. 2
0
        private static void CheckShaderVariants(BundleBuilderData data, BundleBuilderData.BundleInfo bundle, string assetPath, PackagePlatform platform)
        {
#if UNITY_2018_1_OR_NEWER
            if (!data.extractShaderVariantCollections)
            {
                return;
            }

            if (!assetPath.EndsWith(".shadervariants"))
            {
                return;
            }

            var shaderVariants          = AssetDatabase.LoadMainAssetAtPath(assetPath);
            var shaderVariantCollection = shaderVariants as ShaderVariantCollection;
            if (shaderVariantCollection != null)
            {
                var shaderInfos = ShaderUtil.GetAllShaderInfo();
                foreach (var shaderInfo in shaderInfos)
                {
                    var shader     = Shader.Find(shaderInfo.name);
                    var shaderPath = AssetDatabase.GetAssetPath(shader);
                    if (shaderPath.StartsWith("Assets/"))
                    {
                        //TODO: check if in shaderVariants

                        CollectAsset(data, bundle, shaderPath, platform);
                    }
                }
            }
#endif
        }
Esempio n. 3
0
        public void ShaderHasErrors()
        {
            var infos = ShaderUtil.GetAllShaderInfo();

            foreach (var info in infos)
            {
                Assert.IsFalse(info.hasErrors, "Shader '{0}' has errors.", info.name);
            }
        }
Esempio n. 4
0
 private void Awake()
 {
     // 获取所有Shader
     ShaderInfo[] shaderLists = ShaderUtil.GetAllShaderInfo();
     shaderNameLists = new string[shaderLists.Length];
     for (int i = 0; i < shaderLists.Length; i++)
     {
         shaderNameLists[i] = shaderLists[i].name;
         if (shaderNameLists[i] == "LayaAir3D/Mesh/PBR(Standard)")
         {
             selectShaderIndex = i;
         }
     }
 }
Esempio n. 5
0
        public static List <Shader> GetAllShaders(bool supportedOnly)
        {
            List <Shader> shaders = new List <Shader>();

            ShaderInfo[] shaderInfos = ShaderUtil.GetAllShaderInfo();
            for (int i = 0; i < shaderInfos.Length; i++)
            {
                ShaderInfo info = shaderInfos[i];
                if (supportedOnly && !info.supported)
                {
                    continue;
                }
                shaders.Add(Shader.Find(info.name));
            }
            return(shaders);
        }
        public void OnAwake(AtlasConfiguration configuration)
        {
            _index     = 0;
            _layouts   = configuration.MeshLayouts;
            _materials = new List <Material>();
            _shaders   = ShaderUtil.GetAllShaderInfo().Where(w => w.supported).Select(w => w.name).ToList();

            foreach (var group in _layouts.GroupBy(w => w.Channel))
            {
                var value = group.First().Material.shader.name;
                var isAllMaterialEquals = group.All(w => w.Material.shader.name == value);

                var material = !isAllMaterialEquals ? new Material(Shader.Find("Standard")) : Object.Instantiate(group.First().Material);
                material.name = $"Material (Layer {group.Key})";
                _materials.Add(material);
            }
        }
Esempio n. 7
0
 private static void CheckShaderVariants(BundleBuilderData data, BundleBuilderData.BundleInfo bundle, Object shaderVariants,
                                         string assetPath, PackagePlatform platform)
 {
     #if UNITY_2018_1_OR_NEWER
     var shaderVariantCollection = shaderVariants as ShaderVariantCollection;
     if (shaderVariantCollection != null)
     {
         var shaderInfos = ShaderUtil.GetAllShaderInfo();
         foreach (var shaderInfo in shaderInfos)
         {
             var shader     = Shader.Find(shaderInfo.name);
             var shaderPath = AssetDatabase.GetAssetPath(shader);
             if (shaderPath.StartsWith("Assets/"))
             {
                 CollectAsset(data, bundle, shader, shaderPath, platform);
             }
         }
     }
     #endif
 }
Esempio n. 8
0
    public void OnGUI()
    {
        // DisplayShaderContext(EditorGUILayout.GetControlRect());
        string[] strs = new[]
        {
            "数组下标0",
            "数组下标1",
            "数组下标2",
        };

        int[] intArr = new[]
        {
            1,
            2,
            3,
        };
        //字符选择,返回选择的字符数组下标
        this.index = EditorGUILayout.Popup(this.index, strs);

        //字符选择,返回对应的整数数组的整数值
        this.index = EditorGUILayout.IntPopup(this.index, strs, intArr);

        Debug.Log("index:" + index);

        //枚举选择
        this.mEnum = (EnumTest)EditorGUILayout.EnumPopup(this.mEnum);

        // shader 下拉列表
        EditorGUILayout.LabelField("Shader下拉列表");
        ShaderInfo[] shaderLists = ShaderUtil.GetAllShaderInfo();
        string[]     nameLists   = new string[shaderLists.Length];
        for (int i = 0; i < shaderLists.Length; i++)
        {
            nameLists[i] = shaderLists[i].name;
        }
        EditorGUILayout.Popup(this.index, nameLists);
    }
 private void OnEnable()
 {
     shaderOptions = ShaderUtil.GetAllShaderInfo().Select(x => x.name).ToArray();
     shaderIndex   = Array.IndexOf(shaderOptions, "Standard");
 }
Esempio n. 10
0
 public static string[] GetShaderNames()
 {
     return(ShaderUtil.GetAllShaderInfo().Where(x => x.name != "Hidden/Daihenka/Editor/ColoredTexture").Select(x => x.name).ToArray());
 }
Esempio n. 11
0
        protected override void OnInspector()
        {
            var clashes = CachedInstances.Where(d => d.Index == Target.Index);

            BeginError(clashes.Count() > 1);
            Draw("index", "This allows you to set the ID of this group (e.g. 100).\n\nNOTE: This number should be unique, and not shared by any other <b>P3dGroupData</b>.");
            EndError();
            Draw("textureDatas", "This allows you to specify the way each channel of this group's pixels are mapped to textures. This is mainly used by the in-editor painting mateiral builder tool.");
            Draw("shaderData", "This allows you to specify which shaders and their proprties are associated with this group.");

            CheckForDuplicates();

            Separator();

            EditorGUILayout.LabelField("Current Groups", EditorStyles.boldLabel);

            var groupDatas = CachedInstances.OrderBy(d => d.Index);

            EditorGUI.BeginDisabledGroup(true);
            foreach (var groupData in groupDatas)
            {
                if (groupData != null)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(groupData.name);
                    EditorGUILayout.IntField(groupData.Index);
                    EditorGUILayout.EndHorizontal();
                }
            }
            EditorGUI.EndDisabledGroup();

            Separator();

            EditorGUILayout.LabelField("Shader Properties", EditorStyles.boldLabel);

            filter = EditorGUILayout.TextField("Filter", filter);
            clean  = EditorGUILayout.Toggle("Clean", clean);

            var text = "";

            if (string.IsNullOrEmpty(filter) == false)
            {
                var tokens = filter.Split(' ');

                if (entries.Count == 0)
                {
                    foreach (var shaderInfo in ShaderUtil.GetAllShaderInfo())
                    {
                        var entry = new Entry();

                        entry.Path = shaderInfo.name;
                        entry.TexEnvs.AddRange(P3dHelper.GetTexEnvs(Shader.Find(shaderInfo.name)));

                        entries.Add(entry);
                    }
                }

                foreach (var entry in entries)
                {
                    foreach (var texEnv in entry.TexEnvs)
                    {
                        foreach (var token in tokens)
                        {
                            if (string.IsNullOrEmpty(token) == false)
                            {
                                if (Contains(texEnv.Name, token) == true || Contains(texEnv.Desc, token) == true || Contains(entry.Path, token) == true)
                                {
                                    var line = "";

                                    if (clean == true)
                                    {
                                        line += texEnv.Name + "@" + entry.Path + "\n";
                                    }
                                    else
                                    {
                                        line += texEnv.Name + " - " + texEnv.Desc + " - " + entry.Path + "\n";
                                    }

                                    if (text.Contains(line) == false)
                                    {
                                        text += line;
                                    }

                                    continue;
                                }
                            }
                        }
                    }
                }

                EditorGUILayout.TextArea(text, GUILayout.ExpandHeight(true));
            }
        }
    void OnGUI()
    {
        Event e = Event.current;

        using (var scrollScope = new EditorGUILayout.ScrollViewScope(scrollPos))
        {
            scrollPos = scrollScope.scrollPosition;
            for (int i = 0; i < shaderMappings.Count; i++)
            {
                using (var vScope = new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
                {
                    using (var hScope = new EditorGUILayout.HorizontalScope())
                    {
                        string prefix = shaderMappings[i].show.target ? "-" : "+";
                        EditorGUILayout.LabelField($"{prefix} {shaderMappings[i].sourceShader.name}", EditorStyles.boldLabel);
                        if (EditorGUILayout.DropdownButton(new GUIContent(shaderMappings[i].targetShader ? shaderMappings[i].targetShader.name : "Target Shader"), FocusType.Passive))
                        {
                            var menu  = new GenericMenu();
                            var infos = ShaderUtil.GetAllShaderInfo();
                            foreach (var info in infos)
                            {
                                var j = i;
                                menu.AddItem(new GUIContent(info.name), shaderMappings[i].targetShader && shaderMappings[i].targetShader.name.Equals(info.name), () =>
                                {
                                    shaderMappings[j].AssignTarget(Shader.Find(info.name));
                                });
                            }
                            menu.ShowAsContext();
                        }
                    }
                    Rect r = GUILayoutUtility.GetLastRect();
                    if (e.type == EventType.MouseDown && e.button == 0 && r.Contains(e.mousePosition))
                    {
                        shaderMappings[i].show.target = !shaderMappings[i].show.target;
                    }
                    using (var fadeScope = new EditorGUILayout.FadeGroupScope(shaderMappings[i].show.faded))
                    {
                        if (fadeScope.visible)
                        {
                            if (shaderMappings[i].targetShader == null)
                            {
                                continue;
                            }
                            if (shaderMappings[i].targetShader == shaderMappings[i].sourceShader)
                            {
                                continue;
                            }
                            EditorGUI.indentLevel++;
                            using (var vScope2 = new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
                            {
                                foreach (var prop in shaderMappings[i].sourceShaderProps)
                                {
                                    var j = i;
                                    using (var hScope = new EditorGUILayout.HorizontalScope())
                                    {
                                        EditorGUILayout.LabelField(prop.name);
                                        if (shaderMappings[i].targetShaderProps.ContainsKey(prop.type))
                                        {
                                            if (EditorGUILayout.DropdownButton(new GUIContent(shaderMappings[i].propertyMapping.ContainsKey(prop) ? shaderMappings[i].propertyMapping[prop].name : "None"), FocusType.Passive))
                                            {
                                                var menu = new GenericMenu();
                                                menu.AddItem(new GUIContent("None"), false, () =>
                                                {
                                                    shaderMappings[j].propertyMapping.Remove(prop);
                                                });
                                                foreach (var p in shaderMappings[i].targetShaderProps[prop.type])
                                                {
                                                    menu.AddItem(new GUIContent(p.name), false, () =>
                                                    {
                                                        shaderMappings[j].propertyMapping[prop] = p;
                                                    });
                                                }
                                                menu.ShowAsContext();
                                            }
                                        }
                                        else
                                        {
                                            EditorGUILayout.LabelField($"No {prop.type} properties");
                                        }
                                    }
                                }
                            }
                            EditorGUI.indentLevel--;
                            using (var hScope = new EditorGUILayout.HorizontalScope(EditorStyles.helpBox))
                            {
                                GUILayout.FlexibleSpace();
                                if (GUILayout.Button(new GUIContent("Material List", "List of materials that will be converted")))
                                {
                                    var materials = AssetDatabase.FindAssets("t:Material").Select(guid => AssetDatabase.LoadAssetAtPath <Material>(AssetDatabase.GUIDToAssetPath(guid))).Where(m => m.shader == shaderMappings[i].sourceShader);
                                    MaterialConverterListWindow.Open(materials.ToArray());
                                }
                                if (GUILayout.Button("Convert Materials"))
                                {
                                    var targetShader = shaderMappings[i].targetShader;
                                    var materials    = AssetDatabase.FindAssets("t:Material").Select(guid => AssetDatabase.LoadAssetAtPath <Material>(AssetDatabase.GUIDToAssetPath(guid))).Where(m => m.shader == shaderMappings[i].sourceShader);
                                    foreach (var mat in materials)
                                    {
                                        foreach (var key in shaderMappings[i].propertyMapping.Keys)
                                        {
                                            switch (key.type)
                                            {
                                            case ShaderUtil.ShaderPropertyType.Color:
                                                shaderMappings[i].propertyMapping[key].value = mat.GetColor(key.name);
                                                break;

                                            case ShaderUtil.ShaderPropertyType.Float:
                                            case ShaderUtil.ShaderPropertyType.Range:
                                                shaderMappings[i].propertyMapping[key].value = mat.GetFloat(key.name);
                                                break;

                                            case ShaderUtil.ShaderPropertyType.TexEnv:
                                                shaderMappings[i].propertyMapping[key].value = mat.GetTexture(key.name);
                                                break;

                                            case ShaderUtil.ShaderPropertyType.Vector:
                                                shaderMappings[i].propertyMapping[key].value = mat.GetVector(key.name);
                                                break;
                                            }
                                        }
                                        mat.shader = shaderMappings[i].targetShader;
                                        foreach (var key in shaderMappings[i].propertyMapping.Keys)
                                        {
                                            switch (key.type)
                                            {
                                            case ShaderUtil.ShaderPropertyType.Color:
                                                // Debug.Log($"SetColor: {(Color)shaderMappings[i].propertyMapping[key].value}");
                                                mat.SetColor(shaderMappings[i].propertyMapping[key].name, (Color)shaderMappings[i].propertyMapping[key].value);
                                                break;

                                            case ShaderUtil.ShaderPropertyType.Float:
                                            case ShaderUtil.ShaderPropertyType.Range:
                                                // Debug.Log($"SetFloat: {(float)shaderMappings[i].propertyMapping[key].value}");
                                                mat.SetFloat(shaderMappings[i].propertyMapping[key].name, (float)shaderMappings[i].propertyMapping[key].value);
                                                break;

                                            case ShaderUtil.ShaderPropertyType.TexEnv:
                                                // Debug.Log($"SetTexture: {(Texture)shaderMappings[i].propertyMapping[key].value}");
                                                mat.SetTexture(shaderMappings[i].propertyMapping[key].name, (Texture)shaderMappings[i].propertyMapping[key].value);
                                                break;

                                            case ShaderUtil.ShaderPropertyType.Vector:
                                                // Debug.Log($"SetVector: {(Vector4)shaderMappings[i].propertyMapping[key].value}");
                                                mat.SetVector(shaderMappings[i].propertyMapping[key].name, (Vector4)shaderMappings[i].propertyMapping[key].value);
                                                break;
                                            }
                                        }
                                    }
                                    shaderMappings[i] = new ShaderMapping(targetShader, this);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Esempio n. 13
0
        void OnGUI()
        {
            files.Clear();

            scrollPosition = GUILayout.BeginScrollView(scrollPosition);

            if (edtex != null)
            {
                float bannerWidth  = Screen.width - 10;
                float bannerHeight = bannerWidth * (edtex.height / (float)edtex.width);

                EditorGUILayout.LabelField(new GUIContent(edtex), GUILayout.Width(bannerWidth), GUILayout.Height(bannerHeight));

                EditorGUILayout.Space();
            }

            GUILayout.Label("Q3 BSP File Selection", EditorStyles.boldLabel);

            EditorGUILayout.Space();

            DirectoryInfo directory = new DirectoryInfo(Application.dataPath);

            FileInfo[] fileinfos = directory.GetFiles("*" + ".bsp", SearchOption.AllDirectories);

            string[] names = new string[fileinfos.Length];

            if (dirpath == null)
            {
                dirpath = Application.dataPath;
            }

            int count = 0;

            for (int i = 0; i < fileinfos.Length; i++)
            {
                FileInfo finfo = fileinfos[i];

                if (finfo == null)
                {
                    continue;
                }

                names[count++] = finfo.Name;
                files.Add(finfo.FullName);

                if (i == selectedingrid)
                {
                    dirpath = finfo.Directory.ToString();
                }
            }

            dirpath = dirpath.Replace("\\", "/");
            dirpath = dirpath.Replace(Application.dataPath, "Assets");

            if (count != 0)
            {
                selectedingrid = GUILayout.SelectionGrid(selectedingrid, names, 3);
            }
            else
            {
                GUIStyle s = new GUIStyle();
                s.normal.textColor = Color.red;
                s.wordWrap         = true;

                GUILayout.Label("No BSP files found. please make sure you have extraacted them from the pk3 file and have imported the file/folder to Unity. e.g. can be found in assets.", s);
            }

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            GUILayout.Label("Import Options", EditorStyles.boldLabel);

            EditorGUILayout.Space();

            importtextures = GUILayout.Toggle(importtextures, "Import Textures.");

            if (importtextures)
            {
                GUILayout.BeginHorizontal();

                nonlightmapshader = EditorGUILayout.ObjectField("Shader", nonlightmapshader, typeof(Shader), true) as Shader;

                if (GUILayout.Button("List Internal Shaders."))
                {
                    GenericMenu menu = new GenericMenu();

                    ShaderInfo[] infos = ShaderUtil.GetAllShaderInfo();

                    foreach (ShaderInfo si in infos)
                    {
                        bool b = false;

                        if (nonlightmapshader == null)
                        {
                            b = false;
                        }
                        else
                        {
                            if (nonlightmapshader.name == si.name)
                            {
                                b = true;
                            }
                        }

                        menu.AddItem(new GUIContent(si.name), b, MenuSelectionN, Shader.Find(si.name));
                    }

                    // display the menu
                    menu.ShowAsContext();
                }

                GUILayout.EndHorizontal();
            }

            EditorGUILayout.Space();

            importlightmaps = GUILayout.Toggle(importlightmaps, "Import Lightmaps.");

            if (importlightmaps)
            {
                GUILayout.BeginHorizontal();

                lightmapshader = EditorGUILayout.ObjectField("Shader", lightmapshader, typeof(Shader), true) as Shader;

                if (GUILayout.Button("List Internal Shaders."))
                {
                    GenericMenu menu = new GenericMenu();

                    ShaderInfo[] infos = ShaderUtil.GetAllShaderInfo();

                    foreach (ShaderInfo si in infos)
                    {
                        bool b = false;

                        if (lightmapshader == null)
                        {
                            b = false;
                        }
                        else
                        {
                            if (lightmapshader.name == si.name)
                            {
                                b = true;
                            }
                        }

                        menu.AddItem(new GUIContent(si.name), b, MenuSelectionL, Shader.Find(si.name));
                    }

                    // display the menu
                    menu.ShowAsContext();
                }

                GUILayout.EndHorizontal();
            }

            EditorGUILayout.Space();

            addcolliders = GUILayout.Toggle(addcolliders, "Add Collider/s.");

            if (addcolliders)
            {
                pmat = EditorGUILayout.ObjectField("Material", pmat, typeof(PhysicMaterial), true) as PhysicMaterial;
            }

            EditorGUILayout.Space();

            usereplacmenttex = GUILayout.Toggle(usereplacmenttex, "Use Replacement Texture for Non Found.");

            if (usereplacmenttex)
            {
                replacementtexture = EditorGUILayout.ObjectField("Replacement Texture", replacementtexture, typeof(Texture2D), true) as Texture2D;
            }

            EditorGUILayout.Space();

            makestatic = GUILayout.Toggle(makestatic, "Make objects static.");

            EditorGUILayout.Space();

            tezlevel = EditorGUILayout.IntSlider("Tesselation Level", tezlevel, 3, 50);

            EditorGUILayout.Space();

            printentitylump = GUILayout.Toggle(printentitylump, "Print the Entity List to console.");

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            if (GUILayout.Button("Import with selected settings."))
            {
                ImportQ3BSP(files[selectedingrid].ToString());
            }

            GUILayout.EndScrollView();
        }