-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from hhzzff/dev
feat: ✨ Added basic functions dealing with ship & bullet mes…
- Loading branch information
Showing
10 changed files
with
5,690 additions
and
3,468 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using Grpc.Core; | ||
using Protobuf; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEditor.Experimental.GraphView; | ||
using UnityEngine; | ||
using UnityEngine.SceneManagement; | ||
|
||
public class MessageReceiverLive : MonoBehaviour | ||
{ | ||
public static string IP = null; | ||
public static string Port = null; | ||
public static string filename = null; | ||
|
||
public static MessageOfMap map; | ||
|
||
// Start is called before the first frame update | ||
async void Start() | ||
{ | ||
try { | ||
var channel = new Channel(IP + ":" + Port, ChannelCredentials.Insecure); | ||
var client = new AvailableService.AvailableServiceClient(channel); | ||
PlayerMsg msg = new PlayerMsg(); | ||
msg.PlayerId = -1; | ||
msg.ShipType = ShipType.NullShipType; | ||
msg.TeamId = -1; | ||
msg.X = msg.Y = -1; | ||
var response = client.AddPlayer(msg); | ||
if (await response.ResponseStream.MoveNext()) { | ||
var responseVal = response.ResponseStream.Current; | ||
map = responseVal.ObjMessage[0].MapMessage; | ||
} | ||
while (await response.ResponseStream.MoveNext()) { | ||
var responseVal = response.ResponseStream.Current; | ||
Receive(responseVal); | ||
} | ||
IP = null; | ||
Port = null; | ||
}catch (RpcException) { | ||
IP = null; | ||
Port = null; | ||
} | ||
} | ||
private void Receive(MessageToClient message) { | ||
foreach (var messageOfObj in message.ObjMessage) { | ||
switch (messageOfObj.MessageOfObjCase) { | ||
case MessageOfObj.MessageOfObjOneofCase.ShipMessage: | ||
if(MessageManager.GetInstance().ShipG[messageOfObj.ShipMessage.Guid] == null){ | ||
MessageManager.GetInstance().ShipG[messageOfObj.ShipMessage.Guid] = | ||
Instantiate(ParaDefine.GetInstance().PT(messageOfObj.ShipMessage.ShipType), | ||
new Vector3(messageOfObj.ShipMessage.X, messageOfObj.ShipMessage.Y), | ||
Quaternion.identity, | ||
GameObject.Find("Ship").transform); | ||
MessageManager.GetInstance().Ship[messageOfObj.ShipMessage.Guid] = messageOfObj.ShipMessage; | ||
} | ||
break; | ||
case MessageOfObj.MessageOfObjOneofCase.BulletMessage: | ||
if(MessageManager.GetInstance().BulletG[messageOfObj.BulletMessage.Guid] == null){ | ||
MessageManager.GetInstance().BulletG[messageOfObj.BulletMessage.Guid] = | ||
Instantiate(ParaDefine.GetInstance().PT(messageOfObj.BulletMessage.Type), | ||
new Vector3(messageOfObj.BulletMessage.X, messageOfObj.BulletMessage.Y), | ||
Quaternion.identity, | ||
GameObject.Find("Bullet").transform); | ||
MessageManager.GetInstance().Bullet[messageOfObj.BulletMessage.Guid] = messageOfObj.BulletMessage; | ||
} | ||
break; | ||
case MessageOfObj.MessageOfObjOneofCase.FactoryMessage: | ||
break; | ||
case MessageOfObj.MessageOfObjOneofCase.CommunityMessage: | ||
break; | ||
case MessageOfObj.MessageOfObjOneofCase.FortMessage: | ||
break; | ||
case MessageOfObj.MessageOfObjOneofCase.WormholeMessage: | ||
break; | ||
case MessageOfObj.MessageOfObjOneofCase.HomeMessage: | ||
break; | ||
case MessageOfObj.MessageOfObjOneofCase.ResourceMessage: | ||
break; | ||
default: break; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Protobuf; | ||
using UnityEngine; | ||
|
||
public class MessageManager : Singleton<MessageManager> | ||
{ | ||
|
||
public Dictionary <long, MessageOfShip> Ship = new Dictionary<long, MessageOfShip>(); | ||
public Dictionary <long, GameObject> ShipG = new Dictionary<long, GameObject>(); | ||
public Dictionary <long, MessageOfBullet> Bullet = new Dictionary<long, MessageOfBullet>(); | ||
public Dictionary <long, GameObject> BulletG = new Dictionary<long, GameObject>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,64 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
using Protobuf; | ||
public class ParaDefine : SingletonDontDestory<ParaDefine> | ||
{ | ||
public enum PlaceType { | ||
Space, | ||
Ruin, | ||
Home, | ||
Shadow, | ||
Asteroid, | ||
Resource, | ||
Community, | ||
Factory, | ||
Fortress, | ||
}; | ||
public GameObject spaceG, ruinG, homeG, shadowG, asteroidG, resourceG, communityG, factoryG, fortressG; | ||
public GameObject spaceG, ruinG, homeplaceG, shadowG, asteroidG, resourceG, communityG, factoryG, fortG; | ||
public GameObject civilianshipG, militaryshipG, flagshipG; | ||
public GameObject laserG, plasmaG, shellG, missileG, arcG; | ||
public GameObject PT(PlaceType _placeType) { | ||
switch (_placeType) { | ||
case PlaceType.Space: | ||
return spaceG; | ||
case PlaceType.Ruin: | ||
return ruinG; | ||
case PlaceType.Home: | ||
return homeG; | ||
case PlaceType.HomePlace: | ||
return homeplaceG; | ||
case PlaceType.Shadow: | ||
return shadowG; | ||
case PlaceType.Asteroid: | ||
return asteroidG; | ||
case PlaceType.Community: | ||
return communityG; | ||
case PlaceType.Factory: | ||
return factoryG; | ||
case PlaceType.Fortress: | ||
return fortressG; | ||
case PlaceType.Resource: | ||
return resourceG; | ||
default: return null; | ||
} | ||
} | ||
|
||
public GameObject PT(ConstructionType _constructionType) { | ||
switch (_constructionType) { | ||
case ConstructionType.Community: | ||
return communityG; | ||
case ConstructionType.Factory: | ||
return factoryG; | ||
case ConstructionType.Fort: | ||
return fortG; | ||
default: return null; | ||
} | ||
} | ||
public GameObject PT(ShipType _shipType) { | ||
switch (_shipType) { | ||
case ShipType.CivilianShip: | ||
return civilianshipG; | ||
case ShipType.MilitaryShip: | ||
return militaryshipG; | ||
case ShipType.FlagShip: | ||
return flagshipG; | ||
default: return null; | ||
} | ||
} | ||
public GameObject PT(BulletType _bulletType) { | ||
switch (_bulletType) { | ||
case BulletType.Laser: | ||
return laserG; | ||
case BulletType.Plasma: | ||
return plasmaG; | ||
case BulletType.Shell: | ||
return shellG; | ||
case BulletType.Missile: | ||
return missileG; | ||
case BulletType.Arc: | ||
return arcG; | ||
default: return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.