Ejemplo n.º 1
0
        private void Init()
        {
            if (null == frustumRenderer)
            {
                GameObject frustum = transform.Find("Frustum").gameObject;
                frustumRenderer         = frustum.GetComponent <LineRenderer>();
                frustumRenderer.enabled = false;
            }
            if (null == disabledLayer)
            {
                disabledLayer = transform.Find("Rotate/PreviewDisabledLayer").gameObject;
                disabledLayer.SetActive(false);
            }

            // Init UI
            if (null == focalSlider)
            {
                nameLabel = transform.Find("Rotate/Name/Name").GetComponent <UILabel>();
                // Hack : force TMPro properties when component is enabled
                UIUtils.SetTMProStyle(nameLabel.gameObject, minSize: 6f, maxSize: 72f, alignment: TextAlignmentOptions.Center);
                nameLabel.Text = gameObject.name;
                nameLabel.onReleaseEvent.AddListener(OnNameClicked);
                nameLabel.NeedsRebuild = true;

                // FOCAL
                focalSlider = gameObject.GetComponentInChildren <UISlider>(true);
                focalSlider.onSlideEventInt.AddListener(OnFocalSliderChange);
                focalSlider.onClickEvent.AddListener(OnFocalClicked);
                focalSlider.onReleaseEvent.AddListener(OnFocalReleased);
                // Hack : force TMPro properties when component is enabled
                UIUtils.SetTMProStyle(focalSlider.gameObject, minSize: 1f, maxSize: 1.5f);
                focalSlider.NeedsRebuild = true;

                inFrontButton = transform.Find("Rotate/UI/InFront").GetComponentInChildren <UIButton>(true);
                inFrontButton.onCheckEvent.AddListener(OnSetInFront);
                inFrontButton.NeedsRebuild = true;

                touchScreen = transform.Find("Rotate/CameraPreview/TouchScreen").GetComponentInChildren <UITouchScreen>(true);
                touchScreen.touchEvent.AddListener(OnTouch);
                touchScreen.onClickEvent.AddListener(OnTouchClicked);
                touchScreen.onReleaseEvent.AddListener(OnTouchReleased);

                focusButton = transform.Find("Rotate/UI/FocusButton").GetComponentInChildren <UIButton>(true);
                focusButton.onCheckEvent.AddListener(OnCheckFocusButton);

                videoOutputButton = transform.Find("Rotate/UI/VideoOutputButton").GetComponentInChildren <UIButton>(true);
                videoOutputButton.onCheckEvent.AddListener(OnCheckVideoOutput);

                snapshotButton = transform.Find("Rotate/UI/SnapshotButton").GetComponentInChildren <UIButton>(true);
                snapshotButton.onReleaseEvent.AddListener(OnSnapshot);

                colimatorLineRenderer = gameObject.GetComponent <LineRenderer>();
                colimatorLineRenderer.positionCount = 2;
                colimatorLineRenderer.SetPosition(0, transform.position);
                colimatorLineRenderer.startWidth = lineRendererWidth / GlobalState.WorldScale;
                colimatorLineRenderer.endWidth   = lineRendererWidth / GlobalState.WorldScale;
                colimatorLineRenderer.enabled    = false;
            }
        }
Ejemplo n.º 2
0
        public static UITouchScreen Create(CreateTouchScreenParams input)
        {
            GameObject go = new GameObject(input.widgetName)
            {
                tag = "UICollider"
            };

            // Find the anchor of the parent if it is a UIElement
            Vector3 parentAnchor = Vector3.zero;

            if (input.parent)
            {
                UIElement elem = input.parent.gameObject.GetComponent <UIElement>();
                if (elem)
                {
                    parentAnchor = elem.Anchor;
                }
            }

            UITouchScreen uiTouchScreen = go.AddComponent <UITouchScreen>();

            uiTouchScreen.relativeLocation        = input.relativeLocation;
            uiTouchScreen.transform.parent        = input.parent;
            uiTouchScreen.transform.localPosition = parentAnchor + input.relativeLocation;
            uiTouchScreen.transform.localRotation = Quaternion.identity;
            uiTouchScreen.transform.localScale    = Vector3.one;
            uiTouchScreen.width     = input.width;
            uiTouchScreen.height    = input.height;
            uiTouchScreen.thickness = input.thickness;

            BoxCollider collider = go.AddComponent <BoxCollider>();

            collider.size      = new Vector3(uiTouchScreen.width, uiTouchScreen.height, uiTouchScreen.thickness);
            collider.center    = new Vector3(uiTouchScreen.width * 0.5f, -uiTouchScreen.height * 0.5f, -uiTouchScreen.thickness * 0.5f);
            collider.isTrigger = true;

            UIUtils.SetRecursiveLayer(go, "CameraHidden");

            return(uiTouchScreen);
        }
Ejemplo n.º 3
0
        private const int RT_DEPTH  = 0;//24;

        public override GameObject CreateInstance(GameObject source, Transform parent = null, bool isPrefab = false)
        {
            GameObject newCamera = GameObject.Instantiate(source, parent);

            VRInput.DeepSetLayer(newCamera, "CameraHidden");

            newCamera.GetComponentInChildren <CameraController>(true).CopyParameters(source.GetComponentInChildren <CameraController>(true));

            if (!GlobalState.Settings.DisplayGizmos)
            {
                GlobalState.SetGizmoVisible(newCamera, false);
            }

            // Add UI
            if (isPrefab)
            {
                Transform uiRoot = newCamera.transform.Find("Rotate/Name");

                if (null == uiRoot.Find("Name"))
                {
                    UILabel nameLabel = UILabel.Create(new UILabel.CreateLabelParams
                    {
                        parent       = uiRoot,
                        widgetName   = "Name",
                        caption      = "Camera",
                        width        = 1.4f,
                        height       = 0.25f,
                        labelContent = UILabel.LabelContent.TextOnly,
                    });
                    {
                        TextMeshProUGUI text = nameLabel.gameObject.GetComponentInChildren <TextMeshProUGUI>();
                        text.enableAutoSizing = true;
                        text.fontSizeMin      = 6f;
                        text.fontSizeMax      = 72f;
                        text.alignment        = TextAlignmentOptions.Center;
                    }
                    nameLabel.baseColor.useConstant = true;
                    nameLabel.baseColor.constant    = new Color(0, 0, 0, 0);
                    nameLabel.SetLightLayer(2);
                }

                uiRoot = newCamera.transform.Find("Rotate/UI");
                if (null == uiRoot.Find("Focal"))
                {
                    // Focal slider
                    UISlider focalSlider = UISlider.Create(new UISlider.CreateArgs
                    {
                        parent           = uiRoot,
                        widgetName       = "Focal",
                        caption          = "Focal",
                        currentValue     = 35f,
                        sliderBegin      = 0.15f,
                        sliderEnd        = 0.86f,
                        relativeLocation = new Vector3(-0.30f, -0.03f, -UISlider.default_thickness),
                        width            = 0.3f,
                        height           = 0.02f,
                        railMargin       = 0.002f,
                        knobRadius       = 0.007f
                    });
                    focalSlider.DataCurve = GlobalState.Settings.focalCurve;

                    focalSlider.SetLightLayer(2);
                }

                // In front button
                if (null == uiRoot.Find("InFront"))
                {
                    UIButton inFrontButton = UIButton.Create(new UIButton.CreateButtonParams
                    {
                        parent             = uiRoot,
                        widgetName         = "InFront",
                        caption            = "Always in Front",
                        buttonContent      = UIButton.ButtonContent.ImageOnly,
                        icon               = UIUtils.LoadIcon("back"),
                        width              = 0.02f,
                        height             = 0.02f,
                        iconMarginBehavior = UIButton.IconMarginBehavior.UseIconMargin,
                        iconMargin         = 0.002f,
                        relativeLocation   = new Vector3(-0.30f, -0.005f, -UIButton.default_thickness)
                    });
                    inFrontButton.isCheckable   = true;
                    inFrontButton.baseSprite    = UIUtils.LoadIcon("back");
                    inFrontButton.checkedSprite = UIUtils.LoadIcon("front");
                    inFrontButton.SetLightLayer(2);
                }

                // Touch screen
                uiRoot = newCamera.transform.Find("Rotate/CameraPreview");
                UITouchScreen touchScreen = UITouchScreen.Create(new UITouchScreen.CreateTouchScreenParams
                {
                    parent           = uiRoot,
                    width            = 1f,
                    height           = 1f,
                    thickness        = 0.01f,
                    relativeLocation = new Vector3(-0.5f, 0.5f, -0.03f)
                });
                touchScreen.SetLightLayer(2);
                touchScreen.gameObject.SetActive(false);

                // Focus button
                uiRoot = newCamera.transform.Find("Rotate/UI");
                UIButton focusButton = UIButton.Create(new UIButton.CreateButtonParams
                {
                    parent             = uiRoot,
                    widgetName         = "FocusButton",
                    caption            = "Enable Touch Screen Focus",
                    buttonContent      = UIButton.ButtonContent.ImageOnly,
                    icon               = UIUtils.LoadIcon("dof"),
                    width              = 0.02f,
                    height             = 0.02f,
                    iconMarginBehavior = UIButton.IconMarginBehavior.UseIconMargin,
                    iconMargin         = 0.002f,
                    relativeLocation   = new Vector3(-0.27f, -0.005f, -UIButton.default_thickness)
                });
                focusButton.isCheckable   = true;
                focusButton.baseSprite    = UIUtils.LoadIcon("dof");
                focusButton.checkedSprite = UIUtils.LoadIcon("dof");
                focusButton.SetLightLayer(2);

                // Video output button
                uiRoot = newCamera.transform.Find("Rotate/UI");
                UIButton videoOutputButton = UIButton.Create(new UIButton.CreateButtonParams
                {
                    parent             = uiRoot,
                    widgetName         = "VideoOutputButton",
                    caption            = "Outputs camera to video file",
                    buttonContent      = UIButton.ButtonContent.ImageOnly,
                    icon               = UIUtils.LoadIcon("record_video"),
                    width              = 0.02f,
                    height             = 0.02f,
                    iconMarginBehavior = UIButton.IconMarginBehavior.UseIconMargin,
                    iconMargin         = 0.002f,
                    relativeLocation   = new Vector3(-0.02f, -0.005f, -UIButton.default_thickness)
                });
                videoOutputButton.isCheckable   = true;
                videoOutputButton.baseSprite    = UIUtils.LoadIcon("record_video");
                videoOutputButton.checkedSprite = UIUtils.LoadIcon("record_video");
                videoOutputButton.SetLightLayer(2);

                // Snapshot button
                uiRoot = newCamera.transform.Find("Rotate/UI");
                UIButton snapshotButton = UIButton.Create(new UIButton.CreateButtonParams
                {
                    parent             = uiRoot,
                    widgetName         = "SnapshotButton",
                    caption            = "Outputs camera to image file",
                    buttonContent      = UIButton.ButtonContent.ImageOnly,
                    icon               = UIUtils.LoadIcon("snapshot"),
                    width              = 0.02f,
                    height             = 0.02f,
                    iconMarginBehavior = UIButton.IconMarginBehavior.UseIconMargin,
                    iconMargin         = 0.002f,
                    relativeLocation   = new Vector3(-0.05f, -0.005f, -UIButton.default_thickness)
                });
                snapshotButton.SetLightLayer(2);
            }

            return(newCamera);
        }