コード例 #1
0
        public UIView AddView(string name, Transform parent)
        {
            if (!m_uiDefs.ContainsKey(name))
            {
                Debug.LogError("uidefs do't contain " + name);
            }
            UIDef def = m_uiDefs[name];
            Type  t   = Type.GetType(def.script);

            if (!t.IsSubclassOf(typeof(UIView)))
            {
                Debug.LogError("script is't inherit from UIView");
            }
            var prefab = ResourceLoader.Load <GameObject>(def.prefab);
            var go     = GameObject.Instantiate(prefab, parent);

            go.gameObject.name = name;
            var view = (UIView)go.AddComponent(t);

            view.Init(m_currentId++, def);
            if (!m_views.ContainsKey(name))
            {
                m_views.Add(name, new Dictionary <int, UIView>());
            }
            m_views[name].Add(view.id, view);
            go.gameObject.name = go.gameObject.name + "_" + m_views[name].Count;
            view.onDestroy    += OnViewDestroy;
            return(view);
        }
コード例 #2
0
 public virtual void Init(int id, UIDef def)
 {
     this.id  = id;
     this.def = def;
 }