void Start()
    {
        // Store reference to attached component
        controller = GetComponent <CharacterController>();

        myMI = GameObject.Find("MouseInteraction").GetComponent <MouseInteraction>();
    }
Beispiel #2
0
 private void Awake()
 {
     _interaction           = FindObjectOfType <MouseInteraction>();
     _candleData            = FindObjectOfType <CandleBehaviour>();
     _interaction.Hover    += InteractableUI;
     _interaction.HoverOff += ResetUI;
 }
Beispiel #3
0
 private void Awake()
 {
     _cam   = Camera.main;
     _crate = transform.parent;
     _z     = _crate.position.z;
     _y     = _crate.position.y;
     _mouse = FindObjectOfType <MouseInteraction>();
 }
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();
            MouseInteraction testScript = (MouseInteraction)target;

            if (GUILayout.Button("Test wut"))
            {
                testScript.TestFunction1();
            }
        }
Beispiel #5
0
        protected override void Update(GameTime gameTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            MouseInteraction.Update();
            CurrentScene.Update();

            base.Update(gameTime);
        }
Beispiel #6
0
    public void OnDrop(PointerEventData eventData)
    {
        TileData         td = GetComponent <TileData>();
        MouseInteraction mi = eventData.pointerDrag.transform.GetComponent <MouseInteraction>();

        if (Item != null)
        {
            //mi.ResetPosition();
        }
        else
        {
            mi.SetPoint(td.GetPoint());
            MouseInteraction.DraggedObject.transform.SetParent(transform);
        }
    }
Beispiel #7
0
            public NavigableUIList(ITypedDataCursor <UIListState> state, Camera camera, Action <int> selectItem)
            {
                _isInteractable = state.To(s => s.IsInteractable);
                _selectItem     = selectItem;

                _highlightedIndex = state.To(s => s.HighlightedIndex);
                MouseHighlight.Initialize(state);
                MouseInteraction.LeftMouseClick(state.To(s => s.Items).Get(), selectItem);

                _controllerHighlight = ControllerHighlight.CreateControllerIndexUpdater(
                    cursor: state,
                    itemSelector: (items, currentIndex, inputDirection) => {
                    return(ControllerHighlight.MoveControllerIndex(camera.WorldToScreenPoint, items, currentIndex, inputDirection));
                });

                Highlighter.Initialize(state);
            }
 // Use this for initialization
 private void Start()
 {
     instance            = this;
     cameraTransform     = Camera.main.GetComponent <CameraFollow>().transform;
     itemInfoUITransform = itemInfoUI.GetComponent <RectTransform>();
 }
    public override void OnInspectorGUI()
    {
        MouseInteraction myMouseInteraction = (MouseInteraction)target;

        if (!myMouseInteraction.useCenterScreen && !myMouseInteraction.useTouchClick)
        {
            interactionMode = InteractionMode.Mouse;
        }
        else if (!myMouseInteraction.useTouchClick)
        {
            interactionMode = InteractionMode.CenterOfTheScreen;
        }
        else
        {
            interactionMode = InteractionMode.TouchClick;
        }

        // Settings of the Mouse Interaction script

        EditorGUILayout.Separator();          // Blank Line (space separator)

        // Interaction Color
        myMouseInteraction.interactionColor = EditorGUILayout.ColorField(new GUIContent("Interaction Color", "Color change of the interacted object."), myMouseInteraction.interactionColor);
        // Interaction Speed
        myMouseInteraction.interactionSpeed = EditorGUILayout.FloatField(new GUIContent("Interaction Speed", "Fade speed of the color change (slow -> quick)"), myMouseInteraction.interactionSpeed);
        // Emission Intensity
        myMouseInteraction.emissionIntensity = EditorGUILayout.Slider(new GUIContent("Emission Intensity", "Emission intensity (doesn't work with material which has no emissive intensity)"), myMouseInteraction.emissionIntensity, 0.0f, 1.0f);

        EditorGUILayout.Separator();          // Blank Line (space separator)

        // Interaction Mode
        interactionMode = (InteractionMode)EditorGUILayout.EnumPopup(new GUIContent("Interaction Mode", "How the interaction work (mouse over, center of the screen or simple touch/click)"), interactionMode);
        switch (interactionMode)
        {
        case InteractionMode.Mouse:
            myMouseInteraction.useCenterScreen = false;
            myMouseInteraction.useTouchClick   = false;
            break;

        case InteractionMode.CenterOfTheScreen:
            myMouseInteraction.useCenterScreen = true;
            myMouseInteraction.useTouchClick   = false;
            break;

        case InteractionMode.TouchClick:
            myMouseInteraction.useCenterScreen = false;
            myMouseInteraction.useTouchClick   = true;
            break;

        default:
            break;
        }
        // Mouse Cursor
        if (interactionMode != InteractionMode.Mouse)
        {
            GUI.enabled = false;
        }
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel(new GUIContent("Mouse Cursor", "Cursor sprite when interaction with the object (texture must be a Cursor in import settings)"));
        myMouseInteraction.mouseCursor = (Texture2D)EditorGUILayout.ObjectField(myMouseInteraction.mouseCursor, typeof(Texture2D), false);
        EditorGUILayout.EndHorizontal();
        GUI.enabled = true;
        // Interaction distance
        myMouseInteraction.interactionDistance = EditorGUILayout.IntField(new GUIContent("Interaction Distance", "Max distance of the interaction (1000 = far away, 6 = melee range)"), myMouseInteraction.interactionDistance);
        // Grouped Interaction
        myMouseInteraction.groupedInteraction = EditorGUILayout.Toggle(new GUIContent("Grouped Interaction", "Interaction with all objects of the same parent."), myMouseInteraction.groupedInteraction);
        // Number Of Ascent
        if (!myMouseInteraction.groupedInteraction)
        {
            GUI.enabled = false;
        }
        myMouseInteraction.numberOfAscent = EditorGUILayout.IntSlider(new GUIContent("Number Of Ascent", "Number of ascent to define the parent for the Grouped Interaction setting."), myMouseInteraction.numberOfAscent, 0, 4);
        GUI.enabled = true;
        // Interaction Animation
        myMouseInteraction.interactionAnim = (AnimationClip)EditorGUILayout.ObjectField(new GUIContent("Interaction Animation", "Animation played when interacted."), myMouseInteraction.interactionAnim, typeof(AnimationClip), false);
        if (myMouseInteraction.interactionAnim == null)
        {
            GUI.enabled = false;
        }
        // Animation Loop
        myMouseInteraction.animationLoop = EditorGUILayout.Toggle(new GUIContent("Animation Loop", "Loop the interacted animation."), myMouseInteraction.animationLoop);
        // Animation Reset
        if (!myMouseInteraction.animationLoop)
        {
            GUI.enabled = false;
        }
        myMouseInteraction.animationReset = EditorGUILayout.Toggle(new GUIContent("Animation Reset", "[Loop animation only] Reset the animation loop when the interaction exit."), myMouseInteraction.animationReset);
        GUI.enabled = true;

        EditorGUILayout.Separator();          // Blank Line (space separator)

        // Show Tooltip (Beginning of a group list where settings are disabled if you don't want to show tooltip)
        myMouseInteraction.showTooltip = EditorGUILayout.BeginToggleGroup(new GUIContent("Show Tooltip", "Show a text over the interacted object."), myMouseInteraction.showTooltip);
        EditorGUI.indentLevel++;
        // Tooltip UI Panel
        myMouseInteraction.tooltipUIPanel = (GameObject)EditorGUILayout.ObjectField(new GUIContent("Tooltip UI Panel", "Show a predefined UI Panel over the interacted object."), myMouseInteraction.tooltipUIPanel, typeof(GameObject), true);
        // Check out of screen

        /*if(interactionMode != InteractionMode.Mouse || myMouseInteraction.tooltipUIPanel == null) {
         *      GUI.enabled = false ;
         * }
         * myMouseInteraction.checkOutOfScreen = EditorGUILayout.Toggle(new GUIContent("Check Out of the Screen", "[Mouse interaction only] Check if the UI Panel is outside the screen, and auto change its anchor (no effect if no UI Panel are defined)"), myMouseInteraction.checkOutOfScreen) ;
         * GUI.enabled = true ;*/
        // Fixed to the Object
        myMouseInteraction.fixedToTheObject = EditorGUILayout.Toggle(new GUIContent("Fixed to the Object", "Show the tooltip over the object instead of over the mouse."), myMouseInteraction.fixedToTheObject);
        // Tooltip Position
        myMouseInteraction.tooltipPosition = EditorGUILayout.Vector2Field(new GUIContent("Tooltip Position", "Position of the tooltip showed over the interacted object."), myMouseInteraction.tooltipPosition);
        // Tooltip Text
        myMouseInteraction.tooltipText = EditorGUILayout.TextField(new GUIContent("Tooltip Text", "Text to show over the interacted object."), myMouseInteraction.tooltipText);
        if (myMouseInteraction.tooltipText == "")
        {
            GUI.enabled = false;
        }
        EditorGUI.indentLevel++;
        // Tooltip Text Color
        myMouseInteraction.tooltipColor = EditorGUILayout.ColorField(new GUIContent("Text Color", "[Requires Tooltip Text] Color of the text showed over the interacted object."), myMouseInteraction.tooltipColor);
        // Tooltip Text Size
        myMouseInteraction.tooltipSize = EditorGUILayout.IntField(new GUIContent("Text Size", "[Requires Tooltip Text] Size of the text showed over the interacted object."), myMouseInteraction.tooltipSize);
        // Tooltip Text Scaled
        myMouseInteraction.textResized = EditorGUILayout.Toggle(new GUIContent("Text Resized", "Resize the text, relative to the distance between the object and the camera."), myMouseInteraction.textResized);
        // Tooltip Text Font
        myMouseInteraction.tooltipFont = (Font)EditorGUILayout.ObjectField(new GUIContent("Text Font", "[Requires Tooltip Text] Font of the text showed over the interacted object."), myMouseInteraction.tooltipFont, typeof(Font), false);
        // Tooltip Alignment
        myMouseInteraction.tooltipAlignment = (MouseInteraction.TooltipAlignment)EditorGUILayout.EnumPopup(new GUIContent("Text Alignment", "Alignment of the text showed over the interacted object."), myMouseInteraction.tooltipAlignment);
        // Tooltip Shadow Color
        myMouseInteraction.tooltipShadowColor = EditorGUILayout.ColorField(new GUIContent("Text Shadow Color", "Color of the text shadow showed over the interacted object."), myMouseInteraction.tooltipShadowColor);
        // Tooltip Shadow Position
        myMouseInteraction.tooltipShadowPosition = EditorGUILayout.Vector2Field(new GUIContent("Text Shadow Position", "Position of the text shadow showed over the interacted object."), myMouseInteraction.tooltipShadowPosition);
        EditorGUI.indentLevel--;
        GUI.enabled = true;
        EditorGUI.indentLevel--;
        EditorGUILayout.EndToggleGroup();     // End of the group list (of Show Tooltip)

        EditorGUILayout.Separator();          // Blank Line (space separator)

        // Warning messages
        // Check if the interacted object has a collider
        if (!myMouseInteraction.transform.gameObject.GetComponent <Collider>())
        {
            EditorGUILayout.HelpBox("Don't forget to attach a collider to this object.", MessageType.Warning);
        }
        // Advice for the Touch/Click interaction
        if (myMouseInteraction.useTouchClick && !myMouseInteraction.fixedToTheObject && myMouseInteraction.showTooltip)
        {
            EditorGUILayout.HelpBox("In Touch/Click interaction, 'Fixed to the object' setting is recommended for mobile uses.", MessageType.Warning);
        }
        // Check if the object has an animation component for the Interaction Animation setting
        if (myMouseInteraction.interactionAnim != null && myMouseInteraction.GetComponent <Animation>() == null)
        {
            EditorGUILayout.HelpBox("There is no Animation Component attached to this object.", MessageType.Error);
        }
        // Check if the object has the good number of parent, related to the Number Of Ascent setting
        if (myMouseInteraction.groupedInteraction)
        {
            bool      error_parent   = false;
            Transform current_parent = myMouseInteraction.transform.parent;
            for (int i = 1; i <= myMouseInteraction.numberOfAscent; i++)
            {
                if (current_parent == null)
                {
                    error_parent = true;
                    break;
                }
                else
                {
                    current_parent = current_parent.parent;
                }
            }
            if (error_parent)
            {
                EditorGUILayout.HelpBox("Number Of Ascent value is too high, this object doesn't have enough parent.", MessageType.Error);
            }
        }
        // Check if the UI Panel has a RectTransform component

        /*if(myMouseInteraction.checkOutOfScreen && myMouseInteraction.tooltipUIPanel != null) {
         *      if(myMouseInteraction.tooltipUIPanel.GetComponent<RectTransform>() == null)
         *              EditorGUILayout.HelpBox("Your UI Panel must have a RectTransform component.", MessageType.Error) ;
         * }*/
    }
Beispiel #10
0
 private void Awake()
 {
     _player = FindObjectOfType <MouseInteraction>();
 }
Beispiel #11
0
        protected override void Update(GameTime gameTime)
        {
            _elapsed_time += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            ClickTimer    += gameTime.ElapsedGameTime.TotalMilliseconds;

            if (_elapsed_time > 1000.0f)
            {
                fps                = _total_frames;
                _total_frames      = 0;
                _elapsed_time      = 0.0f;
                SunCollisionActive = true;
            }

            InputManager.Update();
            MouseInteraction.Update();

            if (Mouse.GetState().LeftButton == ButtonState.Released)
            {
                LeftButtonPressed = false;
            }

            if (Mouse.GetState().RightButton == ButtonState.Pressed)
            {
                if (!RightButtonPressed)
                {
                    Observer.Camera.MouseSensity = .00025f;
                    MousePositionSpace           = MouseInteraction.GetXZAtY(MouseInteraction.GetRay(GraphicsDevice,
                                                                                                     Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 1f, 1000.0f),
                                                                                                     Observer.Camera.ViewMatrix),
                                                                             Observer.Camera.CameraPosition.Y);


                    MousePositionSpace = new Vector3(MousePositionSpace.X - CelestialBody.GLOBALX, MousePositionSpace.Y - CelestialBody.GLOBALY, MousePositionSpace.Z - CelestialBody.GLOBALZ);


                    RightButtonPressed = true;
                }

                Observer.Camera.SetLookAt(MousePositionSpace, Zoom);
            }

            if (Mouse.GetState().RightButton == ButtonState.Released)
            {
                Observer.Camera.MouseSensity = .0008f;
                RightButtonPressed           = false;
            }

            if (MouseInteraction.IsScrollingUp)
            {
                Zoom -= 5.5f;
                Observer.Camera.Move(new Vector3(0, 0, -5.5f));
            }
            if (MouseInteraction.IsScrollingDown)
            {
                Zoom += 5.5f;
                Observer.Camera.Move(new Vector3(0, 0, 5.5f));
            }

            Observer.Camera.Update();

            CelestialBody.GLOBALX = Observer.Camera.CameraPosition.X;
            CelestialBody.GLOBALY = Observer.Camera.CameraPosition.Y;
            CelestialBody.GLOBALZ = Observer.Camera.CameraPosition.Z;

            for (int i = 0; i < CelestialBodies.Count; i++)
            {
                CelestialBodies[i].Update(gameTime);
                if (SunCollisionActive)
                {
                    if (CelestialBodies[i].Name != "Sun")
                    {
                        if (CelestialBodies[i].BoundingBox.Intersects(CelestialBodies.Find(p => p.Name == "Sun").BoundingBox))
                        {
                            CelestialBodies.RemoveAt(i);
                        }
                    }
                }
            }

            if (Mouse.GetState().LeftButton == ButtonState.Pressed)
            {
                if (!LeftButtonPressed)
                {
                    LeftButtonPressed = true;
                    Ray r = ToolKit.CalculateRay(new Vector2(Mouse.GetState().X, Mouse.GetState().Y),
                                                 Observer.Camera.ViewMatrix, Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                                                                                                                 GraphicsDevice.Viewport.AspectRatio, 0.01f, 150000.0f),
                                                 GraphicsDevice.Viewport);

                    if (ClickTimer < TimerDelay)
                    {
                        for (int i = 0; i < CelestialBodies.Count; i++)
                        {
                            if (r.Intersects(CelestialBodies[i].BoundingBox) > 1)
                            {
                                Observer.Camera.Flush();
                                UI.SetPlanet(CelestialBodies[i]);
                                CelestialBodies[i].Follow();
                                break;
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < CelestialBodies.Count; i++)
                        {
                            if (r.Intersects(CelestialBodies[i].BoundingBox) > 1)
                            {
                                UI.SetPlanet(CelestialBodies[i]);
                                CelestialBodies[i].SetFocus();
                                break;
                            }
                        }
                    }
                    ClickTimer = 0;
                }
            }



            UI.UpdateQR(gameTime);

            CelestialBodies = CelestialBodies.OrderByDescending(p => p.DistanceToObserver).ToList();
        }
Beispiel #12
0
        protected override void LoadContent()
        {
            #region "CONSOLE"
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine(".::XNA CELESTIAL MECHANICS SIMULATION::.");
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine("PROGRAMMED;BIIZNILLAH; BY φConst");
            Console.WriteLine();
            Console.WriteLine("CREDITS: ");
            Console.WriteLine("THE SUN EFFECT ACHIEVED WITH THE BLOOMCOMPONENT.CS AND EFFECT FILES OF http://xbox.create.msdn.com/en-US/education/catalog/sample/bloom");
            Console.WriteLine("THE FORMULAS; PLOTTERS; METHODS;");
            Console.WriteLine("USED IN THIS APPLICATION ARE LISTED IN THE REGISTER");
            Console.WriteLine("THIS APPLICATION USES A FIXED POINT METHOD!!!");
            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("ATTENTION: THE CALCULATED VALUES IN THIS APPLICATION ARE APPROXIMATIONS!!!");
            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine("SPECS: " + GraphicsDevice.DisplayMode);
            System.Threading.Thread.Sleep(1000);
            //Console.Write("VSYNCH ON/OFF: ");
            //bool vsync = Console.ReadLine().ToUpper() == "ON";
            Console.Write("SIMULATOR_MODE SOLAR/TBODY: ");
            SIMULATOR_TYPE = Console.ReadLine().ToUpper() == "SOLAR" ? SIMULATOR_MODE.SIMULATOR_SOLARSYSTEM : SIMULATOR_MODE.SIMULATOR_THREE_BODY_P;
            Console.WriteLine("Listening to commands...");
            new Thread(new ThreadStart(() =>
            {
                while (!IsExit)
                {
                    Console.Write("root>");
                    string data = Console.ReadLine();
                    switch (data.ToUpper())
                    {
                    case "EXIT":
                        Exit();
                        Environment.Exit(Environment.ExitCode);
                        break;

                    case "RESTART":
                        Exit();
                        System.Windows.Forms.Application.Restart();
                        Environment.Exit(Environment.ExitCode);
                        break;
                    }
                }
            })).Start();
            #endregion
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("Loading content...");
            Console.ForegroundColor = ConsoleColor.Gray;
            this.IsFixedTimeStep    = false;
            this.GraphicsDeviceManager.PreferredBackBufferWidth       = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
            this.GraphicsDeviceManager.PreferredBackBufferHeight      = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
            this.GraphicsDeviceManager.SynchronizeWithVerticalRetrace = false;
            this.GraphicsDeviceManager.ApplyChanges();

            spriteBatch  = new SpriteBatch(GraphicsDevice);
            InputManager = new InputManager();
            DebugFont    = Content.Load <SpriteFont>("DebugFont");

            LineBatch.Init(GraphicsDevice);
            Observer = new Observer(this, GraphicsDevice, "Observer1");
            CelestialBody.GLOBALSCALE = 50000.0f;
            CelestialBody.DEBUGFONT   = DebugFont;
            LoadCelestialBodies();
            IsGameContinuing = true;

            InputManager.BindKey(new Key(Keys.Y, true), new KeyAction(new Action(() =>
            {
                IsGameContinuing = !IsGameContinuing;
                IsMouseVisible   = !IsMouseVisible;
                if (!IsMouseVisible)
                {
                    Mouse.SetPosition(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2);
                }
            }), new Action(() => { })));

            InputManager.BindKey(new Key(Keys.Escape, true), new KeyAction(new Action(() => { IsExit = true; Exit(); }), new Action(() => { })));
            InputManager.BindKey(new Key(Keys.F11, true), new KeyAction(new Action(() => { ShowDebug = !ShowDebug; }), new Action(() => { })));

            UI = new GUI.UI(this, new System.Drawing.Point(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - 288, 0), CelestialBodies[1]);
            UI.Show();

            SpeechRecognizer = new SpeechRecognizer(this);

            //ADD COMMANDS
            SpeechRecognizer.AddCommand("Beende", new Action(() => { SpeechRecognizer.IsRunning = false; Exit(); }));
            SpeechRecognizer.AddCommand("Vogelperspektive", new Action(() =>
            {
                Observer.Camera.SetPosition(new Vector3(Observer.Camera.CameraPosition.X, 3945000.0f, 0));
            }));


            for (int i = 0; i < CelestialBodies.Count; i++)
            {
                var Body = CelestialBodies[i];
                SpeechRecognizer.AddCommand("Markiere " + Body.Name, new Action(() =>
                {
                    Body.SetFocus();
                    UI.SetPlanet(Body);
                }));
                SpeechRecognizer.AddCommand("Folge " + Body.Name, new Action(() =>
                {
                    Body.Follow();
                }));
                SpeechRecognizer.AddCommand("Gehe zu " + Body.Name, new Action(() =>
                {
                    Observer.Camera.SetPosition(new Vector3((float)Body.XCoord, Observer.Camera.CameraPosition.Y, (float)Body.YCoord));
                    Observer.Camera.CameraPosition = new Vector3(Observer.Camera.CameraPosition.X, MathHelper.Lerp(Observer.Camera.CameraPosition.Y, 0, 0.8f), Observer.Camera.CameraPosition.Z);
                }));
            }

            SpeechRecognizer.Run();

            //NetworkAPI = new NetworkAPI(this, "p5cms.esy.es", "P5", "Input.php");
            //NetworkAPI.Start();

            Grid            = new Grid3D(GraphicsDevice);
            Grid.MaxColumn  = 50;
            Grid.MaxRows    = 50;
            Grid.StepHeight = 150000;
            Grid.StepWidth  = 150000;
            Grid.Color      = new Color(55, 55, 55);
            Grid.CreateGrid();

            MouseInteraction = new MouseInteraction();
        }