Search Unity

Why unity ebooks is often awful?

Discussion in 'General Discussion' started by mahdiii, Mar 17, 2018.

Thread Status:
Not open for further replies.
  1. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    856
    For example Unity in Action book is bullshit
    I do not know how it has been published
    It has abused a lot of things and is misleading

    In page 182, instead of using events, it has preferred to use foreach loop on manager interface!!
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. [RequireComponent(typeof(PlayerManager))]
    5. [RequireComponent(typeof(InventoryManager))]
    6. public class Managers : MonoBehaviour {
    7. public static PlayerManager Player {get; private set;}
    8. public static InventoryManager Inventory {get; private set;}
    9. private List<IGameManager> _startSequence;
    10. void Awake() {
    11. Player = GetComponent<PlayerManager>();
    12. Inventory = GetComponent<InventoryManager>();
    13. _startSequence = new List<IGameManager>();
    14. _startSequence.Add(Player);
    15. _startSequence.Add(Inventory);
    16. StartCoroutine(StartupManagers());
    17. }
    18. private IEnumerator StartupManagers() {
    19. foreach (IGameManager manager in _startSequence) {
    20. manager.Startup();
    21. }
    22. yield return null;
    23. int numModules = _startSequence.Count;
    24. int numReady = 0;
    25. while (numReady < numModules) {
    26. int lastReady = numReady;
    27. numReady = 0;
    28. foreach (IGameManager manager in _startSequence) {
    29. if (manager.status == ManagerStatus.Started) {
    30. numReady++;
    31. }
    32. }
    33. if (numReady > lastReady)
    34. Debug.Log("Progress: " + numReady + "/" + numModules);
    35. yield return null;
    36. }
    37. Debug.Log("All managers started up");
    38. }
    39. }

    In page 188, it uses OnGUI!!

    Code (CSharp):
    1. public class BasicUI : MonoBehaviour {
    2. void OnGUI() {
    3. int posX = 10;
    4. int posY = 10;
    5. int width = 100;
    6. int height = 30;
    7. int buffer = 10;
    8. List<string> itemList = Managers.Inventory.GetItemList();
    9. if (itemList.Count == 0) {
    10. GUI.Box(new Rect(posX, posY, width, height), "No Items");
    11. }
    12. foreach (string item in itemList) {
    13. int count = Managers.Inventory.GetItemCount(item);
    14. Texture2D image = Resources.Load<Texture2D>("Icons/"+item);
    15. GUI.Box(new Rect(posX, posY, width, height),
    16. new GUIContent("(" + count + ")", image));
    17. posX += width+buffer;
    18. }
    19. }
    20. }
    and blah blah
     
  2. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,157
    All ebooks are mostly awful.
     
  3. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    856
    I do not know why!!!
    Other software is not. Unity ebooks are so awful
    Instead of discussion about architecture and design correctly, they implement bullshit codes
    Physics.AddForce, raycast ,...
    I do not understand, they are books or a blog for a newbie student
     
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,192
    You'd have to ask @jhocking. He's the author.

    You're the first person I've heard say anything of the sort about this book.

    I know there are a number of people on these forums and elsewhere that will tell you that foreach is evil, that the performance is far inferior to the alternatives, and that the garbage generated by it will cause you all manner of problems but the reality is that it's perfectly fine if you use it appropriately.

    For the code snippet you posted he's only using it within Awake which means it's not happening every frame.

    OnGUI has perfectly valid uses. Just because we have newer alternatives doesn't mean it's no longer valid.

    Have you ever tried teaching a beginner? One important thing to remember is that it's very easy to overwhelm someone who has just started learning game development. Best practices are best left for after they're no longer completely new.

    Agreed, and I strongly suspect the bulk of them are generated rather than hand created.
     
    Amon, jhocking, mahdiii and 1 other person like this.
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Try emailing the author. It's not forum business.
     
    mahdiii likes this.
Thread Status:
Not open for further replies.