![]() |
|
#2
|
|||
|
|||
|
Yes a Singleton Pattern in a DLL.
http://en.wikipedia.org/wiki/Singleton_pattern Example Singleton (threadsafe) Code:
public sealed class Singleton
{
public int planeCount { get; set; }
private static readonly Lazy<Singleton> lazy = new Lazy<Singleton>(() => new Singleton());
public static Singleton GetInstance { get { return lazy.Value; } }
private Singleton()
{
// Initialisations
}
}
Code:
//$reference parts/core/MyDll.dll
using System;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;
using MyNameSpace;
public class Mission : AMission
{
Singleton s=Singleton.GetInstance; // get access to the singleton or create it if not exist.
public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex)
{
base.OnPlaceEnter(player, actor, placeIndex);
s.planeCount += 1; // example
}
}
Last edited by FG28_Kodiak; 05-24-2012 at 09:48 AM. |
| Thread Tools | |
| Display Modes | |
|
|