// Use this for initialization
        void Start()
        {
            currentMode        = DesignerMode.Shell;
            modeText.text      = "Shell mode";
            kMeansPoints.text  = "0";
            impulsePoints.text = numImpulses.ToString();
            splineCanvas       = FindObjectOfType <SplineCanvas>();

            NumKMeansPoints = 10;
        }
Exemplo n.º 2
0
        private void OnStartup(object sender, StartupEventArgs e)
        {
            // Carga del control principal aqui.
            this.customServiceId = Convert.ToInt32(e.InitParams[SessionConstants.IdCustomerServiceDataToUse], CultureInfo.InvariantCulture);
            this.designerMode    = (DesignerMode)(Convert.ToInt32(e.InitParams[SessionConstants.DesignerMode], CultureInfo.InvariantCulture));

            if (designerMode == DesignerMode.ServiceDesigner)
            {
                this.RootVisual = new ServiceDesignerSilverlight(this.customServiceId);
            }
            else
            {
                this.RootVisual = new DataModelDesignerSilverlight();
            }
        }
        // Update is called once per frame
        void Update()
        {
            if (Input.GetButtonDown("ToggleMode"))
            {
                if (currentMode == DesignerMode.Shell)
                {
                    currentMode   = DesignerMode.Curve;
                    modeText.text = "Curve mode";
                }
                else if (currentMode == DesignerMode.Curve)
                {
                    currentMode   = DesignerMode.Curvature;
                    modeText.text = "Curvature mode";
                }
                else if (currentMode == DesignerMode.Curvature)
                {
                    currentMode   = DesignerMode.Shell;
                    modeText.text = "Shell mode";
                }
            }

            RaycastHit hitInfo = new RaycastHit();

            if (Input.GetMouseButtonDown(0) && RaycastShells(Input.mousePosition, out hitInfo))
            {
                TelescopeShell selection   = hitInfo.collider.GetComponent <TelescopeShell>();
                DraggablePoint draggablePt = hitInfo.collider.GetComponent <DraggablePoint>();

                if (selection)
                {
                    SelectShell(selection);
                }

                else if (draggablePt)
                {
                    draggable     = draggablePt;
                    selectedDepth = Camera.main.WorldToScreenPoint(draggablePt.transform.position).z;
                }
            }

            else if (Input.GetKeyDown("r") && RaycastShells(Input.mousePosition, out hitInfo))
            {
                DraggablePoint draggablePt = hitInfo.collider.GetComponent <DraggablePoint>();

                if (draggablePt && draggablePt.parentSpline)
                {
                    Debug.Log("Reverse " + draggablePt.parentSpline.name);
                    draggablePt.parentSpline.Reverse();
                }
            }


            else if (Input.GetKeyDown("j") && RaycastShells(Input.mousePosition, out hitInfo))
            {
                DraggablePoint draggablePt = hitInfo.collider.GetComponent <DraggablePoint>();

                if (draggablePt)
                {
                    if (draggablePt.Type == PointType.Bulb)
                    {
                        draggablePt.SwitchBulbType(PointType.EmptyJuncture);
                    }
                    else if (draggablePt.Type == PointType.EmptyJuncture)
                    {
                        draggablePt.SwitchBulbType(PointType.Bulb);
                    }
                }
            }

            else if (Input.GetMouseButton(0) && draggable)
            {
                Vector3 clickPos = Input.mousePosition;
                clickPos.z = selectedDepth;
                Vector3 worldPos = Camera.main.ScreenToWorldPoint(clickPos);

                DraggablePoint intersectedBulb = splineCanvas.IntersectedBulb(worldPos);

                if (draggable.Type == PointType.Spline && draggable.IsEndPoint() && intersectedBulb)
                {
                    draggable.AttachToBulb(intersectedBulb);
                }
                else
                {
                    draggable.Move(worldPos);
                }
            }

            else if (Input.GetMouseButtonDown(1) && RaycastShells(Input.mousePosition, out hitInfo))
            {
                Vector3        clickPos = Input.mousePosition;
                DraggablePoint clicked  = hitInfo.collider.GetComponent <DraggablePoint>();

                if (clicked)
                {
                    if (Input.GetKey("left ctrl"))
                    {
                        clicked.Delete();
                    }
                    else
                    {
                        clicked.Duplicate();
                    }
                }

                // Store the eye-space position of the click.
                // Use eye space because we always want moving up/down to correspond
                // to bigger or smaller, regardless of camera orientation.
                lastMousePos   = clickPos;
                lastMousePos.z = selectedDepth;
                lastMousePos   = Camera.main.ScreenToViewportPoint(lastMousePos);
            }

            else if (Input.GetMouseButtonDown(2) && RaycastShells(Input.mousePosition, out hitInfo))
            {
                Vector3 clickPos = Input.mousePosition;

                // Store the eye-space position of the click.
                // Use eye space because we always want moving up/down to correspond
                // to bigger or smaller, regardless of camera orientation.
                lastMousePos   = clickPos;
                lastMousePos.z = selectedDepth;
                lastMousePos   = Camera.main.ScreenToViewportPoint(lastMousePos);
            }

            else if (Input.mouseScrollDelta.y != 0 && RaycastShells(Input.mousePosition, out hitInfo))
            {
                DraggablePoint draggablePt = hitInfo.collider.GetComponent <DraggablePoint>();
                if (draggablePt)
                {
                    float change = Input.mouseScrollDelta.y * 0.05f;
                    draggablePt.Resize(change);
                }
            }

            else if (Input.GetKeyDown("delete") && RaycastShells(Input.mousePosition, out hitInfo))
            {
                DraggablePoint draggablePt = hitInfo.collider.GetComponent <DraggablePoint>();

                if (draggablePt)
                {
                    draggablePt.Delete();
                }
            }

            else if (Input.GetKeyDown("b") && RaycastShells(Input.mousePosition, out hitInfo))
            {
                DraggablePoint draggablePt = hitInfo.collider.GetComponent <DraggablePoint>();

                if (draggablePt)
                {
                    draggablePt.ReplaceWithBulb();
                }
            }

            else if (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(2))
            {
                draggable = null;
            }

            else if (Input.GetButtonDown("Cancel"))
            {
                Deselect();
            }

            else if (Input.GetButtonDown("Submit"))
            {
                Debug.Log("submit");
            }

            shootTime += Time.deltaTime;
            if (shootTime > shootDelay && Input.GetKey("z"))
            {
                ShootSphere();
            }
        }