Beispiel #1
0
 private void Update()
 {
     if (DoVisualize)
     {
         DPhysicsManager.Visualize();
     }
 }
Beispiel #2
0
    void OnGUI()
    {
        //GUI stuff :P
        if (!Started)
        {
            GUILayout.Label("Rows: ");
            int tempRows;
            if (int.TryParse(GUILayout.TextField(Rows.ToString()), out tempRows))
            {
                Rows = tempRows;
            }

            GUILayout.Label("Columns: ");
            int tempColumns;
            if (int.TryParse(GUILayout.TextField(Columns.ToString()), out tempColumns))
            {
                Columns = tempColumns;
            }
            GUILayout.Label("Speed: ");
            double tempSpeed;
            if (double.TryParse(GUILayout.TextField(Speed.ToString()), out tempSpeed))
            {
                Speed = tempSpeed;
            }
            if (GUILayout.Button("Start!"))
            {
                Started = true;
                Starter(Rows, Columns, Speed);
            }
        }
        else
        {
            if (GUILayout.Button("Clear"))
            {
                //This dessimilate and destroys all existing physics objects.
                //While dessimilation is optional, it significantly improves performance when there are many objects.
                for (int i = 0; i < DPhysicsManager.SimObjects.Length; i++)
                {
                    Body body = DPhysicsManager.SimObjects[i];
                    if (body == null)
                    {
                        continue;
                    }
                    DPhysicsManager.Dessimilate(body);
                    Destroy(body.gameObject);
                }
                Started = false;
            }
        }
        //Camera stuff
        GUILayout.Label("Camera Height");
        camHeight = GUILayout.VerticalSlider(camHeight, 100, 10);
        Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, camHeight, Camera.main.transform.position.z);
    }
Beispiel #3
0
    private void FixedUpdate()
    {
        DarkRiftAPI.Recieve();
        //Adjust the simulation rate based on how many frames in advance we have
        //This prevents lag stutters and promotes responsiveness
        //If we have 0 frames ahead, we cannot go ahead (hence the if statement)
        //ForeSight代表还有多少数据帧没有被执行
        if (ForeSight > 0)
        {
            float NewSimRate = (TargetSimulationRate * 1.1f) - (ForeSight * TargetSimulationRate * .1f);
            if (NewSimRate < TargetSimulationRate / 2)            //相当于数据帧缓存超过6那么就加速一倍执行fixedupdate
            {
                NewSimRate  = TargetSimulationRate / 2;
                DoVisualize = false;
            }
            else
            {
                DoVisualize = true;
            }
            Time.fixedDeltaTime = NewSimRate;
            ForeSight--;

            //Get our current frame
            Frame CurrentFrame = Frames [_StepCount];
            //Get the commands of our current frame and execute them
            List <Command> CurrentCommands = Command.Deserialize(CurrentFrame._Data);
            foreach (Command com in CurrentCommands)
            {
                //Executes the command...
                //Explore to TestCommands.cs to find the game logic behind commands
                TestCommands.Execute(com);
            }

            //Spawns a few objects in the beginning
            if (_StepCount == 0)
            {
                TestSpawn();
            }

            //Simulate the physics
            DPhysicsManager.Simulate();

            //Increase our step and advance forward in time
            _StepCount++;
        }
    }
 void Update()
 {
     //This call will communicate with Unity's rendering and transform components
     //This is optional and does not affect the simulation
     DPhysicsManager.Visualize();
 }
 void FixedUpdate()
 {
     //Remember to simulate DPhysics with this call
     DPhysicsManager.Simulate();
 }
Beispiel #6
0
 void Update()
 {
     //This call will communicate with Unity's rendering and transform components
     DPhysicsManager.Visualize();
 }