当前位置: 首页>>代码示例>>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;未经允许,请勿转载。