diff --git a/Assets/Test.unity b/Assets/Test.unity index c2ba08d..ee59065 100755 Binary files a/Assets/Test.unity and b/Assets/Test.unity differ diff --git a/Assets/Warehouse Row.prefab b/Assets/Warehouse Row.prefab new file mode 100755 index 0000000..16a6097 Binary files /dev/null and b/Assets/Warehouse Row.prefab differ diff --git a/Assets/Warehouse Row.prefab.meta b/Assets/Warehouse Row.prefab.meta new file mode 100755 index 0000000..3d8ab3b --- /dev/null +++ b/Assets/Warehouse Row.prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1e48cc47058f70a40832134fa11986fd +timeCreated: 1464030617 +licenseType: Free +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/WarehouseColumn.cs b/Assets/WarehouseColumn.cs new file mode 100755 index 0000000..6b534b6 --- /dev/null +++ b/Assets/WarehouseColumn.cs @@ -0,0 +1,35 @@ +using UnityEngine; +using System.Collections; +using System.Collections.Generic; + +[ExecuteInEditMode] +public class WarehouseColumn : MonoBehaviour { + + private BezierCurve curve; + private Transform rows; + + private float offset = 0.0f; + + void Awake() { + curve = transform.Find("Curve").GetComponent(); + rows = transform.Find("Rows"); + } + + void Start () { + + } + + void Update() { + if (Application.isPlaying) { + offset += Time.deltaTime; + } + + foreach (Transform row in rows) { + var i = row.GetSiblingIndex(); + var distance = (float)i / (rows.childCount) * curve.length + offset; + distance = Mathf.Repeat(distance, curve.length); + var pos = curve.GetPointAtDistance(distance); + row.position = pos; + } + } +} diff --git a/Assets/WarehouseColumn.cs.meta b/Assets/WarehouseColumn.cs.meta new file mode 100755 index 0000000..5f7598f --- /dev/null +++ b/Assets/WarehouseColumn.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: c88cdd3c5a01be746a69b3b3cc95d136 +timeCreated: 1464021754 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/WarehouseRow.cs b/Assets/WarehouseRow.cs index 4ae5bd6..ccd9eef 100755 --- a/Assets/WarehouseRow.cs +++ b/Assets/WarehouseRow.cs @@ -5,83 +5,48 @@ using UnityEditor; [ExecuteInEditMode] public class WarehouseRow : MonoBehaviour { - public GameObject[] Prefabs; - public bool ShowInEditor = false; + public string Category; BezierCurve curve; - - List furnitures; + Transform furniture; float offset = 0; - // Use this for initialization + void Awake() { + curve = transform.Find("Curve").GetComponent(); + furniture = transform.Find("Furniture"); + } + void Start() { - curve = GetComponent(); - furnitures = new List(); - -#if UNITY_EDITOR - EditorApplication.playmodeStateChanged += StateChange; -#endif - spawnPrefabs(); + // Set up text + transform.Find("Text/Number").GetComponent().text = (transform.GetSiblingIndex() + 1).ToString(); + transform.Find("Text/Category").GetComponent().text = Category; } - public void OnEnable() { - spawnPrefabs(); - } + //void spawnPrefabs() { + // if (furnitures.Count == 0) { + // for (int i = 0; i < Prefabs.Length; i++) { + // var prefab = Prefabs[i]; - void OnDisable() { - foreach (var item in furnitures) { - GameObject.DestroyImmediate(item); - } - furnitures.Clear(); - } + // GameObject furniture = Instantiate(prefab); + // furniture.transform.SetParent(transform); + // furniture.layer = 8; + // furnitures.Add(furniture); + // } + // } + //} - void OnDestroy() { - foreach (var item in furnitures) { - GameObject.DestroyImmediate(item); - } - furnitures.Clear(); - } - - void StateChange() { - if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying) { - OnDisable(); - } - } - - void OnValidate() { - foreach (var item in furnitures) { - GameObject.DestroyImmediate(item); - } - furnitures.Clear(); - spawnPrefabs(); - } - - void spawnPrefabs() { - if (furnitures.Count == 0) { - for (int i = 0; i < Prefabs.Length; i++) { - var prefab = Prefabs[i]; - - GameObject furniture = Instantiate(prefab); - furniture.transform.SetParent(transform); - furnitures.Add(furniture); - } - } - } - - // Update is called once per frame void Update() { if (Application.isPlaying) { - offset += Time.deltaTime; + //offset += Time.deltaTime; } - for (int i = 0; i < furnitures.Count; i++) { - var furniture = furnitures[i]; - - var distance = (float)i / (furnitures.Count - 1) * curve.length + offset; + foreach (Transform t in furniture) { + var i = t.GetSiblingIndex(); + var distance = (float)i / (furniture.childCount) * curve.length + offset; distance = Mathf.Repeat(distance, curve.length); var pos = curve.GetPointAtDistance(distance); - furniture.transform.position = pos; + t.position = pos; } } }