protected void LoadAssEntity(AssignmentEntityRenderer entityRenderer)
        {
            Debug.Log("dd");
            compDisp.Clear();

            currentRenderer = entityRenderer;
            currentEntity   = entityRenderer.mapSystem.assignmentEntityDictionary[entityRenderer.aeID];
            id.text         = currentEntity.aeID.ToString();
            floor.text      = currentEntity.floor.ToString();
            rad.text        = currentEntity.radius.ToString();
            rot.text        = currentEntity.theta.ToString();
            posX.text       = currentEntity.pos.x.ToString();
            posY.text       = currentEntity.pos.y.ToString();
            string a = "";

            foreach (int i in currentEntity.assignmentIDList)
            {
                a += i + " ";
            }
            assignments.text = a;

            Observable
            .CombineLatest(posX.ObserveEveryValueChanged(__ => __.text), posY.ObserveEveryValueChanged(__ => __.text))
            .Where(__ => editorSystem.currentMode.Value == EditorSystem.EditMode.VALUES)
            .Subscribe(_pos => {
                float pos0, pos1;
                bool canParse;
                canParse = float.TryParse(_pos[0], out pos0);
                canParse = float.TryParse(_pos[1], out pos1) && canParse;
                if (canParse)
                {
                    currentRenderer.transform.localPosition = new Vector2(pos0, pos1);
                }
            }).AddTo(compDisp);

            rot.ObserveEveryValueChanged(__ => __.text)
            .Where(__ => editorSystem.currentMode.Value == EditorSystem.EditMode.VALUES)
            .Subscribe(_rot => {
                float rotOut;
                if (float.TryParse(_rot, out rotOut))
                {
                    currentRenderer.transform.rotation = Quaternion.Euler(0, 0, rotOut);
                }
            });

            rad.ObserveEveryValueChanged(__ => __.text)
            .Where(__ => currentRenderer.myType == AEType.wall)
            .Where(__ => editorSystem.currentMode.Value == EditorSystem.EditMode.VALUES)
            .Subscribe(_rad => {
                float radOut;
                if (float.TryParse(_rad, out radOut))
                {
                    currentRenderer.GetComponentInChildren <SpriteRenderer>().size =
                        new Vector2(radOut, currentRenderer.GetComponentInChildren <SpriteRenderer>().size.y);
                }
            });

            rad.ObserveEveryValueChanged(__ => __.text)
            .Where(__ => currentRenderer.myType == AEType.computer)
            .Where(__ => editorSystem.currentMode.Value == EditorSystem.EditMode.VALUES)
            .Subscribe(_rad => {
                float radOut;
                if (float.TryParse(_rad, out radOut))
                {
                    currentRenderer.GetComponentInChildren <SpriteRenderer>().size =
                        new Vector2(radOut, radOut) * 2;
                }
            });

            entityRenderer.ObserveEveryValueChanged(__ => __.transform.localPosition)
            .Where(__ => editorSystem.currentMode.Value == EditorSystem.EditMode.TRANSFORM)
            .Subscribe(pos => {
                posX.text = pos.x.ToString();
                posY.text = pos.y.ToString();
            }).AddTo(compDisp);

            entityRenderer.ObserveEveryValueChanged(__ => __.transform.localEulerAngles)
            .Where(__ => editorSystem.currentMode.Value == EditorSystem.EditMode.TRANSFORM)
            .Subscribe(_rot => {
                rot.text = _rot.z.ToString();
            }).AddTo(compDisp);

            currentRenderer.GetComponentInChildren <SpriteRenderer>().ObserveEveryValueChanged(__ => __.size)
            .Where(__ => editorSystem.currentMode.Value == EditorSystem.EditMode.TRANSFORM)
            .Subscribe(_size => {
                rad.text = _size.x.ToString();
            }).AddTo(compDisp);
        }
Esempio n. 2
0
        // Use this for initialization
        void Start()
        {
            this.UpdateAsObservable()
            .Where(__ => Input.GetKeyDown(KeyCode.F2))
            .Subscribe(__ =>
            {
                editorOn.Value = !editorOn.Value;
            });

            this.UpdateAsObservable()
            .Where(__ => editorOn.Value)
            .Where(__ => currentMode.Value == EditMode.NONE)
            .Where(__ => Input.GetKeyDown(KeyCode.F3))
            .Subscribe(__ =>
            {
                CreateNew(AEType.computer);
            });

            this.UpdateAsObservable()
            .Where(__ => editorOn.Value)
            .Where(__ => currentMode.Value == EditMode.NONE)
            .Where(__ => Input.GetKeyDown(KeyCode.F4))
            .Subscribe(__ =>
            {
                CreateNew(AEType.wall);
            });

            this.UpdateAsObservable()
            .Where(__ => this.currentMode.Value == EditMode.TRANSFORM)
            .Subscribe(__ =>
            {
                if (Input.GetKey(KeyCode.A))
                {
                    Vector3 screenToWorld             = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    selectedEntity.transform.position = new Vector3(screenToWorld.x, screenToWorld.y, selectedEntity.transform.position.z);
                }
                if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.D))
                {
                    mousePos = Input.mousePosition;
                }
                else if (Input.GetKey(KeyCode.S))
                {
                    float deltaY = Input.mousePosition.y - mousePos.y;
                    selectedEntity.transform.Rotate(0, 0, deltaY * Time.deltaTime * 10);
                    mousePos = Input.mousePosition;
                }
                else if (Input.GetKey(KeyCode.D))
                {
                    float deltaX = Input.mousePosition.x - mousePos.x;
                    Vector2 size = selectedEntity.GetComponentInChildren <SpriteRenderer>().size;
                    selectedEntity.GetComponentInChildren <SpriteRenderer>().size = new Vector2(size.x + deltaX * Time.deltaTime, size.y);
                    mousePos = Input.mousePosition;
                }
            });

            editorOn.AsObservable()
            .Subscribe(flag =>
            {
                editorCanvas.SetActive(flag);
            });

            mapSystem.SubjectAssignmentEntityRendererClicked.AsObservable()
            .Where(__ => editorOn.Value)
            .Subscribe(ent =>
            {
                if (currentMode.Value == EditMode.NONE || selectedEntity != ent)
                {
                    currentMode.Value = EditMode.VALUES;
                    selectedEntity    = ent;
                    SubjectAssignmentEntityRendererSelected_Edit.OnNext(ent);
                }
                else
                {
                    if (currentMode.Value == EditMode.TRANSFORM)
                    {
                        Debug.Log("current mode :: values");
                        currentMode.Value = EditMode.VALUES;
                    }
                    else
                    {
                        Debug.Log("current mode :: transform");
                        currentMode.Value = EditMode.TRANSFORM;
                    }
                }
            });
        }