Note that there are some explanatory texts on larger screens.

plurals
  1. PO.net dynamic loading
    primarykey
    data
    text
    <p>I've seen some other responses about this and they talk about interfaces but I'm pretty sure you can do this with classes and base classes but I can't this to work.</p> <pre><code>Public Class Behavior Private _name As String Public ReadOnly Property Name As String Get Return _name End Get End Property Public Property EditorUpdate As Boolean Public Sub New(ByVal name As String) _name = name EditorUpdate = False End Sub Public Overridable Sub Update() End Sub ' runs right away in editor mode. also runs when in stand alone game mode right away Public Overridable Sub Start() End Sub ' runs after game mode is done and right before back in editor mode Public Overridable Sub Finish() End Sub ' runs right when put into game mode Public Overridable Sub Initialize() End Sub ' runs when the game is complete in stand alone mode to clean up Public Overridable Sub Destroy() End Sub </code></pre> <p>End Class</p> <pre><code>Public Class CharacterController Inherits Behavior.Behavior Public Sub New() MyBase.New("Character Controller") End Sub Public Overrides Sub Update() ' TODO: call UpdateController() ' THINK: how can UpdateController() get the controller entity it's attached to? ' Behaviors need a way to get the entity they are attached to. Have that set when it's assigned in the ctor? End Sub </code></pre> <p>End Class</p> <pre><code>Dim plugins() As String Dim asm As Assembly plugins = Directory.GetFileSystemEntries(Path.Combine(Application.StartupPath, "Plugins"), "*.dll") For i As Integer = 0 To plugins.Length - 1 asm = Assembly.LoadFrom(plugins(i)) For Each t As Type In asm.GetTypes If t.IsPublic Then If t.BaseType.Name = "Behavior" Then behaviorTypes.Add(t.Name, t) Dim b As Behavior.Behavior b = CType(Activator.CreateInstance(t), Behavior.Behavior) 'Dim o As Object = Activator.CreateInstance(t) End If End If Next Next </code></pre> <p>When it tries to convert whatever Activator.CreateInstance(t) returns to the base class of type Behavior I'm getting invalid cast exception. That type should be of CharacterController which is defined as a child of Behavior so why wouldn't it let me cast that? I've done something like this before but I can't find my code. What am I missing?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload