Are there any architecture which make game algorithm be independent of the unity engine and not monobaviour. I means thath I can run the code in C# project.
Sure, write any algorithm that does not use MonoBehaviors!
Do you have an actual problem you’re trying to solve or is this just academic word-noodling?
Why use Unity Engine if you don’t want to use Unity Engine?
First reason to come on mind is to use unity engine for presentation purposes, while game algorithm resides in cloud and written in different language. Why not?
Yes, you can make a separate DLL however you want and import it into your unity project.
You will probably want to make at least one monobehaviour script to act as a starting point and as the “glue” between your non-unity code and the unity presentation layer.
About half of my game’s code is just regular C# classes - most t of the important systems. I use classes derived from monobehaviour for things that need to be represented in the game world, or need to be driven by the game loop (Update, etc), but most everything else I don’t.
It’s a great way to learn seperation of concerns, especially for the case @palex-nx mentioned.
For instance, program Tetris and then try to make as few as possible adjustments to that code base when you turn it into a console application, a Unity application, or XNA… whatever.
Besides that, it is also pretty common in digitization of non-game applications, which may have primarily used WinForms, WPF, Xamarin Forms or any other framework for their presentation layer, and now attempt to make the switch to using some 3D engine.
You need at least one monobehaviour because that is the only entry point that you have in Unity’s run-time loop. You can create a single “master” monobehaviour that initializes all of your game data in the Start method and has all your main loop logic in the Update method. All of the other logic can go into non-monobehaviour classes.
For my last game, all my gameplay logic is in plain old C# with nothing Unity-specific, and I compile the exact same source code files into both the Unity game client and an ASP.NET Core web server that hosts online games. Avoids a lot of duplicated work.
All of the UI-related code uses UnityEngine stuff, though.