public float colliderSize; // Rail collider area (xyz) // Initialize the size of the rail by iterating through the waypoints void Start() { this.gameObject.tag = "Rail"; // Makes this object a Rail (for the lazy) int i; for (i = 0; i < this.transform.childCount; i++) { arrayRWP.Add(this.transform.GetChild(i).position); // Add child to the list iteratively //this.transform.GetChild(i).gameObject.AddComponent() if (i < this.transform.childCount - 1) { rldists.Add(Vector3.Distance(this.transform.GetChild(i).position, this.transform.GetChild(i + 1).position)); arrayRvec.Add(this.transform.GetChild(i + 1).position - this.transform.GetChild(i).position); } } railpos = arrayRWP.ToArray(); // Convert the list into a vector array arrayRWP.Release(); rdists = rldists.ToArray(); rldists.Release(); railvecs = arrayRvec.ToArray(); arrayRvec.Release(); for (i = 0; i < this.transform.childCount - 1; i++) { makeColliders(i); } }
public MeshRenderer mRenderer = null; // Mesh renderer for this screen public virtual void UpdateGeometry() { int vertex_count = verts.size; //Safety check to ensure we get valid values if (vertex_count > 0 && (vertex_count == uvs.size && vertex_count == cols.size) && (vertex_count % 4) == 0) { if (mFilter == null) { mFilter = gameObject.GetComponent <MeshFilter>(); } if (mFilter == null) { mFilter = gameObject.AddComponent <MeshFilter>(); } // Create the mesh if (mMesh == null) { mMesh = new Mesh(); mMesh.hideFlags = HideFlags.DontSave; mMesh.name = "Mesh"; mMesh.MarkDynamic(); } mMesh.Clear(); mMesh.vertices = verts.ToArray(); mMesh.uv = uvs.ToArray(); mMesh.colors32 = cols.ToArray(); int triangleCount = (vertex_count >> 1) * 3; mMesh.triangles = GenerateCachedIndexBuffer(vertex_count, triangleCount); mFilter.mesh = mMesh; if (mRenderer == null) { mRenderer = gameObject.GetComponent <MeshRenderer>(); } if (mRenderer == null) { mRenderer = gameObject.AddComponent <MeshRenderer>(); } this.UpdateMaterials(); } else { if (mFilter.mesh != null) { mFilter.mesh.Clear(); } Debug.LogError("UIWidgets must fill the buffer with 4 vertices per quad. Found " + vertex_count); } }
/// <summary> /// Show the selection wizard. /// </summary> static public void Show <T> (OnSelectionCallback cb, int?index) where T : Object { System.Type type = typeof(T); XfgjComponentSelector comp = ScriptableWizard.DisplayWizard <XfgjComponentSelector>("Select a " + GetName(type)); comp.mType = type; comp.mCallback = cb; comp.index = index; if (type == typeof(UIAtlas) || type == typeof(UIFont)) { BetterList <T> list = new BetterList <T>(); string[] paths = AssetDatabase.GetAllAssetPaths(); for (int i = 0; i < paths.Length; ++i) { string path = paths[i]; if (path.EndsWith(".prefab", System.StringComparison.OrdinalIgnoreCase)) { GameObject obj = AssetDatabase.LoadMainAssetAtPath(path) as GameObject; if (obj != null && PrefabUtility.GetPrefabType(obj) == PrefabType.Prefab) { T t = obj.GetComponent(typeof(T)) as T; if (t != null) { list.Add(t); } } } } comp.mObjects = list.ToArray(); } else if (type == typeof(SceneAsset)) { BetterList <Object> list = new BetterList <Object>(); string[] paths = AssetDatabase.GetAllAssetPaths(); for (int i = 0; i < paths.Length; ++i) { string path = paths[i]; if (path.EndsWith(XfgjEditor.SCENE_EXT, System.StringComparison.OrdinalIgnoreCase) && path.Contains(XfgjEditor.SCENE_FOLDER)) { SceneAsset sceneAsset = SceneAsset.CreateInstance <SceneAsset>(); sceneAsset.assetPath = path; list.Add(sceneAsset); } } comp.mObjects = list.ToArray(); } else { comp.mObjects = Resources.FindObjectsOfTypeAll(typeof(T)); } }
protected virtual void BuildMesh() { _verts.Clear(); _tris.Clear(); _colours.Clear(); //--- int vc = _verts.size; Vector3 scale = Vector3.one * SCALE; // points for (int i = 0; i < _verlet._points.Length; ++i) { Vector3 pos = _verlet._points[i].curr_mat.GetColumn(3); //UtilShape.BuildCube(pos, Quaternion.identity, scale * 0.3f, ref _verts, ref _tris); UtilShape.BuildSphere(pos, Quaternion.identity, scale * 0.3f, 8, 6, ref _verts, ref _tris); } for (int c = vc; c < _verts.size; ++c) { _colours.Add(col_joint); } vc = _verts.size; // connections for (int i = 0; i < _verlet._pos_constraints.Length; ++i) { Verlet.ConstraintPosition cp = _verlet._pos_constraints[i]; Vector3 p0 = _verlet.GetPointPos(cp.index_0); Vector3 p1 = _verlet.GetPointPos(cp.index_1); UtilShape.BuildCylinder(p0, p1, SCALE * 0.2f, ref _verts, ref _tris); Debug.DrawLine(transform.position + p0, transform.position + p1, Color.red); } for (int c = vc; c < _verts.size; ++c) { _colours.Add(col_stem); } vc = _verts.size; //--- _mf.mesh.Clear(); _mf.mesh.vertices = _verts.ToArray(); _mf.mesh.triangles = _tris.ToArray(); _mf.mesh.colors = _colours.ToArray(); _mf.mesh.RecalculateBounds(); _mf.mesh.RecalculateNormals(); }
public void Add(BetterList <T> list, int length) { AllocateMore(length); T[] array = list.ToArray(); if (array == null) { return; } System.Array.Copy(array, 0, buffer, size, length); size += length; }
private void RenderLines() { if (mMesh.vertexCount != mVertexList.size) { mMesh.Clear(); } mMesh.vertices = mVertexList.ToArray(); int indexCount = (mVertexList.size - 2) * 3; mMesh.colors = (mColorList.ToArray()); mMesh.SetTriangles(mTriangles, 0); mFilter.mesh = mMesh; }
private int railc; // current collided rail collider void Awake() { int i, j; allRails = GameObject.FindGameObjectsWithTag("Rail"); for (i = 0; i < allRails.Length; i++) { for (j = 0; j < allRails[i].transform.childCount - 1; j++) { vecLRails.Add(allRails[i].transform.GetChild(j + 1).position - allRails[i].transform.GetChild(j).position); posLRails.Add(allRails[i].transform.GetChild(j)); //Debug.Log("railVecs: "+(Vector3)(allRails[i].transform.GetChild(j+1).position - allRails[i].transform.GetChild(j).position)); } } vecRails = vecLRails.ToArray(); vecLRails.Release(); posRails = posLRails.ToArray(); posLRails.Release(); }
/// <summary> /// Search the entire project for required assets. /// </summary> void Search() { mSearched = true; string[] paths = AssetDatabase.GetAllAssetPaths(); bool isComponent = mType.IsSubclassOf(typeof(Component)); BetterList <Object> list = new BetterList <Object>(); for (int i = 0; i < paths.Length; ++i) { string path = paths[i]; if (path.EndsWith(".prefab", System.StringComparison.OrdinalIgnoreCase)) { EditorUtility.DisplayProgressBar("Loading", "Searching assets, please wait...", (float)i / paths.Length); Object obj = AssetDatabase.LoadMainAssetAtPath(path); if (obj == null) { continue; } if (!isComponent) { System.Type t = obj.GetType(); if (t == mType || t.IsSubclassOf(mType)) { list.Add(obj); } } else if (PrefabUtility.GetPrefabType(obj) == PrefabType.Prefab) { Object t = (obj as GameObject).GetComponent(mType); if (t != null) { list.Add(t); } } } } list.Sort(delegate(Object a, Object b) { return(a.name.CompareTo(b.name)); }); mObjects = list.ToArray(); EditorUtility.ClearProgressBar(); }
protected override void GeneratePlant() { BetterList <InitPoint> points = new BetterList <InitPoint>(); InitPoint p = new InitPoint(); p.pos = Vector3.zero; p.is_fixed = true; points.Add(p); int num_links = Random.Range(min_links, max_links); int attempt_count = 0; const int max_attempt = 1000; int link_count = 0; while (link_count < num_links && attempt_count < max_attempt) { attempt_count++; InitPoint prev_point = points[link_count]; p = new InitPoint(); float link_height = Random.Range(min_link_height, max_link_height); float offset = Random.Range(min_offset, max_offset); Vector3 rnd = Random.insideUnitSphere * offset; p.pos = prev_point.pos + new Vector3(0f, link_height, 0f) + rnd; p.parent = link_count; p.soft_clamp = true; p.soft_min = 0f; p.soft_max = 0.1f; points.Add(p); link_count++; } init_data = points.ToArray(); }
static void CompareTwoAtlas(){ GameObject[] gameObjs = Selection.gameObjects; UIAtlas oldUIAltas = gameObjs[0].GetComponent<UIAtlas>(); UIAtlas newUIAltas = gameObjs[1].GetComponent<UIAtlas>(); BetterList<string> oldNames = oldUIAltas.GetListOfSprites(); BetterList<string> newNames = newUIAltas.GetListOfSprites(); Debug.Log("Old Counts:"+oldNames.ToArray().Length); Debug.Log("New Counts:"+newNames.ToArray().Length); foreach(string name in oldNames){ newNames.Remove(name); Debug.Log("delete:"+name); } foreach(string name in newNames){ Debug.LogWarning("The New Texture:"+name); } }
protected virtual void BuildMesh() { _verts.Clear(); _tris.Clear(); _colours.Clear(); //--- int vc = _verts.size; //UtilShape.BuildSphere(Vector3.zero, Quaternion.identity, Vector3.one, 24, 16, // ref _verts, ref _tris); for (int i = vc; i < _verts.size; ++i) { _colours.Add(Color.white); } vc = _verts.size; UtilShape.BuildSphere(new Vector3(0f, 0f, 0f), Quaternion.identity, Vector3.one * 1f, 12, 8, ref _verts, ref _tris); for (int i = vc; i < _verts.size; ++i) { _colours.Add(Color.cyan); } vc = _verts.size; //--- _mf.mesh.Clear(); _mf.mesh.vertices = _verts.ToArray(); _mf.mesh.triangles = _tris.ToArray(); _mf.mesh.colors = _colours.ToArray(); _mf.mesh.RecalculateBounds(); _mf.mesh.RecalculateNormals(); }
internal static string getSprite(UIAtlas atlas, string uispriteName, ExportPreset preset) { Material atlasMaterial = atlas.spriteMaterial; Texture2D texture2D = (Texture2D)atlasMaterial.GetTexture("_MainTex"); string res = null; if (texture2D != null) { string picturePath = AssetDatabase.GetAssetPath(texture2D.GetInstanceID()); //Texture2D copyTexture = DuplicateTexture(texture2D); //picturePath = path.Split('.')[0] + ".png"; string texturePath = new WXTexture(texture2D).Export(preset); JSONObject metadata = TextureUtil.getMeta(texture2D); BetterList <string> allSpriteList = atlas.GetListOfSprites(); string[] list = allSpriteList.ToArray(); foreach (string spriteName in list) { UISpriteData currentData = atlas.GetSprite(spriteName); WXSpriteFrame spriteConverter = new WXSpriteFrame(currentData, texturePath, picturePath); string uuid = spriteConverter.Export(preset); // 这里不需要了,外部去给hierarchyContext addResource就好 if (spriteName == uispriteName) { res = uuid; return(res); // WXBeefBallExportContext.addDep(uuid); } //else //{ // WXBeefBallExportContext.addNoDependence(uuid); //} } } return(res); }
//------- public Verlet(Plant.InitPoint[] init_data, Transform parent) { _parent = parent; // init from init data //-------------------------------------------------- _points = new Point[init_data.Length]; for (int i = 0; i < init_data.Length; ++i) { if (init_data[i].parent < 0) { init_data[i].is_fixed = true; } // transform init_data[i].pos *= Plant.SCALE; _points[i] = new Point(); _points[i].curr_mat.SetTRS(init_data[i].pos, Quaternion.identity, Vector3.one); _points[i].prev_mat = _points[i].curr_mat; _points[i].is_fixed = init_data[i].is_fixed; } BetterList <ConstraintPosition> new_const_pos = new BetterList <ConstraintPosition>(); for (int i = 0; i < init_data.Length; ++i) { if (init_data[i].parent >= 0) { ConstraintPosition cp = new ConstraintPosition(); cp.index_0 = i; cp.index_1 = init_data[i].parent; new_const_pos.Add(cp); } } _pos_constraints = new ConstraintPosition[0]; if (new_const_pos.size > 0) { _pos_constraints = new_const_pos.ToArray(); } BetterList <ConstraintSoft> new_const_soft = new BetterList <ConstraintSoft>(); for (int i = 0; i < init_data.Length; ++i) { if (init_data[i].soft_clamp) { ConstraintSoft cs = new ConstraintSoft(); cs.index_0 = i; cs.index_parent = init_data[i].parent; cs.min_dist = init_data[i].soft_min * Plant.SCALE; cs.max_dist = init_data[i].soft_max * Plant.SCALE; new_const_soft.Add(cs); } } _soft_constraints = new ConstraintSoft[0]; if (new_const_soft.size > 0) { _soft_constraints = new_const_soft.ToArray(); } //-------------------------------------------------- for (int i = 0; i < _pos_constraints.Length; ++i) { Vector3 p0 = _points[_pos_constraints[i].index_0].curr_mat.GetColumn(3); Vector3 p1 = _points[_pos_constraints[i].index_1].curr_mat.GetColumn(3); float d = Vector3.Distance(p0, p1); _pos_constraints[i].rest_length = d; } for (int i = 0; i < _soft_constraints.Length; ++i) { Vector3 p0 = _points[_soft_constraints[i].index_0].curr_mat.GetColumn(3); Vector3 p1 = _points[_soft_constraints[i].index_parent].curr_mat.GetColumn(3); Vector3 offset = p0 - p1; _soft_constraints[i].target_offset = offset; } }
protected override void GeneratePlant() { BetterList <InitPoint> points = new BetterList <InitPoint>(); InitPoint p = new InitPoint(); p.pos = Vector3.zero; p.is_fixed = true; points.Add(p); float height = Random.Range(min_height, max_height); int num_fuzz = Random.Range(min_fuzz, max_fuzz); float fuzz_dist = Random.Range(min_fuzz_dist, max_fuzz_dist); p = new InitPoint(); p.pos = new Vector3(0f, height, 0f); p.parent = 0; p.soft_min = 0.05f; p.soft_max = 0.05f; p.soft_clamp = true; points.Add(p); BetterList <Vector3> fuzz_points = new BetterList <Vector3>(); BetterList <Vector3> fuzz_directions = new BetterList <Vector3>(); fuzz_directions.Add(-Vector3.up); int attempt_count = 0; const int max_attempt = 1000; int fuzz_count = 0; while (fuzz_count < num_fuzz && attempt_count < max_attempt) { attempt_count++; p = new InitPoint(); Vector3 rnd = Random.insideUnitSphere * fuzz_dist; rnd += rnd.normalized * 0.2f; p.pos = new Vector3(0f, height, 0f) + rnd; float min_angle = GetMinAngle(ref fuzz_directions, rnd); if (min_angle < 10f) { continue; } float min_dist = GetMinDist(ref fuzz_points, p.pos); if (min_dist < 0.5f) { continue; } p.parent = 1; p.soft_clamp = true; p.soft_min = 0.05f; p.soft_max = 0.1f; points.Add(p); fuzz_count++; fuzz_directions.Add(rnd); fuzz_points.Add(p.pos); } init_data = points.ToArray(); }
/// <summary> /// Create a bitmap font from the specified dynamic font. /// </summary> static public bool CreateFont(Font ttf, int size, int faceIndex, string characters, out BMFont font, out Texture2D tex) { font = null; tex = null; if (ttf == null || !isPresent) { return(false); } IntPtr lib = IntPtr.Zero; IntPtr face = IntPtr.Zero; if (FT_Init_FreeType(out lib) != 0) { Debug.LogError("Failed to initialize FreeType"); return(false); } string fileName = Application.dataPath.Substring(0, Application.dataPath.Length - "Assets".Length) + UnityEditor.AssetDatabase.GetAssetPath(ttf); if (!File.Exists(fileName)) { Debug.LogError("Unable to use the chosen font."); } else if (FT_New_Face(lib, fileName, faceIndex, out face) != 0) { Debug.LogError("Unable to use the chosen font (FT_New_Face)."); } else { font = new BMFont(); font.charSize = size; Color32 white = Color.white; BetterList <int> entries = new BetterList <int>(); BetterList <Texture2D> textures = new BetterList <Texture2D>(); FT_FaceRec faceRec = (FT_FaceRec)Marshal.PtrToStructure(face, typeof(FT_FaceRec)); FT_Set_Pixel_Sizes(face, 0, (uint)size); // Calculate the baseline value that would let the printed font be centered vertically //int ascender = (faceRec.met.ascender >> 6); //int descender = (faceRec.descender >> 6); //int baseline = ((ascender - descender) >> 1); //if ((baseline & 1) == 1) --baseline; //Debug.Log(ascender + " " + descender + " " + baseline); // Space character is not renderable FT_Load_Glyph(face, FT_Get_Char_Index(face, 32), FT_LOAD_DEFAULT); FT_GlyphSlotRec space = (FT_GlyphSlotRec)Marshal.PtrToStructure(faceRec.glyph, typeof(FT_GlyphSlotRec)); // Space is not visible and doesn't have a texture BMGlyph spaceGlyph = font.GetGlyph(32, true); spaceGlyph.offsetX = 0; spaceGlyph.offsetY = 0; spaceGlyph.advance = (space.metrics.horiAdvance >> 6); spaceGlyph.channel = 15; spaceGlyph.x = 0; spaceGlyph.y = 0; spaceGlyph.width = 0; spaceGlyph.height = 0; // Save kerning information for (int b = 0; b < characters.Length; ++b) { uint ch2 = characters[b]; if (ch2 == 32) { continue; } FT_Vector vec; if (FT_Get_Kerning(face, ch2, 32, 0, out vec) != 0) { continue; } int offset = (vec.x >> 6); if (offset != 0) { spaceGlyph.SetKerning((int)ch2, offset); } } // Run through all requested characters foreach (char ch in characters) { uint charIndex = FT_Get_Char_Index(face, (uint)ch); FT_Load_Glyph(face, charIndex, FT_LOAD_DEFAULT); FT_GlyphSlotRec glyph = (FT_GlyphSlotRec)Marshal.PtrToStructure(faceRec.glyph, typeof(FT_GlyphSlotRec)); FT_Render_Glyph(ref glyph, FT_Render_Mode.FT_RENDER_MODE_NORMAL); if (glyph.bitmap.width > 0 && glyph.bitmap.rows > 0) { byte[] buffer = new byte[glyph.bitmap.width * glyph.bitmap.rows]; Marshal.Copy(glyph.bitmap.buffer, buffer, 0, buffer.Length); Texture2D texture = new Texture2D(glyph.bitmap.width, glyph.bitmap.rows, UnityEngine.TextureFormat.ARGB32, false); Color32[] colors = new Color32[buffer.Length]; for (int i = 0, y = 0; y < glyph.bitmap.rows; ++y) { for (int x = 0; x < glyph.bitmap.width; ++x) { white.a = buffer[i++]; colors[x + glyph.bitmap.width * (glyph.bitmap.rows - y - 1)] = white; } } // Save the texture texture.SetPixels32(colors); texture.Apply(); textures.Add(texture); entries.Add(ch); // Record the metrics BMGlyph bmg = font.GetGlyph(ch, true); bmg.offsetX = (glyph.metrics.horiBearingX >> 6); bmg.offsetY = -(glyph.metrics.horiBearingY >> 6); bmg.advance = (glyph.metrics.horiAdvance >> 6); bmg.channel = 15; // Save kerning information for (int b = 0; b < characters.Length; ++b) { uint ch2 = characters[b]; if (ch2 == ch) { continue; } FT_Vector vec; if (FT_Get_Kerning(face, ch2, ch, 0, out vec) != 0) { continue; } int offset = (vec.x / 64); if (offset != 0) { bmg.SetKerning((int)ch2, offset); } } } } // Create a packed texture with all the characters tex = new Texture2D(32, 32, TextureFormat.ARGB32, false); Rect[] rects = tex.PackTextures(textures.ToArray(), 1); // Make the RGB channel pure white Color32[] cols = tex.GetPixels32(); for (int i = 0, imax = cols.Length; i < imax; ++i) { Color32 c = cols[i]; c.r = 255; c.g = 255; c.b = 255; cols[i] = c; } tex.SetPixels32(cols); tex.Apply(); font.texWidth = tex.width; font.texHeight = tex.height; int min = int.MaxValue; int max = int.MinValue; // Other glyphs are visible and need to be added for (int i = 0; i < entries.size; ++i) { // Destroy the texture now that it's a part of an atlas UnityEngine.Object.DestroyImmediate(textures[i]); textures[i] = null; Rect rect = rects[i]; // Set the texture coordinates BMGlyph glyph = font.GetGlyph(entries[i], true); glyph.x = Mathf.RoundToInt(rect.x * font.texWidth); glyph.y = Mathf.RoundToInt(rect.y * font.texHeight); glyph.width = Mathf.RoundToInt(rect.width * font.texWidth); glyph.height = Mathf.RoundToInt(rect.height * font.texHeight); // Flip the Y since the UV coordinate system is different glyph.y = font.texHeight - glyph.y - glyph.height; max = Mathf.Max(max, -glyph.offsetY); min = Mathf.Min(min, -glyph.offsetY - glyph.height); } int baseline = size + min; baseline += ((max - min - size) >> 1); // Offset all glyphs so that they are not using the baseline for (int i = 0; i < entries.size; ++i) { BMGlyph glyph = font.GetGlyph(entries[i], true); glyph.offsetY += baseline; } } if (face != IntPtr.Zero) { FT_Done_Face(face); } #if !UNITY_3_5 if (lib != IntPtr.Zero) { FT_Done_FreeType(lib); } #endif return(tex != null); }
/// <summary> /// Draw the inspector widget. /// </summary> public override void OnInspectorGUI() { EditorGUIUtility.LookLikeControls(80f); InvDatabase db = target as InvDatabase; NGUIEditorTools.DrawSeparator(); InvBaseItem item = null; if (db.items == null || db.items.Count == 0) { mIndex = 0; } else { mIndex = Mathf.Clamp(mIndex, 0, db.items.Count - 1); item = db.items[mIndex]; } if (mConfirmDelete) { // Show the confirmation dialog GUILayout.Label("Are you sure you want to delete '" + item.name + "'?"); NGUIEditorTools.DrawSeparator(); GUILayout.BeginHorizontal(); { GUI.backgroundColor = Color.green; if (GUILayout.Button("Cancel")) { mConfirmDelete = false; } GUI.backgroundColor = Color.red; if (GUILayout.Button("Delete")) { NGUIEditorTools.RegisterUndo("Delete Inventory Item", db); db.items.RemoveAt(mIndex); mConfirmDelete = false; } GUI.backgroundColor = Color.white; } GUILayout.EndHorizontal(); } else { // Database icon atlas UIAtlas atlas = EditorGUILayout.ObjectField("Icon Atlas", db.iconAtlas, typeof(UIAtlas), false) as UIAtlas; if (atlas != db.iconAtlas) { NGUIEditorTools.RegisterUndo("Databse Atlas change", db); db.iconAtlas = atlas; foreach (InvBaseItem i in db.items) { i.iconAtlas = atlas; } } // Database ID int dbID = EditorGUILayout.IntField("Database ID", db.databaseID); if (dbID != db.databaseID) { NGUIEditorTools.RegisterUndo("Database ID change", db); db.databaseID = dbID; } // "New" button GUI.backgroundColor = Color.green; if (GUILayout.Button("New Item")) { NGUIEditorTools.RegisterUndo("Add Inventory Item", db); InvBaseItem bi = new InvBaseItem(); bi.iconAtlas = db.iconAtlas; bi.id16 = (db.items.Count > 0) ? db.items[db.items.Count - 1].id16 + 1 : 0; db.items.Add(bi); mIndex = db.items.Count - 1; if (item != null) { bi.name = "Copy of " + item.name; bi.description = item.description; bi.slot = item.slot; bi.color = item.color; bi.iconName = item.iconName; bi.attachment = item.attachment; bi.minItemLevel = item.minItemLevel; bi.maxItemLevel = item.maxItemLevel; foreach (InvStat stat in item.stats) { InvStat copy = new InvStat(); copy.id = stat.id; copy.amount = stat.amount; copy.modifier = stat.modifier; bi.stats.Add(copy); } } else { bi.name = "New Item"; bi.description = "Item Description"; } item = bi; } GUI.backgroundColor = Color.white; if (item != null) { NGUIEditorTools.DrawSeparator(); // Navigation section GUILayout.BeginHorizontal(); { if (mIndex == 0) { GUI.color = Color.grey; } if (GUILayout.Button("<<")) { mConfirmDelete = false; --mIndex; } GUI.color = Color.white; mIndex = EditorGUILayout.IntField(mIndex + 1, GUILayout.Width(40f)) - 1; GUILayout.Label("/ " + db.items.Count, GUILayout.Width(40f)); if (mIndex + 1 == db.items.Count) { GUI.color = Color.grey; } if (GUILayout.Button(">>")) { mConfirmDelete = false; ++mIndex; } GUI.color = Color.white; } GUILayout.EndHorizontal(); NGUIEditorTools.DrawSeparator(); // Item name and delete item button GUILayout.BeginHorizontal(); { string itemName = EditorGUILayout.TextField("Item Name", item.name); GUI.backgroundColor = Color.red; if (GUILayout.Button("Delete", GUILayout.Width(55f))) { mConfirmDelete = true; } GUI.backgroundColor = Color.white; if (!itemName.Equals(item.name)) { NGUIEditorTools.RegisterUndo("Rename Item", db); item.name = itemName; } } GUILayout.EndHorizontal(); string itemDesc = GUILayout.TextArea(item.description, 200, GUILayout.Height(100f)); InvBaseItem.Slot slot = (InvBaseItem.Slot)EditorGUILayout.EnumPopup("Slot", item.slot); string iconName = ""; float iconSize = 64f; bool drawIcon = false; float extraSpace = 0f; if (item.iconAtlas != null) { BetterList <string> sprites = item.iconAtlas.GetListOfSprites(); sprites.Insert(0, "<None>"); int index = 0; string spriteName = (item.iconName != null) ? item.iconName : sprites[0]; // We need to find the sprite in order to have it selected if (!string.IsNullOrEmpty(spriteName)) { for (int i = 1; i < sprites.size; ++i) { if (spriteName.Equals(sprites[i], System.StringComparison.OrdinalIgnoreCase)) { index = i; break; } } } // Draw the sprite selection popup index = EditorGUILayout.Popup("Icon", index, sprites.ToArray()); UIAtlas.Sprite sprite = (index > 0) ? item.iconAtlas.GetSprite(sprites[index]) : null; if (sprite != null) { iconName = sprite.name; Material mat = item.iconAtlas.spriteMaterial; if (mat != null) { Texture2D tex = mat.mainTexture as Texture2D; if (tex != null) { drawIcon = true; Rect rect = sprite.outer; if (item.iconAtlas.coordinates == UIAtlas.Coordinates.Pixels) { rect = NGUIMath.ConvertToTexCoords(rect, tex.width, tex.height); } GUILayout.Space(4f); GUILayout.BeginHorizontal(); { GUILayout.Space(Screen.width - iconSize); DrawSprite(tex, rect, null, false); } GUILayout.EndHorizontal(); extraSpace = iconSize * (float)sprite.outer.height / sprite.outer.width; } } } } // Item level range GUILayout.BeginHorizontal(); GUILayout.Label("Level Range", GUILayout.Width(77f)); int min = EditorGUILayout.IntField(item.minItemLevel, GUILayout.MinWidth(40f)); int max = EditorGUILayout.IntField(item.maxItemLevel, GUILayout.MinWidth(40f)); if (drawIcon) { GUILayout.Space(iconSize); } GUILayout.EndHorizontal(); // Game Object attachment field, left of the icon GUILayout.BeginHorizontal(); GameObject go = (GameObject)EditorGUILayout.ObjectField("Attachment", item.attachment, typeof(GameObject), false); if (drawIcon) { GUILayout.Space(iconSize); } GUILayout.EndHorizontal(); // Color tint field, left of the icon GUILayout.BeginHorizontal(); Color color = EditorGUILayout.ColorField("Color", item.color); if (drawIcon) { GUILayout.Space(iconSize); } GUILayout.EndHorizontal(); // Calculate the extra spacing necessary for the icon to show up properly and not overlap anything if (drawIcon) { extraSpace = Mathf.Max(0f, extraSpace - 60f); GUILayout.Space(extraSpace); } // Item stats NGUIEditorTools.DrawSeparator(); if (item.stats != null) { for (int i = 0; i < item.stats.Count; ++i) { InvStat stat = item.stats[i]; GUILayout.BeginHorizontal(); { InvStat.Identifier iden = (InvStat.Identifier)EditorGUILayout.EnumPopup(stat.id, GUILayout.Width(80f)); // Color the field red if it's negative, green if it's positive if (stat.amount > 0) { GUI.backgroundColor = Color.green; } else if (stat.amount < 0) { GUI.backgroundColor = Color.red; } int amount = EditorGUILayout.IntField(stat.amount, GUILayout.Width(40f)); GUI.backgroundColor = Color.white; InvStat.Modifier mod = (InvStat.Modifier)EditorGUILayout.EnumPopup(stat.modifier); GUI.backgroundColor = Color.red; if (GUILayout.Button("X", GUILayout.Width(20f))) { NGUIEditorTools.RegisterUndo("Delete Item Stat", db); item.stats.RemoveAt(i); --i; } else if (iden != stat.id || amount != stat.amount || mod != stat.modifier) { NGUIEditorTools.RegisterUndo("Item Stats", db); stat.id = iden; stat.amount = amount; stat.modifier = mod; } GUI.backgroundColor = Color.white; } GUILayout.EndHorizontal(); } } if (GUILayout.Button("Add Stat", GUILayout.Width(80f))) { NGUIEditorTools.RegisterUndo("Add Item Stat", db); InvStat stat = new InvStat(); stat.id = InvStat.Identifier.Armor; item.stats.Add(stat); } // Save all values if (!itemDesc.Equals(item.description) || slot != item.slot || go != item.attachment || color != item.color || min != item.minItemLevel || max != item.maxItemLevel || !iconName.Equals(item.iconName)) { NGUIEditorTools.RegisterUndo("Item Properties", db); item.description = itemDesc; item.slot = slot; item.attachment = go; item.color = color; item.iconName = iconName; item.minItemLevel = min; item.maxItemLevel = max; } } } }
/// <summary> /// Set the draw call's geometry. /// </summary> public void Set(BetterList<Vector3> verts, BetterList<Vector3> norms, BetterList<Vector4> tans, BetterList<Vector2> uvs, BetterList<Color> cols) { int count = verts.size; // Safety check to ensure we get valid values if (count > 0 && (count == uvs.size && count == cols.size) && (count % 4) == 0) { int index = 0; // It takes 6 indices to draw a quad of 4 vertices int indexCount = (count >> 1) * 3; // Populate the index buffer if (mIndices == null || mIndices.Length != indexCount) { mIndices = new int[indexCount]; for (int i = 0; i < count; i += 4) { mIndices[index++] = i; mIndices[index++] = i + 1; mIndices[index++] = i + 2; mIndices[index++] = i + 2; mIndices[index++] = i + 3; mIndices[index++] = i; } } // Cache all components if (mFilter == null) mFilter = gameObject.GetComponent<MeshFilter>(); if (mFilter == null) mFilter = gameObject.AddComponent<MeshFilter>(); if (mRen == null) mRen = gameObject.GetComponent<MeshRenderer>(); if (mRen == null) { mRen = gameObject.AddComponent<MeshRenderer>(); UpdateMaterials(); } if (verts.size < 65000) { if (mMesh == null) { mMesh = new Mesh(); mMesh.name = "UIDrawCall for " + mSharedMat.name; } else { mMesh.Clear(); } // Set the mesh values mMesh.vertices = verts.ToArray(); if (norms != null) mMesh.normals = norms.ToArray(); if (tans != null) mMesh.tangents = tans.ToArray(); mMesh.uv = uvs.ToArray(); mMesh.colors = cols.ToArray(); mMesh.triangles = mIndices; mMesh.RecalculateBounds(); mFilter.mesh = mMesh; } else { if (mMesh != null) mMesh.Clear(); Debug.LogError("Too many vertices on one panel: " + verts.size); } } else { if (mMesh != null) mMesh.Clear(); Debug.LogError("UIWidgets must fill the buffer with 4 vertices per quad. Found " + count); } }
public void Set(BetterList<Vector3> verts, BetterList<Vector3> norms, BetterList<Vector4> tans, BetterList<Vector2> uvs, BetterList<Color32> cols) { int size = verts.size; if (((size > 0) && (size == uvs.size)) && ((size == cols.size) && ((size % 4) == 0))) { if (this.mFilter == null) { this.mFilter = base.gameObject.GetComponent<MeshFilter>(); } if (this.mFilter == null) { this.mFilter = base.gameObject.AddComponent<MeshFilter>(); } if (verts.size < 0xfde8) { int indexCount = (size >> 1) * 3; bool flag = (this.mIndices == null) || (this.mIndices.Length != indexCount); if (this.mMesh == null) { this.mMesh = new Mesh(); this.mMesh.hideFlags = HideFlags.DontSave; this.mMesh.name = (this.mMaterial == null) ? "Mesh" : this.mMaterial.name; this.mMesh.MarkDynamic(); flag = true; } bool flag2 = (((uvs.buffer.Length != verts.buffer.Length) || (cols.buffer.Length != verts.buffer.Length)) || ((norms != null) && (norms.buffer.Length != verts.buffer.Length))) || ((tans != null) && (tans.buffer.Length != verts.buffer.Length)); if (flag2 || (verts.buffer.Length > 0xfde8)) { if (flag2 || (this.mMesh.vertexCount != verts.size)) { this.mMesh.Clear(); flag = true; } this.mMesh.vertices = verts.ToArray(); this.mMesh.uv = uvs.ToArray(); this.mMesh.colors32 = cols.ToArray(); if (norms != null) { this.mMesh.normals = norms.ToArray(); } if (tans != null) { this.mMesh.tangents = tans.ToArray(); } } else { if (this.mMesh.vertexCount != verts.buffer.Length) { this.mMesh.Clear(); flag = true; } this.mMesh.vertices = verts.buffer; this.mMesh.uv = uvs.buffer; this.mMesh.colors32 = cols.buffer; if (norms != null) { this.mMesh.normals = norms.buffer; } if (tans != null) { this.mMesh.tangents = tans.buffer; } } if (flag) { this.mIndices = this.GenerateCachedIndexBuffer(size, indexCount); this.mMesh.triangles = this.mIndices; } if (this.mClipping != Clipping.None) { this.mMesh.RecalculateBounds(); } this.mFilter.mesh = this.mMesh; } else { if (this.mFilter.mesh != null) { this.mFilter.mesh.Clear(); } Debug.LogError("Too many vertices on one panel: " + verts.size); } if (this.mRenderer == null) { this.mRenderer = base.gameObject.GetComponent<MeshRenderer>(); } if (this.mRenderer == null) { this.mRenderer = base.gameObject.AddComponent<MeshRenderer>(); } this.UpdateMaterials(); } else { if (this.mFilter.mesh != null) { this.mFilter.mesh.Clear(); } Debug.LogError("UIWidgets must fill the buffer with 4 vertices per quad. Found " + size); } }
public void Set(BetterList <Vector3> verts, BetterList <Vector3> norms, BetterList <Vector4> tans, BetterList <Vector2> uvs, BetterList <Color32> cols) { var size = verts.size; if (size > 0 && size == uvs.size && size == cols.size && size % 4 == 0) { if (mFilter == null) { mFilter = gameObject.GetComponent <MeshFilter>(); } if (mFilter == null) { mFilter = gameObject.AddComponent <MeshFilter>(); } if (mRen == null) { mRen = gameObject.GetComponent <MeshRenderer>(); } if (mRen == null) { mRen = gameObject.AddComponent <MeshRenderer>(); UpdateMaterials(); } else if (mClippedMat != null && mClippedMat.mainTexture != mSharedMat.mainTexture) { UpdateMaterials(); } if (verts.size < 65000) { var num2 = (size >> 1) * 3; var rebuildIndices = mIndices == null || mIndices.Length != num2; if (rebuildIndices) { mIndices = new int[num2]; var num3 = 0; for (var i = 0; i < size; i += 4) { mIndices[num3++] = i; mIndices[num3++] = i + 1; mIndices[num3++] = i + 2; mIndices[num3++] = i + 2; mIndices[num3++] = i + 3; mIndices[num3++] = i; } } var mesh = GetMesh(ref rebuildIndices, verts.size); mesh.vertices = verts.ToArray(); if (norms != null) { mesh.normals = norms.ToArray(); } if (tans != null) { mesh.tangents = tans.ToArray(); } mesh.uv = uvs.ToArray(); mesh.colors32 = cols.ToArray(); if (rebuildIndices) { mesh.triangles = mIndices; } mesh.RecalculateBounds(); mFilter.mesh = mesh; } else { if (mFilter.mesh != null) { mFilter.mesh.Clear(); } Debug.LogError("Too many vertices on one panel: " + verts.size); } } else { if (mFilter.mesh != null) { mFilter.mesh.Clear(); } Debug.LogError("UIWidgets must fill the buffer with 4 vertices per quad. Found " + size); } }
/// <summary> /// Set the draw call's geometry. /// </summary> public void UpdateGeometry() { int count = verts.size; // Safety check to ensure we get valid values if (count > 0 && (count == uvs.size && count == cols.size) && (count % 4) == 0) { // Cache all components if (mFilter == null) { mFilter = gameObject.GetComponent <MeshFilter>(); } if (mFilter == null) { mFilter = gameObject.AddComponent <MeshFilter>(); } if (verts.size < 65000) { // Populate the index buffer int indexCount = (count >> 1) * 3; bool setIndices = (mIndices == null || mIndices.Length != indexCount); // Create the mesh if (mMesh == null) { mMesh = new Mesh(); mMesh.hideFlags = HideFlags.DontSave; mMesh.name = (mMaterial != null) ? mMaterial.name : "Mesh"; mMesh.MarkDynamic(); setIndices = true; } #if !UNITY_FLASH // If the buffer length doesn't match, we need to trim all buffers bool trim = (uvs.buffer.Length != verts.buffer.Length) || (cols.buffer.Length != verts.buffer.Length) || (norms.buffer != null && norms.buffer.Length != verts.buffer.Length) || (tans.buffer != null && tans.buffer.Length != verts.buffer.Length); // Non-automatic render queues rely on Z position, so it's a good idea to trim everything if (!trim && panel.renderQueue != UIPanel.RenderQueue.Automatic) { trim = (mMesh == null || mMesh.vertexCount != verts.buffer.Length); } // NOTE: Apparently there is a bug with Adreno devices: // http://www.tasharen.com/forum/index.php?topic=8415.0 // According to version notes it's fixed in 4.5 rc5. #if !UNITY_4_3 || !UNITY_ANDROID // If the number of vertices in the buffer is less than half of the full buffer, trim it if (!trim && (verts.size << 1) < verts.buffer.Length) { trim = true; } #endif mTriangles = (verts.size >> 1); if (trim || verts.buffer.Length > 65000) { if (trim || mMesh.vertexCount != verts.size) { mMesh.Clear(); setIndices = true; } mMesh.vertices = verts.ToArray(); mMesh.uv = uvs.ToArray(); mMesh.colors32 = cols.ToArray(); if (norms != null) { mMesh.normals = norms.ToArray(); } if (tans != null) { mMesh.tangents = tans.ToArray(); } } else { if (mMesh.vertexCount != verts.buffer.Length) { mMesh.Clear(); setIndices = true; } mMesh.vertices = verts.buffer; mMesh.uv = uvs.buffer; mMesh.colors32 = cols.buffer; if (norms != null) { mMesh.normals = norms.buffer; } if (tans != null) { mMesh.tangents = tans.buffer; } } #else mTriangles = (verts.size >> 1); if (mMesh.vertexCount != verts.size) { mMesh.Clear(); setIndices = true; } mMesh.vertices = verts.ToArray(); mMesh.uv = uvs.ToArray(); mMesh.colors32 = cols.ToArray(); if (norms != null) { mMesh.normals = norms.ToArray(); } if (tans != null) { mMesh.tangents = tans.ToArray(); } #endif if (setIndices) { mIndices = GenerateCachedIndexBuffer(count, indexCount); mMesh.triangles = mIndices; } #if !UNITY_FLASH if (trim || !alwaysOnScreen) #endif mMesh.RecalculateBounds(); mFilter.mesh = mMesh; } else { mTriangles = 0; if (mFilter.mesh != null) { mFilter.mesh.Clear(); } Debug.LogError("Too many vertices on one panel: " + verts.size); } if (mRenderer == null) { mRenderer = gameObject.GetComponent <MeshRenderer>(); } if (mRenderer == null) { mRenderer = gameObject.AddComponent <MeshRenderer>(); #if UNITY_EDITOR mRenderer.enabled = isActive; #endif } UpdateMaterials(); } else { if (mFilter.mesh != null) { mFilter.mesh.Clear(); } Debug.LogError("UIWidgets must fill the buffer with 4 vertices per quad. Found " + count); } verts.Clear(); uvs.Clear(); cols.Clear(); norms.Clear(); tans.Clear(); }
/// <summary> /// Set the draw call's geometry. /// </summary> public void Set(BetterList<Vector3> verts, BetterList<Vector3> norms, BetterList<Vector4> tans, BetterList<Vector2> uvs, BetterList<Color32> cols) { int count = verts.size; // Safety check to ensure we get valid values if (count > 0 && (count == uvs.size && count == cols.size) && (count % 4) == 0) { // Cache all components if (mFilter == null) mFilter = gameObject.GetComponent<MeshFilter>(); if (mFilter == null) mFilter = gameObject.AddComponent<MeshFilter>(); if (mRen == null) mRen = gameObject.GetComponent<MeshRenderer>(); if (mRen == null) { mRen = gameObject.AddComponent<MeshRenderer>(); #if UNITY_EDITOR mRen.enabled = isActive; #endif UpdateMaterials(); } else if (mMat != null && mMat.mainTexture != mSharedMat.mainTexture) { UpdateMaterials(); } if (verts.size < 65000) { int indexCount = (count >> 1) * 3; bool rebuildIndices = (mIndices == null || mIndices.Length != indexCount); // Populate the index buffer if (rebuildIndices) { // It takes 6 indices to draw a quad of 4 vertices mIndices = new int[indexCount]; int index = 0; for (int i = 0; i < count; i += 4) { mIndices[index++] = i; mIndices[index++] = i + 1; mIndices[index++] = i + 2; mIndices[index++] = i + 2; mIndices[index++] = i + 3; mIndices[index++] = i; } } // Set the mesh values Mesh mesh = GetMesh(ref rebuildIndices, verts.size); mesh.vertices = verts.ToArray(); if (norms != null) mesh.normals = norms.ToArray(); if (tans != null) mesh.tangents = tans.ToArray(); mesh.uv = uvs.ToArray(); mesh.colors32 = cols.ToArray(); if (rebuildIndices) mesh.triangles = mIndices; mesh.RecalculateBounds(); mFilter.mesh = mesh; } else { if (mFilter.mesh != null) mFilter.mesh.Clear(); Debug.LogError("Too many vertices on one panel: " + verts.size); } } else { if (mFilter.mesh != null) mFilter.mesh.Clear(); Debug.LogError("UIWidgets must fill the buffer with 4 vertices per quad. Found " + count); } }
/// <summary> /// Create a bitmap font from the specified dynamic font. /// </summary> static public bool CreateFont (Font ttf, int size, int faceIndex, string characters, out BMFont font, out Texture2D tex) { font = null; tex = null; if (ttf == null || !isPresent) return false; IntPtr lib = IntPtr.Zero; IntPtr face = IntPtr.Zero; if (FT_Init_FreeType(out lib) != 0) { Debug.LogError("Failed to initialize FreeType"); return false; } string fileName = Application.dataPath.Substring(0, Application.dataPath.Length - "Assets".Length) + UnityEditor.AssetDatabase.GetAssetPath(ttf); if (!File.Exists(fileName)) { Debug.LogError("Unable to use the chosen font."); } else if (FT_New_Face(lib, fileName, faceIndex, out face) != 0) { Debug.LogError("Unable to use the chosen font (FT_New_Face)."); } else { font = new BMFont(); font.charSize = size; Color32 white = Color.white; BetterList<int> entries = new BetterList<int>(); BetterList<Texture2D> textures = new BetterList<Texture2D>(); FT_FaceRec faceRec = (FT_FaceRec)Marshal.PtrToStructure(face, typeof(FT_FaceRec)); FT_Set_Pixel_Sizes(face, 0, (uint)size); // Calculate the baseline value that would let the printed font be centered vertically //int ascender = (faceRec.met.ascender >> 6); //int descender = (faceRec.descender >> 6); //int baseline = ((ascender - descender) >> 1); //if ((baseline & 1) == 1) --baseline; //Debug.Log(ascender + " " + descender + " " + baseline); // Space character is not renderable FT_Load_Glyph(face, FT_Get_Char_Index(face, 32), FT_LOAD_DEFAULT); FT_GlyphSlotRec space = (FT_GlyphSlotRec)Marshal.PtrToStructure(faceRec.glyph, typeof(FT_GlyphSlotRec)); // Space is not visible and doesn't have a texture BMGlyph spaceGlyph = font.GetGlyph(32, true); spaceGlyph.offsetX = 0; spaceGlyph.offsetY = 0; spaceGlyph.advance = (space.metrics.horiAdvance >> 6); spaceGlyph.channel = 15; spaceGlyph.x = 0; spaceGlyph.y = 0; spaceGlyph.width = 0; spaceGlyph.height = 0; // Save kerning information for (int b = 0; b < characters.Length; ++b) { uint ch2 = characters[b]; if (ch2 == 32) continue; FT_Vector vec; if (FT_Get_Kerning(face, ch2, 32, 0, out vec) != 0) continue; int offset = (vec.x >> 6); if (offset != 0) spaceGlyph.SetKerning((int)ch2, offset); } // Run through all requested characters foreach (char ch in characters) { uint charIndex = FT_Get_Char_Index(face, (uint)ch); FT_Load_Glyph(face, charIndex, FT_LOAD_DEFAULT); FT_GlyphSlotRec glyph = (FT_GlyphSlotRec)Marshal.PtrToStructure(faceRec.glyph, typeof(FT_GlyphSlotRec)); FT_Render_Glyph(ref glyph, FT_Render_Mode.FT_RENDER_MODE_NORMAL); if (glyph.bitmap.width > 0 && glyph.bitmap.rows > 0) { byte[] buffer = new byte[glyph.bitmap.width * glyph.bitmap.rows]; Marshal.Copy(glyph.bitmap.buffer, buffer, 0, buffer.Length); Texture2D texture = new Texture2D(glyph.bitmap.width, glyph.bitmap.rows, UnityEngine.TextureFormat.ARGB32, false); Color32[] colors = new Color32[buffer.Length]; for (int i = 0, y = 0; y < glyph.bitmap.rows; ++y) { for (int x = 0; x < glyph.bitmap.width; ++x) { white.a = buffer[i++]; colors[x + glyph.bitmap.width * (glyph.bitmap.rows - y - 1)] = white; } } // Save the texture texture.SetPixels32(colors); texture.Apply(); textures.Add(texture); entries.Add(ch); // Record the metrics BMGlyph bmg = font.GetGlyph(ch, true); bmg.offsetX = (glyph.metrics.horiBearingX >> 6); bmg.offsetY = -(glyph.metrics.horiBearingY >> 6); bmg.advance = (glyph.metrics.horiAdvance >> 6); bmg.channel = 15; // Save kerning information for (int b = 0; b < characters.Length; ++b) { uint ch2 = characters[b]; if (ch2 == ch) continue; FT_Vector vec; if (FT_Get_Kerning(face, ch2, ch, 0, out vec) != 0) continue; int offset = (vec.x / 64); if (offset != 0) bmg.SetKerning((int)ch2, offset); } } } // Create a packed texture with all the characters tex = new Texture2D(32, 32, TextureFormat.ARGB32, false); Rect[] rects = tex.PackTextures(textures.ToArray(), 1); // Make the RGB channel pure white Color32[] cols = tex.GetPixels32(); for (int i = 0, imax = cols.Length; i < imax; ++i) { Color32 c = cols[i]; c.r = 255; c.g = 255; c.b = 255; cols[i] = c; } tex.SetPixels32(cols); tex.Apply(); font.texWidth = tex.width; font.texHeight = tex.height; int min = int.MaxValue; int max = int.MinValue; // Other glyphs are visible and need to be added for (int i = 0; i < entries.size; ++i) { // Destroy the texture now that it's a part of an atlas UnityEngine.Object.DestroyImmediate(textures[i]); textures[i] = null; Rect rect = rects[i]; // Set the texture coordinates BMGlyph glyph = font.GetGlyph(entries[i], true); glyph.x = Mathf.RoundToInt(rect.x * font.texWidth); glyph.y = Mathf.RoundToInt(rect.y * font.texHeight); glyph.width = Mathf.RoundToInt(rect.width * font.texWidth); glyph.height = Mathf.RoundToInt(rect.height * font.texHeight); // Flip the Y since the UV coordinate system is different glyph.y = font.texHeight - glyph.y - glyph.height; max = Mathf.Max(max, -glyph.offsetY); min = Mathf.Min(min, -glyph.offsetY - glyph.height); } int baseline = size + min; baseline += ((max - min - size) >> 1); // Offset all glyphs so that they are not using the baseline for (int i = 0; i < entries.size; ++i) { BMGlyph glyph = font.GetGlyph(entries[i], true); glyph.offsetY += baseline; } } if (face != IntPtr.Zero) FT_Done_Face(face); #if !UNITY_3_5 if (lib != IntPtr.Zero) FT_Done_FreeType(lib); #endif return (tex != null); }
/// <summary> /// 寻找所有类型的预制体 /// </summary> /// <param name="mType">M type.</param> public static Object[] Search(params System.Type[] mType) { string[] mExtensions = new string[] { ".prefab" }; string[] paths = AssetDatabase.GetAllAssetPaths(); // bool isComponent = mType.IsSubclassOf(typeof(Component)); BetterList <Object> list = new BetterList <Object>(); for (int i = 0; i < paths.Length; ++i) { string path = paths[i]; bool valid = false; for (int b = 0; b < mExtensions.Length; ++b) { if (path.EndsWith(mExtensions[b], System.StringComparison.OrdinalIgnoreCase)) { valid = true; break; } } if (!valid) { continue; } // EditorUtility.DisplayProgressBar("资源找寻中", "机器正在使出吃奶的劲搜索预制体,切勿浮躁,耐心等候……", (float)i / paths.Length); Object obj = AssetDatabase.LoadMainAssetAtPath(path); if (obj == null || list.Contains(obj)) { continue; } for (int numType = 0; numType < mType.Length; numType++) { bool isComponent = mType[numType].IsSubclassOf(typeof(Component)); if (!isComponent) { System.Type t = obj.GetType(); if (t == mType[numType] || t.IsSubclassOf(mType[numType]) && !list.Contains(obj)) { list.Add(obj); } } else if (PrefabUtility.GetPrefabType(obj) == PrefabType.Prefab) { GameObject gameobj = obj as GameObject; Object t = gameobj.GetComponent(mType[numType]); if (t != null && !list.Contains(t)) { list.Add(t); } Object[] listPre = gameobj.GetComponentsInChildren(mType[numType], true); for (int num = 0; num < listPre.Length; num++) { if (!list.Contains(listPre[num])) { list.Add(listPre[num]); } } } } EditorUtility.DisplayProgressBar("资源找寻中", "机器正在使出吃奶的劲搜索预制体,切勿浮躁,耐心等候……", (float)i / paths.Length); } //list.Sort(delegate(Object a, Object b) { return a.name.CompareTo(b.name); }); EditorUtility.ClearProgressBar(); return(list.ToArray()); }
public void TextChange() { CheckObjLoaded(); if (mText.Length > numCount) { Debug.LogError("TextWrapEx,图文混排越界!"); return; } for (int i = mText.Length; i < numCount; i++) { transList[i].gameObject.SetActive(false); } symbolList.Clear(); for (int i = 0; i < mText.Length; i++) { symbolList.Add(mText[i].ToString()); } switch (mMode) { case WrapMode.L_R: { for (int i = 0; i < symbolList.size; i++) { int index = atlas.keys.IndexOf(symbolList[i]); if (index >= 0) { rectTransList[i].sizeDelta = mImageSize; SetImage(i, atlas.values[index], new Vector3(mImageSize.x / 2.0f + (mImageSize.x + mInterval) * i, 0, 0)); } else { Debug.LogError(string.Format("TextWrapEx存在未识别的标示符 :{0}!", symbolList.ToArray().JoinToString(" "))); return; } } } break; case WrapMode.R_L: { for (int i = symbolList.size - 1; i >= 0; i--) { int index = atlas.keys.IndexOf(symbolList[i]); if (index >= 0) { rectTransList[i].sizeDelta = mImageSize; SetImage(i, atlas.values[index], new Vector3(mImageSize.x / 2.0f - (mImageSize.x + mInterval) * (symbolList.size - 1 - i), 0, 0)); } else { Debug.LogError("TextWrapEx存在未识别的标示符!"); return; } } } break; case WrapMode.Center: { for (int i = 0; i < symbolList.size; i++) { int index = atlas.keys.IndexOf(symbolList[i]); if (index >= 0) { rectTransList[i].sizeDelta = mImageSize; SetImage(i, atlas.values[index], new Vector3(mImageSize.x / 2.0f + (mImageSize.x + mInterval) * (i - (symbolList.size - 1) / 2.0f), 0, 0)); } else { Debug.LogError("TextWrapEx存在未识别的标示符!---> " + symbolList[i] + " -----> " + symbolList.ToArray().JoinToString(" ")); return; } } } break; } }
/// <summary> /// Set the draw call's geometry. /// </summary> public void Set( BetterList <Vector3> verts, BetterList <Vector3> norms, BetterList <Vector4> tans, BetterList <Vector2> uvs, BetterList <Color32> cols) { int count = verts.size; // Safety check to ensure we get valid values if (count > 0 && (count == uvs.size && count == cols.size) && (count % 4) == 0) { // Cache all components if (mFilter == null) { mFilter = gameObject.GetComponent <MeshFilter>(); } if (mFilter == null) { mFilter = gameObject.AddComponent <MeshFilter>(); } if (verts.size < 65000) { // Populate the index buffer int indexCount = (count >> 1) * 3; bool setIndices = (mIndices == null || mIndices.Length != indexCount); // Create the mesh if (mMesh == null) { mMesh = new Mesh(); mMesh.hideFlags = HideFlags.DontSave; mMesh.name = (mMaterial != null) ? mMaterial.name : "Mesh"; #if !UNITY_3_5 mMesh.MarkDynamic(); #endif setIndices = true; } #if !UNITY_FLASH // If the buffer length doesn't match, we need to trim all buffers bool trim = (uvs.buffer.Length != verts.buffer.Length) || (cols.buffer.Length != verts.buffer.Length) || (norms != null && norms.buffer.Length != verts.buffer.Length) || (tans != null && tans.buffer.Length != verts.buffer.Length); // Non-automatic render queues rely on Z position, so it's a good idea to trim everything if (!trim && panel.renderQueue != UIPanel.RenderQueue.Automatic) { trim = (mMesh == null || mMesh.vertexCount != verts.buffer.Length); } mTriangles = (verts.size >> 1); if (trim || verts.buffer.Length > 65000) { if (trim || mMesh.vertexCount != verts.size) { mMesh.Clear(); setIndices = true; } mMesh.vertices = verts.ToArray(); mMesh.uv = uvs.ToArray(); mMesh.colors32 = cols.ToArray(); if (norms != null) { mMesh.normals = norms.ToArray(); } if (tans != null) { mMesh.tangents = tans.ToArray(); } } else { if (mMesh.vertexCount != verts.buffer.Length) { mMesh.Clear(); setIndices = true; } mMesh.vertices = verts.buffer; mMesh.uv = uvs.buffer; mMesh.colors32 = cols.buffer; if (norms != null) { mMesh.normals = norms.buffer; } if (tans != null) { mMesh.tangents = tans.buffer; } } #else mTriangles = (verts.size >> 1); if (mMesh.vertexCount != verts.size) { mMesh.Clear(); setIndices = true; } mMesh.vertices = verts.ToArray(); mMesh.uv = uvs.ToArray(); mMesh.colors32 = cols.ToArray(); if (norms != null) { mMesh.normals = norms.ToArray(); } if (tans != null) { mMesh.tangents = tans.ToArray(); } #endif if (setIndices) { mIndices = GenerateCachedIndexBuffer(count, indexCount); mMesh.triangles = mIndices; } if (trim || !alwaysOnScreen) { mMesh.RecalculateBounds(); } mFilter.mesh = mMesh; } else { mTriangles = 0; if (mFilter.mesh != null) { mFilter.mesh.Clear(); } Debug.LogError("Too many vertices on one panel: " + verts.size); } if (mRenderer == null) { mRenderer = gameObject.GetComponent <MeshRenderer>(); } if (mRenderer == null) { mRenderer = gameObject.AddComponent <MeshRenderer>(); #if UNITY_EDITOR mRenderer.enabled = isActive; #endif } UpdateMaterials(); } else { if (mFilter.mesh != null) { mFilter.mesh.Clear(); } Debug.LogError("UIWidgets must fill the buffer with 4 vertices per quad. Found " + count); } }
public void UpdateGeometry(int widgetCount) { this.widgetCount = widgetCount; int size = verts.size; if (size > 0 && size == uvs.size && size == cols.size && size % 4 == 0) { if (mFilter == null) { mFilter = base.gameObject.GetComponent <MeshFilter>(); } if (mFilter == null) { mFilter = base.gameObject.AddComponent <MeshFilter>(); } if (verts.size < 65000) { int num = (size >> 1) * 3; bool flag = mIndices == null || mIndices.Length != num; if (mMesh == null) { mMesh = new Mesh(); mMesh.hideFlags = HideFlags.DontSave; mMesh.name = ((!(mMaterial != null)) ? "[NGUI] Mesh" : ("[NGUI] " + mMaterial.name)); mMesh.MarkDynamic(); flag = true; } bool flag2 = uvs.buffer.Length != verts.buffer.Length || cols.buffer.Length != verts.buffer.Length || (norms.buffer != null && norms.buffer.Length != verts.buffer.Length) || (tans.buffer != null && tans.buffer.Length != verts.buffer.Length); if (!flag2 && panel.renderQueue != 0) { flag2 = (mMesh == null || mMesh.vertexCount != verts.buffer.Length); } if (!flag2 && verts.size << 1 < verts.buffer.Length) { flag2 = true; } mTriangles = verts.size >> 1; if (flag2 || verts.buffer.Length > 65000) { if (flag2 || mMesh.vertexCount != verts.size) { mMesh.Clear(); flag = true; } mMesh.vertices = verts.ToArray(); mMesh.uv = uvs.ToArray(); mMesh.colors32 = cols.ToArray(); if (norms != null) { mMesh.normals = norms.ToArray(); } if (tans != null) { mMesh.tangents = tans.ToArray(); } } else { if (mMesh.vertexCount != verts.buffer.Length) { mMesh.Clear(); flag = true; } mMesh.vertices = verts.buffer; mMesh.uv = uvs.buffer; mMesh.colors32 = cols.buffer; if (norms != null) { mMesh.normals = norms.buffer; } if (tans != null) { mMesh.tangents = tans.buffer; } } if (flag) { mIndices = GenerateCachedIndexBuffer(size, num); mMesh.triangles = mIndices; } if (flag2 || !alwaysOnScreen) { mMesh.RecalculateBounds(); } mFilter.mesh = mMesh; } else { mTriangles = 0; if (mFilter.mesh != null) { mFilter.mesh.Clear(); } Debug.LogError("Too many vertices on one panel: " + verts.size); } if (mRenderer == null) { mRenderer = base.gameObject.GetComponent <MeshRenderer>(); } if (mRenderer == null) { mRenderer = base.gameObject.AddComponent <MeshRenderer>(); } UpdateMaterials(); } else { if (mFilter.mesh != null) { mFilter.mesh.Clear(); } Debug.LogError("UIWidgets must fill the buffer with 4 vertices per quad. Found " + size); } verts.Clear(); uvs.Clear(); cols.Clear(); norms.Clear(); tans.Clear(); }
public void Set(BetterList <Vector3> verts, BetterList <Vector3> norms, BetterList <Vector4> tans, BetterList <Vector2> uvs, BetterList <Color32> cols) #endif { int count = verts.size; // Safety check to ensure we get valid values if (count > 0 && (count == uvs.size && count == cols.size) && (count % 4) == 0) { // Cache all components if (mFilter == null) { mFilter = gameObject.GetComponent <MeshFilter>(); } if (mFilter == null) { mFilter = gameObject.AddComponent <MeshFilter>(); } if (mRen == null) { mRen = gameObject.GetComponent <MeshRenderer>(); } if (mRen == null) { mRen = gameObject.AddComponent <MeshRenderer>(); UpdateMaterials(); } else if (mClippedMat != null && mClippedMat.mainTexture != mSharedMat.mainTexture) { UpdateMaterials(); } if (verts.size < 65000) { int indexCount = (count >> 1) * 3; bool rebuildIndices = (mIndices == null || mIndices.Length != indexCount); // Populate the index buffer if (rebuildIndices) { // It takes 6 indices to draw a quad of 4 vertices mIndices = new int[indexCount]; int index = 0; for (int i = 0; i < count; i += 4) { mIndices[index++] = i; mIndices[index++] = i + 1; mIndices[index++] = i + 2; mIndices[index++] = i + 2; mIndices[index++] = i + 3; mIndices[index++] = i; } } // Set the mesh values Mesh mesh = GetMesh(ref rebuildIndices, verts.size); mesh.vertices = verts.ToArray(); if (norms != null) { mesh.normals = norms.ToArray(); } if (tans != null) { mesh.tangents = tans.ToArray(); } mesh.uv = uvs.ToArray(); #if UNITY_3_5_4 mesh.colors = cols.ToArray(); #else mesh.colors32 = cols.ToArray(); #endif if (rebuildIndices) { mesh.triangles = mIndices; } mesh.RecalculateBounds(); mFilter.mesh = mesh; } else { if (mFilter.mesh != null) { mFilter.mesh.Clear(); } Debug.LogError("Too many vertices on one panel: " + verts.size); } } else { if (mFilter.mesh != null) { mFilter.mesh.Clear(); } Debug.LogError("UIWidgets must fill the buffer with 4 vertices per quad. Found " + count); } }
public void UpdateGeometry(int widgetCount) { //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Expected O, but got Unknown //IL_0415: Unknown result type (might be due to invalid IL or missing references) //IL_042b: Unknown result type (might be due to invalid IL or missing references) //IL_0467: Unknown result type (might be due to invalid IL or missing references) //IL_0489: Unknown result type (might be due to invalid IL or missing references) //IL_04a9: Unknown result type (might be due to invalid IL or missing references) //IL_04bf: Unknown result type (might be due to invalid IL or missing references) this.widgetCount = widgetCount; int size = verts.size; if (size > 0 && size == uvs.size && size == cols.size && size % 4 == 0) { if (mFilter == null) { mFilter = this.get_gameObject().GetComponent <MeshFilter>(); } if (mFilter == null) { mFilter = this.get_gameObject().AddComponent <MeshFilter>(); } if (verts.size < 65000) { int num = (size >> 1) * 3; bool flag = mIndices == null || mIndices.Length != num; if (mMesh == null) { mMesh = new Mesh(); mMesh.set_hideFlags(52); mMesh.set_name((!(mMaterial != null)) ? "[NGUI] Mesh" : ("[NGUI] " + mMaterial.get_name())); mMesh.MarkDynamic(); flag = true; } bool flag2 = uvs.buffer.Length != verts.buffer.Length || cols.buffer.Length != verts.buffer.Length || (norms.buffer != null && norms.buffer.Length != verts.buffer.Length) || (tans.buffer != null && tans.buffer.Length != verts.buffer.Length); if (!flag2 && panel.renderQueue != 0) { flag2 = (mMesh == null || mMesh.get_vertexCount() != verts.buffer.Length); } mTriangles = verts.size >> 1; if (flag2 || verts.buffer.Length > 65000) { if (flag2 || mMesh.get_vertexCount() != verts.size) { mMesh.Clear(); flag = true; } mMesh.set_vertices(verts.ToArray()); mMesh.set_uv(uvs.ToArray()); mMesh.set_colors32(cols.ToArray()); if (norms != null) { mMesh.set_normals(norms.ToArray()); } if (tans != null) { mMesh.set_tangents(tans.ToArray()); } } else { if (mMesh.get_vertexCount() != verts.buffer.Length) { mMesh.Clear(); flag = true; } mMesh.set_vertices(verts.buffer); mMesh.set_uv(uvs.buffer); mMesh.set_colors32(cols.buffer); if (norms != null) { mMesh.set_normals(norms.buffer); } if (tans != null) { mMesh.set_tangents(tans.buffer); } } if (flag) { mIndices = GenerateCachedIndexBuffer(size, num); mMesh.set_triangles(mIndices); } if (flag2 || !alwaysOnScreen) { mMesh.RecalculateBounds(); } mFilter.set_mesh(mMesh); } else { mTriangles = 0; if (mFilter.get_mesh() != null) { mFilter.get_mesh().Clear(); } Debug.LogError((object)("Too many vertices on one panel: " + verts.size)); } if (mRenderer == null) { mRenderer = this.get_gameObject().GetComponent <MeshRenderer>(); } if (mRenderer == null) { mRenderer = this.get_gameObject().AddComponent <MeshRenderer>(); } UpdateMaterials(); } else { if (mFilter.get_mesh() != null) { mFilter.get_mesh().Clear(); } Debug.LogError((object)("UIWidgets must fill the buffer with 4 vertices per quad. Found " + size)); } verts.Clear(); uvs.Clear(); cols.Clear(); norms.Clear(); tans.Clear(); }
public void UpdateGeometry() { int vertex_count = verts.size; //Safety check to ensure we get valid values if (vertex_count > 0 && (vertex_count == uvs.size && vertex_count == cols.size) && (vertex_count % 4) == 0) { if (mFilter == null) { mFilter = gameObject.GetComponent <MeshFilter>(); } if (mFilter == null) { mFilter = gameObject.AddComponent <MeshFilter>(); } // Create the mesh if (mMesh == null) { mMesh = new Mesh(); mMesh.hideFlags = HideFlags.DontSave; mMesh.name = "Mesh"; mMesh.MarkDynamic(); } mMesh.Clear(); mMesh.vertices = verts.ToArray(); mMesh.uv = uvs.ToArray(); mMesh.colors32 = cols.ToArray(); mMesh.normals = vertex1.ToArray(); mMesh.tangents = vertex2.ToArray(); mMesh.uv1 = vertex3.ToArray(); int triangleCount = (vertex_count >> 1) * 3; mMesh.triangles = GenerateCachedIndexBuffer(vertex_count, triangleCount); mFilter.mesh = mMesh; if (mRenderer == null) { mRenderer = gameObject.GetComponent <MeshRenderer>(); } if (mRenderer == null) { mRenderer = gameObject.AddComponent <MeshRenderer>(); } mPopEntryManagerV2.Instance.index++; //mRenderer.sortingLayerName = "" //FX.ToString(); mRenderer.sortingOrder = mPopEntryManagerV2.Instance.index; this.UpdateMaterials(); } else { //if (mFilter.mesh != null) mFilter.mesh.Clear(); Debug.LogError("UIWidgets must fill the buffer with 4 vertices per quad. Found " + vertex_count); } }
public void Set(BetterList <Vector3> verts, BetterList <Vector3> norms, BetterList <Vector4> tans, BetterList <Vector2> uvs, BetterList <Color32> cols) { int size = verts.size; if (((size > 0) && (size == uvs.size)) && ((size == cols.size) && ((size % 4) == 0))) { if (this.mFilter == null) { this.mFilter = base.gameObject.GetComponent <MeshFilter>(); } if (this.mFilter == null) { this.mFilter = base.gameObject.AddComponent <MeshFilter>(); } if (this.mRen == null) { this.mRen = base.gameObject.GetComponent <MeshRenderer>(); } if (this.mRen == null) { this.mRen = base.gameObject.AddComponent <MeshRenderer>(); this.UpdateMaterials(); } else if ((this.mClippedMat != null) && (this.mClippedMat.mainTexture != this.mSharedMat.mainTexture)) { this.UpdateMaterials(); } if (verts.size < 0xfde8) { int num2 = (size >> 1) * 3; bool rebuildIndices = (this.mIndices == null) || (this.mIndices.Length != num2); if (rebuildIndices) { this.mIndices = new int[num2]; int num3 = 0; for (int i = 0; i < size; i += 4) { this.mIndices[num3++] = i; this.mIndices[num3++] = i + 1; this.mIndices[num3++] = i + 2; this.mIndices[num3++] = i + 2; this.mIndices[num3++] = i + 3; this.mIndices[num3++] = i; } } Mesh mesh = this.GetMesh(ref rebuildIndices, verts.size); mesh.vertices = verts.ToArray(); if (norms != null) { mesh.normals = norms.ToArray(); } if (tans != null) { mesh.tangents = tans.ToArray(); } mesh.uv = uvs.ToArray(); mesh.colors32 = cols.ToArray(); if (rebuildIndices) { mesh.triangles = this.mIndices; } mesh.RecalculateBounds(); this.mFilter.mesh = mesh; } else { if (this.mFilter.mesh != null) { this.mFilter.mesh.Clear(); } Debug.LogError("Too many vertices on one panel: " + verts.size); } } else { if (this.mFilter.mesh != null) { this.mFilter.mesh.Clear(); } Debug.LogError("UIWidgets must fill the buffer with 4 vertices per quad. Found " + size); } }
public static bool LoadCSV(byte[] bytes) { if (bytes == null) { return(false); } ByteReader reader = new ByteReader(bytes); // The first line should contain "KEY", followed by languages. BetterList <string> header = reader.ReadCSV(); // There must be at least two columns in a valid CSV file if (header.size < 2) { return(false); } header.RemoveAt(0); _langIndex = 0; _langs = new string[header.size]; for (int i = 0; i < header.size; i++) { _langs[i] = header[i]; } _langMap = new Dictionary <string, string[]>(); _langKeys = new List <string>(); for (; ;) { BetterList <string> temp = reader.ReadCSV(); if (temp == null || temp.size == 0) { break; } string key = temp[0]; if (string.IsNullOrEmpty(key)) { continue; } var fields = new string[_langs.Length]; for (int i = 1; i < temp.size; i++) { try { fields[i - 1] = temp[i]; } catch (Exception) { Debug.LogErrorFormat("当前key解析出错:{0}", key, string.Join("|", temp.ToArray())); throw; } } if (_langMap.ContainsKey(key)) { Debug.LogErrorFormat("存在重复ID,请检查配置表:<{0}> 行号:{1}", key, _langKeys.Count + 2); } else { _langMap.Add(key, fields); _langKeys.Add(key); } } UIRoot.BroadcastMessage("OnLocalize", SendMessageOptions.DontRequireReceiver); Debug.LogFormat("Load Localization csv success! langs:{0} key:{1}", _langs.Length, _langMap.Count); return(true); }
/// <summary> /// Set the draw call's geometry. /// </summary> public void Set(BetterList <Vector3> verts, BetterList <Vector3> norms, BetterList <Vector4> tans, BetterList <Vector2> uvs, BetterList <Color> cols) { int count = verts.size; // Safety check to ensure we get valid values if (count > 0 && (count == uvs.size && count == cols.size) && (count % 4) == 0) { int index = 0; // It takes 6 indices to draw a quad of 4 vertices int indexCount = (count >> 1) * 3; // Populate the index buffer if (mIndices == null || mIndices.Length != indexCount) { mIndices = new int[indexCount]; for (int i = 0; i < count; i += 4) { mIndices[index++] = i; mIndices[index++] = i + 1; mIndices[index++] = i + 2; mIndices[index++] = i + 2; mIndices[index++] = i + 3; mIndices[index++] = i; } } // Cache all components if (mFilter == null) { mFilter = gameObject.GetComponent <MeshFilter>(); } if (mFilter == null) { mFilter = gameObject.AddComponent <MeshFilter>(); } if (mRen == null) { mRen = gameObject.GetComponent <MeshRenderer>(); } if (mRen == null) { mRen = gameObject.AddComponent <MeshRenderer>(); UpdateMaterials(); } if (verts.size < 65000) { if (mMesh == null) { mMesh = new Mesh(); mMesh.name = "UIDrawCall for " + mSharedMat.name; } else { mMesh.Clear(); } // Set the mesh values mMesh.vertices = verts.ToArray(); if (norms != null) { mMesh.normals = norms.ToArray(); } if (tans != null) { mMesh.tangents = tans.ToArray(); } mMesh.uv = uvs.ToArray(); mMesh.colors = cols.ToArray(); mMesh.triangles = mIndices; mMesh.RecalculateBounds(); mFilter.mesh = mMesh; } else { if (mMesh != null) { mMesh.Clear(); } Debug.LogError("Too many vertices on one panel: " + verts.size); } } else { if (mMesh != null) { mMesh.Clear(); } Debug.LogError("UIWidgets must fill the buffer with 4 vertices per quad. Found " + count); } }
/// <summary> /// Set the draw call's geometry. /// </summary> public void Set (BetterList<Vector3> verts, BetterList<Vector3> norms, BetterList<Vector4> tans, BetterList<Vector2> uvs, BetterList<Color32> cols) { int count = verts.size; // Safety check to ensure we get valid values if (count > 0 && (count == uvs.size && count == cols.size) && (count % 4) == 0) { // Cache all components if (mFilter == null) mFilter = gameObject.GetComponent<MeshFilter>(); if (mFilter == null) mFilter = gameObject.AddComponent<MeshFilter>(); if (verts.size < 65000) { // Populate the index buffer int indexCount = (count >> 1) * 3; bool setIndices = (mIndices == null || mIndices.Length != indexCount); // Create the mesh if (mMesh == null) { mMesh = new Mesh(); mMesh.hideFlags = HideFlags.DontSave; mMesh.name = (mMaterial != null) ? mMaterial.name : "Mesh"; #if !UNITY_3_5 mMesh.MarkDynamic(); #endif setIndices = true; } // If the buffer length doesn't match, we need to trim all buffers bool trim = (uvs.buffer.Length != verts.buffer.Length) || (cols.buffer.Length != verts.buffer.Length) || (norms != null && norms.buffer.Length != verts.buffer.Length) || (tans != null && tans.buffer.Length != verts.buffer.Length); if (trim || verts.buffer.Length > 65000) { if (trim || mMesh.vertexCount != verts.size) { mMesh.Clear(); setIndices = true; } mMesh.vertices = verts.ToArray(); mMesh.uv = uvs.ToArray(); mMesh.colors32 = cols.ToArray(); if (norms != null) mMesh.normals = norms.ToArray(); if (tans != null) mMesh.tangents = tans.ToArray(); } else { if (mMesh.vertexCount != verts.buffer.Length) { mMesh.Clear(); setIndices = true; } mMesh.vertices = verts.buffer; mMesh.uv = uvs.buffer; mMesh.colors32 = cols.buffer; if (norms != null) mMesh.normals = norms.buffer; if (tans != null) mMesh.tangents = tans.buffer; } if (setIndices) { mIndices = GenerateCachedIndexBuffer(count, indexCount); mMesh.triangles = mIndices; } if (!alwaysOnScreen) mMesh.RecalculateBounds(); mFilter.mesh = mMesh; } else { if (mFilter.mesh != null) mFilter.mesh.Clear(); Debug.LogError("Too many vertices on one panel: " + verts.size); } if (mRenderer == null) mRenderer = gameObject.GetComponent<MeshRenderer>(); if (mRenderer == null) { mRenderer = gameObject.AddComponent<MeshRenderer>(); #if UNITY_EDITOR mRenderer.enabled = isActive; #endif } UpdateMaterials(); } else { if (mFilter.mesh != null) mFilter.mesh.Clear(); Debug.LogError("UIWidgets must fill the buffer with 4 vertices per quad. Found " + count); } }