示例#1
0
    public static void CreateShadersAssets()
    {
        var           allFiles = Directory.GetFiles(Application.streamingAssetsPath + "/PackFx", "*.*", SearchOption.AllDirectories);
        List <string> files    = new List <string>();

        foreach (string file in allFiles)
        {
            if (file.ToLower().EndsWith(".hlsl") || file.ToLower().EndsWith(".glsl"))
            {
                files.Add(file);
            }
        }
        foreach (string file in files)
        {
            string pathName = file.Substring((Application.streamingAssetsPath + "/PackFx/").Length);
            string dirName  = Path.GetDirectoryName(Application.dataPath + "/Resources/PKFxShaders/" + pathName);
            if (!Directory.Exists(dirName))
            {
                Directory.CreateDirectory(dirName);
            }
            string filePath = dirName + "/" + Path.GetFileNameWithoutExtension(pathName) + ".asset";
            if (!File.Exists(filePath))
            {
                string assetPath = ("Assets" + filePath.Substring(Application.dataPath.Length)).Replace('\\', '/');
                UnityEngine.Debug.Log("[PKFX] Creating " + assetPath);
                PkFxCustomShader shaderAsset = ScriptableObject.CreateInstance <PkFxCustomShader>();
                shaderAsset.m_GlobalShader = true;
                shaderAsset.m_ShaderName   = pathName.Replace('\\', '/');
                AssetDatabase.CreateAsset(shaderAsset, assetPath);
            }
        }
        AssetDatabase.SaveAssets();
    }
    //----------------------------------------------------------------------------

    private void ReloadConstants(bool flush)
    {
        serializedObject.Update();
        PkFxCustomShader customShader = (serializedObject.targetObject as PkFxCustomShader);

        int count = -1;

        if (customShader.m_Api == PkFxCustomShader.EShaderApi.GL && !m_InShaderConstantsLoading)
        {
            PKFxManager.ShaderConstantsCount(customShader.m_ShaderName, (int)customShader.m_Api);
            GL.IssuePluginEvent(PKFxManager.GetGLConstantsCountEvent(), (int)(PKFxManager.POPCORN_MAGIC_NUMBER | 0x00004000));
            m_InShaderConstantsLoading = true;
        }
        else
        {
            count = PKFxManager.ShaderConstantsCount(customShader.m_ShaderName, (int)customShader.m_Api);
        }

        if (count != -1)
        {
            m_InShaderConstantsLoading = false;
            List <PKFxManager.ShaderConstantDesc> FxAttributesDesc = PKFxManager.ListShaderConstantsFromName(customShader.m_ShaderName, count);
            customShader.LoadShaderConstants(FxAttributesDesc, flush);
            EditorUtility.SetDirty(target as PkFxCustomShader);
            AssetDatabase.SaveAssets();
            serializedObject.ApplyModifiedProperties();
            serializedObject.Update();
        }
    }