Exemplo n.º 1
0
        private static void _SetAssetBundleNameAndVariant(Shader shader, string bundleName, string variantName)
        {
            bool   isBundledShader = !string.IsNullOrEmpty(bundleName);
            string fileName        = RuntimeShaderUtil.GetShaderInfoFileName(shader);

            if (isBundledShader)
            {
                AssetImporter importer = AssetImporter.GetAtPath("Assets" + RuntimeShaderUtil.GetPath(true) + "/" + fileName);
                importer.SetAssetBundleNameAndVariant(bundleName, variantName);
            }
        }
Exemplo n.º 2
0
        private static void _Create(Shader shader, string bundleName, string variantName)
        {
            if (shader == null)
            {
                throw new System.ArgumentNullException("shader");
            }

            int propertyCount = ShaderUtil.GetPropertyCount(shader);

            RuntimeShaderInfo shaderInfo = new RuntimeShaderInfo();

            shaderInfo.Name = shader.name;
            if (!shader.HasMappedInstanceID())
            {
                //bool create = EditorUtility.DisplayDialog("RuntimeShaderInfo Generator", "Unable to create RuntimeShaderInfo. Please Create or Update ResourceMap", "Create", "Cancel");
                //if (create)
                //{
                //    ResourceMapGen.CreateResourceMap(true);
                //}

                return;
            }

            shaderInfo.InstanceId           = shader.GetMappedInstanceID();
            shaderInfo.PropertyCount        = propertyCount;
            shaderInfo.PropertyDescriptions = new string[propertyCount];
            shaderInfo.PropertyNames        = new string[propertyCount];
            shaderInfo.PropertyRangeLimits  = new RuntimeShaderInfo.RangeLimits[propertyCount];
            shaderInfo.PropertyTexDims      = new TextureDimension[propertyCount];
            shaderInfo.PropertyTypes        = new RTShaderPropertyType[propertyCount];
            shaderInfo.IsHidden             = new bool[propertyCount];

            for (int i = 0; i < propertyCount; ++i)
            {
                shaderInfo.PropertyDescriptions[i] = ShaderUtil.GetPropertyDescription(shader, i);
                shaderInfo.PropertyNames[i]        = ShaderUtil.GetPropertyName(shader, i);
                shaderInfo.PropertyRangeLimits[i]  = new RuntimeShaderInfo.RangeLimits(
                    ShaderUtil.GetRangeLimits(shader, i, 0),
                    ShaderUtil.GetRangeLimits(shader, i, 1),
                    ShaderUtil.GetRangeLimits(shader, i, 2));
                shaderInfo.PropertyTexDims[i] = ShaderUtil.GetTexDim(shader, i);

                RTShaderPropertyType          rtType = RTShaderPropertyType.Unknown;
                ShaderUtil.ShaderPropertyType type   = ShaderUtil.GetPropertyType(shader, i);
                if (m_typeToType.ContainsKey(type))
                {
                    rtType = m_typeToType[type];
                }

                shaderInfo.PropertyTypes[i] = rtType;
                shaderInfo.IsHidden[i]      = ShaderUtil.IsShaderPropertyHidden(shader, i);
            }

            string fullPath = Application.dataPath + RuntimeShaderUtil.GetPath(true);

            Directory.CreateDirectory(fullPath);

            string fileName = RuntimeShaderUtil.GetShaderInfoFileName(shader);

            string path = Path.Combine(fullPath, fileName);

            bool refresh = !File.Exists(path);

            File.WriteAllText(path, JsonUtility.ToJson(shaderInfo));

            if (refresh)
            {
                AssetDatabase.Refresh();
            }
        }