public void setMaterial(Callback onFinishCallback, object orgs) { finishCallback = onFinishCallback; callbackPrgs = orgs; #if UNITY_EDITOR if (!CLCfgBase.self.isEditMode || Application.isPlaying) { if (string.IsNullOrEmpty(materialName)) { Debug.LogWarning(" then materialName is null===" + render.transform.parent.parent.name); } else { CLMaterialPool.borrowObjAsyn(materialName, (Callback)onGetMat); } } else { string tmpPath = "Assets/" + CLPathCfg.self.basePath + "/upgradeRes4Dev/other/Materials/" + materialName.Replace(".", "/") + ".mat"; Debug.Log(tmpPath); Material mat = AssetDatabase.LoadAssetAtPath( tmpPath, typeof(UnityEngine.Object)) as Material; CLMaterialPool.resetTexRef(materialName, mat, null, null); onGetMat(materialName, mat); } #else CLMaterialPool.borrowObjAsyn(materialName, (Callback)onGetMat); #endif }
public void switchByName(string cellName, Animator animator, object callback) { if (!isInited) { init(); } int index = MapEx.getInt(mapIndex, cellName); if (needSwitchController) { if (animator != null) { animator.runtimeAnimatorController = animatorControllers [index]; } else { Debug.LogError("animator is null"); } } if (switchType == CLSwitchType.showOrHide) { for (int i = 0; i < partObjs.Count; i++) { if (i == index) { NGUITools.SetActive(partObjs [i], true); } else { NGUITools.SetActive(partObjs [i], false); } } Utl.doCallback(callback); } else if (switchType == CLSwitchType.switchShader) { if (render.sharedMaterial != null) { string mName = render.sharedMaterial.name; // mName = mName.Replace(" (Instance)", ""); CLMaterialPool.returnObj(mName); render.sharedMaterial = null; } setMat(render, materialNames [index], callback); } }
public static void cleanTexRef(string name, Material mat) { ArrayList propNames = null; ArrayList texNames = null; ArrayList texPaths = null; if (CLMaterialPool.getMaterialTexCfg(name, ref propNames, ref texNames, ref texPaths)) { if (propNames != null) { for (int i = 0; i < propNames.Count; i++) { mat.SetTexture(propNames[i].ToString(), null); } } } }
public void cleanMaterial() { if (switchType == CLSwitchType.switchShader) { if (render.sharedMaterial != null) { #if UNITY_EDITOR if (Application.isPlaying) { CLMaterialPool.returnObj(render.sharedMaterial.name); } #else CLMaterialPool.returnObj(render.sharedMaterial.name); #endif render.sharedMaterial = null; } } }
public void cleanRefAssets() { #if UNITY_EDITOR foreach (var matInfor in materials) { string matPath = "Assets/" + CLPathCfg.self.basePath + "/upgradeRes4Dev/other/Materials/" + matInfor.materialName.Replace(".", "/") + ".mat"; Debug.Log("matPath==" + matPath); Material mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material; if (mat == null) { continue; } CLMaterialPool.cleanTexRef(matInfor.materialName, mat); if (matInfor.render.sharedMaterials != null && matInfor.render.sharedMaterials.Length > matInfor.index) { Material[] mats = matInfor.render.sharedMaterials; mats [matInfor.index] = null; matInfor.render.sharedMaterials = mats; if (matInfor.index == 0) { matInfor.render.sharedMaterial = null; matInfor.render.material = null; } } } foreach (var meshInfor in meshs) { if (meshInfor.meshFilter != null) { meshInfor.meshFilter.sharedMesh = null; } if (meshInfor.skinnedMesh != null) { meshInfor.skinnedMesh.sharedMesh = null; } if (meshInfor.animator != null) { meshInfor.animator.avatar = null; } } #endif }
public void setMat(Renderer render, string materialName, object callback) { ArrayList list = new ArrayList(); list.Add(render); list.Add(materialName); list.Add(callback); #if UNITY_EDITOR if (Application.isPlaying) { CLMaterialPool.borrowObjAsyn(materialName, (Callback)onSetPrefab, list); } else { string path = "Assets/" + CLPathCfg.self.basePath + "/upgradeRes4Dev/other/Materials/" + materialName.Replace(".", "/") + ".mat"; Material mat = AssetDatabase.LoadAssetAtPath(path, typeof(Material)) as Material; render.sharedMaterial = mat; } #else CLMaterialPool.borrowObjAsyn(materialName, (Callback)onSetPrefab, list); #endif }
public void returnMaterial() { CLMaterialPool.returnObj(materialName); }