Beispiel #1
0
        public static GameObject LoadToGameR(ModelElement mod, TempReflection reflections)
        {
            if (mod == null)
            {
#if DEBUG
                Debug.Log("Mod is null");
#endif
                return(null);
            }
            mod.Instantiate();
            if (reflections != null)
            {
                if (GetObject(mod.Context, reflections, mod) == 2)//如果是ModelInital则子物体由ModelInital自己创建维护
                {
                    return(mod.Main);
                }
            }
            var t = mod.Context;
            var c = mod.child;
            for (int i = 0; i < c.Count; i++)
            {
                LoadToGameR(c[i], reflections);
            }
            return(mod.Main);
        }
Beispiel #2
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="container">容器实例</param>
 /// <param name="mod">UI模型名称</param>
 public HotUILinker(UIContainer container, UIElement mod)
 {
     con                   = container;
     model                 = mod.mod;
     middle                = new ObjectLinker(container, mod);
     middle.ItemUpdate     = MItemUpdate;
     middle.LayoutCallback = MCalculItemHigh;
     middle.ItemCreate     = MItemCreate;
     initializer           = new UIInitializer(TempReflection.ObjectFields(typeof(T)));
 }
Beispiel #3
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="container">容器实例</param>
 /// <param name="mod">UI模型名称</param>
 public HotUILinker(UIContainer container, string mod)
 {
     con                   = container;
     model                 = HGUIManager.FindChild(container.model, mod);
     middle                = new ObjectLinker(container);
     middle.ItemUpdate     = MItemUpdate;
     middle.CalculItemHigh = MCalculItemHigh;
     middle.ItemCreate     = MItemCreate;
     initializer           = new UIInitializer(TempReflection.ObjectFields(typeof(T)));
 }
Beispiel #4
0
        /// <summary>
        /// 对象反射
        /// </summary>
        /// <param name="t"></param>
        /// <param name="reflections"></param>
        /// <param name="mod"></param>
        static int GetObject(Transform t, TempReflection reflections, ModelElement mod)
        {
            int state = 0;

            for (int i = 0; i < reflections.Top; i++)
            {
                var m = reflections.All[i];
                if (m.name == t.name)
                {
                    state = 1;
                    if (m.FieldType == typeof(GameObject))
                    {
                        m.Value = t.gameObject;
                    }
                    else if (typeof(EventCallBack).IsAssignableFrom(m.FieldType))
                    {
                        m.Value = EventCallBack.RegEvent(t as RectTransform, m.FieldType);
                    }
                    else if (typeof(ModelInitalS).IsAssignableFrom(m.FieldType))
                    {
                        var obj = Activator.CreateInstance(m.FieldType) as ModelInitalS;
                        obj.Initial(mod);
                        m.Value = obj;
                        state   = 2;
                    }
                    else if (typeof(ModelInital).IsAssignableFrom(m.FieldType))
                    {
                        var obj = Activator.CreateInstance(m.FieldType) as ModelInital;
                        obj.Initial(mod);
                        m.Value = obj;
                    }
                    else if (typeof(Component).IsAssignableFrom(m.FieldType))
                    {
                        m.Value = t.GetComponent(m.FieldType);
                    }
                    reflections.Top--;
                    var j = reflections.Top;
                    var a = reflections.All[j];
                    reflections.All[i] = a;
                    reflections.All[j] = m;
                    return(state);
                }
            }
            return(0);
        }
Beispiel #5
0
        /// <summary>
        /// 对象转换到反射列表
        /// </summary>
        /// <param name="type">类型</param>
        /// <returns></returns>
        public static TempReflection ObjectFields(Type type)
        {
            var            fs   = type.GetFields();
            TempReflection temp = new TempReflection();

            temp.Top = fs.Length;
            ReflectionModel[] reflections = new ReflectionModel[temp.Top];
            for (int i = 0; i < fs.Length; i++)
            {
                ReflectionModel r = new ReflectionModel();
                r.field        = fs[i];
                r.FieldType    = fs[i].FieldType;
                r.name         = fs[i].Name;
                reflections[i] = r;
            }
            temp.All = reflections;
            return(temp);
        }
Beispiel #6
0
 public static ModelElement LoadToGameR(string asset, string mod, TempReflection reflections)
 {
     if (prefabs == null)
     {
         return(null);
     }
     for (int i = 0; i < prefabs.Count; i++)
     {
         if (mod == prefabs[i].name)
         {
             if (asset == prefabs[i].name)
             {
                 var m = prefabs[i].models.Find(mod);
                 LoadToGameR(m, reflections);
                 return(m);
             }
         }
     }
     return(null);
 }