Skip to content
This repository was archived by the owner on Mar 24, 2019. It is now read-only.

Commit 54aa28d

Browse files
committed
Added Message sending to example and updated lib to v1.0.1
1 parent 923046f commit 54aa28d

4 files changed

Lines changed: 38 additions & 30 deletions

File tree

Assets/MLAPI/Lib/MLAPI.dll

20.5 KB
Binary file not shown.

Assets/MenuScene.unity

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,13 @@ MonoBehaviour:
385385
- Name: UDP Socket
386386
Port: 7777
387387
Websockets: 0
388-
Channels: []
389-
MessageTypes: []
388+
Channels:
389+
- Name: ColorChannel
390+
Type: 3
391+
Encrypted: 0
392+
MessageTypes:
393+
- Name: OnChangeColor
394+
Passthrough: 0
390395
RegisteredScenes:
391396
- MenuScene
392397
NetworkedPrefabs:

Assets/PlayerTest.cs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using MLAPI.Attributes;
22
using MLAPI.MonoBehaviours.Core;
3+
using MLAPI.NetworkingManagerComponents.Binary;
34
using UnityEngine;
45
using UnityEngine.UI;
56

@@ -10,17 +11,31 @@ public class PlayerTest : NetworkedBehaviour
1011
public Text TextField;
1112
public GameObject cubePrefab;
1213
public GameObject spherePrefab;
14+
public Material planeMaterial;
1315

1416
public override void NetworkStart()
1517
{
16-
if (isServer)
18+
if (isServer && isLocalPlayer)
1719
MySyncedName = "SyncVarTest: " + Random.Range(50, 10000);
20+
21+
planeMaterial = GameObject.Find("Plane").GetComponent<MeshRenderer>().material;
22+
if (isClient)
23+
RegisterMessageHandler("OnChangeColor", OnChangeColor);
24+
}
25+
26+
private void OnChangeColor(uint clientId, byte[] data)
27+
{
28+
BitReader reader = new BitReader(data);
29+
float r = reader.ReadFloat();
30+
float g = reader.ReadFloat();
31+
float b = reader.ReadFloat();
32+
planeMaterial.color = new Color(r, g, b);
1833
}
1934

2035
private void OnGUI()
2136
{
2237
int y = 25;
23-
if (isServer)
38+
if (isServer && isLocalPlayer)
2439
{
2540
y += 25;
2641
if (GUI.Button(new Rect(200, y, 200, 20), "Change Text with SyncVar"))
@@ -43,25 +58,25 @@ private void OnGUI()
4358
go.transform.position = transform.position + new Vector3(0, 3f, 0);
4459
go.GetComponent<NetworkedObject>().Spawn();
4560
}
61+
62+
y += 25;
63+
if (GUI.Button(new Rect(200, y, 200, 20), "Set random plane color"))
64+
{
65+
planeMaterial.color = Random.ColorHSV();
66+
using (BitWriter writer = new BitWriter())
67+
{
68+
writer.WriteFloat(planeMaterial.color.r);
69+
writer.WriteFloat(planeMaterial.color.g);
70+
writer.WriteFloat(planeMaterial.color.b);
71+
SendToClientsTarget("OnChangeColor", "ColorChannel", writer.Finalize());
72+
}
73+
}
4674
}
4775
}
4876

4977
private void Update()
5078
{
5179
TextField.text = MySyncedName;
52-
if(isServer && Input.GetKeyDown(KeyCode.Space) && Input.GetKeyDown(KeyCode.LeftShift) && isLocalPlayer)
53-
{
54-
GameObject go = Instantiate(cubePrefab);
55-
go.transform.position = transform.position + new Vector3(0, 1f, 0);
56-
go.GetComponent<NetworkedObject>().Spawn();
57-
}
58-
else if(isServer && Input.GetKeyDown(KeyCode.Space) && isLocalPlayer)
59-
{
60-
MySyncedName = "SyncVarTest: " + Random.Range(50, 10000) + " (Press space on server)";
61-
GameObject go = Instantiate(spherePrefab);
62-
go.transform.position = transform.position + new Vector3(0, 1f, 0);
63-
go.GetComponent<NetworkedObject>().Spawn();
64-
}
6580
}
6681

6782
}

Assets/ThirdPersonController.prefab

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ GameObject:
421421
- component: {fileID: 114766929903620868}
422422
- component: {fileID: 114687023312749170}
423423
- component: {fileID: 114639041936224248}
424-
- component: {fileID: 114491358826367966}
425424
m_Layer: 0
426425
m_Name: ThirdPersonController
427426
m_TagString: Untagged
@@ -1997,7 +1996,7 @@ Transform:
19971996
m_PrefabParentObject: {fileID: 0}
19981997
m_PrefabInternal: {fileID: 100100000}
19991998
m_GameObject: {fileID: 1880393464162266}
2000-
m_LocalRotation: {x: 0.5326752, y: 0.070340455, z: 0.83613276, w: -0.110415146}
1999+
m_LocalRotation: {x: 0.53267515, y: 0.07034045, z: 0.83613265, w: -0.11041513}
20012000
m_LocalPosition: {x: 0.000022271464, y: -0.00006150465, z: 0.026027026}
20022001
m_LocalScale: {x: 1, y: 1, z: 1}
20032002
m_Children:
@@ -2559,17 +2558,6 @@ MonoBehaviour:
25592558
cubePrefab: {fileID: 1595020433191848, guid: 03a297f61fe3ef344989473054d7a493, type: 2}
25602559
spherePrefab: {fileID: 1631893145635948, guid: 02e37f97df7ed8d459e06fd7c4e9e5df,
25612560
type: 2}
2562-
--- !u!114 &114491358826367966
2563-
MonoBehaviour:
2564-
m_ObjectHideFlags: 1
2565-
m_PrefabParentObject: {fileID: 0}
2566-
m_PrefabInternal: {fileID: 100100000}
2567-
m_GameObject: {fileID: 1329915689972608}
2568-
m_Enabled: 1
2569-
m_EditorHideFlags: 0
2570-
m_Script: {fileID: -1450621975, guid: 21c7301987155c0499132f8dc0b202f5, type: 3}
2571-
m_Name:
2572-
m_EditorClassIdentifier:
25732561
--- !u!114 &114639041936224248
25742562
MonoBehaviour:
25752563
m_ObjectHideFlags: 1

0 commit comments

Comments
 (0)