[TASK] Initial commit with basic product setup
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
namespace Mapbox.Unity.MeshGeneration.Modifiers
|
||||
{
|
||||
using Mapbox.Unity.MeshGeneration.Data;
|
||||
using Mapbox.Unity.MeshGeneration.Components;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
[CreateAssetMenu(menuName = "Mapbox/Modifiers/Add Monobehaviours Modifier")]
|
||||
public class AddMonoBehavioursModifier : GameObjectModifier
|
||||
{
|
||||
[SerializeField]
|
||||
AddMonoBehavioursModifierType[] _types;
|
||||
private HashSet<string> _scripts;
|
||||
private string _tempId;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
if (_scripts == null)
|
||||
{
|
||||
_scripts = new HashSet<string>();
|
||||
_tempId = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Run(VectorEntity ve, UnityTile tile)
|
||||
{
|
||||
foreach (var t in _types)
|
||||
{
|
||||
_tempId = ve.GameObject.GetInstanceID() + t.Type.FullName;
|
||||
if (!_scripts.Contains(_tempId))
|
||||
{
|
||||
ve.GameObject.AddComponent(t.Type);
|
||||
_scripts.Add(_tempId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3b6ec6b924494ffda604db0a299df8d
|
||||
timeCreated: 1499897465
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,35 @@
|
||||
namespace Mapbox.Unity.MeshGeneration.Modifiers
|
||||
{
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
[Serializable]
|
||||
public class AddMonoBehavioursModifierType
|
||||
{
|
||||
[SerializeField]
|
||||
string _typeString;
|
||||
|
||||
Type _type;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[SerializeField]
|
||||
MonoScript _script;
|
||||
#endif
|
||||
|
||||
public Type Type
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_type == null)
|
||||
{
|
||||
_type = Type.GetType(_typeString);
|
||||
}
|
||||
return _type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90b119b6678da4c80a69a3a4d8793d7f
|
||||
timeCreated: 1499897465
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace Mapbox.Unity.MeshGeneration.Modifiers
|
||||
{
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.MeshGeneration.Components;
|
||||
using Mapbox.Unity.MeshGeneration.Data;
|
||||
|
||||
[CreateAssetMenu(menuName = "Mapbox/Modifiers/Add To Collection Modifier")]
|
||||
public class AddToCollectionModifier : GameObjectModifier
|
||||
{
|
||||
[SerializeField]
|
||||
private FeatureCollectionBase _collection;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_collection.Initialize();
|
||||
}
|
||||
|
||||
public override void Run(VectorEntity ve, UnityTile tile)
|
||||
{
|
||||
_collection.AddFeature(new double[] { ve.Transform.position.x, ve.Transform.position.z }, ve);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4538b91da572dfa41adf689573eaba4b
|
||||
timeCreated: 1519739956
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,176 @@
|
||||
namespace Mapbox.Unity.MeshGeneration.Modifiers
|
||||
{
|
||||
using Mapbox.Unity.MeshGeneration.Data;
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.MeshGeneration.Components;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using Mapbox.Unity.Map;
|
||||
|
||||
[CreateAssetMenu(menuName = "Mapbox/Modifiers/Collider Modifier")]
|
||||
public class ColliderModifier : GameObjectModifier
|
||||
{
|
||||
//[SerializeField]
|
||||
//private ColliderType _colliderType;
|
||||
private IColliderStrategy _colliderStrategy;
|
||||
|
||||
[SerializeField]
|
||||
ColliderOptions _options;
|
||||
|
||||
|
||||
public override void SetProperties(ModifierProperties properties)
|
||||
{
|
||||
_options = (ColliderOptions)properties;
|
||||
_options.PropertyHasChanged += UpdateModifier;
|
||||
}
|
||||
|
||||
public override void UnbindProperties()
|
||||
{
|
||||
_options.PropertyHasChanged -= UpdateModifier;
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
//no need to reset strategy objects on map reinit as we're caching feature game objects as well
|
||||
//creating a new one iff we don't already have one. if you want to reset/recreate you have to clear stuff inside current/old one first.
|
||||
|
||||
switch (_options.colliderType)
|
||||
{
|
||||
case ColliderType.None:
|
||||
_colliderStrategy = null;
|
||||
break;
|
||||
case ColliderType.BoxCollider:
|
||||
_colliderStrategy = new BoxColliderStrategy();
|
||||
break;
|
||||
case ColliderType.MeshCollider:
|
||||
_colliderStrategy = new MeshColliderStrategy();
|
||||
break;
|
||||
case ColliderType.SphereCollider:
|
||||
_colliderStrategy = new SphereColliderStrategy();
|
||||
break;
|
||||
default:
|
||||
_colliderStrategy = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Run(VectorEntity ve, UnityTile tile)
|
||||
{
|
||||
// if collider exists. remove it.
|
||||
RemoveColliderFrom(ve);
|
||||
if (_colliderStrategy != null)
|
||||
{
|
||||
_colliderStrategy.AddColliderTo(ve);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveColliderFrom(VectorEntity ve)
|
||||
{
|
||||
var existingCollider = ve.GameObject.GetComponent<Collider>();
|
||||
if (existingCollider != null)
|
||||
{
|
||||
UnityEngine.Object.Destroy(existingCollider);
|
||||
if (_colliderStrategy != null)
|
||||
{
|
||||
_colliderStrategy.Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class BoxColliderStrategy : IColliderStrategy
|
||||
{
|
||||
private Dictionary<GameObject, BoxCollider> _colliders;
|
||||
|
||||
public BoxColliderStrategy()
|
||||
{
|
||||
_colliders = new Dictionary<GameObject, BoxCollider>();
|
||||
}
|
||||
|
||||
public void AddColliderTo(VectorEntity ve)
|
||||
{
|
||||
if (_colliders.ContainsKey(ve.GameObject))
|
||||
{
|
||||
_colliders[ve.GameObject].center = ve.Mesh.bounds.center;
|
||||
_colliders[ve.GameObject].size = ve.Mesh.bounds.size;
|
||||
}
|
||||
else
|
||||
{
|
||||
_colliders.Add(ve.GameObject, ve.GameObject.AddComponent<BoxCollider>());
|
||||
}
|
||||
}
|
||||
public void Reset()
|
||||
{
|
||||
if (_colliders != null)
|
||||
{
|
||||
_colliders.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MeshColliderStrategy : IColliderStrategy
|
||||
{
|
||||
private Dictionary<GameObject, MeshCollider> _colliders;
|
||||
|
||||
public MeshColliderStrategy()
|
||||
{
|
||||
_colliders = new Dictionary<GameObject, MeshCollider>();
|
||||
}
|
||||
|
||||
public void AddColliderTo(VectorEntity ve)
|
||||
{
|
||||
if (_colliders.ContainsKey(ve.GameObject))
|
||||
{
|
||||
_colliders[ve.GameObject].sharedMesh = ve.Mesh;
|
||||
}
|
||||
else
|
||||
{
|
||||
_colliders.Add(ve.GameObject, ve.GameObject.AddComponent<MeshCollider>());
|
||||
}
|
||||
}
|
||||
public void Reset()
|
||||
{
|
||||
if (_colliders != null)
|
||||
{
|
||||
_colliders.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SphereColliderStrategy : IColliderStrategy
|
||||
{
|
||||
private Dictionary<GameObject, SphereCollider> _colliders;
|
||||
|
||||
public SphereColliderStrategy()
|
||||
{
|
||||
_colliders = new Dictionary<GameObject, SphereCollider>();
|
||||
}
|
||||
|
||||
public void AddColliderTo(VectorEntity ve)
|
||||
{
|
||||
if (_colliders.ContainsKey(ve.GameObject))
|
||||
{
|
||||
_colliders[ve.GameObject].center = ve.Mesh.bounds.center;
|
||||
_colliders[ve.GameObject].radius = ve.Mesh.bounds.extents.magnitude;
|
||||
}
|
||||
else
|
||||
{
|
||||
_colliders.Add(ve.GameObject, ve.GameObject.AddComponent<SphereCollider>());
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
if (_colliders != null)
|
||||
{
|
||||
_colliders.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface IColliderStrategy
|
||||
{
|
||||
void AddColliderTo(VectorEntity ve);
|
||||
void Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 288d05a2dbabb0f46a5fa6c85102780a
|
||||
timeCreated: 1494350918
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Mapbox.Unity.MeshGeneration.Modifiers
|
||||
{
|
||||
using Mapbox.Unity.MeshGeneration.Data;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(menuName = "Mapbox/Modifiers/Disable Mesh Renderer Modifier")]
|
||||
public class DisableMeshRendererModifier : GameObjectModifier
|
||||
{
|
||||
public override void Run(VectorEntity ve, UnityTile tile)
|
||||
{
|
||||
ve.MeshRenderer.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0fe0aeb4b2814799b34ce6cfd6308a1
|
||||
timeCreated: 1508781994
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,36 @@
|
||||
namespace Mapbox.Unity.MeshGeneration.Modifiers
|
||||
{
|
||||
using Mapbox.Unity.MeshGeneration.Data;
|
||||
using Mapbox.Unity.MeshGeneration.Components;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
[CreateAssetMenu(menuName = "Mapbox/Modifiers/Add Feature Behaviour Modifier")]
|
||||
public class FeatureBehaviourModifier : GameObjectModifier
|
||||
{
|
||||
private Dictionary<GameObject, FeatureBehaviour> _features;
|
||||
private FeatureBehaviour _tempFeature;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
if (_features == null)
|
||||
{
|
||||
_features = new Dictionary<GameObject, FeatureBehaviour>();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Run(VectorEntity ve, UnityTile tile)
|
||||
{
|
||||
if (_features.ContainsKey(ve.GameObject))
|
||||
{
|
||||
_features[ve.GameObject].Initialize(ve);
|
||||
}
|
||||
else
|
||||
{
|
||||
_tempFeature = ve.GameObject.AddComponent<FeatureBehaviour>();
|
||||
_features.Add(ve.GameObject, _tempFeature);
|
||||
_tempFeature.Initialize(ve);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fdf79806a4f74da4aa48339c010a208c
|
||||
timeCreated: 1499897465
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace Mapbox.Unity.MeshGeneration.Modifiers
|
||||
{
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.MeshGeneration.Components;
|
||||
using Mapbox.Unity.MeshGeneration.Data;
|
||||
|
||||
[CreateAssetMenu(menuName = "Mapbox/Modifiers/Layer Modifier")]
|
||||
public class LayerModifier : GameObjectModifier
|
||||
{
|
||||
[SerializeField]
|
||||
private int _layerId;
|
||||
|
||||
public override void Run(VectorEntity ve, UnityTile tile)
|
||||
{
|
||||
ve.GameObject.layer = _layerId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4644f4fa4408d144a9c7927401f3807
|
||||
timeCreated: 1494349551
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,64 @@
|
||||
namespace Mapbox.Unity.MeshGeneration.Modifiers
|
||||
{
|
||||
using Mapbox.Unity.MeshGeneration.Data;
|
||||
using UnityEngine.Assertions;
|
||||
using UnityEngine;
|
||||
|
||||
public class MapboxStylesColorModifier : GameObjectModifier
|
||||
{
|
||||
|
||||
public ScriptablePalette m_scriptablePalette;
|
||||
|
||||
private const string _BASE_COLOR_NAME = "_BaseColor";
|
||||
private const string _DETAIL_ONE_COLOR_NAME = "_DetailColor1";
|
||||
private const string _DETAIL_TWO_COLOR_NAME = "_DetailColor2";
|
||||
|
||||
private int _baseColorId;
|
||||
private int _detailOneColorId;
|
||||
private int _detailTWoColorId;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
if (m_scriptablePalette == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_baseColorId = Shader.PropertyToID(_BASE_COLOR_NAME);
|
||||
_detailOneColorId = Shader.PropertyToID(_DETAIL_ONE_COLOR_NAME);
|
||||
_detailTWoColorId = Shader.PropertyToID(_DETAIL_TWO_COLOR_NAME);
|
||||
}
|
||||
|
||||
private Color GetRandomColorFromPalette()
|
||||
{
|
||||
Color color = Color.white;
|
||||
if (m_scriptablePalette.m_colors.Length > 0)
|
||||
{
|
||||
color = m_scriptablePalette.m_colors[Random.Range(0, m_scriptablePalette.m_colors.Length)];
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
public override void Run(VectorEntity ve, UnityTile tile)
|
||||
{
|
||||
if (m_scriptablePalette == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MaterialPropertyBlock propBlock = new MaterialPropertyBlock();
|
||||
|
||||
ve.MeshRenderer.GetPropertyBlock(propBlock);
|
||||
|
||||
Color baseColor = (m_scriptablePalette.m_setBaseColor_Override) ? m_scriptablePalette.m_baseColor_Override : GetRandomColorFromPalette();
|
||||
Color detailColor1 = (m_scriptablePalette.m_setDetailColor1_Override) ? m_scriptablePalette.m_detailColor1_Override : GetRandomColorFromPalette();
|
||||
Color detailColor2 = (m_scriptablePalette.m_setDetailColor2_Override) ? m_scriptablePalette.m_detailColor2_Override : GetRandomColorFromPalette();
|
||||
|
||||
propBlock.SetColor(_baseColorId, baseColor);
|
||||
propBlock.SetColor(_detailOneColorId, detailColor1);
|
||||
propBlock.SetColor(_detailTWoColorId, detailColor2);
|
||||
|
||||
ve.MeshRenderer.SetPropertyBlock(propBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56e8568e69143416293940ecb62ec734
|
||||
timeCreated: 1520460892
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,95 @@
|
||||
namespace Mapbox.Unity.MeshGeneration.Modifiers
|
||||
{
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.MeshGeneration.Components;
|
||||
using Mapbox.Unity.MeshGeneration.Data;
|
||||
using Mapbox.Unity.Map;
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Texture Modifier is a basic modifier which simply adds a TextureSelector script to the features.
|
||||
/// Logic is all pushed into this TextureSelector mono behaviour to make it's easier to change it in runtime.
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "Mapbox/Modifiers/Material Modifier")]
|
||||
public class MaterialModifier : GameObjectModifier
|
||||
{
|
||||
[SerializeField]
|
||||
GeometryMaterialOptions _options;
|
||||
|
||||
public override void SetProperties(ModifierProperties properties)
|
||||
{
|
||||
_options = (GeometryMaterialOptions)properties;
|
||||
_options.PropertyHasChanged += UpdateModifier;
|
||||
}
|
||||
|
||||
public override void UnbindProperties()
|
||||
{
|
||||
_options.PropertyHasChanged -= UpdateModifier;
|
||||
}
|
||||
|
||||
private float GetRenderMode(float val)
|
||||
{
|
||||
return Mathf.Approximately(val, 1.0f) ? 0f : 3f;
|
||||
}
|
||||
|
||||
public override void Run(VectorEntity ve, UnityTile tile)
|
||||
{
|
||||
var min = Math.Min(_options.materials.Length, ve.MeshFilter.mesh.subMeshCount);
|
||||
var mats = new Material[min];
|
||||
|
||||
if (_options.style == StyleTypes.Custom)
|
||||
{
|
||||
for (int i = 0; i < min; i++)
|
||||
{
|
||||
mats[i] = _options.customStyleOptions.materials[i].Materials[UnityEngine.Random.Range(0, _options.customStyleOptions.materials[i].Materials.Length)];
|
||||
}
|
||||
}
|
||||
else if (_options.style == StyleTypes.Satellite)
|
||||
{
|
||||
for (int i = 0; i < min; i++)
|
||||
{
|
||||
mats[i] = _options.materials[i].Materials[UnityEngine.Random.Range(0, _options.materials[i].Materials.Length)];
|
||||
}
|
||||
|
||||
mats[0].mainTexture = tile.GetRasterData();
|
||||
mats[0].mainTextureScale = new Vector2(1f, 1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
float renderMode = 0.0f;
|
||||
switch (_options.style)
|
||||
{
|
||||
case StyleTypes.Light:
|
||||
renderMode = GetRenderMode(_options.lightStyleOpacity);
|
||||
break;
|
||||
case StyleTypes.Dark:
|
||||
renderMode = GetRenderMode(_options.darkStyleOpacity);
|
||||
break;
|
||||
case StyleTypes.Color:
|
||||
renderMode = GetRenderMode(_options.colorStyleColor.a);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < min; i++)
|
||||
{
|
||||
mats[i] = _options.materials[i].Materials[UnityEngine.Random.Range(0, _options.materials[i].Materials.Length)];
|
||||
mats[i].SetFloat("_Mode", renderMode);
|
||||
}
|
||||
}
|
||||
ve.MeshRenderer.materials = mats;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class MaterialList
|
||||
{
|
||||
[SerializeField]
|
||||
public Material[] Materials;
|
||||
|
||||
public MaterialList()
|
||||
{
|
||||
Materials = new Material[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 76c93f3debdba4e48adb1b99cad0a0d2
|
||||
timeCreated: 1508469304
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace Mapbox.Unity.MeshGeneration.Modifiers
|
||||
{
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.MeshGeneration.Components;
|
||||
using Mapbox.Unity.MeshGeneration.Data;
|
||||
|
||||
[CreateAssetMenu(menuName = "Mapbox/Modifiers/Noise Offset Modifier")]
|
||||
public class NoiseOffsetModifier : GameObjectModifier
|
||||
{
|
||||
public override void Run(VectorEntity ve, UnityTile tile)
|
||||
{
|
||||
//create a very small random offset to avoid z-fighting
|
||||
Vector3 randomOffset = Random.insideUnitSphere;
|
||||
randomOffset *= 0.01f;
|
||||
|
||||
ve.GameObject.transform.localPosition += randomOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa6f0c874a917480ab42ea3d79edf819
|
||||
timeCreated: 1532995020
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,116 @@
|
||||
namespace Mapbox.Unity.MeshGeneration.Modifiers
|
||||
{
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.MeshGeneration.Data;
|
||||
using Mapbox.Unity.MeshGeneration.Components;
|
||||
using Mapbox.Unity.MeshGeneration.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
using Mapbox.Unity.Map;
|
||||
using System;
|
||||
|
||||
[CreateAssetMenu(menuName = "Mapbox/Modifiers/Prefab Modifier")]
|
||||
public class PrefabModifier : GameObjectModifier
|
||||
{
|
||||
private Dictionary<GameObject, GameObject> _objects;
|
||||
[SerializeField]
|
||||
private SpawnPrefabOptions _options;
|
||||
private List<GameObject> _prefabList = new List<GameObject>();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
if (_objects == null)
|
||||
{
|
||||
_objects = new Dictionary<GameObject, GameObject>();
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetProperties(ModifierProperties properties)
|
||||
{
|
||||
_options = (SpawnPrefabOptions)properties;
|
||||
_options.PropertyHasChanged += UpdateModifier;
|
||||
}
|
||||
|
||||
public override void Run(VectorEntity ve, UnityTile tile)
|
||||
{
|
||||
if (_options.prefab == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject go = null;
|
||||
|
||||
if (_objects.ContainsKey(ve.GameObject))
|
||||
{
|
||||
go = _objects[ve.GameObject];
|
||||
}
|
||||
else
|
||||
{
|
||||
go = Instantiate(_options.prefab);
|
||||
_prefabList.Add(go);
|
||||
_objects.Add(ve.GameObject, go);
|
||||
go.transform.SetParent(ve.GameObject.transform, false);
|
||||
}
|
||||
|
||||
PositionScaleRectTransform(ve, tile, go);
|
||||
|
||||
if (_options.AllPrefabsInstatiated != null)
|
||||
{
|
||||
_options.AllPrefabsInstatiated(_prefabList);
|
||||
}
|
||||
}
|
||||
|
||||
public void PositionScaleRectTransform(VectorEntity ve, UnityTile tile, GameObject go)
|
||||
{
|
||||
RectTransform goRectTransform;
|
||||
IFeaturePropertySettable settable = null;
|
||||
var centroidVector = new Vector3();
|
||||
foreach (var point in ve.Feature.Points[0])
|
||||
{
|
||||
centroidVector += point;
|
||||
}
|
||||
centroidVector = centroidVector / ve.Feature.Points[0].Count;
|
||||
|
||||
go.name = ve.Feature.Data.Id.ToString();
|
||||
|
||||
goRectTransform = go.GetComponent<RectTransform>();
|
||||
if (goRectTransform == null)
|
||||
{
|
||||
go.transform.localPosition = centroidVector;
|
||||
if (_options.scaleDownWithWorld)
|
||||
{
|
||||
go.transform.localScale = _options.prefab.transform.localScale * (tile.TileScale);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
goRectTransform.anchoredPosition3D = centroidVector;
|
||||
if (_options.scaleDownWithWorld)
|
||||
{
|
||||
goRectTransform.localScale = _options.prefab.transform.localScale * (tile.TileScale);
|
||||
}
|
||||
}
|
||||
|
||||
//go.transform.localScale = Constants.Math.Vector3One;
|
||||
|
||||
settable = go.GetComponent<IFeaturePropertySettable>();
|
||||
if (settable != null)
|
||||
{
|
||||
settable.Set(ve.Feature.Properties);
|
||||
}
|
||||
}
|
||||
|
||||
public override void ClearCaches()
|
||||
{
|
||||
base.ClearCaches();
|
||||
foreach (var gameObject in _objects.Values)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
foreach (var gameObject in _prefabList)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd8aacc1880ff504d9531b4d61c86458
|
||||
timeCreated: 1494349551
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,154 @@
|
||||
// HACK:
|
||||
// This will work out of the box, but it's intended to be an example of how to approach
|
||||
// procedural decoration like this.
|
||||
// A better approach would be to operate on the geometry itself.
|
||||
|
||||
namespace Mapbox.Unity.MeshGeneration.Modifiers
|
||||
{
|
||||
using Mapbox.Unity.MeshGeneration.Data;
|
||||
using Mapbox.Unity.MeshGeneration.Components;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
[CreateAssetMenu(menuName = "Mapbox/Modifiers/Spawn Inside Modifier")]
|
||||
public class SpawnInsideModifier : GameObjectModifier
|
||||
{
|
||||
[SerializeField]
|
||||
int _spawnRateInSquareMeters;
|
||||
|
||||
[SerializeField]
|
||||
int _maxSpawn = 1000;
|
||||
|
||||
[SerializeField]
|
||||
GameObject[] _prefabs;
|
||||
|
||||
[SerializeField]
|
||||
LayerMask _layerMask;
|
||||
|
||||
[SerializeField]
|
||||
bool _scaleDownWithWorld;
|
||||
|
||||
[SerializeField]
|
||||
bool _randomizeScale;
|
||||
|
||||
[SerializeField]
|
||||
bool _randomizeRotation;
|
||||
|
||||
int _spawnedCount;
|
||||
|
||||
private Dictionary<GameObject, List<GameObject>> _objects;
|
||||
private Queue<GameObject> _pool;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
if (_objects == null || _pool == null)
|
||||
{
|
||||
_objects = new Dictionary<GameObject, List<GameObject>>();
|
||||
_pool = new Queue<GameObject>();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Run(VectorEntity ve, UnityTile tile)
|
||||
{
|
||||
_spawnedCount = 0;
|
||||
var collider = ve.GameObject.GetComponent<Collider>();
|
||||
var bounds = collider.bounds;
|
||||
var center = bounds.center;
|
||||
center.y = 0;
|
||||
|
||||
var area = (int)(bounds.size.x * bounds.size.z);
|
||||
int spawnCount = Mathf.Min(area / _spawnRateInSquareMeters, _maxSpawn);
|
||||
while (_spawnedCount < spawnCount)
|
||||
{
|
||||
var x = UnityEngine.Random.Range(-bounds.extents.x, bounds.extents.x);
|
||||
var z = UnityEngine.Random.Range(-bounds.extents.z, bounds.extents.z);
|
||||
var ray = new Ray(bounds.center + new Vector3(x, 100, z), Vector3.down * 2000);
|
||||
|
||||
RaycastHit hit;
|
||||
//Debug.DrawRay(ray.origin, ray.direction * 1000, Color.yellow, 1000);
|
||||
if (Physics.Raycast(ray, out hit, 150, _layerMask))
|
||||
{
|
||||
//Debug.DrawLine(ray.origin, hit.point, Color.red, 1000);
|
||||
var index = UnityEngine.Random.Range(0, _prefabs.Length);
|
||||
var transform = GetObject(index, ve.GameObject).transform;
|
||||
transform.position = hit.point;
|
||||
if (_randomizeRotation)
|
||||
{
|
||||
transform.localEulerAngles = new Vector3(0, UnityEngine.Random.Range(-180f, 180f), 0);
|
||||
}
|
||||
if (!_scaleDownWithWorld)
|
||||
{
|
||||
transform.localScale = Vector3.one / tile.TileScale;
|
||||
}
|
||||
|
||||
if (_randomizeScale)
|
||||
{
|
||||
var scale = transform.localScale;
|
||||
var y = UnityEngine.Random.Range(scale.y * .7f, scale.y * 1.3f);
|
||||
scale.y = y;
|
||||
transform.localScale = scale;
|
||||
}
|
||||
|
||||
}
|
||||
_spawnedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnPoolItem(VectorEntity vectorEntity)
|
||||
{
|
||||
if(_objects.ContainsKey(vectorEntity.GameObject))
|
||||
{
|
||||
foreach (var item in _objects[vectorEntity.GameObject])
|
||||
{
|
||||
item.SetActive(false);
|
||||
_pool.Enqueue(item);
|
||||
}
|
||||
|
||||
_objects[vectorEntity.GameObject].Clear();
|
||||
_objects.Remove(vectorEntity.GameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public override void ClearCaches()
|
||||
{
|
||||
foreach (var go in _pool)
|
||||
{
|
||||
Destroy(go);
|
||||
}
|
||||
_pool.Clear();
|
||||
foreach (var tileObject in _objects)
|
||||
{
|
||||
foreach (var go in tileObject.Value)
|
||||
{
|
||||
Destroy(go);
|
||||
}
|
||||
}
|
||||
_objects.Clear();
|
||||
}
|
||||
|
||||
private GameObject GetObject(int index, GameObject go)
|
||||
{
|
||||
GameObject ob;
|
||||
if (_pool.Count > 0)
|
||||
{
|
||||
ob = _pool.Dequeue();
|
||||
ob.SetActive(true);
|
||||
ob.transform.SetParent(go.transform);
|
||||
}
|
||||
else
|
||||
{
|
||||
ob = ((GameObject)Instantiate(_prefabs[index], go.transform, false));
|
||||
}
|
||||
if (_objects.ContainsKey(go))
|
||||
{
|
||||
_objects[go].Add(ob);
|
||||
}
|
||||
else
|
||||
{
|
||||
_objects.Add(go, new List<GameObject>() { ob });
|
||||
}
|
||||
return ob;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 420705c61d1b6435c8aa7b1cbd0ce80a
|
||||
timeCreated: 1499974418
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace Mapbox.Unity.MeshGeneration.Modifiers
|
||||
{
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.MeshGeneration.Components;
|
||||
using Mapbox.Unity.MeshGeneration.Data;
|
||||
|
||||
[CreateAssetMenu(menuName = "Mapbox/Modifiers/Tag Modifier")]
|
||||
public class TagModifier : GameObjectModifier
|
||||
{
|
||||
[SerializeField]
|
||||
private string _tag;
|
||||
|
||||
public override void Run(VectorEntity ve, UnityTile tile)
|
||||
{
|
||||
ve.GameObject.tag = _tag;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05ccea17608e94fb994579409c52fb80
|
||||
timeCreated: 1513280866
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,55 @@
|
||||
namespace Mapbox.Unity.MeshGeneration.Modifiers
|
||||
{
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.MeshGeneration.Components;
|
||||
using Mapbox.Unity.MeshGeneration.Data;
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Texture Modifier is a basic modifier which simply adds a TextureSelector script to the features.
|
||||
/// Logic is all pushed into this TextureSelector mono behaviour to make it's easier to change it in runtime.
|
||||
/// </summary>
|
||||
|
||||
[Obsolete("Texture Modifier is obsolete. Please use Material Modifier.")]
|
||||
[CreateAssetMenu(menuName = "Mapbox/Modifiers/Texture Modifier")]
|
||||
public class TextureModifier : GameObjectModifier
|
||||
{
|
||||
[SerializeField]
|
||||
private bool _textureTop;
|
||||
[SerializeField]
|
||||
private bool _useSatelliteTexture;
|
||||
[SerializeField]
|
||||
private Material[] _topMaterials;
|
||||
|
||||
[SerializeField]
|
||||
private bool _textureSides;
|
||||
[SerializeField]
|
||||
private Material[] _sideMaterials;
|
||||
|
||||
public override void Run(VectorEntity ve, UnityTile tile)
|
||||
{
|
||||
var _meshRenderer = ve.MeshRenderer;
|
||||
if (_textureSides && _sideMaterials.Length > 0)
|
||||
{
|
||||
_meshRenderer.materials = new Material[2]
|
||||
{
|
||||
_topMaterials[UnityEngine.Random.Range(0, _topMaterials.Length)],
|
||||
_sideMaterials[UnityEngine.Random.Range(0, _sideMaterials.Length)]
|
||||
};
|
||||
}
|
||||
else if (_textureTop)
|
||||
{
|
||||
_meshRenderer.materials = new Material[1]
|
||||
{
|
||||
_topMaterials[UnityEngine.Random.Range(0, _topMaterials.Length)]
|
||||
};
|
||||
}
|
||||
|
||||
if (_useSatelliteTexture)
|
||||
{
|
||||
_meshRenderer.materials[0].mainTexture = tile.GetRasterData();
|
||||
_meshRenderer.materials[0].mainTextureScale = new Vector2(1f, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d86f7dc89b3e33408563e4ada9d1c74
|
||||
timeCreated: 1478553093
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace Mapbox.Unity.MeshGeneration.Modifiers
|
||||
{
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.MeshGeneration.Components;
|
||||
using Mapbox.Unity.MeshGeneration.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Texture Modifier is a basic modifier which simply adds a TextureSelector script to the features.
|
||||
/// Logic is all pushed into this TextureSelector mono behaviour to make it's easier to change it in runtime.
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "Mapbox/Modifiers/Texture MonoBehaviour Modifier")]
|
||||
public class TextureMonoBehaviourModifier : GameObjectModifier
|
||||
{
|
||||
[SerializeField]
|
||||
private bool _textureTop;
|
||||
[SerializeField]
|
||||
private bool _useSatelliteTexture;
|
||||
[SerializeField]
|
||||
private Material[] _topMaterials;
|
||||
|
||||
[SerializeField]
|
||||
private bool _textureSides;
|
||||
[SerializeField]
|
||||
private Material[] _sideMaterials;
|
||||
|
||||
public override void Run(VectorEntity ve, UnityTile tile)
|
||||
{
|
||||
var ts = ve.GameObject.AddComponent<TextureSelector>();
|
||||
ts.Initialize(ve, _textureTop, _useSatelliteTexture, _topMaterials, _textureSides, _sideMaterials);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13b8ea9d54863b642b04d243f6e54eb6
|
||||
timeCreated: 1478553093
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user