Exemple #1
0
    public static GameObject LoadToGame(ModelElement mod, object o, Transform parent, string filter = "mod")
    {
        if (mod == null)
        {
            Debug.Log("Mod is null");
            return(null);
        }
        if (mod.tag == filter)
        {
            return(null);
        }
        var g = ModelManagerUI.CreateNew(mod.data.type);

        if (g == null)
        {
            Debug.Log("Name:" + mod.name + " is null");
            return(null);
        }
        var t = g.transform;

        if (parent != null)
        {
            t.SetParent(parent);
        }
        mod.LoadToObject(t);
        var typ = mod.data.type;

        if ((typ & 0x2) > 0)
        {
            var child = mod.components;
            for (int j = 0; j < child.Count; j++)
            {
                ImageElement e = child[j] as ImageElement;
                if (e != null)
                {
                    mod.Context.GetComponent <Image>().sprite = FindSprite(e.textureName, e.spriteName);
                    break;
                }
            }
        }
        else if ((typ & 0x20) > 0)
        {
            var child = mod.components;
            for (int j = 0; j < child.Count; j++)
            {
                RawImageElement e = child[j] as RawImageElement;
                if (e != null)
                {
                    mod.Context.GetComponent <RawImage>().texture = FindTexture(e.textureName);
                    break;
                }
            }
        }
        mod.Main = g;
        mod.AddSizeScale();
        var c = mod.child;

        for (int i = 0; i < c.Count; i++)
        {
            LoadToGame(c[i], o, t, filter);
        }
        //if (o != null)
        //    GetObject(mod, o, mod);
        return(g);
    }