Skip to content

Commit

Permalink
Merge pull request #59 from hhzzff/dev
Browse files Browse the repository at this point in the history
feat: ✨ Added basic functions dealing with ship & bullet mes…
  • Loading branch information
Cyh28 authored Dec 29, 2023
2 parents 9af126f + 2d6959a commit 56ca14c
Show file tree
Hide file tree
Showing 10 changed files with 5,690 additions and 3,468 deletions.
52 changes: 30 additions & 22 deletions interface/Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -270,36 +270,15 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 2020139210}
- component: {fileID: 2020139209}
- component: {fileID: 2020139211}
- component: {fileID: 2020139212}
m_Layer: 0
m_Name: GameManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &2020139209
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2020139208}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6bd56b6eee0bc3f4da48e1882fd58fdb, type: 3}
m_Name:
m_EditorClassIdentifier:
spaceG: {fileID: 3763284726051510260, guid: 991ffbdd1770fa744ad6e9335807a90e, type: 3}
ruinG: {fileID: 1304984658260562521, guid: 693d92e1c7f9c6e4597faf934cdb42c0, type: 3}
homeG: {fileID: 2487624789702488523, guid: 9ba3f57fff0f3f240aad67b489d717f2, type: 3}
shadowG: {fileID: 0}
asteroidG: {fileID: 73901610976941151, guid: c7b49a90d8bef8d46a4bce231bbd4bbc, type: 3}
resourceG: {fileID: 3917097161056082449, guid: 698b4c070ca03c24486b31eb1e5afe81, type: 3}
communityG: {fileID: 6520154078847335470, guid: 3ca3df56b82e8484ca02de1e96d8cef9, type: 3}
factoryG: {fileID: 6257076823173944538, guid: f0f5b7271131c0f4b97b109570925eb9, type: 3}
fortressG: {fileID: 2765499537454312851, guid: c0434feb803d4aa439d0ae84becb87c6, type: 3}
--- !u!4 &2020139210
Transform:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -328,6 +307,35 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
mapFa: {fileID: 2074007630}
--- !u!114 &2020139212
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2020139208}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6bd56b6eee0bc3f4da48e1882fd58fdb, type: 3}
m_Name:
m_EditorClassIdentifier:
spaceG: {fileID: 3763284726051510260, guid: 991ffbdd1770fa744ad6e9335807a90e, type: 3}
ruinG: {fileID: 1304984658260562521, guid: 693d92e1c7f9c6e4597faf934cdb42c0, type: 3}
homeplaceG: {fileID: 2487624789702488523, guid: 9ba3f57fff0f3f240aad67b489d717f2, type: 3}
shadowG: {fileID: 0}
asteroidG: {fileID: 73901610976941151, guid: c7b49a90d8bef8d46a4bce231bbd4bbc, type: 3}
resourceG: {fileID: 3917097161056082449, guid: 698b4c070ca03c24486b31eb1e5afe81, type: 3}
communityG: {fileID: 6520154078847335470, guid: 3ca3df56b82e8484ca02de1e96d8cef9, type: 3}
factoryG: {fileID: 6257076823173944538, guid: f0f5b7271131c0f4b97b109570925eb9, type: 3}
fortG: {fileID: 2765499537454312851, guid: c0434feb803d4aa439d0ae84becb87c6, type: 3}
civilianshipG: {fileID: 5171509434299531292, guid: bf6625a2d3f00dd48b69ae78320c2ae9, type: 3}
militaryshipG: {fileID: 7636309505896027477, guid: bc122dbec7939954f8fde7be8f609605, type: 3}
flagshipG: {fileID: 9176460285754036534, guid: 3dafac374e7e5334ebdd2c352bfd214a, type: 3}
laserG: {fileID: 0}
plasmaG: {fileID: 0}
shellG: {fileID: 0}
missileG: {fileID: 0}
arcG: {fileID: 0}
--- !u!1 &2074007630
GameObject:
m_ObjectHideFlags: 0
Expand Down
83 changes: 83 additions & 0 deletions interface/Assets/Scripts/Live/MessageReceiverLive.cs
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;
}
}
}
}
3 changes: 2 additions & 1 deletion interface/Assets/Scripts/MapControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using Protobuf;

public class MapControl : MonoBehaviour {
public GameObject mapFa;
Expand Down Expand Up @@ -38,7 +39,7 @@ void Start()
fs.Close();
for (int i = 0; i < 50; i++) {
for (int j = 0; j < 50; j++) {
Instantiate(ParaDefine.GetInstance().PT((ParaDefine.PlaceType)map[i][j]), new Vector3(j, 50 - i, 0), Quaternion.identity, mapFa.transform);
Instantiate(ParaDefine.GetInstance().PT((PlaceType)map[i][j]), new Vector3(j, 50 - i, 0), Quaternion.identity, mapFa.transform);
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions interface/Assets/Scripts/MessageManager.cs
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>();
}
65 changes: 43 additions & 22 deletions interface/Assets/Scripts/ParaDefine.cs
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;
}
}
}
Loading

0 comments on commit 56ca14c

Please sign in to comment.