public void Load(string filename)
 {
     if (!FileReaderProxy.Exists(filename))
     {
         return;
     }
     try
     {
         using (MemoryStream ms = FileReaderProxy.ReadFileAsMemoryStream(filename))
         {
             using (BinaryReader br = new BinaryReader(ms))
             {
                 while (ms.Position <= ms.Length - c_RecordSize)
                 {
                     short row         = br.ReadInt16();
                     short col         = br.ReadInt16();
                     byte  obstacle    = br.ReadByte();
                     byte  oldObstacle = br.ReadByte();
                     Update(row, col, obstacle, oldObstacle);
                 }
                 br.Close();
             }
             ms.Close();
         }
     }
     catch (Exception ex)
     {
         LogUtil.Error("{0}\n{1}", ex.Message, ex.StackTrace);
     }
 }
Esempio n. 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            mFormsTimer          = new System.Windows.Forms.Timer();
            mFormsTimer.Interval = 50;
            mFormsTimer.Tick    += new System.EventHandler(this.TimerEventProcessor);
            mFormsTimer.Start();

            context_        = BufferedGraphicsManager.Current;
            last_tick_time_ = TimeUtility.Instance.GetElapsedTimeUs() / 1000;
            last_movedir_   = 0;
            last_adjust_    = 0;

            operation.SelectedIndex = 0;

            LogUtil.OnOutput += (Log_Type type, string msg) =>
            {
                Console.WriteLine("Log {0}:{1}", type, msg);
            };

            FileReaderProxy.RegisterReadFileHandler((string filePath) =>
            {
                byte[] buffer = null;
                try
                {
                    buffer = File.ReadAllBytes(filePath);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception:{0}\n{1}", ex.Message, ex.StackTrace);
                    return(null);
                }
                return(buffer);
            });
        }
Esempio n. 3
0
    void Update()
    {
#if UNITY_EDITOR
        if (EditorApplication.isPlaying)
        {
            return;
        }

        if (LoadedPrefabId != LinkId)
        {
            FileReaderProxy.MakeSureAllHandlerRegistered();

            NpcConfigProvider.Instance.Clear();
            NpcConfigProvider.Instance.LoadNpcConfig(Application.dataPath + "/StreamingAssets/Public/NpcConfig.txt", "");
            Data_NpcConfig config = NpcConfigProvider.Instance.GetNpcConfigById(LinkId);
            if (config != null)
            {
                // destroy all subobject
                int count = this.gameObject.transform.childCount;
                for (int i = 0; i < count; ++i)
                {
                    GameObject.DestroyImmediate(gameObject.transform.GetChild(i).gameObject);
                }
                //GameObject.DestroyImmediate(LoadedPrefab);

                // create new one
                Object obj = Resources.Load(config.m_Model);
                LoadedPrefab = GameObject.Instantiate(obj, gameObject.transform) as GameObject;

                LoadedPrefabId = LinkId;
            }
        }
#endif
    }
Esempio n. 4
0
        public static void OnStart(string dataPath)
        {
            GfxMoudle.Instance.RegisteLog();

            HomePath.Instance.SetHomePath(dataPath);

            FileReaderProxy.RegisterReadFileHandler((string filePath) =>
            {
                try
                {
                    return(File.ReadAllBytes(filePath));
                }
                catch (Exception e)
                {
                    LogUtil.Error("Exception:{0}\n{1}", e.Message, e.StackTrace);
                    return(null);
                }
            });

            LoadConfig();

            GfxMoudle.Instance.OnStart(s_Logic);

            s_Logic.OnStart();
        }
Esempio n. 5
0
 void InitDefault(string filename)
 {
     using (MemoryStream ms = FileReaderProxy.ReadFileAsMemoryStream(filename))
     {
         using (BinaryReader br = new BinaryReader(ms))
         {
             map_width_  = (float)br.ReadDouble();
             map_height_ = (float)br.ReadDouble();
             cell_width_ = (float)br.ReadDouble();
             GetCell(new Vector3(map_width_, 0, map_height_), out max_row_, out max_col_);
             max_row_++;
             max_col_++;
             if (max_col_ % 2 == 0)
             {
                 max_row_++;
             }
             cells_arr_ = new byte[max_row_, max_col_];
             int row = 0;
             int col = 0;
             while (ms.Position < ms.Length && row < max_row_)
             {
                 cells_arr_[row, col] = br.ReadByte();
                 if (++col >= max_col_)
                 {
                     col = 0;
                     ++row;
                 }
             }
             br.Close();
         }
     }
 }
        public bool ParseTiledData(string xml_file, float width, float height)
        {
            map_width_  = width;
            map_height_ = height;

            XmlDocument xmldoc = new XmlDocument();

            System.IO.Stream ms = null;
            try
            {
                ms = FileReaderProxy.ReadFileAsMemoryStream(xml_file);
                if (ms == null)
                {
                    return(false);
                }
                xmldoc.Load(ms);
            }
            catch (System.IO.FileNotFoundException ex)
            {
                LogUtil.Error("config xml file {0} not find!\n{1}", xml_file, ex.Message);
                return(false);
            }
            catch (Exception ex)
            {
                LogUtil.Error("parse xml file {0} error!\n{1}", xml_file, ex.Message);
                return(false);
            }
            finally
            {
                if (ms != null)
                {
                    ms.Close();
                }
            }

            XmlNode     root      = xmldoc.SelectSingleNode("map");
            XmlNodeList objgroups = root.SelectNodes("objectgroup");

            foreach (XmlNode objgroup in objgroups)
            {
                string groupName = objgroup.Attributes["name"].Value;
                foreach (XmlNode obj in objgroup.ChildNodes)
                {
                    if (groupName == "walktriangle")
                    {
                        ParseObject(obj, walk_triangle_list_, null);
                    }
                    else if (groupName == "obstacle")
                    {
                        ParseObject(obj, obstacle_area_list_, obstacle_line_list_);
                    }
                    else
                    {
                        ParseObject(obj, walk_area_list_, null);
                    }
                }
            }
            return(true);
        }
Esempio n. 7
0
    private void Init(string[] args)
    {
        m_NameHandleCallback = this.OnNameHandleChanged;
        m_MsgCallback        = this.OnMessage;
        m_CmdCallback        = this.OnCommand;
        m_MsgResultCallback  = this.OnMessageResult;
        CenterClientApi.Init("store", args.Length, args, m_NameHandleCallback, m_MsgCallback, m_MsgResultCallback, m_CmdCallback);

        m_Channel = new PBChannel(DashFire.DataStore.MessageMapping.Query,
                                  DashFire.DataStore.MessageMapping.Query);
        m_Channel.DefaultServiceName = "Lobby";
        LogSys.Init("./config/logconfig.xml");
        DataStoreConfig.Init();

        ArkCrossEngine.GlobalVariables.Instance.IsClient = false;

        FileReaderProxy.RegisterReadFileHandler((string filePath) =>
        {
            byte[] buffer = null;
            try
            {
                buffer = File.ReadAllBytes(filePath);
            }
            catch (Exception e)
            {
                LogSys.Log(LOG_TYPE.ERROR, "Exception:{0}\n{1}", e.Message, e.StackTrace);
                return(null);
            }
            return(buffer);
        }, (string filepath) => { return(File.Exists(filepath)); });
        LogSystem.OnOutput += (Log_Type type, string msg) =>
        {
            switch (type)
            {
            case Log_Type.LT_Debug:
                LogSys.Log(LOG_TYPE.DEBUG, msg);
                break;

            case Log_Type.LT_Info:
                LogSys.Log(LOG_TYPE.INFO, msg);
                break;

            case Log_Type.LT_Warn:
                LogSys.Log(LOG_TYPE.WARN, msg);
                break;

            case Log_Type.LT_Error:
            case Log_Type.LT_Assert:
                LogSys.Log(LOG_TYPE.ERROR, msg);
                break;
            }
        };

        DbThreadManager.Instance.Init(DataStoreConfig.LoadThreadNum, DataStoreConfig.SaveThreadNum);
        DataOpSystem.Instance.Init(m_Channel);
        DataCacheSystem.Instance.Init();
        LogSys.Log(LOG_TYPE.INFO, "DataStore initialized");
    }
Esempio n. 8
0
        public bool ParseTiledData(string xml_file, float mapwidth, float mapheight, float scale, out string txt)
        {
            txt = "";
            XmlDocument xmldoc = new XmlDocument();

            System.IO.Stream ms = null;
            try
            {
                ms = FileReaderProxy.ReadFileAsMemoryStream(xml_file);
                if (ms == null)
                {
                    return(false);
                }
                xmldoc.Load(ms);
            }
            catch (System.IO.FileNotFoundException ex)
            {
                LogSystem.Error("config xml file {0} not find!\n{1}", xml_file, ex.Message);
                return(false);
            }
            catch (Exception ex)
            {
                LogSystem.Error("parse xml file {0} error!\n{1}", xml_file, ex.Message);
                return(false);
            }
            finally
            {
                if (ms != null)
                {
                    ms.Close();
                }
            }

            XmlNode       root      = xmldoc.SelectSingleNode("map");
            XmlNodeList   objgroups = root.SelectNodes("objectgroup");
            StringBuilder sb        = new StringBuilder();

            sb.AppendLine("类型\t名称\t是否多边形\t点XZ列表");
            foreach (XmlNode objgroup in objgroups)
            {
                string groupName = objgroup.Attributes["name"].Value;
                foreach (XmlNode obj in objgroup.ChildNodes)
                {
                    string objName = obj.Attributes["name"].Value;
                    sb.Append(groupName).Append("\t").Append(objName).Append("\t");
                    TiledData td = new TiledData(mapwidth * scale, mapheight * scale);
                    if (td.CollectDataFromXml(obj))
                    {
                        sb.Append(td.IsPolygon).Append("\t");
                        AppendPointList(td.GetPoints(), scale, sb);
                        sb.AppendLine();
                    }
                }
            }
            txt = sb.ToString();
            return(true);
        }
Esempio n. 9
0
    private byte[] LoadLogicResource(ref string resource)
    {
        byte[] content = FileReaderProxy.ReadFileAsArray(resource);
        string text    = Encoding.UTF8.GetString(content);

        if (text.StartsWith(BOMMarkUtf8))
        {
            text = text.Remove(0, BOMMarkUtf8.Length);
        }
        resource = ScriptManager.Instance.GetLuaScriptPathForDebugger(resource, false);
        return(System.Text.Encoding.UTF8.GetBytes(text));
    }
Esempio n. 10
0
 // 从文件读取
 public bool Init(string filename)
 {
     if (!FileReaderProxy.Exists(filename))
     {
         return(false);
     }
     try
     {
         using (MemoryStream ms = FileReaderProxy.ReadFileAsMemoryStream(filename))
         {
             using (BinaryReader br = new BinaryReader(ms))
             {
                 map_width_  = (float)br.ReadDouble();
                 map_height_ = (float)br.ReadDouble();
                 cell_width_ = (float)br.ReadDouble();
                 GetCell(new Vector3(map_width_, 0, map_height_), out max_row_, out max_col_);
                 max_row_++;
                 max_col_++;
                 if (max_col_ % 2 == 0)
                 {
                     max_row_++;
                 }
                 cells_arr_ = new byte[max_row_, max_col_];
                 int row = 0;
                 int col = 0;
                 while (ms.Position < ms.Length && row < max_row_)
                 {
                     cells_arr_[row, col] = br.ReadByte();
                     if (++col >= max_col_)
                     {
                         col = 0;
                         ++row;
                     }
                 }
                 br.Close();
             }
         }
     }
     catch (Exception e)
     {
         LogUtil.Error("{0}\n{1}", e.Message, e.StackTrace);
         return(false);
     }
     return(true);
 }
Esempio n. 11
0
        public bool Initial(string filename)
        {
            bool result = false;

            using (MemoryStream ms = FileReaderProxy.ReadFileAsMemoryStream(filename))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    float unclampedGridSizeX = br.ReadSingle();
                    float unclampedGridSizeY = br.ReadSingle();
                    unclampedGridSize = new Vector2(unclampedGridSizeX, unclampedGridSizeY);

                    float gridCoordinateCenterX = br.ReadSingle();
                    float gridCoordinateCenterY = br.ReadSingle();
                    float gridCoordinateCenterZ = br.ReadSingle();
                    gridCoordinateCenter = new Vector3(gridCoordinateCenterX, gridCoordinateCenterY, gridCoordinateCenterZ);

                    nodeSize = br.ReadSingle();

                    maxNodeNumInWidth = br.ReadInt32();
                    maxNodeNumInDepth = br.ReadInt32();

                    m_NodeSizeSelfAdaption = br.ReadBoolean();

                    result = GenerateMatrix();
                    if (result)
                    {
                        m_Nodes = new byte[nodeNumInWidth * nodeNumInDepth];
                        for (int z = 0; z < nodeNumInDepth; z++)
                        {
                            for (int x = 0; x < nodeNumInWidth; x++)
                            {
                                byte walkable = br.ReadByte();
                                m_Nodes[z * nodeNumInWidth + x] = walkable;
                            }
                        }
                    }

                    br.Close();
                }
            }

            return(result);
        }
Esempio n. 12
0
 // 从文件读取
 public bool Init(string filename)
 {
     if (!FileReaderProxy.Exists(filename))
     {
         return(false);
     }
     try
     {
         if (filename.Contains("cow_walkable"))
         {
             InitCow(filename);
         }
         else
         {
             InitDefault(filename);
         }
     }
     catch (Exception e)
     {
         LogSystem.Error("{0}\n{1}", e.Message, e.StackTrace);
         return(false);
     }
     return(true);
 }
Esempio n. 13
0
        public bool Load(string file)
        {
            // temp, for test
            if (file.ToLower().EndsWith(".dsl"))
            {
                byte[] content = FileReaderProxy.ReadFileAsArray(file);
                string text    = Encoding.UTF8.GetString(content);

                // remove BOM if used
                if (text.StartsWith(BOMMarkUtf8))
                {
                    text = text.Remove(0, BOMMarkUtf8.Length);
                }

                //DashFire.LogSystem.Debug("ScriptableDataFile.Load {0}:\n{1}", file, content);
                return(LoadFromString(text, file));
            }
            else
            {
                Env = ScriptManager.Instance.SetupNewEnv(file, false);
                ScriptManager.Instance.ExecuteFile(file, false, Env, file);
                OnStart           = ScriptManager.Instance.QueryAction_1("start", Env, false);
                OnNpcStore        = ScriptManager.Instance.QueryAction_1("npcstore", Env, false);
                OnCityUserMove    = ScriptManager.Instance.QueryAction_1("cityusermove", Env, false);
                OnObjArrived      = ScriptManager.Instance.QueryAction_1("objarrived", Env, false);
                OnCityPlayerMove  = ScriptManager.Instance.QueryAction_1("cityplayermove", Env, false);
                OnPlayerMoveToPos = ScriptManager.Instance.QueryAction_1("playermovetopos", Env, false);
                OnAiMoveStop      = ScriptManager.Instance.QueryAction_1("aimovestopped", Env, false);
            }

            return(true);

#if false
            //string content = File.ReadAllText(file);
            byte[] content = FileReaderProxy.ReadFileAsArray(file);
            string text    = Encoding.UTF8.GetString(content);

            // remove BOM if used
            if (text.StartsWith(BOMMarkUtf8))
            {
                text = text.Remove(0, BOMMarkUtf8.Length);
            }

            //DashFire.LogSystem.Debug("ScriptableDataFile.Load {0}:\n{1}", file, content);
            return(LoadFromString(text, file));
#else
            /*
             * byte[] content = FileReaderProxy.ReadFileAsArray(file);
             * string text = Encoding.UTF8.GetString(content);
             * if ( text.StartsWith(BOMMarkUtf8) )
             * {
             *  text = text.Remove(0, BOMMarkUtf8.Length);
             * }
             */

            Env = ScriptManager.Instance.SetupNewEnv(file, false);
            ScriptManager.Instance.ExecuteFile(file, false, Env, file);
            OnStart           = ScriptManager.Instance.QueryAction_1("start", Env, false);
            OnNpcStore        = ScriptManager.Instance.QueryAction_1("npcstore", Env, false);
            OnCityUserMove    = ScriptManager.Instance.QueryAction_1("cityusermove", Env, false);
            OnObjArrived      = ScriptManager.Instance.QueryAction_1("objarrived", Env, false);
            OnCityPlayerMove  = ScriptManager.Instance.QueryAction_1("cityplayermove", Env, false);
            OnPlayerMoveToPos = ScriptManager.Instance.QueryAction_1("playermovetopos", Env, false);
            OnAiMoveStop      = ScriptManager.Instance.QueryAction_1("aimovestopped", Env, false);

            return(true);
#endif
        }
Esempio n. 14
0
        private void Init(string[] args)
        {
            m_NameHandleCallback = this.OnNameHandleChanged;
            m_MsgCallback        = this.OnMessage;
            m_CmdCallback        = this.OnCommand;
            m_MsgResultCallback  = this.OnMessageResult;
            CenterClientApi.Init("roomserver", args.Length, args, m_NameHandleCallback, m_MsgCallback, m_MsgResultCallback, m_CmdCallback);

            Console.WriteLine("begin init roomserver...");
            HomePath.InitHomePath();

            bool ret = LogSys.Init("./config/logconfig.xml");

            System.Diagnostics.Debug.Assert(ret);

            last_tick_time_          = TimeUtility.GetServerMilliseconds();
            last_send_roominfo_time_ = last_tick_time_;
            is_continue_register_    = true;
            channel_ = new PBChannel(MessageMapping.Query, MessageMapping.Query);
            channel_.DefaultServiceName = "Lobby";
            lobby_connector_            = new Connector(channel_);

            server_ip_   = "127.0.0.1";
            server_port_ = 9528;

            StringBuilder sb = new StringBuilder(256);

            if (CenterClientApi.GetConfig("name", sb, 256))
            {
                room_server_name_ = sb.ToString();
            }
            if (CenterClientApi.GetConfig("ServerIp", sb, 256))
            {
                server_ip_ = sb.ToString();
            }
            if (CenterClientApi.GetConfig("ServerPort", sb, 256))
            {
                server_port_ = uint.Parse(sb.ToString());
            }
            if (CenterClientApi.GetConfig("Debug", sb, 256))
            {
                int debug = int.Parse(sb.ToString());
                if (debug != 0)
                {
                    GlobalVariables.Instance.IsDebug = true;
                }
            }

            GlobalVariables.Instance.IsClient = false;

            FileReaderProxy.RegisterReadFileHandler((string filePath) =>
            {
                byte[] buffer = null;
                try
                {
                    buffer = File.ReadAllBytes(filePath);
                }
                catch (Exception e)
                {
                    LogSys.Log(LOG_TYPE.ERROR, "Exception:{0}\n{1}", e.Message, e.StackTrace);
                    return(null);
                }
                return(buffer);
            }, (string filepath) => { return(File.Exists(filepath)); });
            LogSystem.OnOutput += (Log_Type type, string msg) =>
            {
                switch (type)
                {
                case Log_Type.LT_Debug:
                    LogSys.Log(LOG_TYPE.DEBUG, msg);
                    break;

                case Log_Type.LT_Info:
                    LogSys.Log(LOG_TYPE.INFO, msg);
                    break;

                case Log_Type.LT_Warn:
                    LogSys.Log(LOG_TYPE.WARN, msg);
                    break;

                case Log_Type.LT_Error:
                case Log_Type.LT_Assert:
                    LogSys.Log(LOG_TYPE.ERROR, msg);
                    break;
                }
            };

            LoadData();

            LogSys.Log(LOG_TYPE.DEBUG, "room server init ip: {0}  port: {1}", server_ip_, server_port_);

            ret = Serialize.Init();
            if (!ret)
            {
                LogSys.Log(LOG_TYPE.DEBUG, "Serialize init error !!!");
            }
            else
            {
                LogSys.Log(LOG_TYPE.DEBUG, "Serialize init OK.");
            }

            thread_count_          = 16;
            per_thread_room_count_ = 20;
            uint tick_interval = 50;

            room_mgr_ = new RoomManager(thread_count_, per_thread_room_count_,
                                        tick_interval, lobby_connector_);
            room_mgr_.Init();
            IOManager.Instance.Init((int)server_port_);
            room_mgr_.StartRoomThread();
            AiViewManager.Instance.Init();
            SceneLogicViewManager.Instance.Init();
            ImpactViewManager.Instance.Init();

            ServerSkillSystem.StaticInit();
            ServerStorySystem.StaticInit();
            DashFire.GmCommands.GmStorySystem.StaticInit();

            channel_.Register <Msg_LR_ReplyRegisterRoomServer>(HandleReplyRegisterRoomServer);
            room_mgr_.RegisterMsgHandler(channel_);

            LogSys.Log(LOG_TYPE.DEBUG, "room server init ok.");
        }
Esempio n. 15
0
        static void Main(string[] args)
        {
            if (args.Length != 5)
            {
                Console.WriteLine("[Usage:]lobbyrobot robotGroup threadnum robotnumperthread gmscript.gm url");
                Console.WriteLine("Current args num: {0}", args.Length);
                return;
            }
            int    robotGroup     = int.Parse(args[0]);
            int    threadNum      = int.Parse(args[1]);
            int    robotNum       = int.Parse(args[2]);
            string wayPointScript = args[3];
            string url            = args[4];
            string gmTxt          = File.ReadAllText(wayPointScript);
            // file name as scene id
            string filename = Path.GetFileNameWithoutExtension(wayPointScript);
            int    sceneId  = int.Parse(filename);

            Console.WriteLine("====================================================");
            Console.WriteLine("robot group: {0}", robotGroup);
            Console.WriteLine("thread num: {0}", threadNum);
            Console.WriteLine("robot num per thread: {0}", robotNum);
            Console.WriteLine("gmScript {0}:", wayPointScript);
            Console.WriteLine("url: {0}", url);
            Console.WriteLine("====================================================");
            Console.WriteLine("{0}", gmTxt);
            Console.WriteLine("====================================================");
            Console.WriteLine("Load tables ...");
            LogSystem.OnOutput = (Log_Type type, string msg) =>
            {
                Console.WriteLine(msg);
            };

            FileReaderProxy.RegisterReadFileHandler((string filePath) =>
            {
                byte[] buffer = null;
                try
                {
                    buffer = File.ReadAllBytes(filePath);
                }
                catch (Exception e)
                {
                    LogSystem.Error("Exception:{0}\n{1}", e.Message, e.StackTrace);
                    return(null);
                }
                return(buffer);
            }, (string path) => { return(File.Exists(path)); });

            GlobalVariables.Instance.IsClient = false;
            string tmpPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            HomePath.CurHomePath = Path.Combine(tmpPath, "../DcoreEnv/bin");
            Console.WriteLine("home path:{0}", HomePath.CurHomePath);

            SceneConfigProvider.Instance.Load(FilePathDefine_Server.C_SceneConfig, "ScenesConfigs");
            ItemConfigProvider.Instance.Load(FilePathDefine_Server.C_ItemConfig, "ItemConfig");
            PlayerConfigProvider.Instance.LoadPlayerConfig(FilePathDefine_Server.C_PlayerConfig, "PlayerConfig");
            SkillConfigProvider.Instance.CollectData(SkillConfigType.SCT_SKILL, FilePathDefine_Server.C_SkillSystemConfig, "SkillConfig");
            SkillConfigProvider.Instance.CollectData(SkillConfigType.SCT_IMPACT, FilePathDefine_Server.C_ImpactSystemConfig, "ImpactConfig");
            Console.WriteLine("Startup robots ...");

            List <RobotThread> threads = new List <RobotThread>();

            for (int i = 0; i < threadNum; ++i)
            {
                RobotThread thread = new RobotThread();
                threads.Add(thread);

                thread.Start();
                for (int j = 0; j < robotNum; ++j)
                {
                    string user = string.Format("robot_{0}_{1}_{2}", robotGroup, i, j);
                    string pwd  = "robot";
                    thread.QueueAction(thread.AddRobot, url, user, pwd, gmTxt, sceneId);
                }
            }
            Console.WriteLine("Enter infinite running ...");
            for (;;)
            {
                Thread.Sleep(1000);
            }
        }
Esempio n. 16
0
    // Use this for initialization
    internal void Start()
    {
        UnityEngine.Application.targetFrameRate = 30;
#if (UNITY_IOS || UNITY_ANDROID) && !(UNITY_EDITOR)
        QualitySettings.vSyncCount = 2;
#endif
        try
        {
            if (!GameControler.IsInited)
            {
                // register to game thread
                ArkProfiler.RegisterOutput(LogicSystem.LogFromGfx);
                // register to gfx thread, output to game console
                ArkProfiler.RegisterOutput2(UnityEngine.Debug.Log);

                // register file read handler
                FileReaderProxy.RegisterReadFileHandler(EngineReadFileProxy, EngineFileExistsProxy);

                /// Unity Editor: <path_to_project_folder>/Assets
                /// iOS player: <path_to_player_app_bundle>/<AppName.app>/Data (this folder is read only, use Application.persistentDataPath to save data).
                /// Android: Normally it would point directly to the APK. The exception is if you are running a split binary build in which case it points to the the OBB instead.
                string dataPath = UnityEngine.Application.dataPath;
                /// Point to data path which have write permission
                string persistentDataPath = Application.persistentDataPath;
                /// Point to readonly data, note some platofrm like android points to compressed apk, witch cant be directory accesssed, use www. etc instead
                string streamingAssetsPath = UnityEngine.Application.streamingAssetsPath;
                /// Point to temp data path, may clean by system
                string tempPath = UnityEngine.Application.temporaryCachePath;
                LogicSystem.LogFromGfx("dataPath:{0} persistentDataPath:{1} streamingAssetsPath:{2} tempPath:{3}", dataPath, persistentDataPath, streamingAssetsPath, tempPath);
                Debug.Log(string.Format("dataPath:{0} persistentDataPath:{1} streamingAssetsPath:{2} tempPath:{3}", dataPath, persistentDataPath, streamingAssetsPath, tempPath));

                // store log in tempPath, others to persistentDataPath
#if !UNITY_EDITOR
                GlobalVariables.Instance.IsDevice = true;
#else
                // if in editor, use streamingAssetsPath instead
                GlobalVariables.Instance.IsDevice = false;
#endif

#if UNITY_ANDROID || UNITY_WEBGL
                if (!UnityEngine.Application.isEditor)
                {
                    streamingAssetsPath = persistentDataPath + "/Tables";
                }
#endif

#if UNITY_WEBGL
                // init web socket before gamelogic initialize
                m_WebSocket = new WebGLSocket();
                ArkCrossEngine.Network.WebSocketWrapper.Instance.SetInstance(m_WebSocket);
#endif

                LogSystem.OnOutput2 = (Log_Type type, string msg) =>
                {
#if DEBUG
                    if (Log_Type.LT_Error == type)
                    {
                        UnityEngine.Debug.LogError(msg);
                    }
                    else if (Log_Type.LT_Info != type)
                    {
                        UnityEngine.Debug.LogWarning(msg);
                    }
#endif
                };

                GameControler.Init(tempPath, streamingAssetsPath);

                NormLog.Instance.Init();
                NormLog.Instance.Record(GameEventCode.GameStart);

                LogicSystem.LogFromGfx("game log saved to: {0}", tempPath);
            }

            // try preload all skills used by npc in spec scene, also character
            LogicSystem.OnAfterLoadScene += AfterLoadScene;
        }
        catch (Exception ex)
        {
            LogicSystem.LogErrorFromGfx("GameLogic.Start throw exception:{0}\n{1}", ex.Message, ex.StackTrace);
            Debug.Log(string.Format("GameLogic.Start throw exception:{0}\n{1}", ex.Message, ex.StackTrace));
        }
    }
Esempio n. 17
0
        private void Init(string[] args)
        {
            m_NameHandleCallback = this.OnNameHandleChanged;
            m_MsgCallback        = this.OnMessage;
            m_CmdCallback        = this.OnCommand;
            m_MsgResultCallback  = this.OnMessageResult;
            CenterClientApi.Init("lobby", args.Length, args, m_NameHandleCallback, m_MsgCallback, m_MsgResultCallback, m_CmdCallback);

            LogSys.Init("./config/logconfig.xml");
            LobbyConfig.Init();

            if (LobbyConfig.IsDebug)
            {
                GlobalVariables.Instance.IsDebug = true;
            }

            GlobalVariables.Instance.IsClient = false;

            FileReaderProxy.RegisterReadFileHandler((string filePath) =>
            {
                byte[] buffer = null;
                try
                {
                    buffer = File.ReadAllBytes(filePath);
                }
                catch (Exception e)
                {
                    LogSys.Log(LOG_TYPE.ERROR, "Exception:{0}\n{1}", e.Message, e.StackTrace);
                    return(null);
                }
                return(buffer);
            }, (string filePath) =>
            {
                return(File.Exists(filePath));
            });
            LogSystem.OnOutput += (Log_Type type, string msg) =>
            {
                switch (type)
                {
                case Log_Type.LT_Debug:
                    LogSys.Log(LOG_TYPE.DEBUG, msg);
                    break;

                case Log_Type.LT_Info:
                    LogSys.Log(LOG_TYPE.INFO, msg);
                    break;

                case Log_Type.LT_Warn:
                    LogSys.Log(LOG_TYPE.WARN, msg);
                    break;

                case Log_Type.LT_Error:
                case Log_Type.LT_Assert:
                    LogSys.Log(LOG_TYPE.ERROR, msg);
                    break;
                }
            };

            LoadData();

            LogSys.Log(LOG_TYPE.INFO, "Init Config ...");
            s_Instance = this;
            InstallMessageHandlers();
            LogSys.Log(LOG_TYPE.INFO, "Init Messenger ...");
            m_DataStoreThread.Init(m_StoreChannel);
            LogSys.Log(LOG_TYPE.INFO, "Init DataStore ...");
            m_ServerBridgeThread.Init(m_BridgeChannel);
            LogSys.Log(LOG_TYPE.INFO, "Init BillingClient ...");
            m_GmServerThread.Init(m_GmSvrChannel);
            LogSys.Log(LOG_TYPE.INFO, "Init GmServerThread ...");
            Start();
            LogSys.Log(LOG_TYPE.INFO, "Start Threads ...");
        }