Exemple #1
0
        /// <summary>
        /// 将假结构体中的数据载入到组件实体中
        /// </summary>
        /// <param name="fake">假结构体数据</param>
        /// <param name="com">unity组件</param>
        /// <param name="initializer">初始化器,用于反射</param>
        public unsafe override void LoadToObject(FakeStruct fake, Component com, Initializer initializer)
        {
            //TransfromData src = new TransfromData();
            //unsafe { transHelper.LoadData((byte*)&src,fake.ip); }
            var src   = (TransfromData *)fake.ip;
            var buff  = fake.buffer;
            var trans = com as Transform;

            com.name = buff.GetData(src->name) as string;
            com.tag  = buff.GetData(src->tag) as string;
            trans.localEulerAngles = src->localEulerAngles;
            trans.localPosition    = src->localPosition;
            trans.localScale       = src->localScale;
            trans.gameObject.layer = src->layer;

            Int16[] chi = fake.buffer.GetData(src->child) as Int16[];
            if (chi != null)
            {
                for (int i = 0; i < chi.Length; i++)
                {
                    var fs = buff.GetData(chi[i]) as FakeStruct;
                    if (fs != null)
                    {
                        var go = gameobjectBuffer.CreateNew(fs.GetInt64(0));
                        if (go != null)
                        {
                            go.transform.SetParent(trans);
                            this.LoadToObject(fs, go.transform, initializer);
                        }
                    }
                }
            }

            Int16[] coms = buff.GetData(src->coms) as Int16[];
            if (coms != null)
            {
                for (int i = 0; i < coms.Length; i++)
                {
                    int index = coms[i];
                    i++;
                    int type = coms[i];
                    var fs   = buff.GetData(index) as FakeStruct;
                    if (fs != null)
                    {
                        var loader = gameobjectBuffer.GetDataLoader(type);
                        if (loader != null)
                        {
                            loader.initializer = initializer;
                            loader.LoadToComponent(fs, com, fake);
                        }
                    }
                }
            }

            if (initializer != null)
            {
                initializer.Initialiezd(fake, trans);
                initializer.AddContext(trans, src->insID);
            }
        }
Exemple #2
0
    static GameObject CreateGameObject(huqiang.Core.HGUI.UIElement ui, Initializer ini)
    {
        GameObject go = new GameObject();

        go.name = ui.name;
        switch (ui.TypeName)
        {
        case huqiang.Core.HGUI.UIType.UIElement:
            var tar = go.AddComponent <UIElement>();
            tar.Content = ui;
            break;

        case huqiang.Core.HGUI.UIType.HImage:
            var img = go.AddComponent <HImage>();
            img.Content = ui as huqiang.Core.HGUI.HImage;
            break;

        case huqiang.Core.HGUI.UIType.HText:
            var txt = go.AddComponent <HText>();
            txt.Content = ui as huqiang.Core.HGUI.HText;
            break;

        case huqiang.Core.HGUI.UIType.TextBox:
            var tb = go.AddComponent <TextBox>();
            tb.Content = ui as huqiang.Core.HGUI.TextBox;
            break;

        case huqiang.Core.HGUI.UIType.HLine:
            var line = go.AddComponent <HLine>();
            line.Content = ui as huqiang.Core.HGUI.HLine;
            break;

        case huqiang.Core.HGUI.UIType.HGraphics:
            var gra = go.AddComponent <HGraphics>();
            gra.Content = ui as huqiang.Core.HGUI.HGraphics;
            break;

        case huqiang.Core.HGUI.UIType.HCanvas:
            var can = go.AddComponent <HCanvas>();
            can.Content = ui as huqiang.Core.HGUI.HCanvas;
            break;
        }
        ui.Context = go.transform;
        unsafe
        {
            var src = (huqiang.Core.UIData.UIElementData *)ui.mod.ip;
            ini.AddContext(ui.Context, src->insID);
            LoadHelper(go, ui.mod.buffer, src->ex, ini);
            LoadHelper(go, ui.mod.buffer, src->composite, ini);
            LoadHelper(go, ui.mod.buffer, src->ex, ini);
        }

        if (ui.parent != null)
        {
            ui.Context.SetParent(ui.parent.Context);
            ui.Context.localPosition = ui.localPosition;
            ui.Context.localRotation = ui.localRotation;
            ui.Context.localScale    = ui.localScale;
        }
        var c = ui.child.Count;

        for (int i = 0; i < c; i++)
        {
            CreateGameObject(ui.child[i], ini);
        }
        return(go);
    }