public void CreateNew(AEType _type) { AssignmentEntity newEntity = new AssignmentEntity(); int newID = 1000; while (mapSystem.assignmentEntityDictionary.ContainsKey(newID)) { newID++; } newEntity.aeID = newID; newEntity.aeType = _type; newEntity.floor = mapSystem.currentFloor.Value; newEntity.pos = Vector2.zero; newEntity.radius = .5f; newEntity.theta = 0; mapSystem.assignmentEntityDictionary.Add(newEntity.aeID, newEntity); AssignmentEntityRenderer newRenderer = _type == AEType.computer ? GameObject.Instantiate(assCompPrefab, mapSystem.coordinate) : GameObject.Instantiate(assWallPrefab, mapSystem.coordinate); newRenderer.Initialize(newEntity.aeID, infoSystem, mapSystem); mapSystem.SelectAssignmentEntityRenderer(newRenderer); }
public void Initialize(int _aeID, InfoSystem _is, MapSystem _ms) { aeID = _aeID; infoSystem = _is; mapSystem = _ms; compDisp.Clear(); AssignmentEntity myEntity = mapSystem.assignmentEntityDictionary[aeID]; transform.parent = mapSystem.coordinate;//mapSystem.floorList[myEntity.floor - 1].transform; transform.localPosition = myEntity.pos; SpriteRenderer sr = GetComponentInChildren <SpriteRenderer>(); if (myEntity.aeType == AEType.computer) { sr.size = new Vector2(myEntity.radius, myEntity.radius) * 2; GetComponentInChildren <CircleCollider2D>().radius = myEntity.radius; } else { transform.rotation = Quaternion.Euler(new Vector3(0, 0, myEntity.theta)); sr.size = new Vector2(myEntity.radius, sr.size.y); GetComponentInChildren <BoxCollider2D>().size = sr.size; } mapSystem.currentFloor.AsObservable() .Subscribe(f => { Vector2 targetScale = InCurrentFloor() ? new Vector2(1, 1) : Vector2.zero; Ease ease = InCurrentFloor() ? Ease.OutBack : Ease.InBack; transform.DOScale(targetScale, .3f) .SetEase(ease); }).AddTo(compDisp); mapSystem.SubjectAssignmentEntityModified.AsObservable() .Where(id => id == aeID) .Subscribe(id => { Initialize(id, infoSystem, mapSystem); }).AddTo(compDisp); selected.AsObservable() .Where(flag => flag) .Subscribe(flag => { mapSystem.SetCurrentFloor(mapSystem.assignmentEntityDictionary[aeID].floor); mapSystem.SelectAssignmentEntityRenderer(this); }).AddTo(compDisp); infoSystem.SubjectQueriedAssignmentsChanged.AsObservable() .Subscribe(l => { bool flag = false; foreach (int _id in l) { if (myEntity.assignmentIDList.Contains(_id)) { flag = true; break; } } queried.Value = flag; }).AddTo(compDisp); infoSystem.SelectedAssignmentID.AsObservable() .Subscribe(_id => { selected.Value = myEntity.assignmentIDList.Contains(_id); }).AddTo(compDisp); }