protected void LoadElement(FakeStruct fake, UIElement tar) { tar.Clear(); UIElementData tmp = new UIElementData(); unsafe { UIElementData *src = &tmp; ElementHelper.LoadData((byte *)src, fake.ip); } tar.m_sizeDelta = tmp.m_sizeDelta; tar.Pivot = tmp.Pivot; tar.scaleType = tmp.scaleType; tar.anchorType = tmp.anchorType; tar.anchorPointType = tmp.anchorPointType; tar.anchorOffset = tmp.anchorOffset; tar.marginType = tmp.marginType; tar.parentType = tmp.parentType; tar.margin = tmp.margin; tar.Mask = tmp.Mask; tar.eventType = tmp.eventType; tar.compositeType = tmp.compositeType; tar.userEvent = null; tar.composite = null; tar.SizeChanged = null; }
protected unsafe void SaveScript(byte *ip, UIElement src) { UIElementData *tar = (UIElementData *)ip; tar->m_sizeDelta = src.m_sizeDelta; tar->Pivot = src.Pivot; tar->scaleType = src.scaleType; tar->anchorType = src.anchorType; tar->anchorPointType = src.anchorPointType; tar->anchorOffset = src.anchorOffset; tar->marginType = src.marginType; tar->parentType = src.parentType; tar->margin = src.margin; tar->Mask = src.Mask; tar->eventType = src.eventType; tar->compositeType = src.compositeType; }
protected unsafe void SaveUIElement(Transform trans, FakeStruct fake) { var buffer = fake.buffer; UIElementData *tar = (UIElementData *)fake.ip; tar->type = fake.buffer.AddData("UIElement"); tar->insID = trans.GetInstanceID(); tar->activeSelf = trans.gameObject.activeSelf; tar->name = buffer.AddData(trans.name); tar->localPosition = trans.localPosition; tar->localScale = trans.localScale; tar->localRotation = trans.localRotation; var con = trans.GetComponent <huqiang.Helper.HGUI.UIContext>(); if (con != null) { var src = con.GetUIData(); tar->m_sizeDelta = src.m_sizeDelta; tar->Pivot = src.Pivot; tar->scaleType = src.scaleType; tar->anchorType = src.anchorType; tar->anchorPointType = src.anchorPointType; tar->anchorOffset = src.anchorOffset; tar->marginType = src.marginType; tar->parentType = src.parentType; tar->margin = src.margin; tar->Mask = src.Mask; tar->eventType = src.eventType; tar->compositeType = src.compositeType; tar->type = fake.buffer.AddData(src.TypeName); tar->insID = src.GetInstanceID(); tar->activeSelf = src.activeSelf; } var hleps = con.GetComponents <UIHelper>(); if (hleps != null) { for (int i = 0; i < hleps.Length; i++) { hleps[i].ToBufferData(buffer, tar); } } int c = trans.childCount; if (c > 0) { Int16[] buf = new short[c]; for (int i = 0; i < c; i++) { var son = trans.GetChild(i); var ui = son.GetComponent <Helper.HGUI.UIContext>(); string tn = "UIElement"; if (ui == null) { Debug.LogWarning("没有UI元素:" + son.name); } else { tn = ui.GetType().Name; } var load = uiBuffer.FindDataLoader(tn); if (load != null) { var fs = load.SaveUI(son, buffer); if (fs == null) { Debug.LogError("Save Error:" + son.name); } buf[i] = (Int16)buffer.AddData(fs); } else { Debug.LogError(tn + " type is null"); } } tar->child = buffer.AddData(buf); } }
protected unsafe void LoadUIElement(HGUI.UIElement tar, FakeStruct fake, HGUI.UIInitializer initializer) { UIElementData tmp = new UIElementData(); unsafe { UIElementData *src = &tmp; ElementHelper.LoadData((byte *)src, fake.ip); } tar.mod = fake; var buffer = fake.buffer; tar.activeSelf = tmp.activeSelf; tar.name = buffer.GetData(tmp.name) as string; tar.localPosition = tmp.localPosition; tar.localScale = tmp.localScale; tar.localRotation = tmp.localRotation; tar.m_sizeDelta = tmp.m_sizeDelta; tar.Pivot = tmp.Pivot; tar.scaleType = tmp.scaleType; tar.anchorType = tmp.anchorType; tar.anchorPointType = tmp.anchorPointType; tar.anchorOffset = tmp.anchorOffset; tar.marginType = tmp.marginType; tar.parentType = tmp.parentType; tar.margin = tmp.margin; tar.Mask = tmp.Mask; tar.eventType = tmp.eventType; tar.compositeType = tmp.compositeType; tar.userEvent = null; tar.composite = null; tar.SizeChanged = null; Int16[] chi = buffer.GetData(tmp.child) as Int16[]; if (chi != null) { for (int i = 0; i < chi.Length; i++) { var fs = buffer.GetData(chi[i]) as FakeStruct; if (fs != null) { var son = uiBuffer.Clone(fs, initializer); if (son != null) { son.SetParent(tar); } } else { Debug.LogError("child is null"); } } } #if UNITY_EDITOR if (Application.isPlaying) #endif tar.Initial(fake, initializer); if (initializer != null) { initializer.Initialiezd(fake, tar); initializer.AddContext(tar, tmp.insID); } }
public static Vector2 GetSize(UIElement parent, FakeStruct ele) { unsafe { Vector2 psize = Vector2.zero; UIElementData *up = (UIElementData *)ele.ip; switch (up->parentType) { case ParentType.Screen: psize = HCanvas.MainCanvas.m_sizeDelta; break; case ParentType.Tranfrom: if (parent != null) { psize = parent.m_sizeDelta; } break; } switch (up->marginType) { case MarginType.None: return(up->m_sizeDelta); case MarginType.Margin: psize.x -= up->margin.left + up->margin.right; psize.y -= up->margin.top + up->margin.down; return(psize); case MarginType.MarginRatio: psize.x *= (1 - up->margin.left - up->margin.right); psize.y *= (1 - up->margin.top - up->margin.down); return(psize); case MarginType.MarginX: psize.x -= up->margin.left + up->margin.right; psize.y = up->m_sizeDelta.y; return(psize); case MarginType.MarginY: psize.x = up->m_sizeDelta.x; psize.y -= up->margin.top + up->margin.down; return(psize); case MarginType.MarginRatioX: psize.x *= (1 - up->margin.left - up->margin.right); psize.y = up->m_sizeDelta.y; return(psize); case MarginType.MarginRatioY: psize.x = up->m_sizeDelta.x; psize.y *= (1 - up->margin.top - up->margin.down); return(psize); case MarginType.Size: psize.x -= up->margin.left; psize.y -= up->margin.down; return(psize); case MarginType.Ratio: psize.x *= (1 - up->margin.left); psize.y *= (1 - up->margin.down); return(psize); case MarginType.SizeX: psize.x -= up->margin.left; psize.y = up->m_sizeDelta.y; return(psize); case MarginType.SizeY: psize.x = up->m_sizeDelta.x; psize.y -= up->margin.down; return(psize); case MarginType.RatioX: psize.x *= (1 - up->margin.left); psize.y = up->m_sizeDelta.y; return(psize); case MarginType.RatioY: psize.x = up->m_sizeDelta.x; psize.y *= (1 - up->margin.down); return(psize); } return(up->m_sizeDelta); } }