Exemplo n.º 1
0
        public BaseUI ShowUi(string uiName, params object[] param)
        {
            var baseUi = mKeyToUi.GetValEx(uiName);

            if (null != baseUi)
            {
                baseUi.OnShow();
                return(baseUi);
            }

            var assetPath = GetAssetPath(uiName);
            var prefab    = ResourceSys.Instance.Load <GameObject>(assetPath);

            if (prefab == null)
            {
                DCLog.LogEx("null asset ", assetPath, uiName);
                return(null);
            }
            var instance = UnityEngine.Object.Instantiate(prefab, UiRoot);

            baseUi = instance.GetComponent <BaseUI>();
            baseUi.Init(param);

            mKeyToUi.Add(uiName, baseUi);
            mUiStack.Push(baseUi);

            return(baseUi);
        }
Exemplo n.º 2
0
        void FixedUpdate()
        {
            //delete first
            if (mToDelPhysicTimerSet.Count > 0)
            {
                mPhysicTimerSet.RemoveWhere(MatchForFixedUpdate);
                mToDelPhysicTimerSet.Clear();
            }

            if (mPhysicTimerSet.Count > 0)
            {
                mPhysicTimersToInvoke.AddRange(mPhysicTimerSet);
                DCLog.LogEx("physic timer count ", mPhysicTimersToInvoke.Count);
                foreach (var timer in mPhysicTimersToInvoke)
                {
                    timer.Update();
                }
                mPhysicTimersToInvoke.Clear();
            }

            //avoid执行中添加新action
            mNextFixedUpdateToInvokes.AddRange(mNextFixedUpdate);
            mNextFixedUpdate.Clear();
            foreach (var action in mNextFixedUpdateToInvokes)
            {
                if (action != null)
                {
                    action();
                }
            }
            mNextFixedUpdateToInvokes.Clear();
        }
Exemplo n.º 3
0
 public void Dispatch(ClientHandler clientHandler, int id, ProtoPacket packet)
 {
     DCLog.LogEx("handle req ", id);
     if (mIdToDelegates.TryGetValue(id, out var handler))
     {
         handler.DynamicInvoke(clientHandler, id, packet);
     }
 }
Exemplo n.º 4
0
 void OnDestroy()
 {
     DCLog.Log("end main");
     mChannel.DisposeRes();
     mChannel.Close();
     mServer.DisposeRes();
     mServer.Close();
 }
Exemplo n.º 5
0
        void Start()
        {
            var asset1 = Resources.Load <TextAsset>("test");     //not null
            var asset2 = Resources.Load <TextAsset>("test.txt"); //null

            DCLog.Log("end");

//            Resources.Load<Texture2D>("");
        }
Exemplo n.º 6
0
        public static void Test()
        {
            var asset1 = AssetDatabase.LoadAssetAtPath <TextAsset>("Assets/DCMMO/Resources/test");     //null
            var asset2 = AssetDatabase.LoadAssetAtPath <TextAsset>("Assets/DCMMO/Resources/test.txt"); //not null

            //asset bundle need extension

            DCLog.Log("end");
        }
Exemplo n.º 7
0
 public static void RemoveNormal(DCBaseTimer timer)
 {
     if (null == Instance)
     {
         return;
     }
     DCLog.Log("add to remove");
     Instance.mToDelTimerSet.Add(timer);
 }
Exemplo n.º 8
0
        public void ReleaseId(int id)
        {
            var index = id - base_index;

            if (index < 0 || index >= mIdPool.Length)
            {
                DCLog.Log("out range id: " + id);
                return;
            }
            mIdPool[index] = 0;
        }
Exemplo n.º 9
0
        public void AddSys(BaseSys sys)
        {
            if (mTypeToSys.ContainsKey(sys.GetType()))
            {
                DCLog.Err("duplicated sys: " + sys);
                return;
            }

            mTypeToSys.Add(sys.GetType(), sys);
            mSysList.Add(sys);
        }
Exemplo n.º 10
0
        void OnAddRoleRes(int id, ProtoPacket proto)
        {
            //yeah , let's go to the game world
            DCLog.Log("yeah , let's go to the game world!");
            Close();

            MsgSys.Send(PlayerEvt.close_select_role_ui);

            var sceneId = ParamsCfgMgr.Instance.GetInt((int)PParamsConfig.BeginnerScene);

            LoadScene(sceneId);
        }
Exemplo n.º 11
0
        void LoadScene(int sceneId)
        {
            var mapCfg = MapCfgMgr.Instance.GetMapConfigByID(sceneId);

            if (null != mapCfg)
            {
                SceneManager.LoadScene(System.IO.Path.GetFileNameWithoutExtension(mapCfg.AssetPath));
            }
            else
            {
                DCLog.Err("can not load level with id : {0}", sceneId);
            }
        }
Exemplo n.º 12
0
        private void OnRoleRes(int id, ProtoPacket protoPkt)
        {
            if (DCGameProtocol.CheckError(id, protoPkt) != ErrorCode.UNIVERSAL)
            {
                var errorRes = protoPkt.GetError();
                DCLog.LogEx(errorRes.No, errorRes.OpCode, errorRes.Msg);
                return;
            }

            var roleRes = (PRoleRes)protoPkt.ProtoObj;

            mRoleList.Clear();
            mRoleList.AddRange(roleRes.Infos);
        }
Exemplo n.º 13
0
        public void OnReceive(Packet packet)
        {
            var protoPacket = ProtoPacket.FromRecvBuf(packet.Bytes, 0, packet.Length);
            var id          = protoPacket.protoId;

            DCLog.LogEx("receive protoId ", id);
            if (id > 0)
            {
                mIdToRecord.Remove(id);

                //长期监听的先执行
                Invoke(id, protoPacket, mIdToNormalHandler);

                Invoke(id, protoPacket, mIdToOnceHandler);
                mIdToOnceHandler.Remove(id);
            }
        }
Exemplo n.º 14
0
        public void Destroy()
        {
            DCLog.Log("Destroy 1");
            if (mDestroyed)
            {
                return;
            }
            mDestroyed = true;
            DCLog.Log("Destroy 2");

            if (mPhysic)
            {
                DCTimer.RemovePhysic(this);
            }
            else
            {
                DCTimer.RemoveNormal(this);
            }
        }
Exemplo n.º 15
0
        void Update()
        {
            //update 类型的timer
            //delete first
            if (mToDelTimerSet.Count > 0)
            {
                mTimerSet.RemoveWhere(MatchForUpdate);
                mToDelTimerSet.Clear();
            }

            if (mTimerSet.Count > 0)
            {
                mTimersToInvoke.AddRange(mTimerSet);
                DCLog.LogEx("timer count ", mTimersToInvoke.Count);
                foreach (var timer in mTimersToInvoke)
                {
                    timer.Update();
                }
                mTimersToInvoke.Clear();
            }

            //延时执行部分
            foreach (var actionRecord in mActionRecords)
            {
                actionRecord.Update();
                if (actionRecord.IsComplete())
                {
                    mActionRecordsToDel.Add(actionRecord);
                }
            }

            //防止action update的时候有往集合里面增加的操作
            if (mActionRecordsToDel.Count > 0)
            {
                mActionRecords.RemoveWhere(MatchDelRecord);
                foreach (var record in mActionRecordsToDel)
                {
                    record.Notify();
                }
                mActionRecordsToDel.Clear();
            }
        }
Exemplo n.º 16
0
        public Dictionary <string, string> BuildAssetExtensionMap(string root)
        {
            var allFile = Directory.GetFiles(root, "*.*", SearchOption.AllDirectories).Where((item) => !item.EndsWith("meta")).ToList();

            DCLog.Log(allFile.Count.ToString());

            var dic = new Dictionary <string, string>();

            foreach (var aFile in allFile)
            {
                var unixFilePath = aFile.Replace('\\', '/');
                var assetPath    = unixFilePath.Replace(Application.dataPath, "Assets");

                var point          = assetPath.LastIndexOf('.');
                var pathWithOutExt = assetPath.Substring(0, point);
                var ext            = assetPath.Substring(point);
                dic.Add(pathWithOutExt, ext);
            }

            return(dic);
        }
Exemplo n.º 17
0
        void OnLoginComplete(int code, string result)
        {
            if (code == 1)
            {
                var jsonNode = JSON.Parse(result);
                int svrCode  = jsonNode["result"];
                if (svrCode == 1)
                {
                    var token = jsonNode["token"];
                    DCLog.Log(token);
                    PlayerDataMgr.Instance.UserToken = token;

                    //to login game svr
                    var svrCfg = GameServerDataMgr.Instance.GetLastLoginSvr();
                    RequestRoleData(svrCfg);
                }
            }
            else if (code == 2)
            {
                DCLog.LogEx("net or http error ", result);
            }
        }
Exemplo n.º 18
0
        void OnLoginSvrComplete(int id, ProtoPacket proto)
        {
            DCLog.Log("to game world");

            Close();
        }
Exemplo n.º 19
0
 void OnReceive(Packet packet)
 {
     DCLog.LogEx("from server: ", Encoding.UTF8.GetString(packet.Bytes, 0, packet.Length));
 }