void init() { if (!isFinishInit || asset == null) { isFinishInit = true; if (!string.IsNullOrEmpty(instance.soundFileName) && CLPathCfg.self != null) { string tmpPath = CLPathCfg.self.basePath + "/upgradeRes4Dev/other/sound/" + instance.soundFileName; asset = ECLEditorUtl.getObjectByPath(tmpPath); } } }
public Object getMaterial(string path) { if (MaterialMap [path] == null) { string matPath = PStr.b().a(CLPathCfg.self.basePath).a("/") .a("upgradeRes4Dev").a("/other/Materials/").a(path.Replace(".", "/")).a(".mat").e(); // Debug.Log (matPath); Object obj = ECLEditorUtl.getObjectByPath(matPath); MaterialMap [path] = obj; return(obj); } else { return((Object)(MaterialMap [path])); } }
public Mesh getMesh(string path, string meshName) { if (MeshMap [path] == null) { string matPath = PStr.b().a(CLPathCfg.self.basePath).a("/") .a("upgradeRes4Dev").a("/other/model/").a(path.Replace(".", "/")).a(".FBX").e(); Debug.Log(matPath); MeshMap [path] = ECLEditorUtl.getObjectByPath(matPath); } GameObject mi = MeshMap [path] as GameObject; if (mi != null) { MeshFilter[] mfs = mi.GetComponentsInChildren <MeshFilter>(); if (mfs != null && mfs.Length > 0) { for (int i = 0; i < mfs.Length; i++) { if (mfs [i].sharedMesh.name == meshName) { return(mfs[i].sharedMesh); } } } else { SkinnedMeshRenderer[] smrs = mi.GetComponentsInChildren <SkinnedMeshRenderer>(); if (smrs != null) { for (int i = 0; i < smrs.Length; i++) { if (smrs [i].sharedMesh.name == meshName) { return(smrs[i].sharedMesh); } } } } } return(null); }
public static void doCleanModelMaterials(string matPath) { checkModleSetting(matPath); ModelImporter mi = ModelImporter.GetAtPath(matPath) as ModelImporter; if (mi != null) { cleanModleMaterials(mi); AssetDatabase.ImportAsset(matPath); } GameObject go = ECLEditorUtl.getObjectByPath(matPath) as GameObject; if (go != null) { MeshRenderer mf = go.GetComponentInChildren <MeshRenderer> (); if (mf != null) { mf.sharedMaterial = null; Material[] mats = mf.sharedMaterials; for (int i = 0; i < mats.Length; i++) { mats [i] = null; } mf.sharedMaterials = mats; } SkinnedMeshRenderer smr = go.GetComponentInChildren <SkinnedMeshRenderer> (); if (smr != null) { smr.sharedMaterial = null; Material[] mats = smr.sharedMaterials; for (int i = 0; i < mats.Length; i++) { mats [i] = null; } smr.sharedMaterials = mats; } EditorUtility.SetDirty(go); AssetDatabase.WriteImportSettingsIfDirty(matPath); AssetDatabase.Refresh(); } }
public Avatar getAvatar(string path) { if (MeshMap [path] == null) { string matPath = PStr.b().a(CLPathCfg.self.basePath).a("/") .a("upgradeRes4Dev").a("/other/model/").a(path.Replace(".", "/")).a(".FBX").e(); Debug.Log(matPath); MeshMap [path] = ECLEditorUtl.getObjectByPath(matPath); } GameObject mi = MeshMap [path] as GameObject; Animator animator = mi.GetComponent <Animator>(); if (animator == null) { animator = mi.GetComponentInChildren <Animator>(); } if (animator != null) { return(animator.avatar); } return(null); }
void showCellSprite(Hashtable m) { Hashtable d = MapEx.getMap(m, "data"); Texture tex = ECLEditorUtl.getObjectByPath(MapEx.getString(d, "path")) as Texture; if (tex == null) { return; } // NGUIEditorTools.DrawTiledTexture (rect, NGUIEditorTools.backdropTexture); Rect uv = new Rect(MapEx.getInt(d, "x"), MapEx.getInt(d, "y"), MapEx.getInt(d, "width"), MapEx.getInt(d, "height")); uv = NGUIMath.ConvertToTexCoords(uv, tex.width, tex.height); float scaleX = rect.width / uv.width; float scaleY = rect.height / uv.height; // Stretch the sprite so that it will appear proper float aspect = (scaleY / scaleX) / ((float)tex.height / tex.width); Rect clipRect = rect; if (aspect != 1f) { if (aspect < 1f) { // The sprite is taller than it is wider float padding = cellSize * (1f - aspect) * 0.5f; clipRect.xMin += padding; clipRect.xMax -= padding; } else { // The sprite is wider than it is taller float padding = cellSize * (1f - 1f / aspect) * 0.5f; clipRect.yMin += padding; clipRect.yMax -= padding; } } if (GUI.Button(rect, "")) { mSelectedSprite = MapEx.getString(d, "name"); isShowParckerView = false; currSelectSprite = m; } GUI.DrawTextureWithTexCoords(clipRect, tex, uv); // Draw the selection if (mSelectedSprite == MapEx.getString(d, "name")) { NGUIEditorTools.DrawOutline(rect, new Color(0.4f, 1f, 0f, 1f)); } GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f); GUI.contentColor = new Color(1f, 1f, 1f, 0.7f); GUI.Label(new Rect(rect.x, rect.y + rect.height, rect.width, 32f), MapEx.getString(d, "name"), "ProgressBarBack"); GUI.contentColor = Color.white; GUI.backgroundColor = Color.white; GUILayout.Space(cellSize + 30); //这句主要目的是为了可以滑动 rect.y += (cellSize + 30); }
void showSpriteInfor() { if (currSelectSprite == null) { return; } Hashtable d = MapEx.getMap(currSelectSprite, "data"); int times = MapEx.getInt(currSelectSprite, "times"); string name = MapEx.getString(d, "name"); string path = MapEx.getString(d, "path"); int x = MapEx.getInt(d, "x"); int y = MapEx.getInt(d, "y"); int width = MapEx.getInt(d, "width"); int height = MapEx.getInt(d, "height"); int borderLeft = MapEx.getInt(d, "borderLeft"); int borderRight = MapEx.getInt(d, "borderRight"); int borderTop = MapEx.getInt(d, "borderTop"); int borderBottom = MapEx.getInt(d, "borderBottom"); int paddingLeft = MapEx.getInt(d, "paddingLeft"); int paddingRight = MapEx.getInt(d, "paddingRight"); int paddingTop = MapEx.getInt(d, "paddingTop"); int paddingBottom = MapEx.getInt(d, "paddingBottom"); Hashtable atlas = MapEx.getMap(currSelectSprite, "atlas"); string atlasStr = ""; foreach (DictionaryEntry item in atlas) { atlasStr = PStr.b().a(atlasStr).a(",").a(item.Key.ToString()).e(); } Texture tex = ECLEditorUtl.getObjectByPath(path) as Texture; Rect r = Rect.zero; if (tex != null) { float h = 0; float w = position.width - 160; float rate = w / tex.width; if (rate < 1) { h = tex.height * rate; } else { h = tex.height; } h = h > 200 ? h : 200; r = new Rect(0, 0, NumEx.getIntPart(w), NumEx.getIntPart(h)); GUI.DrawTexture(r, tex, ScaleMode.ScaleToFit); GUILayout.Space(r.height + r.y); //这句主要目的是为了可以滑动 } else { r = new Rect(0, 0, position.width - 160, 100); GUILayout.Space(r.height + r.y); //这句主要目的是为了可以滑动 } GUILayout.Space(10); ECLEditorUtl.BeginContents(); { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.TextField("name", name); EditorGUILayout.IntField("times", times); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("x", x); EditorGUILayout.IntField("y", y); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("width", width); EditorGUILayout.IntField("height", height); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("borderLeft", borderLeft); EditorGUILayout.IntField("borderRight", borderRight); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("borderTop", borderTop); EditorGUILayout.IntField("borderBottom", borderBottom); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("paddingLeft", paddingLeft); EditorGUILayout.IntField("paddingRight", paddingRight); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("paddingTop", paddingTop); EditorGUILayout.IntField("paddingBottom", paddingBottom); } EditorGUILayout.EndHorizontal(); EditorGUILayout.TextField("path", path); EditorGUILayout.TextField("Atlas", atlasStr); } ECLEditorUtl.EndContents(); }
bool packTextures(int maxSize, bool unityPacking) //, ref ArrayList outSprites, ref Rect[] rects) { if (packTex != null) { DestroyImmediate(packTex, true); packTex = null; } refreshSelectedCount(); if (selectedCount == 0) { Debug.LogError("Please select some sprites, that need packe"); return(false); } packSprites.Clear(); List <Texture2D> listTexs = new List <Texture2D> (); for (int i = 0; i < mSpriteList.Count; i++) { Hashtable m = mSpriteList [i] as Hashtable; if (MapEx.getBool(m, "selected")) { Hashtable d = MapEx.getMap(m, "data"); string name = MapEx.getString(d, "name"); string path = MapEx.getString(d, "path"); Texture2D tex = ECLEditorUtl.getObjectByPath(path) as Texture2D; listTexs.Add(tex); packSprites.Add(m); } } if (sortSprite != SortSprite.none) { if (sortSprite == SortSprite.SortArea) { packSprites.Sort(CompareSprite); } else { packSprites.Sort(CompareSprite2); } listTexs.Clear(); for (int i = 0; i < packSprites.Count; i++) { Hashtable d = MapEx.getMap(packSprites [i], "data"); string path = MapEx.getString(d, "path"); setTextureReadable("Assets/" + path, TextureImporterFormat.RGBA32, TextureImporterCompression.Uncompressed, true); Texture2D tex = ECLEditorUtl.getObjectByPath(path) as Texture2D; listTexs.Add(tex); } } // for (int i = 0; i < listTexs.Count; i++) { // setTextureReadable (listTexs [i] as Texture, TextureImporterFormat.RGBA32, TextureImporterCompression.Uncompressed, true); // } packTex = new Texture2D(1, 1, TextureFormat.ARGB32, false); if (unityPacking) { packRects = packTex.PackTextures(listTexs.ToArray(), NGUISettings.atlasPadding, maxSize); } else { packRects = UITexturePacker.PackTextures(packTex, listTexs.ToArray(), 4, 4, NGUISettings.atlasPadding, maxSize); } _empty = new Texture2D(packTex.width, packTex.height, TextureFormat.ARGB32, false); bool ret = true; for (int i = 0; i < listTexs.Count; ++i) { Rect rect = NGUIMath.ConvertToPixels(packRects [i], packTex.width, packTex.height, true); packRects [i] = rect; // Apparently Unity can take the liberty of destroying temporary textures without any warning if (listTexs [i] == null) { Debug.LogWarning("Apparently Unity can take the liberty of destroying temporary textures without any warning"); ret = false; break; } // Make sure that we don't shrink the textures if (Mathf.RoundToInt(rect.width) != listTexs [i].width) { Debug.LogError(rect.width + "====" + listTexs [i].width); Debug.LogWarning("Make sure that we don't shrink the textures=" + listTexs [i].name); ret = false; break; } } // for (int i = 0; i < listTexs.Count; i++) { // setTextureReadable (listTexs [i] as Texture, TextureImporterFormat.Automatic, false); // } return(ret); }