Skip to content
This repository was archived by the owner on Dec 5, 2018. It is now read-only.

Commit f117384

Browse files
Added an ExampleEntity entity baked into a snapshot
Includes entity template, prefab, snapshot containing entity and customized Unity Editor menu to provide an easy way of programmatically determining the contents of a snapshot
1 parent 384bca2 commit f117384

File tree

12 files changed

+194
-0
lines changed

12 files changed

+194
-0
lines changed

snapshots/initial_world.snapshot

106 Bytes
Binary file not shown.

workers/unity/Assets/Editor.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using Assets.EntityTemplates;
4+
using Improbable;
5+
using Improbable.Worker;
6+
using UnityEngine;
7+
using JetBrains.Annotations;
8+
using UnityEditor;
9+
10+
public class SnapshotMenu : MonoBehaviour
11+
{
12+
private static readonly string InitialWorldSnapshotPath = Application.dataPath +
13+
"/../../../snapshots/initial_world.snapshot";
14+
15+
[MenuItem("Improbable/Snapshots/Generate Snapshot Programmatically")]
16+
[UsedImplicitly]
17+
private static void GenerateSnapshotProgrammatically()
18+
{
19+
var snapshotEntities = new Dictionary<EntityId, SnapshotEntity>();
20+
var currentEntityId = 0;
21+
22+
snapshotEntities.Add(new EntityId(currentEntityId++), ExampleEntityTemplate.GenerateExampleSnapshotEntityTemplate());
23+
24+
SaveSnapshot(snapshotEntities);
25+
}
26+
27+
private static void SaveSnapshot(IDictionary<EntityId, SnapshotEntity> snapshotEntities)
28+
{
29+
File.Delete(InitialWorldSnapshotPath);
30+
var maybeError = Snapshot.Save(InitialWorldSnapshotPath, snapshotEntities);
31+
32+
if (maybeError.HasValue)
33+
{
34+
Debug.LogErrorFormat("Failed to generate initial world snapshot: {0}", maybeError.Value);
35+
}
36+
else
37+
{
38+
Debug.LogFormat("Successfully generated initial world snapshot at {0}", InitialWorldSnapshotPath);
39+
}
40+
}
41+
}

workers/unity/Assets/Editor/SnapshotMenu.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
6.66 KB
Binary file not shown.

workers/unity/Assets/EntityPrefabs/ExampleEntity.prefab.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

workers/unity/Assets/EntityTemplates.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Improbable.General;
2+
using Improbable.Worker;
3+
using Improbable.Math;
4+
using Improbable.Unity.Core.Acls;
5+
using UnityEngine;
6+
7+
namespace Assets.EntityTemplates
8+
{
9+
public class ExampleEntityTemplate : MonoBehaviour
10+
{
11+
// Template definition for a Example entity
12+
public static SnapshotEntity GenerateExampleSnapshotEntityTemplate()
13+
{
14+
// Set name of Unity prefab associated with this entity
15+
var exampleEntity = new SnapshotEntity { Prefab = "ExampleEntity" };
16+
17+
// Define components attached to snapshot entity
18+
exampleEntity.Add(new WorldTransform.Data(new WorldTransformData(new Coordinates(-5, 10, 0))));
19+
20+
// Grant FSim (server-side) workers write-access over all of this entity's components, read-access for visual (e.g. client) workers
21+
var acl = Acl.GenerateServerAuthoritativeAcl(exampleEntity);
22+
exampleEntity.SetAcl(acl);
23+
24+
return exampleEntity;
25+
}
26+
}
27+
}

workers/unity/Assets/EntityTemplates/ExampleEntityTemplate.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

workers/unity/Assets/Gamelogic.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)