Exemplo n.º 1
0
    public override void OnReceivedMessage(Message message)
    {
        // A scene was changed (next video?)
        if (message.Route == (int)MessageDestination.SCENE_CHANGE)
        {
            // Is the scene valid?
            if (message.Identifier == "VALID")
            {
                // Get the scene node from the message
                SimulationScene scene = (SimulationScene)message.Data;

                // Try to get the scene attribute containing the video URL
                string url; //filePath
                if (scene.GetAttribute("VIDEO_URL", out url))
                {
                    // Right now the video is being loaded dynamically. There is only one video instance in the memory.(The video that is currently playing)
                    int width  = 1920;
                    int height = 1080;

                    string path = Application.dataPath + @"/JsonScene/" + url;

                    _videoPlayer.PlayVideo(path, width, height);

                    string brightness;
                    if (scene.GetAttribute("GENERAL_SETTINGS_SCENE_BRIGHTNESS", out brightness))
                    {
                        int brightnessInt = Int32.Parse(brightness);
                        _videoPlayer.SetExposure(brightnessInt);
                    }
                    else
                    {
                        _videoPlayer.SetExposure(100.0f);
                    }

                    string volume;
                    if (scene.GetAttribute("GENERAL_SETTINGS_SOUND_VOLUME", out volume))
                    {
                        int volumeInt = Int32.Parse(volume);
                        _videoPlayer.SetVolume(volumeInt);
                    }
                    else
                    {
                        _videoPlayer.SetVolume(100.0f);
                    }
                }
                else // Failure, log a message
                {
                    Debug.LogWarning("Failed to get 'VIDEO_URL' attribute from scene node");
                }
            }
        }
        else if (message.Route == (int)MessageDestination.SIMULATION_PAUSE) // Pause Video
        {
            _videoPlayer.PauseVideo();
        }
        else if (message.Route == (int)MessageDestination.SIMULATION_RESUME) // Resume Video
        {
            _videoPlayer.ResumeVideo();
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Create the buttons which represent the choices of the specified decision
    /// </summary>
    /// <param name="decision"></param>
    private void CreateButtonsForDecision(SimulationScene scene)
    {
        // Get the routes
        scene.GetRoutes(decisionChoices);

        // Store all active buttons
        ClearActiveButtons();

        // Create UI choices
        foreach (int i in decisionChoices)
        {
            // Try to get the decision for the choice index
            SimulationScene iScene;
            if (scene.GetSceneFromRoute(i, out iScene))
            {
                string decisionText = "DEFAULT BUTTON\nTEST";// iScene.GetDisplayTitle();
                PlaceButton(i, decisionText);

                //// Try to get the current override title or if not, the next title.
                //string decisionText;
                //if(decision.GetAttribute("OVERRIDE_TITLE", out decisionText) || iDecision.GetAttribute("TITLE", out decisionText))
                //{
                //    PlaceButton(i, decisionText);
                //}
                //else // Failed to get title
                //{
                //    Debug.LogWarning("Failed to get title from decision with ID: " + i);
                //}
            }
            else // Failed to get decision
            {
                Debug.LogWarning("Failed to get decision from ID: " + i);
            }
        }
    }
Exemplo n.º 3
0
        /// <summary>
        /// You know what this does
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            SimulationScene scene = new SimulationScene();

            //Other thing
            Shader shader = new Shader(@"\resources\vertexShader.vs\", @"\resources\fragmentShader.frag");

            //Start game
            scene.Run();
        }
        /// <summary>
        /// Opens a new simulation scene if it is not already open and if any objects are using the simulation scene
        /// </summary>
        void OpenSimulation()
        {
            if (m_SimulationScene == null && UsingSimulation)
            {
                m_SimulationScene = new SimulationScene();
                EditorOnlyDelegates.GetSimulatedContentScene     = () => m_SimulationScene.contentScene;
                EditorOnlyDelegates.GetSimulatedEnvironmentScene = () => m_SimulationScene.environmentScene;

                if (SimulationSceneOpened != null)
                {
                    SimulationSceneOpened();
                }
            }
        }
        /// <summary>
        /// Closes the current simulation scene without changing if any objects are using the simulation scene
        /// </summary>
        public void CloseSimulation()
        {
            if (m_SimulationScene != null)
            {
                if (SimulationSceneClosing != null)
                {
                    SimulationSceneClosing();
                }

                m_SimulationScene.Dispose();
                m_SimulationScene = null;
            }

            EditorOnlyDelegates.GetSimulatedContentScene     = null;
            EditorOnlyDelegates.GetSimulatedEnvironmentScene = null;
        }
Exemplo n.º 6
0
    public override void OnReceivedMessage(Message message)
    {
        if (message.Route == (int)MessageDestination.SCENE_CHANGE)
        {
            if (message.Identifier == "VALID")
            {
                StopAllSources();
                SimulationScene scene = (SimulationScene)message.Data;

                string volumeStr; //filePath
                int    volume = 0;
                if (scene.GetAttribute("GENERAL_SETTINGS_ALARM_VOLUME", out volumeStr))
                {
                    volume = Int32.Parse(volumeStr);
                    if (volume <= 0)
                    {
                        return;
                    }
                }
                string filePath;
                if (scene.GetAttribute("GENERAL_SETTINGS_ALARM_FILE", out filePath))
                {
                    // Add a prefix to fix bad file names
                    string url        = Application.dataPath + @"/JsonScene/" + filePath;
                    string filePrefix = @"file://";
                    url = filePrefix + url;

                    Debug.Log(url);
                    AudioClip clip;
                    if (AudioLoader.LoadAudioClipBlocking(url, out clip))
                    {
                        PlayClip(Vector3.zero, clip, (float)volume / 100, true);
                    }
                    else
                    {
                        Debug.LogError("FAILED TO PLAY CLIP FROM URL " + url);
                    }
                }
            }
        }
    }
Exemplo n.º 7
0
    public void HitBall(int playerId, float angle, float forceFrac)
    {
        //if (playerId != CurrentPlayer) throw new ArgumentException($"Wrong player ID: {playerId}. Expected: {CurrentPlayer}");
        if (forceFrac < 0 || forceFrac > 1)
        {
            throw new ArgumentException($"Invalid force fraction value: {forceFrac}");
        }

        var ballBody = PlayerBalls[playerId].Body;
        var forceVec = Vector3.forward * (MaxStrokeForce * forceFrac);

        ballBody.AddForce(Quaternion.Euler(0, angle, 0) * forceVec, ForceMode.Impulse);
        var trajectory = new Trajectory(FrameDeltaTime);

        var physicsScene = SimulationScene.GetPhysicsScene();

        for (int nSteps = 0; !BallsStopped(); ++nSteps)
        {
            physicsScene.Simulate(FrameDeltaTime);
            trajectory.AddFrame(Frame.Extract(PlayerBalls));
            if (nSteps > 3000)
            {
                Debug.Log($"Ball0Position: {PlayerBalls[0].transform.position}, " +
                          $"Ball0Velocity: {PlayerBalls[0].Body.velocity}, " +
                          $"Ball0Sleeping: {PlayerBalls[0].Body.IsSleeping()}");
                Debug.Log($"Ball1Position: {PlayerBalls[1].transform.position}, " +
                          $"Ball1Velocity: {PlayerBalls[1].Body.velocity}, " +
                          $"Ball1Sleeping: {PlayerBalls[1].Body.IsSleeping()}");
                throw new ApplicationException("Simulation is too long.");
            }
        }

        Events.Enqueue(new Event.PlayTrajectory(trajectory, playerId));

        CurrentPlayer = (CurrentPlayer + 1) % NumberOfPlayers;
    }
    public override void OnReceivedMessage(Message message)
    {
        switch (message.Route)
        {
        case (int)MessageDestination.SIMULATION_PAUSE:
        {
            // Pause the timeline
            timeline.SetPauseState(true);
        }
        break;

        case (int)MessageDestination.SIMULATION_RESUME:
        {
            // Pause the timeline
            timeline.SetPauseState(false);
        }
        break;

        case (int)MessageDestination.SIMULATION_START:
        {
            //timeline.Reset();
        }
        break;

        case (int)MessageDestination.SIMULATION_END:
        {
            timeline.ResetTimeline();
        }
        break;

        case (int)MessageDestination.SCENE_CHANGE:     // A Scene change has occurred
        {
            if (message.Identifier == "VALID")
            {
                SimulationScene scene = (SimulationScene)message.Data;

                // Get the timeline actions and push them to the timeline
                List <ITimelineAction> actions = timeline.GetRawActions();
                scene.GetActions(actions);

                string durationStr;
                if (scene.GetAttribute("DURATION", out durationStr))
                {
                    float duration;
                    if (float.TryParse(durationStr, out duration))
                    {
                        timeline.StartTimeline(duration);
                    }
                    else
                    {
                        Debug.LogWarning("Failed to parse scene duration");
                    }
                }
                else
                {
                    Debug.LogWarning("Failed to get scene duration");
                }
            }
        }
        break;
        }
    }