Semi-proper warehouse scrolling using bezier curves
This commit is contained in:
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
+8
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1e48cc47058f70a40832134fa11986fd
|
||||||
|
timeCreated: 1464030617
|
||||||
|
licenseType: Free
|
||||||
|
NativeFormatImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Executable
+35
@@ -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<BezierCurve>();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable
+12
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c88cdd3c5a01be746a69b3b3cc95d136
|
||||||
|
timeCreated: 1464021754
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+26
-61
@@ -5,83 +5,48 @@ using UnityEditor;
|
|||||||
|
|
||||||
[ExecuteInEditMode]
|
[ExecuteInEditMode]
|
||||||
public class WarehouseRow : MonoBehaviour {
|
public class WarehouseRow : MonoBehaviour {
|
||||||
public GameObject[] Prefabs;
|
public string Category;
|
||||||
public bool ShowInEditor = false;
|
|
||||||
|
|
||||||
BezierCurve curve;
|
BezierCurve curve;
|
||||||
|
Transform furniture;
|
||||||
List<GameObject> furnitures;
|
|
||||||
|
|
||||||
float offset = 0;
|
float offset = 0;
|
||||||
|
|
||||||
// Use this for initialization
|
void Awake() {
|
||||||
|
curve = transform.Find("Curve").GetComponent<BezierCurve>();
|
||||||
|
furniture = transform.Find("Furniture");
|
||||||
|
}
|
||||||
|
|
||||||
void Start() {
|
void Start() {
|
||||||
curve = GetComponent<BezierCurve>();
|
// Set up text
|
||||||
furnitures = new List<GameObject>();
|
transform.Find("Text/Number").GetComponent<TextMesh>().text = (transform.GetSiblingIndex() + 1).ToString();
|
||||||
|
transform.Find("Text/Category").GetComponent<TextMesh>().text = Category;
|
||||||
#if UNITY_EDITOR
|
|
||||||
EditorApplication.playmodeStateChanged += StateChange;
|
|
||||||
#endif
|
|
||||||
spawnPrefabs();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnEnable() {
|
//void spawnPrefabs() {
|
||||||
spawnPrefabs();
|
// if (furnitures.Count == 0) {
|
||||||
}
|
// for (int i = 0; i < Prefabs.Length; i++) {
|
||||||
|
// var prefab = Prefabs[i];
|
||||||
|
|
||||||
void OnDisable() {
|
// GameObject furniture = Instantiate(prefab);
|
||||||
foreach (var item in furnitures) {
|
// furniture.transform.SetParent(transform);
|
||||||
GameObject.DestroyImmediate(item);
|
// furniture.layer = 8;
|
||||||
}
|
// furnitures.Add(furniture);
|
||||||
furnitures.Clear();
|
// }
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
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() {
|
void Update() {
|
||||||
if (Application.isPlaying) {
|
if (Application.isPlaying) {
|
||||||
offset += Time.deltaTime;
|
//offset += Time.deltaTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < furnitures.Count; i++) {
|
foreach (Transform t in furniture) {
|
||||||
var furniture = furnitures[i];
|
var i = t.GetSiblingIndex();
|
||||||
|
var distance = (float)i / (furniture.childCount) * curve.length + offset;
|
||||||
var distance = (float)i / (furnitures.Count - 1) * curve.length + offset;
|
|
||||||
distance = Mathf.Repeat(distance, curve.length);
|
distance = Mathf.Repeat(distance, curve.length);
|
||||||
var pos = curve.GetPointAtDistance(distance);
|
var pos = curve.GetPointAtDistance(distance);
|
||||||
furniture.transform.position = pos;
|
t.position = pos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user