public void ResetAll(App.Model.Master.MBaseMap baseMapMaster = null) { if (baseMapMaster == null) { Debug.LogError("ViewModel.MapId.Value = " + ViewModel.MapId.Value); baseMapMaster = BaseMapCacher.Instance.Get(ViewModel.MapId.Value); } int widthCount = 0; int heightCount = 0; int i = 0; VTile obj = null; foreach (VTile tile in tileUnits) { tile.gameObject.SetActive(false); } if (baseMapMaster.tiles != null && baseMapMaster.tiles.Count > 0) { foreach (App.Model.Master.MTile tile in baseMapMaster.tiles) { i = heightCount * mapWidth + widthCount; obj = tileUnits[i]; obj.gameObject.SetActive(true); App.Model.MTile building = System.Array.Find(ViewModel.Tiles.Value, _ => _.x == widthCount && _.y == heightCount); //if(building != null)Debug.LogError(widthCount + ","+heightCount + ", " + building.Master); string name = ""; if (building != null) { if (building is App.Model.Master.MWorld) { name = (building as App.Model.Master.MWorld).build_name; }/*else if (building is App.Model.Master.MArea) * { * name = (building as App.Model.Master.MArea).build_name; * }*/ } obj.SetData(heightCount * baseMapMaster.width + widthCount, widthCount, heightCount, tile.id, building != null ? building.Master.id : 0, name); widthCount++; if (widthCount >= baseMapMaster.width) { widthCount = 0; heightCount++; } if (heightCount >= baseMapMaster.height) { break; } } } BoxCollider collider = this.GetComponent <BoxCollider>(); collider.size = new Vector3(baseMapMaster.width * tileWidth + 0.345f, baseMapMaster.height * tileHeight + 0.2f, 0f); collider.center = new Vector3(collider.size.x * 0.5f - 0.345f, -collider.size.y * 0.5f + 0.4f, 0f); mousePosition.x = int.MinValue; dragPosition.x = int.MinValue; }
public void MoveToPosition(int x = int.MinValue, int y = 0, App.Model.Master.MBaseMap baseMapMaster = null) { if (baseMapMaster == null) { baseMapMaster = BaseMapCacher.Instance.Get(ViewModel.MapId.Value); } if (x == int.MinValue) { x = Mathf.FloorToInt(baseMapMaster.width / 2f); y = Mathf.FloorToInt(baseMapMaster.height / 2f); } int i = y * mapWidth + x; VTile obj = tileUnits[i]; Camera3dToPosition(obj.transform.position.x, obj.transform.position.y - 9f); obj = tileUnits[0]; minPosition = new Vector2(obj.transform.position.x, obj.transform.position.y - 9f); i = (baseMapMaster.height - 1) * mapWidth + baseMapMaster.width - 1; obj = tileUnits[i]; maxPosition = new Vector2(obj.transform.position.x, obj.transform.position.y - 9f); }
private void CharactersChanged(App.Model.MCharacter[] oldvalue, App.Model.MCharacter[] newvalue) { if (newvalue == null || newvalue.Length == 0) { return; } foreach (App.Model.MCharacter mCharacter in newvalue) { VCharacter vCharacter = vCharacters.Find(_ => _.ViewModel.Id.Value == mCharacter.Id); if (vCharacter == null) { //新建武将 GameObject obj = this.Controller.ScrollViewSetChild(characterLayer.transform, characterPrefab, mCharacter); obj.name = string.Format("Character_{0}_{1}", mCharacter.Belong.ToString(), mCharacter.CharacterId.ToString()); int i = mCharacter.CoordinateY * mapWidth + mCharacter.CoordinateX; VTile vTile = tileUnits[i]; obj.transform.eulerAngles = new Vector3(-30f, 0f, 0f); obj.transform.localPosition = vTile.transform.localPosition; obj.transform.localScale = new Vector3(0.6f, 0.6f, 1f); mCharacter.X = obj.transform.localPosition.x; mCharacter.Y = obj.transform.localPosition.y; mCharacter.Action = App.Model.ActionType.idle; obj.GetComponent <VCharacter>().UpdateView(); } else { vCharacters.Remove(vCharacter); //更新武将 } } if (vCharacters.Count > 0) { //删除多余武将 } vCharacters = characterLayer.GetComponentsInChildren <VCharacter>(true).ToList(); }