Esempio n. 1
0
        public IFrame OpenFrame(int typeId, object userData = null, int frameId = -1, GameObject root = null)
        {
            var frameItem = TableManager.Instance().GetTableItem <ProtoTable.FrameTypeTable>(typeId);

            if (null == frameItem)
            {
                Debug.LogErrorFormat("OpenFrame Failed for typeId = {0} can not be found in FrameTypeTable ...", frameItem);
                return(null);
            }

            int key = GetFrameKey(typeId, frameId);

            if (mKey2Frames.ContainsKey(key))
            {
                IFrame frame = mKey2Frames[key] as IFrame;
                if (null != frame)
                {
                    frame.Close();
                    frame.Create(userData);
                    frame.Open(typeId, frameId, frameItem.ModuleId, frameItem.Layer, root);
                    return(frame);
                }
                else
                {
                    Debug.LogErrorFormat("open frame failed typeId = {0} frameId = {1}", typeId, frame);
                    return(null);
                }
            }
            else
            {
                var assembly = typeof(ClientFrame).Assembly;
                var frame    = assembly.CreateInstance(frameItem.ClassName) as IFrame;
                if (null != frame)
                {
                    frame.Create(userData);
                    frame.Open(typeId, frameId, frameItem.ModuleId, frameItem.Layer, root);
                    mKey2Frames.Add(key, frame);
                }
                return(frame);
            }
        }