Mod.Init C# (CSharp) Метод

Init() публичный Метод

public Init ( ) : bool
Результат bool
    public bool Init()
    {
        if (Inited)
            return true;

        if (JSONSource == null)
        {
            Debug.Log("JSONSource is invalid, returning");

            return false;
        }

        JSONObject Object = JSONObject.Create(JSONSource);

        JSONObject Value = Object.GetField("Name");

        if(Value != null && Value.type == JSONObject.Type.STRING)
        {
            Name = Value.str;
        }

        Value = Object.GetField("Description");

        if (Value != null && Value.type == JSONObject.Type.STRING)
        {
            Description = Value.str;
        }

        Value = Object.GetField("Dependencies");

        if(Value != null && Value.type == JSONObject.Type.STRING)
        {
            Dependencies.AddRange(Value.str.Split("|".ToArray()));
        }

        foreach(string Dependency in Dependencies)
        {
            if(!ModManager.Instance.LoadMod(Dependency))
            {
                Debug.Log("Unable to load Mod Bundle '" + Name + "': Unable to load dependency '" + Dependency + "'");

                return false;
            }
        }

        try
        {
            string AssemblyPath = Path + "/" + Name + ".dll";

        #if MODMANAGER_COMPILES_MODS
            DirectoryInfo SourceDirectory = new DirectoryInfo(Path + "/Scripts/");

            if (SourceDirectory != null && SourceDirectory.Exists)
            {
                List<string> SourceFiles = new List<string>();

                Array.ForEach(SourceDirectory.GetFiles("*.cs", SearchOption.AllDirectories), (FileInfo File) =>
                {
                    SourceFiles.Add(File.FullName);
                });

                string DataPath = Application.dataPath;

        #if UNITY_EDITOR
                DataPath = Application.dataPath + "/../" + Application.productName + "_Data/";
        #endif

                StringBuilder Parameters = new StringBuilder();

                Parameters.Append("-target:library -out:\"" + AssemblyPath + "\"");

                Parameters.Append(" -r:\"" + Application.dataPath + "/../Library/ScriptAssemblies/Assembly-CSharp.dll" + "\"");
                Parameters.Append(" -r:\"" + DataPath + "/Managed/UnityEngine.dll" + "\"");
                Parameters.Append(" -r:\"" + DataPath + "/Managed/UnityEngine.UI.dll" + "\"");

                foreach (string Dependency in Dependencies)
                {
                    Parameters.Append(" -r:\"" + Dependency + "\"");
                }

                foreach(string SourceFile in SourceFiles)
                {
                    Parameters.Append(" \"" + SourceFile + "\"");
                }

                string GMCSFileName = Application.dataPath + "/../Mono/bin/gmcs";

                if(Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer)
                {
                    GMCSFileName += ".bat";
                }

                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo()
                {
                    WorkingDirectory = Environment.CurrentDirectory,
                    FileName = GMCSFileName,
                    Arguments = Parameters.ToString(),
                    UseShellExecute = false,
                    RedirectStandardError = true,
                    RedirectStandardOutput = true,
                    CreateNoWindow = true
                };

                try
                {
                    System.Diagnostics.Process process = System.Diagnostics.Process.Start(startInfo);
                    process.WaitForExit();

                    if (!process.StandardError.EndOfStream)
                    {
                        Debug.Log("Unable to compile Mod Bundle '" + Name + "': " + process.StandardError.ReadToEnd());

                        return false;
                    }

                    if (!process.StandardOutput.EndOfStream)
                    {
                        Debug.Log(process.StandardOutput.ReadToEnd());
                    }
                }
                catch (Exception e)
                {
                    Debug.Log("Unable to compile Mod Bundle '" + Name + "'" + e);

                    return false;
                }
            }
        #endif

            FileInfo AssemblyFileInfo = new FileInfo(AssemblyPath);

            if(AssemblyFileInfo.Exists)
            {
                FileStream AssemblyStream = AssemblyFileInfo.OpenRead();

                BinaryReader Reader = new BinaryReader(AssemblyStream);

                byte[] Content = Reader.ReadBytes((int)Reader.BaseStream.Length);

                ScriptAssembly = Assembly.Load(Content);

                if (ScriptAssembly == null)
                {
                    Debug.Log("Unable to load assembly '" + AssemblyPath + "'");

                    return false;
                }

                Type[] Types = ScriptAssembly.GetTypes();

                Array.ForEach(Types, (Type) =>
                {
                    if (Type.IsSubclassOf(typeof(Moddable)))
                    {
                        Moddables.Add(Type.Name, Type);
                    }
                });
            }
            else
            {
                Debug.Log("Unable to find assembly for Mod Bundle '" + Name + "'");

                return false;
            }
        }
        catch (Exception e)
        {
            Debug.Log("Unable to load script code for Mod Bundle '" + Name + "'");

            return false;
        }

        Inited = true;

        return true;
    }

Usage Example

        public MainWindow()
        {
            InitializeComponent();
            Loaded += MainWindow_Loaded;
            Aardvark.Base.Aardvark.Init();

            var useAardvark = true;

            if (useAardvark)
            {
                app = new Aardvark.Application.WinForms.OpenGlApplication();

                app.Initialize(rc, 1);

                var renderControl = rc;

                var cone                = IndexedGeometryPrimitives.solidCone(V3d.OOO, V3d.OOI, 1.0, 0.2, 12, C4b.Red).ToSg(); // build object from indexgeometry primitives
                var cube                = SgPrimitives.Sg.box(Mod.Init(C4b.Blue), Mod.Init(Box3d.Unit));                       // or directly using scene graph
                var initialViewTrafo    = CameraViewModule.lookAt(V3d.III * 3.0, V3d.OOO, V3d.OOI);
                var controlledViewTrafo = Aardvark.Application.DefaultCameraController.control(renderControl.Mouse, renderControl.Keyboard,
                                                                                               renderControl.Time, initialViewTrafo);
                var frustum = renderControl.Sizes.Select(size => FrustumModule.perspective(60.0, 0.1, 10.0, size.X / (float)size.Y));

                var whiteShader = Aardvark.Base.Rendering.Effects.SimpleLighting.Effect;
                var trafo       = Effects.Trafo.Effect;

                var currentAngle = 0.0;
                var angle        = renderControl.Time.Select(t =>
                {
                    if (true)
                    {
                        return(currentAngle += 0.001);
                    }
                    else
                    {
                        return(currentAngle);
                    }
                });
                var rotatingTrafo = angle.Select((whyCantShadowName) => Trafo3d.RotationZ(whyCantShadowName));

                var sg =
                    new[] { cone, cube.Trafo(rotatingTrafo) }
                .ToSg()
                .WithEffects(new[] { trafo, whiteShader })
                .ViewTrafo(controlledViewTrafo.Select(c => c.ViewTrafo))
                .ProjTrafo(frustum.Select(f => f.ProjTrafo()));

                renderControl.RenderTask =
                    Aardvark.Base.RenderTask.ofArray(
                        new[] {
                    app.Runtime.CompileClear(renderControl.FramebufferSignature, Mod.Init(C4f.Red)),
                    app.Runtime.CompileRender(renderControl.FramebufferSignature, sg)
                }
                        );

                //var r = new System.Windows.Forms.Form();
                //r.Controls.Add(renderControl);
                //r.Show();
            }
        }
All Usage Examples Of Mod::Init
Mod