public static void resetShardAssets(UnityEngine.Object obj) { CLSharedAssets sharedAsset = null; CLRoleAvata avata = null; if (obj != null && obj is GameObject) { // 没搞明白,执行到这里时,textureMgr已经为null了,因此再取一次 sharedAsset = ((GameObject)obj).GetComponent <CLSharedAssets> (); avata = ((GameObject)obj).GetComponent <CLRoleAvata> (); UIFont font = ((GameObject)obj).GetComponent <UIFont> (); if (font != null) { if (!string.IsNullOrEmpty(font.atlasName)) { font.atlas = CLUIInit.self.getAtlasByName(font.atlasName); if (font.atlas) { font.material = font.atlas.spriteMaterial; } } } } else if (obj != null && obj is Material) { CLMaterialPool.resetTexRef(ECLEditorUtl.getAssetName4Upgrade(obj), (Material)obj, null, null); sharedAsset = null; } else { sharedAsset = null; } bool isRefresh = false; if (avata != null) { avata.setDefaultMaterial(); isRefresh = true; } if (sharedAsset != null) { sharedAsset.reset(); sharedAsset.resetAssets(); isRefresh = true; } if (isRefresh && obj is GameObject) { //string path = AssetDatabase.GetAssetPath (obj); //EditorUtility.SetDirty (obj); //AssetDatabase.WriteImportSettingsIfDirty (path); //AssetDatabase.ImportAsset (path); PrefabUtility.SavePrefabAsset(obj as GameObject); } }
public static void cleanShardAssets(UnityEngine.Object obj) { CLSharedAssets sharedAsset = null; CLRoleAvata avata = null; if (obj is GameObject) { sharedAsset = ((GameObject)obj).GetComponent <CLSharedAssets> (); avata = ((GameObject)obj).GetComponent <CLRoleAvata> (); if (AssetDatabase.GetAssetPath(obj).Contains("/other/model/")) { ECLEditorUtl.cleanModleMaterials(AssetDatabase.GetAssetPath(obj)); } UIFont font = ((GameObject)obj).GetComponent <UIFont> (); if (font != null) { string spName = font.spriteName; font.atlas = null; font.material = null; font.spriteName = spName; } } else if (obj is Material) { CLMaterialPool.cleanTexRef(ECLEditorUtl.getAssetName4Upgrade(obj), (Material)obj); sharedAsset = null; } else { sharedAsset = null; } bool isRefresh = false; if (avata != null) { avata.cleanMaterial(); isRefresh = true; } if (sharedAsset != null) { sharedAsset.cleanRefAssets(); isRefresh = true; } if (isRefresh && obj is GameObject) { // AssetDatabase.Refresh (); //string path = AssetDatabase.GetAssetPath (obj); //EditorUtility.SetDirty (obj); //AssetDatabase.WriteImportSettingsIfDirty (path); //AssetDatabase.ImportAsset (path); PrefabUtility.SavePrefabAsset(obj as GameObject); } }
public override void OnInspectorGUI() { avata = (CLRoleAvata)target; ECLEditorUtl.BeginContents(); { if (isAddBones || isShowBones) { GUILayout.BeginHorizontal(); { EditorGUILayout.LabelField("Bone Name", GUILayout.Width(100)); EditorGUILayout.LabelField("Bone Transform", GUILayout.Width(150)); } GUILayout.EndHorizontal(); } if (isShowBones) { for (int i = 0; i < avata.bonesNames.Count; i++) { GUILayout.BeginHorizontal(); { EditorGUILayout.TextField(avata.bonesNames [i], GUILayout.Width(100)); EditorGUILayout.ObjectField(avata.bonesList [i], typeof(Transform), GUILayout.Width(150)); if (GUILayout.Button("-")) { if (EditorUtility.DisplayDialog("Confirm", "确定要删除?", "Okay", "Cancel")) { avata.bonesNames.RemoveAt(i); avata.bonesList.RemoveAt(i); EditorUtility.SetDirty(avata); break; } } } GUILayout.EndHorizontal(); } } if (isAddBones) { GUILayout.BeginHorizontal(); { addBoneName = EditorGUILayout.TextField(addBoneName, GUILayout.Width(100)); addBone = (Transform)(EditorGUILayout.ObjectField(addBone, typeof(Transform), GUILayout.Width(150))); if (GUILayout.Button("+")) { if (string.IsNullOrEmpty(addBoneName)) { EditorUtility.DisplayDialog("Confirm", "Bone Name can not null?", "Okay"); return; } if (avata.bonesMap.ContainsKey(addBoneName)) { EditorUtility.DisplayDialog("Confirm", "Bone Name allready exsit, please check then name Uniqueness?", "Okay"); return; } if (addBone == null) { EditorUtility.DisplayDialog("Confirm", "Bone can not null?", "Okay"); return; } avata.bonesNames.Add(addBoneName); avata.bonesList.Add(addBone); avata.bonesMap [addBoneName] = addBone; EditorUtility.SetDirty(avata); addBone = null; addBoneName = ""; } } GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); { if (GUILayout.Button(isShowBones ? "Hide Bones" : "Show Bones")) { isShowBones = !isShowBones; } if (GUILayout.Button("Add Bones")) { isAddBones = true; } } GUILayout.EndHorizontal(); } ECLEditorUtl.EndContents(); ECLEditorUtl.BeginContents(); { if (avata.bodyPartNames != null) { for (int i = 0; i < avata.bodyPartNames.Count; i++) { GUILayout.BeginHorizontal(); { if (selectedPartindex == i) { GUI.color = Color.yellow; } if (GUILayout.Button(avata.bodyPartNames [i])) { selectedPartindex = i; isShowNewBodyPart = false; } GUI.color = Color.white; if (GUILayout.Button("-", GUILayout.Width(30))) { if (EditorUtility.DisplayDialog("Confirm", "确定要删除?", "Okay", "Cancel")) { avata.bodyPartNames.RemoveAt(i); break; } } } GUILayout.EndHorizontal(); if (selectedPartindex == i) { avata.bodyParts [i] = showOnePart(avata.bodyParts [i], false); } } } if (isShowNewBodyPart) { newBodyPart = newBodyPart == null ? new CLBodyPart() : newBodyPart; newBodyPart = showOnePart(newBodyPart, true); GUILayout.BeginHorizontal(); { if (GUILayout.Button("Clean")) { newBodyPart.cellNames.Clear(); // newBodyPart.materials.Clear (); newBodyPart.materialNames.Clear(); newBodyPart.partObjs.Clear(); newBodyPart.animatorControllers.Clear(); cellName = ""; onePartObj = null; } if (GUILayout.Button("Save Body Part")) { doAddBodyPart(); } } GUILayout.EndHorizontal(); } if (GUILayout.Button("Add Body Part")) { selectedPartindex = -1; newBodyPart = new CLBodyPart(); isShowNewBodyPart = true; } } ECLEditorUtl.EndContents(); testPartName = EditorGUILayout.TextField("Part Name", testPartName); testCellName = EditorGUILayout.TextField("Cell Name", testCellName); if (GUILayout.Button("test")) { avata.setMapindex(); avata.switch2xx(testPartName, testCellName); } if (GUILayout.Button("clean Material")) { avata.cleanMaterial(); } if (GUILayout.Button("set Default Material")) { avata.setDefaultMaterial(); } }