本文整理汇总了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;
//.........这里部分代码省略.........