Advertisement
D8ms

Untitled

Nov 19th, 2012
582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
BOO 3.47 KB | None | 0 0
  1. //At present time, using a custom inspector GUI to save a list of classes that derives from a
  2. //Base class will cause every derived class to be casted to the base class on assembly reload.
  3. //This is a way to work around the force cast issue, by casting everything back on assembly reload.
  4. //Bunch of methods were removed to make this shorter. The info here should give the basic idea.
  5.  
  6. [Serializable]
  7. class SBWrapper (MonoBehaviour):
  8.     public sBs = List[of SpawnBehavior]()
  9.  
  10.     static def UnshaveType(sb as SpawnBehavior):
  11.         if (sb.myType == "Arc"):
  12.             return Arc(sb.amount, sb.angle)
  13.         elif (sb.myType == "DisplaceForward"):
  14.             return DisplaceForward(sb.distance)
  15.         elif (sb.myType == "RandomDirection"):
  16.             return RandomDirection(sb.amount, sb.angle)
  17.         elif (sb.myType == "Wall"):
  18.             return Wall(sb.amount, sb.width)
  19.         else:
  20.             Debug.Log("UnshavedType has encountered an unknown type")
  21.             return SpawnBehavior()
  22.  
  23.     def Awake():
  24.         for i in range(sBs.Count):
  25.             sBs[i] = UnshaveType(sBs[i])
  26.  
  27. ####################################################################################
  28.  
  29. [Serializable]
  30. class SpawnBehavior:
  31.  
  32.     //Ignore is a custom class attribute that marks whether or not the variable should show up
  33.     //in a custom inspector. The attribute takes in a Type as a parameter, marking an exception.
  34.     //In other words, "amount" should show up when the inspector looks at an Arc() class.
  35.     //Would use a list/array of types, but a boo compiler error prevents me from doing so.
  36.  
  37.     [Ignore(typeof(Arc))]
  38.     [Ignore(typeof(RandomDirection))]
  39.     [Ignore(typeof(Wall))]
  40.     public amount as int
  41.     [Ignore(typeof(Arc))]
  42.     [Ignore(typeof(RandomDirection))]
  43.     public angle as single
  44.     [Ignore(typeof(DisplaceForward))]
  45.     public distance as double
  46.     [Ignore(typeof(Wall))]
  47.     public width as double
  48.     [Ignore]
  49.     public myType = "SpawnBehavior"
  50.  
  51.  
  52. ####################################################################################
  53.  
  54. [Serializable]
  55. class DisplaceForward (SpawnBehavior):
  56.     def constructor():
  57.         myType = "DisplaceForward"
  58.        
  59.     def constructor(d as double):
  60.         myType = "DisplaceForward"
  61.         distance = d
  62.  
  63. ####################################################################################
  64.  
  65. [Serializable]
  66. class RandomDirection (SpawnBehavior):
  67.  
  68.     def constructor():
  69.         myType = "RandomDirection"
  70.    
  71.     def constructor(amt as int, ang as single):
  72.         myType = "RandomDirection"
  73.         amount = amt
  74.         angle = ang
  75.  
  76. ####################################################################################
  77.  
  78. [Serializable]
  79. class Wall (SpawnBehavior):
  80.  
  81.     override def Behavior(pransforms as List[of Pransform]):
  82.         ret = List[of Pransform]()
  83.         for pransform in pransforms:
  84.             proxy = pransform
  85.             twidth = (amount - 1 cast double) * width
  86.             proxy.pos +=  proxy.rot * Vector3(twidth / 2, 0, 0)
  87.             ret.Add(proxy)
  88.             for i in range(amount):
  89.                 ret.Add(proxy)
  90.                 proxy.pos -= proxy.rot * Vector3(width, 0, 0)
  91.                 ret.Add(proxy)
  92.         return ret
  93.        
  94.     override def GetName():
  95.         return "                            Wall"
  96.  
  97.     def constructor():
  98.         myType = "Wall"
  99.        
  100.     def constructor(amt as int, w as double):
  101.         myType = "Wall"
  102.         amount = amt
  103.         width = w
  104.  
  105. ####################################################################################
  106.  
  107. [CustomEditor(SBWrapper)]
  108. [CanEditMultipleObjects]
  109. class SBEGUI (Editor):
  110.     sbtype as SBenum
  111.     sbwrapper as SBWrapper
  112.  
  113.     def OnEnable():
  114.         sbwrapper = (target as SBWrapper)
  115.         for i in range(sbwrapper.sBs.Count):
  116.             sbwrapper.sBs[i] = SBWrapper.UnshaveType(sbwrapper.sBs[i])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement