Search Unity

WarpedUtillities, a free map loader.

Discussion in 'Works In Progress - Archive' started by TylerPerry, May 18, 2012.

  1. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    For my game "WarpedRealms" Ive been making a map loader, i call it WarpedUtillites, basically it can can populate a scene with stuff. I think maybe some people may find it useful :)

    This is how it works:

    1: make a map in a text asset(i use a text file) these can use any of these symbols(for terrain): 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E
    and for the trees it only currently only uses " " and "0" But it is simple to add other symbols just by copying sections of code and pasting it.

    2.Set up the variables, these are just corresponding so the variable "TerrainItem0" are corresponding so a 0 will make the "TerrainItem0" these must be sized x=0.5, y can be anything but z must = 0.5(this can be changed but it is easier to just leave it), the other ones are self explanatory, except "level" is for multilevel terrains, this is achieved by making one map that doesn't have the second level then making another map that doesn't include the first layer, then change the level to how high along the y axis you want it and instantiate the terrain.

    3. That's it just hit terrain, or trees and you are good to go it will instantiate the terrain/trees.

    This is it(just add it to a UnityScript file and place it in a folder in your project called "editor"):
    Code (csharp):
    1.  
    2. class WarpedUtillities extends EditorWindow
    3. {
    4.     public var TerrainMAP   : TextAsset ;
    5.     public var FlowersMAP   : TextAsset ;
    6.     public var TreesMAP     : TextAsset ;
    7.     public var Level        : float     ;
    8.     public var TerrainItem0 :  Transform;
    9.     public var TerrainItem1 :  Transform;
    10.     public var TerrainItem2 :  Transform;
    11.     public var TerrainItem3 :  Transform;
    12.     public var TerrainItem4 :  Transform;
    13.     public var TerrainItem5 :  Transform;
    14.     public var TerrainItem6 :  Transform;
    15.     public var TerrainItem7 :  Transform;
    16.     public var TerrainItem8 :  Transform;
    17.     public var TerrainItem9 :  Transform;
    18.     public var TerrainItemA :  Transform;
    19.     public var TerrainItemB :  Transform;
    20.     public var TerrainItemC :  Transform;
    21.     public var TerrainItemD :  Transform;
    22.     public var Tree0        :  Transform;
    23.     public var FlowerItem0 :  Transform;
    24.     public var FlowerItem1 :  Transform;
    25.     public var FlowerItem2 :  Transform;
    26.     public var FlowerItem3 :  Transform;
    27.     public var FlowerItem4 :  Transform;
    28.     public var FlowerItem5 :  Transform;
    29.     public var FlowerItem6 :  Transform;
    30.     public var FlowerItem7 :  Transform;
    31.     public var FlowerItem8 :  Transform;
    32.     public var FlowerItem9 :  Transform;
    33.    
    34.     private var delimiters = new String[1];
    35.     private var TerrainLineNum : int;
    36.     private var TreeLineNum : int;
    37.     private var  TerrainLines : String[];
    38.     private var  TreeLines : String[];
    39.     private var TreeLOCATEX = 0.0;
    40.     private var TreeLOCATEZ = 0.0;
    41.     private var TerrainLOCATEX = 0.0;
    42.     private var TerrainLOCATEZ = 0.0;
    43.    
    44.         @MenuItem ("Window/WarpedUtilities")
    45.        
    46.     static function Init ()
    47.     {        
    48.         var window = ScriptableObject.CreateInstance.<WarpedUtillities>();
    49.         window.Show();
    50.     }
    51.    
    52.     function OnGUI ()
    53.     {  
    54.        
    55.         GUILayout.Label ("Instantiate:", EditorStyles.boldLabel);
    56.  
    57.        
    58.         TerrainMAP =   EditorGUI.ObjectField(Rect(3,20,position.width - position.width/2, 20), "Terrain", TerrainMAP, TextAsset);
    59.         FlowersMAP =   EditorGUI.ObjectField(Rect(3,40,position.width - position.width/2, 20), "Flowers", FlowersMAP, TextAsset);
    60.         TreesMAP   =   EditorGUI.ObjectField(Rect(3,60,position.width - position.width/2, 20), "Trees", TreesMAP, TextAsset);
    61.        
    62.         Level   =   EditorGUI.FloatField(Rect(position.width - position.width/2,40,position.width - position.width/2, 20), "Level", Level);
    63.        
    64.        
    65.         TerrainItem0   =   EditorGUI.ObjectField(Rect(3,80,position.width - position.width/2, 20), "TerrainItem0", TerrainItem0, Transform);
    66.         TerrainItem1   =   EditorGUI.ObjectField(Rect(3,100,position.width - position.width/2, 20), "TerrainItem1", TerrainItem1, Transform);
    67.         TerrainItem2   =   EditorGUI.ObjectField(Rect(3,120,position.width - position.width/2, 20), "TerrainItem2", TerrainItem2, Transform);
    68.         TerrainItem3   =   EditorGUI.ObjectField(Rect(3,140,position.width - position.width/2, 20), "TerrainItem3", TerrainItem3, Transform);
    69.         TerrainItem4   =   EditorGUI.ObjectField(Rect(3,160,position.width - position.width/2, 20), "TerrainItem4", TerrainItem4, Transform);
    70.         TerrainItem5   =   EditorGUI.ObjectField(Rect(3,180,position.width - position.width/2, 20), "TerrainItem5", TerrainItem5, Transform);
    71.         TerrainItem6   =   EditorGUI.ObjectField(Rect(3,200,position.width - position.width/2, 20), "TerrainItem6", TerrainItem6, Transform);
    72.         TerrainItem7   =   EditorGUI.ObjectField(Rect(3,220,position.width - position.width/2, 20), "TerrainItem7", TerrainItem7, Transform);
    73.         TerrainItem8   =   EditorGUI.ObjectField(Rect(3,240,position.width - position.width/2, 20), "TerrainItem8", TerrainItem8, Transform);
    74.         TerrainItem9   =   EditorGUI.ObjectField(Rect(3,260,position.width - position.width/2, 20), "TerrainItem9", TerrainItem9, Transform);
    75.         TerrainItemA   =   EditorGUI.ObjectField(Rect(3,280,position.width - position.width/2, 20), "TerrainItemA", TerrainItemA, Transform);
    76.         TerrainItemB   =   EditorGUI.ObjectField(Rect(3,300,position.width - position.width/2, 20), "TerrainItemB", TerrainItemB, Transform);
    77.         TerrainItemC   =   EditorGUI.ObjectField(Rect(3,320,position.width - position.width/2, 20), "TerrainItemC", TerrainItemC, Transform);
    78.         TerrainItemD   =   EditorGUI.ObjectField(Rect(3,340,position.width - position.width/2, 20), "TerrainItemD", TerrainItemD, Transform);
    79.        
    80.         Tree0   =   EditorGUI.ObjectField(Rect(position.width - position.width/2,20,position.width - position.width/2, 20), "Tree0", Tree0, Transform);
    81.  
    82.        
    83.         FlowerItem0   =   EditorGUI.ObjectField(Rect(position.width - position.width/2,80,position.width - position.width/2, 20), "FlowerItem0", FlowerItem0, Transform);
    84.         FlowerItem1   =   EditorGUI.ObjectField(Rect(position.width - position.width/2,100,position.width - position.width/2, 20), "FlowerItem1", FlowerItem1, Transform);
    85.         FlowerItem2   =   EditorGUI.ObjectField(Rect(position.width - position.width/2,120,position.width - position.width/2, 20), "FlowerItem2", FlowerItem2, Transform);
    86.         FlowerItem3   =   EditorGUI.ObjectField(Rect(position.width - position.width/2,140,position.width - position.width/2, 20), "FlowerItem3", FlowerItem3, Transform);
    87.         FlowerItem4   =   EditorGUI.ObjectField(Rect(position.width - position.width/2,160,position.width - position.width/2, 20), "FlowerItem4", FlowerItem4, Transform);
    88.         FlowerItem5   =   EditorGUI.ObjectField(Rect(position.width - position.width/2,180,position.width - position.width/2, 20), "FlowerItem5", FlowerItem5, Transform);
    89.         FlowerItem6   =   EditorGUI.ObjectField(Rect(position.width - position.width/2,200,position.width - position.width/2, 20), "FlowerItem6", FlowerItem6, Transform);
    90.         FlowerItem7   =   EditorGUI.ObjectField(Rect(position.width - position.width/2,220,position.width - position.width/2, 20), "FlowerItem7", FlowerItem7, Transform);
    91.         FlowerItem8   =   EditorGUI.ObjectField(Rect(position.width - position.width/2,240,position.width - position.width/2, 20), "FlowerItem8", FlowerItem8, Transform);
    92.         FlowerItem9   =   EditorGUI.ObjectField(Rect(position.width - position.width/2,260,position.width - position.width/2, 20), "FlowerItem9", FlowerItem9, Transform);
    93.  
    94.         if (GUI.Button(Rect(10,500,50,20),"Terrain"))
    95.         {
    96.         TerrainLineNum = 0;
    97.         TerrainLOCATEX = 0;
    98.         TerrainLOCATEZ = 0;
    99.         delimiters[0] = "<>";
    100.         TerrainLines = TerrainMAP.text.Split(delimiters, System.StringSplitOptions.None);
    101.         InstantiateTERRAIN ();
    102.         }
    103.        
    104.         if (GUI.Button(Rect(70,500,50,20),"Trees"))
    105.         {
    106.         TreeLineNum = 0;
    107.         TreeLOCATEX = 0;
    108.         TreeLOCATEZ = 0;
    109.         delimiters[0] = "<>";
    110.         TreeLines = TreesMAP.text.Split(delimiters, System.StringSplitOptions.None);
    111.         InstantiateTREES ();
    112.         }
    113.     }
    114.    
    115.    
    116.    
    117.    function InstantiateTERRAIN ()
    118.     {
    119.      for (var Character in TerrainLines[TerrainLineNum])
    120.      {
    121.      switch (Character)
    122.      {
    123.      case ("0"):
    124.      Debug.Log ("ZERO");
    125.      Instantiate (TerrainItem0, Vector3(TerrainLOCATEX, Level, TerrainLOCATEZ), Quaternion.identity);
    126.      TerrainLOCATEX += 0.5;
    127.      Debug.Log ("Works");
    128.      break;
    129.      case ("1"):
    130.      Instantiate (TerrainItem1, Vector3(TerrainLOCATEX, Level, TerrainLOCATEZ), Quaternion.identity);
    131.      TerrainLOCATEX += 0.5;
    132.      break;
    133.           case ("2"):
    134.      Instantiate (TerrainItem2, Vector3(TerrainLOCATEX, Level, TerrainLOCATEZ), Quaternion.identity);
    135.      TerrainLOCATEX += 0.5;
    136.      break;
    137.           case ("3"):
    138.      Instantiate (TerrainItem3, Vector3(TerrainLOCATEX, Level, TerrainLOCATEZ), Quaternion.identity);
    139.      TerrainLOCATEX += 0.5;
    140.      break;
    141.           case ("4"):
    142.      Instantiate (TerrainItem4, Vector3(TerrainLOCATEX, Level, TerrainLOCATEZ), Quaternion.identity);
    143.      TerrainLOCATEX += 0.5;
    144.      break;
    145.                case ("5"):
    146.      Instantiate (TerrainItem5, Vector3(TerrainLOCATEX, Level, TerrainLOCATEZ), Quaternion.identity);
    147.      TerrainLOCATEX += 0.5;
    148.      break;
    149.                case ("6"):
    150.      Instantiate (TerrainItem6, Vector3(TerrainLOCATEX, Level, TerrainLOCATEZ), Quaternion.identity);
    151.      TerrainLOCATEX += 0.5;
    152.      break;
    153.                case ("7"):
    154.      Instantiate (TerrainItem7, Vector3(TerrainLOCATEX, Level, TerrainLOCATEZ), Quaternion.identity);
    155.      TerrainLOCATEX += 0.5;
    156.      break;
    157.                case ("8"):
    158.      Instantiate (TerrainItem8, Vector3(TerrainLOCATEX, Level, TerrainLOCATEZ), Quaternion.identity);
    159.      TerrainLOCATEX += 0.5;
    160.      break;
    161.                case ("9"):
    162.      Instantiate (TerrainItem9, Vector3(TerrainLOCATEX, Level, TerrainLOCATEZ), Quaternion.identity);
    163.      TerrainLOCATEX += 0.5;
    164.      break;
    165.                     case ("A"):
    166.      Instantiate (TerrainItemA, Vector3(TerrainLOCATEX, Level, TerrainLOCATEZ), Quaternion.identity);
    167.      TerrainLOCATEX += 0.5;
    168.      break;
    169.                          case ("B"):
    170.      Instantiate (TerrainItemB, Vector3(TerrainLOCATEX, Level, TerrainLOCATEZ), Quaternion.identity);
    171.      TerrainLOCATEX += 0.5;
    172.      break;
    173.                          case ("C"):
    174.      Instantiate (TerrainItemC, Vector3(TerrainLOCATEX, Level, TerrainLOCATEZ), Quaternion.identity);
    175.      TerrainLOCATEX += 0.5;
    176.      break;
    177.                          case ("D"):
    178.      Instantiate (TerrainItemD, Vector3(TerrainLOCATEX, Level, TerrainLOCATEZ), Quaternion.identity);
    179.      TerrainLOCATEX += 0.5;
    180.      break;
    181.      }
    182.     }
    183.     if (TerrainLineNum <= TerrainLines.Length -1)
    184.     {
    185.     TerrainLOCATEX = 0;
    186.     TerrainLOCATEZ += 0.5;
    187.     TerrainLineNum += 1;
    188.     InstantiateTERRAIN ();
    189.     }
    190.    }
    191.    
    192.    
    193.       function InstantiateTREES ()
    194.    {
    195.      for (var Character2 in TreeLines[TreeLineNum])
    196.      {
    197.      switch (Character2)
    198.      {
    199.      case ("0"):
    200.      Instantiate (Tree0, Vector3(TreeLOCATEX, Level, TreeLOCATEZ), Quaternion.identity);
    201.      TreeLOCATEX += 0.5;
    202.      break;
    203.      case (" "):
    204.      TreeLOCATEX += 0.5;
    205.      break;
    206.     }
    207.     }
    208.     if (TreeLineNum <= TreeLines.Length)
    209.     {
    210.     TreeLOCATEX = 0;
    211.     TreeLOCATEZ += 0.5;
    212.     TreeLineNum += 1;
    213.     InstantiateTREES ();
    214.     }
    215.    }
    216. }
    217.  
    IF YOU USE IT:
    this is free to use for anything you want, commercial non commercial, if you make $100 or if you make $100000000 but if you modify it you must post your upgraded script as a reply to this thread, of course I'm not going to hunt you down if you dont but still just be nice :D


    Please note: I'm not interested in people telling me how ineffective my code is, this isn't a problem as it just loads and doesn't stay in the game or anything, but if you have an urge to fix things feel free :
     
  2. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    This is the kind of results it can give(will edit post):
    With a tree map of this:
    Code (csharp):
    1. 0000000000000000000000000000000000000<>
    2. 000000000000000 000000000000000000000<>
    3. 000000000000000 000000000000000000000<>
    4. 00000000   0000 000000000000000000000<>
    5. 00000000        000000000000000000000<>
    6. 00000000   0000 000000000000000000000<>
    7. 000000000000000 000000000000000000000<>
    8. 000000000000000 000000000000000000000<>
    9. 0000000000000000000000000000000000000<>
    10. 0000000000000000000000000000000000000<>
    11. 0000000000000000000000000000000000000<>
    And a terrain map of this:
    Code (csharp):
    1. 0000000000000084900000000000000000000<>
    2. 0000000000000021300000000000000000000<>
    3. 0000000844490021300000000000000000000<>
    4. 00000002111D44C1300000000000000000000<>
    5. 0000000211111111300000000000000000000<>
    6. 00000002111B55A1300000000000000000000<>
    7. 0000000755560021300000000000000000000<>
    8. 0000000000000021300000000000000000000<>
    9. 0000000000000075600000000000000000000<>
    10. 0000000000000000000000000000000000000<>
    11. 0000000000000000000000000000000000000<>
    With results of this:
     
    Last edited: May 18, 2012
  3. ivanzu

    ivanzu

    Joined:
    Nov 25, 2010
    Posts:
    2,065
    That is one interesting level generator.