Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //At present time, using a custom inspector GUI to save a list of classes that derives from a
- //Base class will cause every derived class to be casted to the base class on assembly reload.
- //This is a way to work around the force cast issue, by casting everything back on assembly reload.
- //Bunch of methods were removed to make this shorter. The info here should give the basic idea.
- [Serializable]
- class SBWrapper (MonoBehaviour):
- public sBs = List[of SpawnBehavior]()
- static def UnshaveType(sb as SpawnBehavior):
- if (sb.myType == "Arc"):
- return Arc(sb.amount, sb.angle)
- elif (sb.myType == "DisplaceForward"):
- return DisplaceForward(sb.distance)
- elif (sb.myType == "RandomDirection"):
- return RandomDirection(sb.amount, sb.angle)
- elif (sb.myType == "Wall"):
- return Wall(sb.amount, sb.width)
- else:
- Debug.Log("UnshavedType has encountered an unknown type")
- return SpawnBehavior()
- def Awake():
- for i in range(sBs.Count):
- sBs[i] = UnshaveType(sBs[i])
- ####################################################################################
- [Serializable]
- class SpawnBehavior:
- //Ignore is a custom class attribute that marks whether or not the variable should show up
- //in a custom inspector. The attribute takes in a Type as a parameter, marking an exception.
- //In other words, "amount" should show up when the inspector looks at an Arc() class.
- //Would use a list/array of types, but a boo compiler error prevents me from doing so.
- [Ignore(typeof(Arc))]
- [Ignore(typeof(RandomDirection))]
- [Ignore(typeof(Wall))]
- public amount as int
- [Ignore(typeof(Arc))]
- [Ignore(typeof(RandomDirection))]
- public angle as single
- [Ignore(typeof(DisplaceForward))]
- public distance as double
- [Ignore(typeof(Wall))]
- public width as double
- [Ignore]
- public myType = "SpawnBehavior"
- ####################################################################################
- [Serializable]
- class DisplaceForward (SpawnBehavior):
- def constructor():
- myType = "DisplaceForward"
- def constructor(d as double):
- myType = "DisplaceForward"
- distance = d
- ####################################################################################
- [Serializable]
- class RandomDirection (SpawnBehavior):
- def constructor():
- myType = "RandomDirection"
- def constructor(amt as int, ang as single):
- myType = "RandomDirection"
- amount = amt
- angle = ang
- ####################################################################################
- [Serializable]
- class Wall (SpawnBehavior):
- override def Behavior(pransforms as List[of Pransform]):
- ret = List[of Pransform]()
- for pransform in pransforms:
- proxy = pransform
- twidth = (amount - 1 cast double) * width
- proxy.pos += proxy.rot * Vector3(twidth / 2, 0, 0)
- ret.Add(proxy)
- for i in range(amount):
- ret.Add(proxy)
- proxy.pos -= proxy.rot * Vector3(width, 0, 0)
- ret.Add(proxy)
- return ret
- override def GetName():
- return " Wall"
- def constructor():
- myType = "Wall"
- def constructor(amt as int, w as double):
- myType = "Wall"
- amount = amt
- width = w
- ####################################################################################
- [CustomEditor(SBWrapper)]
- [CanEditMultipleObjects]
- class SBEGUI (Editor):
- sbtype as SBenum
- sbwrapper as SBWrapper
- def OnEnable():
- sbwrapper = (target as SBWrapper)
- for i in range(sbwrapper.sBs.Count):
- sbwrapper.sBs[i] = SBWrapper.UnshaveType(sbwrapper.sBs[i])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement