• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Thorium/Roll-a-ball-FSharp: Unity 3d game engine tutorial (in F#)

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

Thorium/Roll-a-ball-FSharp

开源软件地址:

https://github.com/Thorium/Roll-a-ball-FSharp

开源编程语言:

F# 100.0%

开源软件介绍:

Unity tutorial: Roll-a-ball F-Sharp

Unity is a multi-platform (3d) game engine. The basic version of Unity is free.

This repository is the first [tutorial from Unity] (http://unity3d.com/learn/tutorials/projects/roll-a-ball/).

The only difference is that F# programming language is used. No neat functional source code, just plain translation.

It seems that Unity doesn't lock the dlls, so you can build new versions on the fly and still Unity keeps bindings which is great.

You have two options, a) either start from scratch or b) run this solution.

How to make a similar solution from scratch

  • Install some version of Unity and a Visual Studio (or MonoDevelop Add-in F# language binding)
  • Create a new Unity project as usual (Instead of desktop I recommend to put the project something like c:\git\Roll-a-ball ) [http://unity3d.com/learn/tutorials/projects/roll-a-ball/set-up] (http://unity3d.com/learn/tutorials/projects/roll-a-ball/set-up) But before proceeding to the second video...
  • With Visual Studio (or MonoDevelop or your favourite editor...) create a new F#-library under your Unity's project path. Un-tick the "Create directory for solution" to save one directory. (I used c:\git\Roll-a-ball and created project called GameLogic.)
  • Add references to UnityEngine.dll (I did have it in C:\Program Files (x86)\Unity\Editor\Data\Managed\ )
  • From project properties, set the build "Output path" to some folder under Unity's Assets-folder, for example: ..\Assets\bin\
  • It seems that Unity 4.x still uses .NET 3.5 (or 2.0) so it is better to change the target framework to .NET 3.5. (I don't know what is the MonoBleedingEdge-folder under Unity, maybe they will update soon...)
  • If you want to be sure to use same components as Unity, replace also mscorlib.dll, System.dll, System.Core.dll from the ones that are found under Unity's folder structure (I have those in C:\Program Files (x86)\Unity\Editor\Data\Mono\lib\mono\2.0\ )
  • For FSharp.Core, the copy-local should be "true" as Unity doesn't have it. These other core-level dll's should have that "false".
  • Write some script, e.g. like this:

namespace RollABall
open UnityEngine

type PlayerController() =
    inherit MonoBehaviour()

    [<SerializeField>]
    let mutable speed = 6.0f

    member x.FixedUpdate () =
        let ``move horizontal`` = Input.GetAxis("Horizontal");
        let ``move vertical`` = Input.GetAxis("Vertical")

        let movement = Vector3(``move horizontal``, 0.0f, ``move vertical``)
        movement * speed * Time.deltaTime
        |> x.rigidbody.AddForce

  • Now, build in Visual Studio, then switch to Unity and open bin-folder from Assets. From Project-window, you should see your fsharp-dll and a little arrow on its right side to extend the details. When you press the arrow, you see the class(es) inside the component and you can directly drag and drop your class to your game object (like the ball in this tutorial).
  • Then just continue the tutorial, but instead of creating every snippet a C#-file, just code F#, build the solution (in VS) and Unity notices the new modifications on the fly.

How to get this repository code running

  • Install Unity (4.6.1-...)
  • Install Visual Studio 2015 (CTP)
  • Open and build GameLogic\GameLogic.sln with Visual Studio. (Leave VS open...)
  • Open project with Unity: Roll-a-ball-FSharp (Yes, the whole folder).
  • Open Scene: _Scenes\MiniGame.unity
  • For some reason Unity may have lost the references. So you have to map those once: from Hierarcy-tab select Player, then from Inspector-tab under Player Controller (Script) select the small circular button next to Script-textbox. A dialog opens then select PlayerController from the list. Do the same for (Hierarchy-tab again) Main Camera, associate it (from Inspector-tab again) to CameraController. Then from Project-tab under Assets go to Prefabs and select PickUp (Cube-icon). From the Inspector-tab select Rotator (Script) and assign it to Rotator. That's it.

Links




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
KogeLabs/Ockero: Ockero: Kotlin OpenGl Game Engine发布时间:2022-06-07
下一篇:
Ceffa/Ryno-Engine: C++ Game Engine发布时间:2022-06-07
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap