static public Shader Get(SsShaderType t, bool unified) { if (!_initialized) { Initialize(); } if (unified) { // experimental... return(_unifiedShaderList[(int)t >> (int)SsShaderType.AlphaShift]); } else { Shader shader; if (_shaderList.TryGetValue(t, out shader)) { return(shader); } else { // not found, could be not yet supported type... return(null); } } }
ToSerial(SsShaderType t) { int i = (int)t; return((i >> (int)SsShaderType.MatColShift) * ((int)SsAlphaBlendOperation.Num * (int)SsColorBlendOperation.Num) + (i >> (int)SsShaderType.AlphaShift) * (int)SsColorBlendOperation.Num + (i & (int)SsShaderType.ColorMask)); }
AddMaterials(SsPartRes part, SsColorBlendOperation colorBlendType) { SsImageFile img = part.imageFile; SsShaderType shaderType = SsShaderManager.EnumToType(colorBlendType, part.AlphaBlendType, SsMaterialColorBlendOperation.Non); Material material = img.GetMaterial(shaderType); if (material) { return; // already added } // create material #if _BUILD_UNIFIED_SHADERS img.useUnifiedShader = _anmRes.UseCgProgram; Shader shader = SsShaderManager.Get(shaderType, _anmRes.UseCgProgram); #else Shader shader = SsShaderManager.Get(shaderType, false); #endif // get material asset path string assetPath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(img.texture)) + "/assets/"; string shaderName = shader.name; shaderName = shaderName.Replace("Ss/", ""); string assetName = assetPath + img.texture.name + "_Mat_" + shaderName + ".asset"; // try to load the exiting Material existedMat = (Material)AssetDatabase.LoadAssetAtPath(assetName, typeof(Material)); Material mat = (existedMat ?? new Material(shader)); mat.SetTexture("_MainTex", img.texture); if (existedMat == null) { // if none, create material as asset file newly // Debug.Log("create material: " + img.path + " shader: " + shaderType); if (!Directory.Exists(assetPath)) { string parentFolder = Path.GetDirectoryName(assetPath.TrimEnd('\\', '/')); AssetDatabase.CreateFolder(parentFolder, "assets"); } AssetDatabase.CreateAsset(mat, assetName); } else { // update the existing content mat.shader = shader; EditorUtility.SetDirty(mat); AssetDatabase.SaveAssets(); //same as EditorApplication.SaveAssets(); } // add to material list img.materials[SsShaderManager.ToSerial(shaderType)] = mat; }
public Material GetMaterial(SsShaderType t) { if (materials == null) { return(null); } int index = SsShaderManager.ToSerial(t); if (index >= materials.Length) { return(null); } return(materials[index]); }
static public void Initialize() { if (_initialized) { return; } // get parted shaders for (int cb = 0; cb < (int)SsColorBlendOperation.Num; ++cb) { for (int ab = 0; ab < (int)SsAlphaBlendOperation.Num; ++ab) { for (int mb = 0; mb < (int)SsMaterialColorBlendOperation.Num; ++mb) { var cbType = (SsColorBlendOperation)cb; var abType = (SsAlphaBlendOperation)ab; var mbType = (SsMaterialColorBlendOperation)mb; SsShaderType key = EnumToType(cbType, abType, mbType); string shaderName = "Ss/" + cbType + "Color" + abType + "Alpha"; // add suffix when material color blending is enabled if (mbType != SsMaterialColorBlendOperation.Non) { shaderName += mbType + "MatCol"; } _shaderList[key] = Shader.Find(shaderName); if (_shaderList[key] == null) { Debug.LogError("not found shader!!: " + shaderName); } } } } #if _BUILD_UNIFIED_SHADERS // get color blend unified shaders for (int ab = 0; ab < (int)SsAlphaBlendOperation.Num; ++ab) { var abType = (SsAlphaBlendOperation)ab; string shaderName = "Ss/UniColor" + abType + "Alpha"; _unifiedShaderList[ab] = Shader.Find(shaderName); if (_unifiedShaderList[ab] == null) { Debug.LogError("not found shader!!: " + shaderName); } } #endif _initialized = true; }
public static Shader Get(SsShaderType t, bool unified) { if (!_initialized) Initialize(); if (unified) { // experimental... return _unifiedShaderList[(int)t >> (int)SsShaderType.AlphaShift]; } else { Shader shader; if (_shaderList.TryGetValue(t, out shader)) { return shader; } else { // not found, could be not yet supported type... return null; } } }
public Material GetMaterial(SsShaderType t) { if (materials == null) return null; int index = SsShaderManager.ToSerial(t); if (index >= materials.Length) return null; return materials[index]; }
public Material GetMaterial(SsShaderType t) { return materials[SsShaderManager.ToSerial(t)]; }
public static int ToSerial(SsShaderType t) { int i = (int)t; return (i >> (int)SsShaderType.MatColShift) * ((int)SsAlphaBlendOperation.Num * (int)SsColorBlendOperation.Num) + (i >> (int)SsShaderType.AlphaShift) * (int)SsColorBlendOperation.Num + (i & (int)SsShaderType.ColorMask); }