//--------------------------------------------------------- // Pokud ma zaregistrovany stejny material a dany material ma totozne renderQueueIdx (ma se renderevoat ve stejnem momentu), prida widget do tohoto rendereru // Jinak naklonuje material a vytvori pro nej novy renderer, ktery vrati. public MFGuiRenderer RegisterWidget(GUIBase_Widget w, Material material, int renderQueueIdx) { MFGuiRenderer guiRenderer = null; //Debug.Log("Widget " + w.name + " layout ID " + w.GetLayoutUniqueId()); if (material) { ulong rendererId = CalcRendererKey(renderQueueIdx, w.GetLayoutUniqueId(), material); if (!m_GUIRenderers.TryGetValue(rendererId, out guiRenderer)) { //GameObject guiRendererHolder = new GameObject("MF Gui Renderer - " + w.name); GameObject guiRendererHolder = new GameObject("MFGuiRenderer-" + material.GetInstanceID() + "-" + renderQueueIdx + "-" + w.name); guiRenderer = guiRendererHolder.AddComponent <MFGuiRenderer>() as MFGuiRenderer; // guiRenderer.allocBlockSize = 10; guiRenderer.plane = MFGuiRenderer.SPRITE_PLANE.XY; // guiRenderer.autoUpdateBounds = true; guiRenderer.UILayer = UILayer; guiRenderer.ZeroLocation = MFGuiRenderer.ZeroLocationEnum.UpperLeft; for (int i = 0; i < sizeof(int) * 8; i++) { if ((UILayer.value & (1 << i)) == (1 << i)) { guiRendererHolder.layer = i; break; } } // prepare new material (clone original and use new renderQueueIdx) Material newMaterial = (Material)Instantiate(material); newMaterial.renderQueue = RENDER_QUEUE_BASE + renderQueueIdx; newMaterial.name = material.name + "-" + material.GetInstanceID() + "-" + renderQueueIdx + "-" + w.name; // set material guiRenderer.material = newMaterial; // Add new GUI Renderer to container m_GUIRenderers.Add(rendererId, guiRenderer); } } if (guiRenderer != null && guiRenderer != w.GetGuiRenderer()) { guiRenderer.RegisterWidget(w); } return(guiRenderer); }
public bool UnRegisterWidget(GUIBase_Widget inWidget, MFGuiRenderer inGuiRenderer) { if (inGuiRenderer != null) { if (0 == inGuiRenderer.UnRegisterWidget(inWidget)) { foreach (KeyValuePair <ulong, MFGuiRenderer> entry in m_GUIRenderers) { if (entry.Value == inGuiRenderer) { m_GUIRenderers.Remove(entry.Key); Destroy(inGuiRenderer.gameObject); break; } } } return(true); } return(false); }