Skip to content

Commit

Permalink
Version 0.5b1 (#10)
Browse files Browse the repository at this point in the history
* SIM-65 (#8)
- Added button to open URL of a neighbourhood

* SIM-66 (#9)

- Added first person camera for plane and tank
- Added UI icons for tank and plane for bottom bar
- Added camera manager for managing active camera
- Added TopText component to seperate code
- Added events when target changed of plane or tank
- Changed all sprites for a nicer background
- Fixed propellor moving for airplane
- Fixed bug with spawn point for plane
- Fixed tank rotating back
- First person HUD text
- Fixed a bug in destroying grid tiles
- Fixed opening a webpage in Unity Editor
- Fixed clicking somewhere when camera is changed
- Fixed opening new tab for WebGL version when opening neighbourhood URL
- Updated Camera Controller for better zooming
- Updated version number of inno setup file
- Updated README
- Updated gif
- Reset highlighting and infopanel when camera is changed
- Splitted functions in AssetsPropertiesApplier
- Tank or plane sprite color now changes when selected
  • Loading branch information
leroyvandijk authored Jun 4, 2020
1 parent 4419091 commit 3ce0da0
Show file tree
Hide file tree
Showing 37 changed files with 1,872 additions and 331 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ If you want to use these assets, read chapter 5.1
| A / Left Arrow | Move the camera to the left |
| S / Down Arrow | Move the camera backwards |
| D / Right Arrow | Move the camera to the right |
| Escape | Go back to the main menu |
| Escape | Go back to the main menu or escape different camera view |
| F4 | Open the debug console |
| Left mouse button | When clicked on a building or vehicle it displays information |
| Hold right mouse button| Rotate the camera around |
Expand Down Expand Up @@ -467,6 +467,8 @@ To use chaos engineering there has been decided to let a tank drive around toget

If a hit happens, a building will collapse and a docker container will real-time be destroyed.

If you click on the tank or the plane in the UI the camera will switch to the vehicle. You can switch back to the normal view by pressing the button again.

There are settings to disable the airplane or tank. There is also a setting where you can set the minimum required buildings.

It is more safe to set this to 2. If you use this in a production environment it could happen that a service with only 1 instance is getting killed.
Expand Down Expand Up @@ -564,19 +566,21 @@ For example, for the scooter the following settings were used:
| Auto Re-path | Enabled |
| Area Mask | Walkable |

5. If the prefab is a tank or a plane, add a camera to the object, align it correctly and give it the correct Tag `TankCamera` or `PlaneCamera`.

## Important! Buildings & Vehicles

These steps are necessary only if you intend to use the team selection.

**The material must not contain any white spaces.**

5. Place the material you used in the Resources/Materials folder.
6. Place the material you used in the Resources/Materials folder.

6. Duplicate the material and rename the duplicated material to **Transparent-** *Material name*. (I know this is not a really nice thing, but it's because of WebGL limitations)
7. Duplicate the material and rename the duplicated material to **Transparent-** *Material name*. (I know this is not a really nice thing, but it's because of WebGL limitations)

7. Set the Rendering mode to **Fade** of the transparent material.
8. Set the Rendering mode to **Fade** of the transparent material.

8. Edit the `config.json` and set all the prefabs to the correct names.
9. Edit the `config.json` and set all the prefabs to the correct names.

For performance reasons it is advised to **enable** GPU instancing for the transparent material and the original prefab material.

Expand Down
Binary file modified img/simtainer.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion innosetup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "SimTainer"
#define MyAppVersion "0.4b1"
#define MyAppVersion "0.5b1"
#define MyAppPublisher "Wehkamp"
#define MyAppExeName "SimTainer.exe"

Expand Down
209 changes: 142 additions & 67 deletions src/Assets/Editor/AssetsPropertiesApplier.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -86,6 +87,7 @@ private enum ComponentType
{
NavMeshAgent,
NotWalkable,
Camera,
None
}

Expand All @@ -100,16 +102,16 @@ private enum ComponentType
private static void ApplyPropertiesToPrefab(string prefabName, string assetBundle, string tag,
ComponentType componentType = ComponentType.None, bool generateTransparentMaterials = false)
{
string[] strings = AssetDatabase.FindAssets(prefabName);
string[] assetGuids = AssetDatabase.FindAssets(prefabName);

for (int i = 0; i < strings.Length; i++)
foreach (string assetGuid in assetGuids)
{
string assetPath = AssetDatabase.GUIDToAssetPath(strings[i]);
string assetPath = AssetDatabase.GUIDToAssetPath(assetGuid);
// Match exact name of prefab
if (Path.GetFileName(assetPath) != prefabName + ".prefab") continue;
Debug.Log($"Handling {prefabName}");
GameObject targetGameObject =
PrefabUtility.LoadPrefabContents(AssetDatabase.GUIDToAssetPath(strings[i]));
PrefabUtility.LoadPrefabContents(AssetDatabase.GUIDToAssetPath(assetGuid));

if (targetGameObject == null)
{
Expand All @@ -120,91 +122,87 @@ private static void ApplyPropertiesToPrefab(string prefabName, string assetBundl
// Already done this one
if (targetGameObject.CompareTag(tag)) continue;

// Mark the object as a dirty object so we can edit it
EditorUtility.SetDirty(targetGameObject);
PrefabUtility.RecordPrefabInstancePropertyModifications(targetGameObject);
switch (componentType)
{
case ComponentType.NavMeshAgent:
if (targetGameObject.GetComponent<NavMeshAgent>() == null)
{
NavMeshAgent n = targetGameObject.AddComponent<NavMeshAgent>();
n.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;
n.avoidancePriority = 0;
n.baseOffset = 0.1f;
n.radius = 1.0f;
}

break;
case ComponentType.NotWalkable:
if (targetGameObject.GetComponent<NavMeshModifier>() == null)
{
NavMeshModifier navMeshModifier = targetGameObject.AddComponent<NavMeshModifier>();
navMeshModifier.overrideArea = true;
navMeshModifier.area = NavMesh.GetAreaFromName("Not Walkable");
}

break;
}

// Set the correct tag of the object
targetGameObject.tag = tag;

AddComponent(componentType, targetGameObject);

Renderer[] renders = targetGameObject.GetComponents<Renderer>();
foreach (Renderer t in renders)
{
if (t.sharedMaterial == null) continue;
ApplyMaterialProperties(assetBundle, t.sharedMaterial);

if (generateTransparentMaterials)
{
CreateTransparentMaterial(assetBundle, t.sharedMaterial);
}
}

Renderer[] childRenderers = targetGameObject.GetComponentsInChildren<Renderer>();
foreach (Renderer t in childRenderers)
{
if (t.sharedMaterial == null) continue;
ApplyMaterialProperties(assetBundle, t.sharedMaterial);

if (generateTransparentMaterials)
{
CreateTransparentMaterial(assetBundle, t.sharedMaterial);
}
}
FixRenderers(renders, assetBundle, generateTransparentMaterials);
FixRenderers(childRenderers, assetBundle, generateTransparentMaterials);

// Finally save the asset. Unload the scene, destroy the objects
PrefabUtility.SaveAsPrefabAsset(targetGameObject, assetPath);
SetAssetBundles(assetBundle, assetPath);
PrefabUtility.UnloadPrefabContents(targetGameObject);
AsyncOperation unloading = SceneManager.UnloadSceneAsync(SceneManager.GetActiveScene(),
UnloadSceneOptions.UnloadAllEmbeddedSceneObjects);

int ticks = 0;
while (unloading != null && !unloading.isDone && ticks < 30)
FinishObject(targetGameObject, assetBundle, assetPath);
}
}

private static void FinishObject(GameObject targetGameObject, string assetBundle, string assetPath)
{
PrefabUtility.SaveAsPrefabAsset(targetGameObject, assetPath);
SetAssetBundles(assetBundle, assetPath);
PrefabUtility.UnloadPrefabContents(targetGameObject);
AsyncOperation unloading = SceneManager.UnloadSceneAsync(SceneManager.GetActiveScene(),
UnloadSceneOptions.UnloadAllEmbeddedSceneObjects);

int ticks = 0;
while (unloading != null && !unloading.isDone && ticks < 30)
{
Thread.Sleep(100);
ticks++;
}
}

/// <summary>
/// Function to apply all material properties of the given renderers.
/// </summary>
/// <param name="renderers"></param>
/// <param name="assetBundle"></param>
/// <param name="generateTransparentMaterials"></param>
private static void FixRenderers(IEnumerable<Renderer> renderers, string assetBundle, bool generateTransparentMaterials)
{
foreach (Renderer renderer in renderers)
{
if (renderer.sharedMaterial == null) continue;

// Apply all material properties
ApplyMaterialProperties(assetBundle, renderer.sharedMaterial);

// Generate a transparent material if required
if (generateTransparentMaterials)
{
Thread.Sleep(100);
ticks++;
CreateTransparentMaterial(assetBundle, renderer.sharedMaterial);
}
}
}

private static void ApplyMaterialProperties(string assetBundleName, Material m)
/// <summary>
/// Function to apply default properties to a material.
/// </summary>
/// <param name="assetBundleName"></param>
/// <param name="material"></param>
private static void ApplyMaterialProperties(string assetBundleName, Material material)
{
if (m.enableInstancing) return;
EditorUtility.SetDirty(m);
m.enableInstancing = true;
SetAssetBundles(assetBundleName, AssetDatabase.GetAssetPath(m.GetInstanceID()));
if (material.enableInstancing) return;
EditorUtility.SetDirty(material);
material.enableInstancing = true;
SetAssetBundles(assetBundleName, AssetDatabase.GetAssetPath(material.GetInstanceID()));
}

/// <summary>
/// Function to create a transparent material based on an existing material
/// </summary>
/// <param name="assetBundleName"></param>
/// <param name="m"></param>
private static void CreateTransparentMaterial(string assetBundleName, Material m)
/// <param name="originalMaterial"></param>
private static void CreateTransparentMaterial(string assetBundleName, Material originalMaterial)
{
string path = AssetDatabase.GetAssetPath(m);
// Get the original path of the material
string path = AssetDatabase.GetAssetPath(originalMaterial);

string newFileName = path.Split('/').Last().Insert(0, "Transparent-");

Expand All @@ -216,10 +214,12 @@ private static void CreateTransparentMaterial(string assetBundleName, Material m
return;
}

Material newMaterial = new Material(Shader.Find(m.shader.name));
Material newMaterial = new Material(Shader.Find(originalMaterial.shader.name));

newMaterial.CopyPropertiesFromMaterial(m);
// Copy the properties from the original material
newMaterial.CopyPropertiesFromMaterial(originalMaterial);

// Set new properties of material to enable transparency
newMaterial.SetInt("_SrcBlend", (int) UnityEngine.Rendering.BlendMode.SrcAlpha);
newMaterial.SetInt("_DstBlend", (int) UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
newMaterial.SetInt("_ZWrite", 0);
Expand All @@ -229,7 +229,11 @@ private static void CreateTransparentMaterial(string assetBundleName, Material m
newMaterial.color = new Color(newMaterial.color.r, newMaterial.color.g, newMaterial.color.b, 0.3f);
newMaterial.renderQueue = 3000;
newMaterial.enableInstancing = true;

// Finally create the material as an asset
AssetDatabase.CreateAsset(newMaterial, newPath);

// And set the correct asset bundle of the material
SetAssetBundles(assetBundleName, newPath);
}

Expand All @@ -243,5 +247,76 @@ private static void SetAssetBundles(string assetBundleName, string assetPath)
if (!string.IsNullOrEmpty(assetPath) && !string.IsNullOrEmpty(assetBundleName))
AssetImporter.GetAtPath(assetPath).SetAssetBundleNameAndVariant(assetBundleName, "");
}

/// <summary>
/// Add a component to a game object based on the component type
/// </summary>
/// <param name="componentType"></param>
/// <param name="targetGameObject"></param>
private static void AddComponent(ComponentType componentType, GameObject targetGameObject)
{
switch (componentType)
{
case ComponentType.NavMeshAgent:
if (targetGameObject.GetComponent<NavMeshAgent>() == null)
{
NavMeshAgent n = targetGameObject.AddComponent<NavMeshAgent>();
n.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;
n.avoidancePriority = 0;
n.baseOffset = 0.1f;
n.radius = 1.0f;
}

break;
case ComponentType.NotWalkable:
if (targetGameObject.GetComponent<NavMeshModifier>() == null)
{
NavMeshModifier navMeshModifier = targetGameObject.AddComponent<NavMeshModifier>();
navMeshModifier.overrideArea = true;
navMeshModifier.area = NavMesh.GetAreaFromName("Not Walkable");
}

break;
case ComponentType.Camera:
// These camera settings are based on the paid assets pack
if (targetGameObject.GetComponent<Camera>() == null)
{
GameObject cameraObject = new GameObject();

Camera camera = cameraObject.AddComponent<Camera>();
camera.clearFlags = CameraClearFlags.Color;
// Set default background color
camera.backgroundColor = new Color32(88, 85, 74, 255);
camera.orthographic = false;

Vector3 defaultPositionForPaidAssetPack = Vector3.zero;
Quaternion defaultRotationForPaidAssetPack = Quaternion.Euler(0, 0, 0);
float defaultFieldOfViewForPaidAssetPack = 0f;
switch (targetGameObject.tag)
{
case "Plane":
cameraObject.tag = "PlaneCamera";

defaultPositionForPaidAssetPack = new Vector3(-0.88f, 25.1f, -4.7f);
defaultRotationForPaidAssetPack = Quaternion.Euler(70, 0, 0);
defaultFieldOfViewForPaidAssetPack = 47.1f;
break;
case "Tank":
cameraObject.tag = "TankCamera";

defaultPositionForPaidAssetPack = new Vector3(-1.08f, 1f, 0.23f);
defaultFieldOfViewForPaidAssetPack = 60f;
break;
}

cameraObject.transform.position = defaultPositionForPaidAssetPack;
cameraObject.transform.rotation = defaultRotationForPaidAssetPack;
camera.fieldOfView = defaultFieldOfViewForPaidAssetPack;
cameraObject.transform.SetParent(targetGameObject.transform);
}

break;
}
}
}
}
8 changes: 8 additions & 0 deletions src/Assets/Plugins/OpenWebpage.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/Assets/Plugins/OpenWebpage/OpenWebpage.jslib
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mergeInto(LibraryManager.library, {

openPage: function (url){
window.open(Pointer_stringify(url),'_blank');
}
});
32 changes: 32 additions & 0 deletions src/Assets/Plugins/OpenWebpage/OpenWebpage.jslib.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3ce0da0

Please sign in to comment.