[1Ed] Prototype 5: Bartok

This chapter differs somewhat from the other prototypes because instead of creating an entirely new project, this one shows you how you can build a different game on top of the prototype projects that you’ve developed while reading this book.

Before starting this project, you should have first completed Chapter 31, “Prototype 4: Prospector Solitaire” so that you understand the inner workings of the card game framework developed in that chapter.

Bartok is the game you first encountered in Chapter 1 , “Thinking Like a Designer.” Now you’ll build it yourself.

Errata

  • p. 653 – See note below about changes to GUIText in Unity 4.6.
  • There is an overload of the Bezier() function missing from code missing from the version of Utils you used in Prospector that is needed for Bartok. Please add the following code after line 328 of Utils.cs

    // The same two functions for Quaternion
    static public Quaternion Bezier( float u, List<Quaternion> vList ) {
        // If there is only one element in vList, return it
        if (vList.Count == 1) {
            return( vList[0] );
        }
        // Otherwise, create vListR, which is all but the 0th element of vList
        // e.g. if vList = [0,1,2,3,4] then vListR = [1,2,3,4]
        List<Quaternion> vListR =  vList.GetRange(1, vList.Count-1);
        // And create vListL, which is all but the last element of vList
        // e.g. if vList = [0,1,2,3,4] then vListL = [0,1,2,3]
        List<Quaternion> vListL = vList.GetRange(0, vList.Count-1);
        // The result is the Slerp of these two shorter Lists
        // It's possible that Quaternion.Slerp may clamp u to [0..1] :(
        Quaternion res = Quaternion.Slerp(Bezier(u,vListL), Bezier(u,vListR), u);
        return( res );
    }
    
    // This version allows an Array or a series of Quaternions as input
    static public Quaternion Bezier( float u, params Quaternion[] vecs ) {
    	return( Bezier( u, new List<Quaternion>(vecs) ) );
    }

    Alternatively, you can replace your Utils.cs file from the Prospector build with the one below.

Unity 4.6 and Unity 5.x Update Deprecating GUIText

With the release of Unity 4.6 came major changes to the GUI (Graphical User Interface) within Unity. This process has continued, and now in Unity 5.4, they have completely deprecated the use of the old immediate mode GUI system. Now, I recommend using the much more robust UGUI (Unity Graphical User Interface) system and have described how to incorporate it into the projects in the first edition of the book here.

Unity 5 Update

Unity made a few changes to their C# code for Unity 5. The PDF below contains full code listings for the Bartok.cs and Utils.cs code files, which each require small changes due to Unity 5. These few changes are all highlighted in yellow in the code listings.

pdf-128C32–Bartok–U5_Code_Changes.pdf

Replacement Utils.cs File

unitypackage_iconUtils_cs – This file is named Utils_cs.txt. Rename it to Utils.cs and use it to replace the Utils.cs file from the Prospector game in order to make Bartok.