How to dynamically create an instance of the script,code in the plugin?

IApplicationShell.cs in OpenEngine.dll

using System;
using System.Text;
using System.Collections;

using UnityEngine;

namespace OpenEngine
{
    public abstract class IApplicationShell
    {

        public virtual void Start()
        {
        }

        public virtual void Awake()
        {

        }

        public virtual void Update()
        {
            //Debug.Log("IApplicationShell::Update()");
        }

        public virtual void OnGUI()
        {

        }

        public virtual void OnLevelWasLoaded(int level)
        {

        }
    }
}

ClientShell.cs in OpenEngine.dll

using System;
using System.Text;
using System.Collections;

using UnityEngine;

namespace OpenEngine.Game
{
    public class ClientShellApp : IApplicationShell
    {
        public override void Start()
        {
            base.Start();

            GameObject mainCamera = GameObject.FindWithTag("MainCamera");

            if (mainCamera)
                mainCamera.gameObject.AddComponent<FixedFollow3DCamera>();
        }

        public override void Awake()
        {
            base.Awake();
        }

        public override void Update()
        {
            //Debug.Log("ClientShell::Update()");
            base.Update();
        }

        public override void OnGUI()
        {
            base.OnGUI();
        }

        public override void OnLevelWasLoaded(int level)
        {
            base.OnLevelWasLoaded(level);
        }
    }
}

MyScript in Editor

using System;
using System.Text;
using disc1.XML;

using OpenEngine;
using UnityEditor;
using UnityEngine;

public class MyScript : MonoBehaviour
{
    public bool isEditor = false;

    private IApplicationShell iApplicationShell = null;

    void Start()
    {
        iApplicationShell.Start();
    }

    void Awake()
    {
        if (isEditor)
        {
            iApplicationShell = new OpenEngine.Editor.EditorShell();   
        }
        else
        {
            iApplicationShell = new OpenEngine.Game.ClientShellApp();
        }

        iApplicationShell.Awake();
    }

    void Update()
    {
        iApplicationShell.Update();
    }

    void OnGUI()
    {
        iApplicationShell.OnGUI();
    }

    void OnLevelWasLoaded(int level)
    {
        iApplicationShell.OnLevelWasLoaded(level);
    }
}

errorCan't add component because class 'FixedFollow3DCamera' doesn't exist!

Edit to cleanup answer to only be about compiled dll issues:

The problem is that AddComponent does a runtime reflection call to add your class, which means it won't be able to find it in your assembly

The solution to this is to make your class in the DLL a partial class, then add another partial class in the project with the same name, inheriting from monobehaviour

This should mean that it'll both compile the DLL and be able to work with AddComponent

Example using your code:

in the DLL:


using System;
using System.Text;
using System.Collections;
using UnityEngine;

namespace OpenEngine.Game
{
    public partial class FixedFollow3DCamera : MonoBehaviour
    {
        protected void Start()
        {
        }

        //other code here
    }
}

and in unity, FixedFollow3DCamera.cs:


namespace OpenEngine.Game
{
    public partial class FixedFollow3DCamera : MonoBehaviour
    {
    }
}