public void Start()
 {
     fadeObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);
     //fadeObject.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
     fadeObject.GetComponent <MeshRenderer>().material = MaterialUtil.CreateFlatMaterial(Color.black, 0.0f);
     fadeObject.SetName("fade_sphere");
     UnityUtil.ReverseMeshOrientation(fadeObject.GetMesh());
     fadeObject.transform.SetParent(UseCamera.transform, false);
     fadeObject.SetLayer(FPlatform.HUDLayer);
 }
Beispiel #2
0
 public void Start()
 {
     fadeObject = new fGameObject(GameObject.CreatePrimitive(PrimitiveType.Sphere), FGOFlags.NoFlags);
     //fadeObject.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
     fadeObject.SetMaterial(MaterialUtil.CreateFlatMaterial(Color.black, 0.0f), true);
     fadeObject.SetName("fade_sphere");
     UnityUtil.ReverseMeshOrientation(fadeObject.GetMesh());
     fadeObject.SetParent(UseCamera.GameObject(), false);
     fadeObject.SetLayer(FPlatform.HUDLayer);
 }
Beispiel #3
0
 public static Material ToUnityMaterial(SOMaterial m)
 {
     if (m.Type == SOMaterial.MaterialType.TextureMap)
     {
         Material unityMat = new Material(Shader.Find("Standard"));
         unityMat.SetName(m.Name);
         unityMat.color = m.RGBColor;
         //if (m.Alpha < 1.0f)
         //    MaterialUtil.SetupMaterialWithBlendMode(unityMat, MaterialUtil.BlendMode.Transparent);
         unityMat.mainTexture = m.MainTexture;
         return(unityMat);
     }
     else if (m.Type == SOMaterial.MaterialType.PerVertexColor)
     {
         return(MaterialUtil.CreateStandardVertexColorMaterial(m.RGBColor));
     }
     else if (m.Type == SOMaterial.MaterialType.TransparentRGBColor)
     {
         return(MaterialUtil.CreateTransparentMaterial(m.RGBColor));
     }
     else if (m.Type == SOMaterial.MaterialType.StandardRGBColor)
     {
         return(MaterialUtil.CreateStandardMaterial(m.RGBColor));
     }
     else if (m.Type == SOMaterial.MaterialType.UnlitRGBColor)
     {
         return(MaterialUtil.CreateFlatMaterial(m.RGBColor));
     }
     else if (m is UnitySOMaterial)
     {
         return((m as UnitySOMaterial).unityMaterial);
     }
     else
     {
         return(MaterialUtil.CreateStandardMaterial(Color.black));
     }
 }
Beispiel #4
0
        public void Create()
        {
            menuContainer = new GameObject(UniqueNames.GetNext("HUDRadialMenu"));

            itemMaterial      = MaterialUtil.CreateFlatMaterial(ItemColor);
            highlightMaterial = MaterialUtil.CreateFlatMaterial(HighlightColor);


            float fInnerRadius = Radius * DeadZoneRadiusFactor;

            centerPoint = AppendUnityPrimitiveGO("center_point", PrimitiveType.Sphere, highlightMaterial, menuContainer, false);
            centerPoint.transform.localScale = fInnerRadius * 0.25f * Vector3.one;

            int   nItems          = TopLevelItems.Count;
            float fWedgeSpan      = (AngleSpan / (float)nItems) - WedgePadding;
            int   nSlicesPerWedge = 64 / nItems;

            float fCurAngle = AngleShift;

            for (int i = 0; i < nItems; ++i)
            {
                Mesh m = MeshGenerators.CreatePuncturedDisc(fInnerRadius, Radius, nSlicesPerWedge,
                                                            fCurAngle, fCurAngle + fWedgeSpan);

                float   fMidAngleRad = (fCurAngle + fWedgeSpan * 0.5f) * Mathf.Deg2Rad;
                Vector2 vMid         = new Vector2(Mathf.Cos(fMidAngleRad), Mathf.Sin(fMidAngleRad));

                TopLevelItems[i].GO = AppendMeshGO(TopLevelItems[i].Label, m, itemMaterial, menuContainer);
                TopLevelItems[i].GO.transform.Rotate(Vector3.right, -90.0f); // ??

                // [TODO] this is to improve font centering. Right now we do absolute centering
                //   but visually this looks wrong because weight of font is below center-y.
                //   Right thing would be to align at top of lowercase letters, rather than center-y
                //   (to fix in future)
                float fudge = 0.0f;
                if (nItems == 2 && i == 1)
                {
                    fudge = -0.1f;
                }

                TextLabelGenerator textGen = new TextLabelGenerator()
                {
                    Text      = TopLevelItems[i].Label, Scale = TextScale,
                    Translate = vMid * (TextCenterPointFactor + fudge) * Radius,
                    Align     = TextLabelGenerator.Alignment.HVCenter
                };
                AddVisualElements(textGen.Generate(), true);

                // debug: add red dots at center points to see how well text is aligned...
                //GameObject tmp = AppendUnityPrimitiveGO("center", PrimitiveType.Sphere, MaterialUtil.CreateStandardMaterial(Color.red), RootGameObject);
                //tmp.transform.localScale = new Vector3(0.15f, 0.15f, 0.15f);
                //tmp.transform.position = textGen.Translate;

                if (TopLevelItems[i].SubItems != null)
                {
                    create_sub_items(TopLevelItems[i], Radius, fCurAngle, fCurAngle + fWedgeSpan);
                }

                fCurAngle += WedgePadding + fWedgeSpan;
            }
        }
Beispiel #5
0
        void InitializeSpatialInput()
        {
            Left  = new SpatialDevice();
            Right = new SpatialDevice();

            Left.CursorDefaultMaterial   = MaterialUtil.CreateTransparentMaterial(ColorUtil.ForestGreen, 0.6f);
            Left.CursorHitMaterial       = MaterialUtil.CreateStandardMaterial(ColorUtil.SelectionGold);
            Left.CursorCapturingMaterial = MaterialUtil.CreateTransparentMaterial(ColorUtil.SelectionGold, 0.75f);
            Left.HandMaterial            = MaterialUtil.CreateTransparentMaterial(ColorUtil.ForestGreen, 0.3f);

            Right.CursorDefaultMaterial   = MaterialUtil.CreateTransparentMaterial(Colorf.DarkRed, 0.6f);
            Right.CursorHitMaterial       = MaterialUtil.CreateStandardMaterial(ColorUtil.PivotYellow);
            Right.CursorCapturingMaterial = MaterialUtil.CreateTransparentMaterial(ColorUtil.PivotYellow, 0.75f);
            Right.HandMaterial            = MaterialUtil.CreateTransparentMaterial(ColorUtil.CgRed, 0.3f);

            CursorVisualAngleInDegrees = 1.5f;

            standardCursorMesh = MeshGenerators.Create3DArrow(1.0f, 1.0f, 1.0f, 0.5f, 16);
            UnityUtil.TranslateMesh(standardCursorMesh, 0, -2.0f, 0);
            activeToolCursorMesh = MeshGenerators.Create3DArrow(1.0f, 1.0f, 1.0f, 1.0f, 16);
            UnityUtil.TranslateMesh(activeToolCursorMesh, 0, -2.0f, 0);

            Left.Cursor = UnityUtil.CreateMeshGO("left_cursor", standardCursorMesh, Left.CursorDefaultMaterial);
            Left.Cursor.transform.localScale    = 0.3f * Vector3.one;
            Left.Cursor.transform.localRotation = Quaternion.AngleAxis(45.0f, new Vector3(1, 0, 1).normalized);
            MaterialUtil.DisableShadows(Left.Cursor);
            Left.Cursor.SetLayer(FPlatform.CursorLayer);
            Left.SmoothedHandFrame = Frame3f.Identity;

            var leftHandMesh = MeshGenerators.Create3DArrow(1.0f, 1.0f, 1.0f, 0.5f, 16);

            Left.Hand = UnityUtil.CreateMeshGO("left_hand", leftHandMesh, Left.HandMaterial);
            UnityUtil.TranslateMesh(leftHandMesh, 0, -1.0f, 0);
            Left.Hand.transform.localScale = 0.1f * Vector3.one;
            Left.Hand.transform.rotation   = Quaternion.FromToRotation(Vector3.up, Vector3.forward);
            Left.Hand.SetLayer(FPlatform.HUDLayer);

            Left.Laser    = new GameObject("left_laser");
            Left.LaserRen = Left.Laser.AddComponent <LineRenderer>();
            Left.LaserRen.SetPositions(new Vector3[2] {
                Vector3.zero, 100 * Vector3.up
            });
            Left.LaserRen.startWidth = Left.LaserRen.endWidth = 0.01f;
            Left.LaserRen.material   = MaterialUtil.CreateFlatMaterial(ColorUtil.ForestGreen, 0.2f);
            Left.Laser.SetLayer(FPlatform.CursorLayer);
            Left.Laser.transform.parent = Left.Cursor.transform;

            Right.Cursor = UnityUtil.CreateMeshGO("right_cursor", standardCursorMesh, Right.CursorDefaultMaterial);
            Right.Cursor.transform.localScale    = 0.3f * Vector3.one;
            Right.Cursor.transform.localRotation = Quaternion.AngleAxis(45.0f, new Vector3(1, 0, 1).normalized);
            MaterialUtil.DisableShadows(Right.Cursor);
            Right.Cursor.SetLayer(FPlatform.CursorLayer);
            Right.SmoothedHandFrame = Frame3f.Identity;

            var rightHandMesh = MeshGenerators.Create3DArrow(1.0f, 1.0f, 1.0f, 0.5f, 16);

            Right.Hand = UnityUtil.CreateMeshGO("right_hand", rightHandMesh, Right.HandMaterial);
            UnityUtil.TranslateMesh(rightHandMesh, 0, -1.0f, 0);
            Right.Hand.transform.localScale = 0.1f * Vector3.one;
            Right.Hand.transform.rotation   = Quaternion.FromToRotation(Vector3.up, Vector3.forward);
            Right.Hand.SetLayer(FPlatform.HUDLayer);

            Right.Laser    = new GameObject("right_laser");
            Right.LaserRen = Right.Laser.AddComponent <LineRenderer>();
            Right.LaserRen.SetPositions(new Vector3[2] {
                Vector3.zero, 100 * Vector3.up
            });
            Right.LaserRen.startWidth = Right.LaserRen.endWidth = 0.01f;
            Right.LaserRen.material   = MaterialUtil.CreateFlatMaterial(ColorUtil.CgRed, 0.2f);
            Right.Laser.SetLayer(FPlatform.CursorLayer);
            Right.Laser.transform.parent = Right.Cursor.transform;

            spatialInputInitialized = true;
        }
Beispiel #6
0
        public static fMaterial ToMaterialf(SOMaterial m)
        {
            fMaterial unityMat = null;

            if (m.Type == SOMaterial.MaterialType.TextureMap)
            {
                unityMat       = new Material(Shader.Find("Standard"));
                unityMat.name  = m.Name;
                unityMat.color = m.RGBColor;
                //if (m.Alpha < 1.0f)
                //    MaterialUtil.SetupMaterialWithBlendMode(unityMat, MaterialUtil.BlendMode.Transparent);
                unityMat.mainTexture = m.MainTexture;
            }
            else if (m.Type == SOMaterial.MaterialType.PerVertexColor)
            {
                unityMat              = MaterialUtil.CreateStandardVertexColorMaterial(m.RGBColor);
                unityMat.renderQueue += m.RenderQueueShift;
                unityMat.SetInt("_Cull", (int)m.CullingMode);
            }
            else if (m.Type == SOMaterial.MaterialType.FlatShadedPerVertexColor)
            {
                unityMat              = MaterialUtil.CreateFlatShadedVertexColorMaterialF(m.RGBColor);
                unityMat.renderQueue += m.RenderQueueShift;
                unityMat.SetInt("_Cull", (int)m.CullingMode);
            }
            else if (m.Type == SOMaterial.MaterialType.TransparentRGBColor)
            {
                unityMat              = MaterialUtil.CreateTransparentMaterial(m.RGBColor);
                unityMat.renderQueue += m.RenderQueueShift;
            }
            else if (m.Type == SOMaterial.MaterialType.StandardRGBColor)
            {
                unityMat              = MaterialUtil.CreateStandardMaterial(m.RGBColor);
                unityMat.renderQueue += m.RenderQueueShift;
            }
            else if (m.Type == SOMaterial.MaterialType.UnlitRGBColor)
            {
                unityMat              = MaterialUtil.CreateFlatMaterial(m.RGBColor);
                unityMat.renderQueue += m.RenderQueueShift;
            }
            else if (m.Type == SOMaterial.MaterialType.DepthWriteOnly)
            {
                unityMat              = MaterialUtil.CreateDepthWriteOnly();
                unityMat.renderQueue += m.RenderQueueShift;
            }
            else if (m.Type == SOMaterial.MaterialType.StandardMesh)
            {
                fMeshMaterial meshMat = MaterialUtil.CreateStandardMeshMaterial(m.RGBColor);
                meshMat.renderQueue += m.RenderQueueShift;
                if (m is SOMeshMaterial)
                {
                    meshMat.InitializeFromSOMaterial(m as SOMeshMaterial);
                }
                unityMat = meshMat;
            }
            else if (m is UnitySOMeshMaterial)
            {
                unityMat = (m as UnitySOMeshMaterial).meshMaterial;
            }
            else if (m is UnitySOMaterial)
            {
                unityMat = (m as UnitySOMaterial).unityMaterial;
            }
            else
            {
                unityMat = MaterialUtil.CreateStandardMaterial(Color.black);
            }

            if ((m.Hints & SOMaterial.HintFlags.UseTransparentPass) != 0)
            {
                SetupMaterialWithBlendMode(unityMat, BlendMode.Transparent);
            }

            if (m.MaterialCustomizerF != null)
            {
                m.MaterialCustomizerF(unityMat);
            }

            return(unityMat);
        }
        public void Initialize(Cockpit cockpit)
        {
            cockpit.Name = "splashCockpit";
            cockpit.DefaultCursorDepth = 3.0f;
            cockpit.PositionMode       = Cockpit.MovementMode.Static;

            // create black sphere around camera to hide existing scene
            fGameObject blackBackground = new fGameObject(
                UnityUtil.CreateMeshGO("background_delete", "icon_meshes/inverted_sphere_tiny", 1.0f,
                                       UnityUtil.MeshAlignOption.AllAxesCentered, MaterialUtil.CreateFlatMaterial(Color.black), false));

            // add as bounds object to do mouse hit-test
            cockpit.Context.Scene.AddWorldBoundsObject(blackBackground);

            // re-parent from Scene so the sphere tracks the camera
            cockpit.FixedCameraTrackingGO.AddChild(blackBackground, false);

            HUDButton title = HUDBuilder.CreateIconClickButton(
                new HUDShape(HUDShapeType.Rectangle, 2.0f, 0.8f),
                3.0f, 0.0f, 2.5f, "simplex_startup/simplex_v2");

            title.Name    = "title";
            title.Enabled = false;
            cockpit.AddUIElement(title, true);

            HUDButton start = HUDBuilder.CreateIconClickButton(
                new HUDShape(HUDShapeType.Rectangle, 0.5f, 0.25f),
                3.0f, 8.0f, -10, "simplex_startup/start_v1");

            start.Name       = "start";
            start.OnClicked += (s, e) => {
                cockpit.ActiveCamera.Animator().DoActionDuringDipToBlack(() => {
                    cockpit.Context.Scene.RemoveWorldBoundsObject(blackBackground);
                    UnityEngine.GameObject.Destroy(blackBackground);
                    cockpit.Context.PushCockpit(
                        new SetupCADCockpit_V1());
                }, 1.0f);
            };
            cockpit.AddUIElement(start, true);

            HUDButton quit = HUDBuilder.CreateIconClickButton(
                new HUDShape(HUDShapeType.Rectangle, 0.5f, 0.25f),
                3.0f, -8.0f, -10, "simplex_startup/quit_v1");

            quit.Name       = "quit";
            quit.OnClicked += (s, e) => {
                FPlatform.QuitApplication();
            };
            cockpit.AddUIElement(quit, true);

            HUDButton logo = HUDBuilder.CreateIconClickButton(
                new HUDShape(HUDShapeType.Rectangle, 0.8f, 0.2f),
                3.0f, 0.0f, -25.0f, "simplex_startup/gradientspace_splash");

            logo.Name    = "logo";
            logo.Enabled = false;
            cockpit.AddUIElement(logo, true);



            HUDButton about_arrow = HUDBuilder.CreateIconClickButton(
                new HUDShape(HUDShapeType.Rectangle, 0.75f, 0.75f),
                3.0f, -30.0f, -10.0f, "simplex_startup/about_arrow");

            about_arrow.Name    = "about_arrow";
            about_arrow.Enabled = false;
            cockpit.AddUIElement(about_arrow, true);


            float     about_text_scale = 3.0f;
            float     angle_left       = -65.0f;
            HUDButton about_text       = HUDBuilder.CreateIconClickButton(
                new HUDShape(HUDShapeType.Rectangle,
                             0.8f * about_text_scale, 1.0f * about_text_scale)
            {
                UseUVSubRegion = false
            },
                3.0f, angle_left, 0.0f, "simplex_startup/about_text");

            UnityUtil.TranslateInFrame(about_text.RootGameObject, 0.0f, -0.5f, 0, CoordSpace.WorldCoords);
            about_text.Name    = "about_text";
            about_text.Enabled = false;
            cockpit.AddUIElement(about_text, true);



            HUDButton controls_arrow = HUDBuilder.CreateIconClickButton(
                new HUDShape(HUDShapeType.Rectangle, 0.75f, 0.75f),
                3.0f, 30.0f, -10.0f, "simplex_startup/controls_arrow");

            controls_arrow.Name    = "controls_arrow";
            controls_arrow.Enabled = false;
            cockpit.AddUIElement(controls_arrow, true);



            float     text_scale     = 3.0f;
            float     angle_right    = 65.0f;
            HUDButton controls_mouse = HUDBuilder.CreateIconClickButton(
                new HUDShape(HUDShapeType.Rectangle, 0.7f * text_scale, 0.7f * text_scale)
            {
                UseUVSubRegion = false
            },
                3.0f, angle_right, 0.0f, "simplex_startup/controls_mouse");

            UnityUtil.TranslateInFrame(controls_mouse.RootGameObject, 0.25f, 0.1f, 0, CoordSpace.WorldCoords);
            controls_mouse.Name    = "controls_mouse";
            controls_mouse.Enabled = false;
            cockpit.AddUIElement(controls_mouse, true);

            HUDButton controls_gamepad = HUDBuilder.CreateIconClickButton(
                new HUDShape(HUDShapeType.Rectangle, 0.7f * text_scale, 0.7f * text_scale)
            {
                UseUVSubRegion = false
            },
                3.0f, angle_right, 0.0f, "simplex_startup/controls_gamepad");

            UnityUtil.TranslateInFrame(controls_gamepad.RootGameObject, 0.25f, 0.1f, 0, CoordSpace.WorldCoords);
            controls_gamepad.Name    = "controls_gamepad";
            controls_gamepad.Enabled = false;
            cockpit.AddUIElement(controls_gamepad, true);
            controls_gamepad.RootGameObject.Hide();



            HUDToggleButton mouse_button = HUDBuilder.CreateToggleButton(
                new HUDShape(HUDShapeType.Rectangle, 1.0f, 1.0f),
                2.9f, angle_right, 0.0f, "simplex_startup/mouse", "simplex_startup/mouse_disabled");

            UnityUtil.TranslateInFrame(mouse_button.RootGameObject, -0.5f, -1.0f, 0, CoordSpace.WorldCoords);
            mouse_button.Name = "mouse_button";
            cockpit.AddUIElement(mouse_button, true);

            HUDToggleButton gamepad_button = HUDBuilder.CreateToggleButton(
                new HUDShape(HUDShapeType.Rectangle, 1.0f, 1.0f),
                2.9f, angle_right, 0.0f, "simplex_startup/gamepad_with_labels", "simplex_startup/gamepad_disabled");

            UnityUtil.TranslateInFrame(gamepad_button.RootGameObject, 0.5f, -1.0f, 0, CoordSpace.WorldCoords);
            gamepad_button.Name = "gamepad_button";
            cockpit.AddUIElement(gamepad_button, true);


            HUDToggleGroup group = new HUDToggleGroup();

            group.AddButton(mouse_button);
            group.AddButton(gamepad_button);
            group.Selected   = 0;
            group.OnToggled += (sender, nSelected) => {
                if (nSelected == 0)
                {
                    controls_gamepad.RootGameObject.Hide();
                    controls_mouse.RootGameObject.Show();
                }
                else
                {
                    controls_gamepad.RootGameObject.Show();
                    controls_mouse.RootGameObject.Hide();
                }
            };



            // setup key handlers (need to move to behavior...)
            cockpit.AddKeyHandler(new SplashScreenKeyHandler(cockpit.Context));

            cockpit.InputBehaviors.Add(new VRMouseUIBehavior(cockpit.Context)
            {
                Priority = 0
            });
            cockpit.InputBehaviors.Add(new VRGamepadUIBehavior(cockpit.Context)
            {
                Priority = 0
            });
            cockpit.InputBehaviors.Add(new VRSpatialDeviceUIBehavior(cockpit.Context)
            {
                Priority = 0
            });
        }