當前位置: 首頁>>代碼示例>>C#>>正文


C# AppHost.GetCacheClient方法代碼示例

本文整理匯總了C#中AppHost.GetCacheClient方法的典型用法代碼示例。如果您正苦於以下問題:C# AppHost.GetCacheClient方法的具體用法?C# AppHost.GetCacheClient怎麽用?C# AppHost.GetCacheClient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在AppHost的用法示例。


在下文中一共展示了AppHost.GetCacheClient方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Start

    void Start()
    {
        // search for textures
        var texturepath = String.Concat(Environment.CurrentDirectory, @"\webroot\textures");
        var info = new DirectoryInfo(texturepath);
        var fileInfo = info.GetFiles();
        var availableTextures = new String[fileInfo.Length];
        foreach(FileInfo file in fileInfo){

            Debug.Log(file.Name);
        }

        // write config file
        string path = String.Concat(Environment.CurrentDirectory, @"\webroot\js\server-config.js");
        TextWriter configFile = new StreamWriter(path);
        configFile.WriteLine("function ServerConfig(){");
        configFile.WriteLine(String.Concat(@"this.ip = """, Network.player.ipAddress, @""";"));
        configFile.WriteLine(String.Concat(@"this.screenWidth = ", Screen.width, @";"));
        configFile.WriteLine(String.Concat(@"this.screenHeight = ", Screen.height, @";"));

        // write texture array
        configFile.WriteLine("this.textures = [");
        for(var i = 0; i < fileInfo.Length; i++){
            if(i == fileInfo.Length - 1) {
                configFile.WriteLine(String.Concat(@"""", fileInfo[i].Name, @""""));
            } else {
                configFile.WriteLine(String.Concat(@"""", fileInfo[i].Name, @""","));
            }
        }
        configFile.WriteLine("]");

        configFile.WriteLine("}");
        configFile.Close ();

        try {
            // create and start the host
            appHost = new AppHost();
            appHost.Config.WebHostPhysicalPath = Path.Combine(Directory.GetCurrentDirectory(), webrootPath);
            appHost.Init();
            appHost.Start(host);
            Debug.Log("Server listening at http://" + Network.player.ipAddress + "/home");
            Cache = appHost.GetCacheClient();
        }
        catch (Exception exeption) {
            Debug.Log(exeption);
            Cache = new MemoryCacheClient();
        }
        var instance = FindObjectOfType(typeof(Exec)) as Exec;
        if (instance == null) {
            instance = gameObject.AddComponent<Exec>();
        }

        wsServer = new WebSocketServer(1081) {
            OnDisconnect = context => {
                print("DISCONNECT");
            },

            // Called when the server connects
            OnConnected = context => {
                var response = (object)null;
                isConnected = true;
                GameObject cached = default(GameObject);
                shouldHideIP = true;
                OnGUI();

                if (!OnlineUsers.ContainsKey(context.ClientAddress.ToString())) {
                    OnlineUsers[context.ClientAddress.ToString()] = context;
                }

                // Called when the server disconnects
                context.SetOnDisconnect((e) => {
                    UserContext ctx = null;
                    OnlineUsers.TryRemove(e.ClientAddress.ToString(), out ctx);
                    if (ctx != null) {
                        Exec.OnMain(() => Debug.Log("User: " + ctx.ClientAddress + " has disconnected"));
                    }
                });

                // Called when new data is received over the socket
                context.SetOnReceive((e) => {
                    try {
                        var jsonObject = JSON.Parse(e.DataFrame.ToString());
                        var eventIdentifier = jsonObject["event_identifier"].Value;
                        var uuid = jsonObject["uuid"].Value;

                        switch (eventIdentifier) {

                        case "create_rect":
                            Exec.OnMain(() => {
                                GameObject rect = GameObject.CreatePrimitive(PrimitiveType.Quad);
                                rect.name = uuid;
                                rect.transform.position = new Vector3(0, 0, zIndexCounter);
                                zIndexCounter--;

                                //set shaders and custom behaviours
                                rect.renderer.material.shader = Shader.Find("Custom/transform");
                                moveRect moveBehaviour = rect.AddComponent("moveRect") as moveRect;
                                projectionMatrix matrix = rect.AddComponent("projectionMatrix") as projectionMatrix;
                                vertexPositions vertexPositioning = rect.AddComponent<vertexPositions> () as vertexPositions;

//.........這裏部分代碼省略.........
開發者ID:Distort-Mapping,項目名稱:distortion,代碼行數:101,代碼來源:StartHost.cs


注:本文中的AppHost.GetCacheClient方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。