public void moveFormLabel(Int64 id_t, Communication.Proto.GameObject gameObjectMessage, ref HashSet <Int64> IDsToDelete) { if (!Program.form.playerLabels.ContainsKey(id_t)) { CreatePlayerLabel(id_t); if (Program.form.playerLabels[id_t].InvokeRequired) { Program.form.playerLabels[id_t].Invoke(new Action <Int64, Communication.Proto.GameObject>(initializeFormLabelMethod), id_t, gameObjectMessage); } else { initializeFormLabelMethod(id_t, gameObjectMessage); } //recordDic[true].Add(id_t); Console.WriteLine("New Form : " + id_t + " (" + gameObjectMessage.PositionX + "," + gameObjectMessage.PositionY + ") " + gameObjectMessage.ObjType); } else { //recordDic[true].Add(id_t); IDsToDelete.Remove(id_t); //Console.WriteLine("Change Form"); } if (Program.form.playerLabels[id_t].InvokeRequired) { Program.form.playerLabels[id_t].Invoke(new Action <Int64, Communication.Proto.GameObject>(RefreshFormLabelMethod), id_t, gameObjectMessage); } else { RefreshFormLabelMethod(id_t, gameObjectMessage); } }
//instantiate different types of objects in the game //warning: this function can be called in the main thread only void _Instantiate(long objKey, GameObjectMessage objValue) { //Debug.Log("试图创建物体" + objValue.ObjType.ToString()+','+objKey.ToString()); if (objValue.ObjType == ObjType.People) { var c = Instantiate(RandomCharacter()); //let the camera follow the player, not others if (objKey == this.playerId) { cameraFollow.target = c;//-1 when playback, so ok } if (playMode == 1) { cameraFollow.charactersQueue.Enqueue(c); } characters.TryAdd(objKey, c.GetComponent <CharacterScript>()); characters[objKey].DecodeMessage(objValue); } else if (objValue.ObjType == ObjType.Block) { var p = Instantiate(this.platform); platforms.TryAdd(objKey, p.GetComponent <PlatformScript>()); platforms[objKey].DecodeMessage(objValue); } else { var i = Instantiate(itemManager.ItemMap(objValue)); items.TryAdd(objKey, i.GetComponent <ItemScript>()); items[objKey].DecodeMessage(objValue); } //Debug.Log("已创建物体" + objValue.ObjType.ToString() + ',' + objKey.ToString()); }
//if DecodeMessage() public void DecodeMessage(GameObjectMessage obj) { position = PositionMessageToVector3((float)obj.PositionX, (float)obj.PositionY); if (obj.BlockType == BlockType.Cooker) { position.y = cookerHeight; } dishType = obj.DishType; }
//update infos of an object void _Update(long objKey, GameObjectMessage objValue, ObjType type) { if (type == ObjType.People) { if (characters.ContainsKey(objKey)) { //Debug.Log("更新角色"); characters[objKey].DecodeMessage(objValue); //Debug.Log("更新完成"); } else { if (!isCharactersExisted.ContainsKey(objKey)) { isCharactersExisted.TryAdd(objKey, true); instantiateTaskQueue.Enqueue(new KeyValuePair <long, GameObjectMessage>(objKey, objValue)); } } //Debug.Log("更新角色"+objKey.ToString()); } else if (objValue.ObjType == ObjType.Block) { if (platforms.ContainsKey(objKey)) { platforms[objKey].DecodeMessage(objValue); } else { if (!isPlatformsExisted.ContainsKey(objKey)) { isPlatformsExisted.TryAdd(objKey, true); instantiateTaskQueue.Enqueue(new KeyValuePair <long, GameObjectMessage>(objKey, objValue)); } } } else { if (items.ContainsKey(objKey)) { items[objKey].DecodeMessage(objValue); } else { if (!isItemsExisted.ContainsKey(objKey)) { isItemsExisted.TryAdd(objKey, true); instantiateTaskQueue.Enqueue(new KeyValuePair <long, GameObjectMessage>(objKey, objValue)); } } } //Debug.Log("更新物体" + type.ToString()); }
// Start is called before the first frame update void Start() { //initialize cookerHeight = 2.2f; position = new Vector3(); dish = null; dishType = DishType.DishEmpty; oldDishType = DishType.DishEmpty; msg = new GameObjectMessage { ObjType = ObjType.Dish }; }
public void initializeFormLabelMethod(Int64 id_t, Communication.Proto.GameObject gameObjectMessage) { switch (gameObjectMessage.ObjType) { case ObjType.People: Program.form.playerLabels[id_t].BackColor = System.Drawing.Color.Red; Program.form.playerLabels[id_t].TabIndex = 1; break; case ObjType.Block: switch (gameObjectMessage.BlockType) { case BlockType.FoodPoint: Program.form.playerLabels[id_t].BackColor = System.Drawing.Color.Purple; Program.form.playerLabels[id_t].Text = gameObjectMessage.DishType.ToString(); break; case BlockType.Cooker: Program.form.playerLabels[id_t].BackColor = System.Drawing.Color.SandyBrown; break; case BlockType.RubbishBin: Program.form.playerLabels[id_t].BackColor = System.Drawing.Color.DarkGreen; break; } break; case ObjType.Dish: Program.form.playerLabels[id_t].BackColor = System.Drawing.Color.LightSalmon; Program.form.playerLabels[id_t].Text = gameObjectMessage.DishType.ToString(); break; case ObjType.Tool: Program.form.playerLabels[id_t].BackColor = System.Drawing.Color.LightCyan; Program.form.playerLabels[id_t].Text = gameObjectMessage.ToolType.ToString(); break; case ObjType.Trigger: Program.form.playerLabels[id_t].BackColor = System.Drawing.Color.DarkBlue; Program.form.playerLabels[id_t].Text = gameObjectMessage.TriggerType.ToString(); break; } Program.form.playerLabels[id_t].Location = new System.Drawing.Point( (int)((gameObjectMessage.PositionX - 0.5) * GameForm.Form1.LABEL_WIDTH + Form1.HALF_LABEL_INTERVAL), Convert.ToInt32((WorldMap.Height - gameObjectMessage.PositionY - 0.5) * GameForm.Form1.LABEL_WIDTH + Form1.HALF_LABEL_INTERVAL)); Program.form.playerLabels[id_t].Size = new System.Drawing.Size(Form1.LABEL_WIDTH - Form1.LABEL_INTERVAL, Form1.LABEL_WIDTH - Form1.LABEL_INTERVAL); Program.form.playerLabels[id_t].BringToFront(); }
// Start is called before the first frame update void Start() { //initialize animator = GetComponentInParent <Animator>(); position = new Vector3(); direction = new Vector3(); isMoving = false; lastReceiveCount = ManagerScript.receiveCount; dish = tool = null; dishType = oldDishType = DishType.DishEmpty; toolType = oldToolType = ToolType.ToolEmpty; msg = new GameObjectMessage(); scale = new Vector3(0.4f, 0.4f, 0.4f); }
public void DecodeMessage(GameObjectMessage obj) { if (teamId < 0) { teamId = obj.Team; } //Debug.Log("-----decode-----"); position = PositionMessageToVector3((float)obj.PositionX, (float)obj.PositionY); //Debug.Log($"*****xposition change to:{position.x}"); direction = DirectionMessageToVector3(obj.Direction); //z?float isMoving = obj.IsMoving; dishType = obj.DishType; toolType = obj.ToolType; lastReceiveCount = ManagerScript.receiveCount; }
public void RefreshFormLabelMethod(Int64 id_t, Communication.Proto.GameObject gameObjectMessage) { switch (gameObjectMessage.ObjType) { case ObjType.People: Program.form.playerLabels[id_t].Location = new System.Drawing.Point( (int)((gameObjectMessage.PositionX - 0.5) * GameForm.Form1.LABEL_WIDTH + Form1.HALF_LABEL_INTERVAL), Convert.ToInt32((WorldMap.Height - gameObjectMessage.PositionY - 0.5) * GameForm.Form1.LABEL_WIDTH + Form1.HALF_LABEL_INTERVAL)); switch ((THUnity2D.Direction)gameObjectMessage.Direction) { case THUnity2D.Direction.Right: Program.form.playerLabels[id_t].Text = "→"; break; case THUnity2D.Direction.RightUp: Program.form.playerLabels[id_t].Text = "↗"; break; case THUnity2D.Direction.Up: Program.form.playerLabels[id_t].Text = "↑"; break; case THUnity2D.Direction.LeftUp: Program.form.playerLabels[id_t].Text = "↖"; break; case THUnity2D.Direction.Left: Program.form.playerLabels[id_t].Text = "←"; break; case THUnity2D.Direction.LeftDown: Program.form.playerLabels[id_t].Text = "↙"; break; case THUnity2D.Direction.Down: Program.form.playerLabels[id_t].Text = "↓"; break; case THUnity2D.Direction.RightDown: Program.form.playerLabels[id_t].Text = "↘"; break; default: break; } if (id_t == this.id) { if (gameObjectMessage.DishType != DishType.DishEmpty) { ChangeControlLabelText("Dish", gameObjectMessage.DishType.ToString()); } else { ChangeControlLabelText("Dish", ""); } if (gameObjectMessage.ToolType != ToolType.ToolEmpty && gameObjectMessage.ToolType != ToolType.ToolSize) { ChangeControlLabelText("Tool", gameObjectMessage.ToolType.ToString()); } else { ChangeControlLabelText("Tool", ""); } } break; case ObjType.Block: switch (gameObjectMessage.BlockType) { case BlockType.FoodPoint: if (gameObjectMessage.DishType == DishType.DishEmpty) { Program.form.playerLabels[id_t].Text = ""; } else { Program.form.playerLabels[id_t].Text = gameObjectMessage.DishType.ToString(); } break; case BlockType.Cooker: if (gameObjectMessage.DishType == DishType.DishEmpty) { Program.form.playerLabels[id_t].Text = ""; } else { Program.form.playerLabels[id_t].Text = gameObjectMessage.DishType.ToString(); } break; } break; case ObjType.Dish: Program.form.playerLabels[id_t].Location = new System.Drawing.Point( (int)((gameObjectMessage.PositionX - 0.5) * GameForm.Form1.LABEL_WIDTH + Form1.HALF_LABEL_INTERVAL), Convert.ToInt32((WorldMap.Height - gameObjectMessage.PositionY - 0.5) * GameForm.Form1.LABEL_WIDTH + Form1.HALF_LABEL_INTERVAL)); Program.form.playerLabels[id_t].Text = gameObjectMessage.DishType.ToString(); break; case ObjType.Tool: Program.form.playerLabels[id_t].Location = new System.Drawing.Point( (int)((gameObjectMessage.PositionX - 0.5) * GameForm.Form1.LABEL_WIDTH + Form1.HALF_LABEL_INTERVAL), Convert.ToInt32((WorldMap.Height - gameObjectMessage.PositionY - 0.5) * GameForm.Form1.LABEL_WIDTH + Form1.HALF_LABEL_INTERVAL)); Program.form.playerLabels[id_t].Text = gameObjectMessage.ToolType.ToString(); break; case ObjType.Trigger: Program.form.playerLabels[id_t].Location = new System.Drawing.Point( (int)((gameObjectMessage.PositionX - 0.5) * GameForm.Form1.LABEL_WIDTH + Form1.HALF_LABEL_INTERVAL), Convert.ToInt32((WorldMap.Height - gameObjectMessage.PositionY - 0.5) * GameForm.Form1.LABEL_WIDTH + Form1.HALF_LABEL_INTERVAL)); break; } }
public GameObject ItemMap(GameObjectMessage objValue) { //Debug.Log(objValue.ObjType.ToString() + ":" + objValue.DishType.ToString()); GameObject retVal; if (objValue.ObjType == ObjType.Dish) { switch (objValue.DishType) { //case DishType.Apple: // retVal = apple; // break; //case DishType.Banana: // retVal = banana; // break; case DishType.Tomato: retVal = tomato; break; case DishType.Potato: retVal = potato; break; //case DishType.Agaric: // retVal = agaric; // break; //case DishType.AgaricFriedEgg: // retVal = agaricFriedEgg; // break; case DishType.Barbecue: retVal = barbecue; break; case DishType.Beef: retVal = beef; break; case DishType.BeefNoodle: retVal = beefNoodle; break; case DishType.Bread: retVal = bread; break; //case DishType.Cabbage: // retVal = cabbage; // break; //case DishType.Cake: // retVal = cake; // break; //case DishType.ChickenMeat: // retVal = chickenMeat; // break; case DishType.CookedRice: retVal = cookedRice; break; //case DishType.Cream: // retVal = cream; // break; case DishType.DarkDish: retVal = darkDish; break; //case DishType.DarkPlum: // retVal = darkPlum; // break; case DishType.Egg: retVal = egg; break; case DishType.Flour: retVal = flour; break; case DishType.FrenchFries: retVal = frenchFries; break; //case DishType.FruitSalad: // retVal = fruitSalad; // break; case DishType.Hamburger: retVal = hamburger; break; //case DishType.Hawthorn: // retVal = hawthorn; // break; case DishType.Ketchup: retVal = ketchup; break; case DishType.Lettuce: retVal = lettuce; break; //case DishType.Milk: // retVal = milk; // break; //case DishType.NeedleMushroom: // retVal = needleMushroom; // break; case DishType.Noodle: retVal = noodle; break; case DishType.OverCookedDish: retVal = darkDish; break; case DishType.OverRice: retVal = overRice; break; //case DishType.PlumJuice: // retVal = plumJuice; // break; //case DishType.PopcornChicken: // retVal = popcornChicken; // break; case DishType.Pork: retVal = pork; break; case DishType.Rice: retVal = rice; break; case DishType.SpicedPot: retVal = spicedPot; break; case DishType.SpicedPot3: retVal = spicedPot; break; case DishType.SpicedPot4: retVal = spicedPot; break; case DishType.SpicedPot5: retVal = spicedPot; break; case DishType.SpicedPot6: retVal = spicedPot; break; //case DishType.SpicedPot7: // retVal = spicedPot; // break; //case DishType.SpicedPot8: // retVal = spicedPot; // break; //case DishType.Strawberry: // retVal = strawberry; // break; //case DishType.StrawberryIcecream: // retVal = strawberryIcecream; // break; //case DishType.SugarCoatedHaws: // retVal = sugarCoatedHaws; // break; case DishType.TomatoFriedEgg: retVal = tomatoFriedEgg; break; case DishType.TomatoFriedEggNoodle: retVal = tomatoFriedEggNoodle; break; case DishType.Wheat: retVal = wheat; break; //case DishType.YellowPheasant: // retVal = yellowPheasant; // break; default: retVal = darkDish; break; } } else if (objValue.ObjType == ObjType.Tool) { switch (objValue.ToolType) { case ToolType.Bow: retVal = bow; break; case ToolType.BreastPlate: retVal = breastPlate; break; case ToolType.Condiment: retVal = condiment; break; case ToolType.Fertilizer: retVal = fertilizer; break; case ToolType.FlashBomb: retVal = flashBomb; break; case ToolType.LandMine: retVal = landMine; break; case ToolType.SpaceGate: retVal = spaceGate; break; case ToolType.SpeedBuff: retVal = speedBuff; break; case ToolType.Stealer: retVal = stealer; break; case ToolType.StrengthBuff: retVal = strengthBuff; break; case ToolType.TeleScope: retVal = teleScope; break; case ToolType.ThrowHammer: retVal = throwHammer; break; case ToolType.TigerShoes: retVal = tigerShoes; break; case ToolType.TrapTool: retVal = trapTool; break; case ToolType.WaveGlueBottle: retVal = waveGlueBottle; break; default: retVal = darkDish; break; } } else { retVal = null; } if (retVal == null) { retVal = darkDish; } return(retVal); }
//if DecodeMessage() public void DecodeMessage(GameObjectMessage obj) { position = PositionMessageToVector3((float)obj.PositionX, (float)obj.PositionY); lastReceiveCount = ManagerScript.receiveCount; }