2using System.Collections;
3using System.Collections.Generic;
4using System.Globalization;
5using System.Runtime.Serialization;
8using NaughtyAttributes;
12using Valve.VR.InteractionSystem;
32 [OnValueChanged(
"EditorBeltLengthChanged")]
37 [OnValueChanged(
"EditorBeltWidthChanged")]
43 private List<GameObject> SpawnBad;
47 private float spawnInterval = 3.0f;
48 private float stopInterval = 4.0f;
49 private float stopTime = 2.0f;
50 private float currentSpeed = 0.0f;
51 private float defaultSpeed = 1.0f;
52 [SerializeField]
internal int repeatTimes = 10;
53 private Material beltMaterial;
54 private System.Random r =
new System.Random();
55 private GameObject canvasSelector;
56 internal GameObject finishBtn, inspector, canvas, stageManagerWindow;
57 [SerializeField]
private bool spawnNow =
true;
58 private bool lastSpawnGood =
true;
60 private GameObject stopTrigger;
61 private GameObject spawn;
62 [SerializeField]
internal bool cookieQuality =
false;
76 repeatTimes = cbm.repeatTimes;
80 FindObjectOfType<StartAction>()?.ShowQualityConnections();
85 FindObjectOfType<StartAction>()?.HideQualityConnections();
93 var sgs = FindObjectsOfType<pb_PrefabBrowserItemButton>(
true);
94 foreach (var sg
in sgs)
98 if (sg.previewImg !=
null)
100 goodImage.texture = sg.previewImg.texture;
104 goodImage.texture = sg.GetComponentInChildren<RawImage>().texture;
111 if (SpawnBad !=
null && SpawnBad.Count > 0)
113 var sgs = FindObjectsOfType<pb_PrefabBrowserItemButton>(
true);
115 foreach (var sg
in sgs)
117 if (sg.asset == SpawnBad[0])
119 if (sg.previewImg !=
null)
120 badImage.texture = sg.previewImg.texture;
122 badImage.texture = sg.GetComponentInChildren<RawImage>().texture;
145 private new void Awake()
147 if (SpawnBad ==
null)
149 SpawnBad =
new List<GameObject>();
153 if (repeatTimes == 0) repeatTimes = 10;
154 cookieQuality = HttpCookie.GetCookie(
"courseModulTypeId") ==
"2";
162 FindObjectOfType<StartAction>()?.ShowQualityConnections();
167 FindObjectOfType<StartAction>()?.HideQualityConnections();
172 public void AddBad(GameObject go) => SpawnBad.Add(go);
182 defaultSpeed =
speed;
183 beltMaterial = GetComponent<Renderer>().material;
185 r =
new System.Random();
187 stageManagerWindow = GameObject.Find(
"StageManager Window");
188 canvasSelector = GameObject.Find(
"Canvas_selector");
191 canvas = GameObject.Find(
"Canvas");
192 var trs = canvas.GetComponentsInChildren<Transform>(
true);
193 foreach (var t
in trs)
194 if (t.name ==
"Inspector")
195 inspector = t.gameObject;
197 trs = inspector.GetComponentsInChildren<Transform>(
true);
198 foreach (var t
in trs)
199 if (t.name ==
"FinishToolPos_Btn")
200 finishBtn = t.gameObject;
202 stopTrigger = FindObjectOfType<ConveyorTrigger>().gameObject;
207 GameObject.Find(
"Btn_StageMgr").GetComponent<
Button>().onClick.Invoke();
210 finishBtn.GetComponent<
Button>().onClick.RemoveAllListeners();
211 finishBtn.GetComponent<
Button>().onClick.AddListener(OnFinishGood);
216 GameObject.Find(
"Btn_StageMgr").GetComponent<
Button>().onClick.Invoke();
219 finishBtn.GetComponent<
Button>().onClick.RemoveAllListeners();
220 finishBtn.GetComponent<
Button>().onClick.AddListener(OnFinishBad);
224 void OnRemovedFromSelection(IEnumerable<GameObject> selection)
227 if (stageManagerWindow.GetComponent<CanvasGroup>().alpha == 0)
228 GameObject.Find(
"Btn_StageMgr").GetComponent<
Button>().onClick.Invoke();
241 if (stageManagerWindow.GetComponent<CanvasGroup>().alpha == 0)
242 GameObject.Find(
"Btn_StageMgr").GetComponent<
Button>().onClick.Invoke();
251 SpawnBad.Add(selection[0]);
254 if (stageManagerWindow.GetComponent<CanvasGroup>().alpha == 0)
255 GameObject.Find(
"Btn_StageMgr").GetComponent<
Button>().onClick.Invoke();
272 if (!inspector.activeSelf)
273 inspector.SetActive(
true);
275 var btnOffset = finishBtn.transform.parent.GetComponent<RectTransform>().rect.width;
277 finishBtn.GetComponent<RectTransform>().anchoredPosition =
new Vector2(-(btnOffset + spacing), 0);
279 finishBtn.SetActive(
true);
284 finishBtn.SetActive(
false);
298 if (spawnInterval > 0)
300 spawnInterval -= Time.deltaTime;
301 if (spawnInterval <= 0)
304 r =
new System.Random();
306 var randomBadIndex = r.Next(SpawnBad.Count);
310 item.AddComponent<Rigidbody>();
312 item.AddComponent<VelocityEstimator>();
313 item.AddComponent<Interactable>();
325 r =
new System.Random();
327 var randomBadIndex = r.Next(SpawnBad.Count);
329 spawn = isGood ?
SpawnGood : SpawnBad[randomBadIndex];
333 spawn.SetActive(
true);
334 spawn.GetComponent<Rigidbody>().isKinematic =
false;
338 lastSpawnGood = isGood;
339 stopTrigger.SetActive(
true);
349 if (stopInterval > 0)
351 stopInterval -= Time.deltaTime;
352 if (stopInterval <= 0)
358 if (
Math.Abs(currentSpeed) < 0.001f)
362 stopTime -= Time.deltaTime;
366 speed = defaultSpeed;
373 beltMaterial.mainTextureScale =
new Vector2(transform.localScale.x * 10, transform.localScale.z * 10);
374 beltMaterial.mainTextureOffset +=
Vector2.up *
speed * 0.1f;
384 if (cookieQuality)
return;
386 cachedStart = FindObjectOfType<StartAction>();
387 if (cachedStart ==
null)
389 cookieQuality =
true;
392 var goodModel = cachedStart.GetInputGood();
393 if (goodModel ==
null)
395 cookieQuality =
true;
399 SpawnBad = cachedStart.GetInputsBad();
406 foreach (var item
in SpawnBad)
409 item.SetActive(
false);
417 if (cookieQuality)
return;
431 if (cookieQuality)
return;
435 foreach (var bad
in SpawnBad)
437 bad.SetActive(
false);
446 if (cookieQuality)
return;
449 spawn.GetComponent<Rigidbody>().isKinematic =
false;
453 var allPosAction = FindObjectsOfType<PositionAction>();
454 foreach (var pa
in allPosAction)
464 if (cookieQuality)
return;
465 spawn.SetActive(
false);
469 private void EditorBeltLengthChanged()
474 private void EditorBeltWidthChanged()
489 defaultSpeed =
speed;
504 var ci = CultureInfo.CurrentCulture;
505 var nfi = ci.NumberFormat;
506 value = value.Replace(
',', nfi.CurrencyDecimalSeparator[0]);
507 value = value.Replace(
'.', nfi.CurrencyDecimalSeparator[0]);
508 var single = Convert.ToSingle(value, ci);
515 var ci = CultureInfo.CurrentCulture;
516 var nfi = ci.NumberFormat;
517 value = value.Replace(
',', nfi.CurrencyDecimalSeparator[0]);
518 value = value.Replace(
'.', nfi.CurrencyDecimalSeparator[0]);
519 var single = Convert.ToSingle(value, ci);
526 transform.localScale =
new Vector3(transform.localScale.x, transform.localScale.y, size);
527 BeltStart.transform.localPosition =
new Vector3(0, -0.105f, -size*10/2-0.085f);
528 BeltEnd.transform.localPosition =
new Vector3(0, -0.105f, size*10/2+0.085f);
534 transform.localScale =
new Vector3(size, transform.localScale.y, transform.localScale.z);
535 BeltStart.transform.localScale =
new Vector3(1, 1, size*10);
536 BeltEnd.transform.localScale =
new Vector3(1, -1, size*10);
540 void OnTriggerStay(Collider col)
552 col.GetComponentInParent<Rigidbody>().transform.position += transform.forward * currentSpeed * Time.deltaTime;
556 private void OnTriggerExit(Collider other)
560 other.GetComponent<Rigidbody>().AddForce(transform.forward * currentSpeed, ForceMode.Impulse);
566 if (currentSpeed != 0)
568 other.GetComponentInParent<Rigidbody>().isKinematic =
false;
572 private void OnDestroy()
577 beltMaterial.mainTextureOffset =
Vector2.zero;
590 info.AddValue(
"speed",
speed);
593 info.AddValue(
"StopTime",
StopTime);
598 info.AddValue(
"repeatTimes", repeatTimes);
601 info.AddValue(
"SpawnGood",
SpawnGood.name);
603 foreach (var o
in SpawnBad)
606 save += o.name +
";";
608 info.AddValue(
"SpawnBad", save);
610 info.AddValue(
"position",
conveyorBelt.transform.position, typeof(Vector3));
611 info.AddValue(
"rotation",
conveyorBelt.transform.rotation, typeof(Quaternion));
617 isEnabled = info.GetBoolean(
"isEnabled");
618 speed = info.GetSingle(
"speed");
621 StopTime = info.GetSingle(
"StopTime");
626 instance.conveyorBelt.transform.position = (Vector3)info.GetValue(
"position", typeof(Vector3));
627 instance.conveyorBelt.transform.rotation = (Quaternion)info.GetValue(
"rotation", typeof(Quaternion));
630 var badString = info.GetString(
"SpawnBad").Split(
';');
631 if (SpawnBad ==
null)
632 SpawnBad =
new List<GameObject>();
633 foreach (var s
in badString)
635 if (
string.IsNullOrEmpty(s))
continue;
650 repeatTimes = info.GetInt32(
"repeatTimes");
UnityEngine.UI.Button Button
void SetBeltLength(float size)
void SetStopTime(string value)
ConveyorBeltManager(SerializationInfo info, StreamingContext context)
void GetObjectData(SerializationInfo info, StreamingContext context)
void SetStopInterval(string value)
void SetSpawnRate(string value)
void SetBeltWidth(float size)
void AddBad(GameObject go)
void OnRepeatTimesEdited(string value)
void SetSpawnPercent(string value)
void SetSpeed(float value)
bool GetUploadedGOFromName(string value, out GameObject retval)
static FileDragAndDrop instance
static List< GameObject > gameObjects
A list of the currently selected GameObjects.
static void AddOnRemovedFromSelectionListener(Callback< IEnumerable< GameObject > > del)
static void AddToSelection(GameObject go)
static void SetInteractable(GameObject go, bool isKinematic=true)
static float StoF(string value)