Skip to content

OpenGolfSim/ogs-unity-developer-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is the experimental OpenGolfSim SDK for Unity, to allow building your own full games that run within the OpenGolfSim desktop platform. It contains open source versions of our core golf physics and IPC communication with the parent OGS process over stdio.

Usage

We also have a more complete example project that shows how to integrate with the SDK, but the basic usage is fairly simple:

public class MyCoolGame : MonoBehaviour
{
  // Create and connect a golf ball sized sphere with a rigid body...
  public GameObject golfBall;
  private Queue<ShotData> shotQueue = new Queue<ShotData>();
  private IpcServer ipc;
  private BallPhysics ballPhysics;

  // ...
  void Start()
  {
    ballPhysics = golfBall.GetComponent<BallPhysics>();
    if (ballPhysics == null) {
      ballPhysics = golfBall.AddComponent<BallPhysics>();
    }
    // Setup IPC with OpenGolfSim
    ipc = gameObject.AddComponent<IpcServer>();
    ipc.setupCallback += SetupGame;
    ipc.shotCallback += EnqueueShot;
  }

  void SetupGame(SetupData setupData)
  {
    // setup players, clubs, etc.
  }

  public void EnqueueShot(ShotData shot)
  {
    Debug.Log($"Received shot: {shot}");
    lock (shotQueue)
    {
      shotQueue.Enqueue(shot);
    }
  }

  void Update()
  {
   
    // receive shots from shot queue
    lock (shotQueue)
    {
        while (shotQueue.Count > 0)
        {
            ShotData shot = shotQueue.Dequeue();
            // Now it's safe to use Unity APIs!
            Debug.Log($"Received a shot in the queue ballSpeed={shot.ballSpeed}");
            bool isPutt = false;

            ballPhysics.LaunchShot(shot, isPutt);
        }
    }
  }


}

About

A Unity SDK for OpenGolfSim core physics and send and communicate with OGS over stdio.

Resources

License

GPL-3.0, Unknown licenses found

Licenses found

GPL-3.0
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages