protected virtual void OnDestroy() // should be called in derived class { if (isSingletonObject) { UnitySingleton <T> ._Destroy(); } }
private Guid SubscribeCore(IEventFilter filter, DataReceiveEventHandler receiveEventHandler, out IReceiverChannel channel) { Guid cookie; // создаем канал ответа (интегральный) var localChannel = UnitySingleton.Resolve <ITransport>().CreateIntegralChannel(); channel = (IReceiverChannel)localChannel; // создаем кук cookie = Guid.NewGuid(); // подписываемся на событие прихода данных по каналу if (receiveEventHandler != null) { channel.DataReceived += receiveEventHandler; } // посылаем команду в Blackboard _localBlackboard.Subscribe(filter, localChannel as ISenderChannel, cookie); return(cookie); }
public void CheckSingletons() { Logger.LogInfo("!! Singletons: "); Logger.LogInfo(" " + UnitySingleton.GetType().Name); Logger.LogInfo(" " + Singleton.GetType().Name); Logger.LogInfo(" " + LazySingleton.GetType().Name); }
protected virtual void Awake() { if (isSingletonObject) { UnitySingleton <T> ._Awake(this as T); } }
// The only callbacks void OnEnable() { Debug.Log("UnitySingleton OnEnable"); if (instance == null) { instance = this; // https://docs.unity3d.com/ScriptReference/HideFlags.html // Will... // 1. Not show in the hierarchy (HideFlags.HideInHierarchy) // 2. Not be saved to the scene ( HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor) // 3. Not be unloaded by Resources.UnloadUnusedAssets (HideFlags.DontUnloadUnusedAsset) // HideFlags.HideAndDontSave = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor | HideFlags.DontUnloadUnusedAsset; instance.hideFlags = HideFlags.HideAndDontSave; } else if (Instance != this) { Debug.LogError("A new instance of SingletonExample was created, marking it for destruction."); if (Application.isEditor) { DestroyImmediate(this); } else { Destroy(this); } } }
protected virtual void OnDestroy() { if (isSingletonObject) { UnitySingleton <T> ._Destroy(); } }
public void Awake() { UnitySingleton <AudioOneShotPlayer> .Register(this); this.worldspaceAudioSources = new ObjectPool <UTKAudioSource>(() => this.CreateAudioSource <UTKAudioSource>(this.worldspacePrefab, this.ReturnAudioSource), 250, this.ReturnAudioSource); this.proximityAudioSources = new ObjectPool <ProximityBasedAudio>(() => this.CreateAudioSource <ProximityBasedAudio>(this.proximityBasedPrefab, this.ReturnAudioSource), 250, this.ReturnAudioSource); this.nonSpatialAudioSources = new ObjectPool <NonSpatialAudioSource>(() => this.CreateAudioSource <NonSpatialAudioSource>(this.nonSpatialPrefab, this.ReturnAudioSource), 250, this.ReturnAudioSource); }
/// <summary> /// Метод подписки на события журнала. /// </summary> /// <param name="filter">Фильтр событий.</param> /// <param name="channel">Канал передачи событий.</param> /// <param name="cookie">Идентификатор подписки.</param> void ISrvcBlackboard.Subscribe(IEventFilter filter, ChannelDescription channel, Guid cookie) { Logger.Debug("ISrvcBlackboard.Subscribe: подписался {0}", cookie); // создаем канал ISenderChannel ch = channel != null?UnitySingleton.Resolve <ITransport>().CreateSenderChannel(channel) : null; _subsribeTask.Run(() => (this as IBlackboard).Subscribe(filter, ch, cookie)); }
public void Awake() { for (int i = 0; i < this.config.Length; i++) { this.configs.Add(this.config[i].tag, this.config[i]); } UnitySingleton <DebrisManager> .Register(this); }
/// <summary> /// Метод подписки на события журнала. /// </summary> /// <param name="filter">Фильтр событий.</param> /// <param name="channel">Канал передачи событий.</param> /// <param name="cookie">Идентификатор подписки.</param> void IBlackboard.Subscribe(IEventFilter filter, ISenderChannel channel, Guid cookie) { // локальный подписчик if (filter.Host == UnitySingleton.Resolve <ITransport>().HostID) { // добавляем нового подписчика в карту _localEventsSubscribers.Add(cookie, filter, channel); } }
protected virtual void Awake() // should be called in derived class { if (isSingletonObject) { UnitySingleton <T> ._Awake(this as T); //Debug.Log( "Awake: " + this.GetType().Name ); } }
void StopTracking() { foreach (var guid in _listCookies2Unsubscribe) { UnitySingleton.Resolve <IBlackboardWrapper>().Unsubscribe(guid); } _listCookies2Unsubscribe.Clear(); }
protected virtual void Awake() // should be called in derived class { if (isSingletonObject) { #if UNITY_FLASH UnitySingleton <T> ._Awake(this); #else UnitySingleton <T> ._Awake(this as T); #endif //Debug.Log( "Awake: " + this.GetType().Name ); } }
public void SubscribeEvent(IEnumerable <Guid> guidEventIds, DataReceiveEventHandler handler) { var filter = new EventFilter(); filter.Types.AddRange(guidEventIds); Guid guidEventCookie; IReceiverChannel eventChannel; UnitySingleton.Resolve <IBlackboardWrapper>().Subscribe(filter, out eventChannel, handler, out guidEventCookie); _listCookies2Unsubscribe.Add(guidEventCookie); }
void Awake() { if (instance != null && instance != this) { Destroy(this.gameObject); return; } else { instance = this; } DontDestroyOnLoad(this.gameObject); }
static int Awake(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); UnitySingleton <LogRecord> obj = (UnitySingleton <LogRecord>)ToLua.CheckObject <UnitySingleton <LogRecord> >(L, 1); obj.Awake(); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public Tester() { var transport = new Transport(Guid.NewGuid()); UnitySingleton.RegisterInstance(transport); UnitySingleton.RegisterInstance <ITransport>(transport); var blackboardWrapper = new BlackboardWrapper(); // регистрируем в Unity UnitySingleton.RegisterInstance(blackboardWrapper); UnitySingleton.RegisterInstance <IBlackboardWrapper>(blackboardWrapper); // подписываемся на таймер генерации события GenerationEvent1 += OnGenerationEvent1; }
private void OnGenerationEvent1() { EventGenerationTimer1.Change(Timeout.Infinite, 0); try { ++_eventCount; var newTime = DateTime.Now; //var eventParams = new List<Event.EventParam> //{ // new Event.EventParam("%s", "UserEvent"), // new Event.EventParam("%Count", (_eventCount).ToString()),//count // new Event.EventParam("%Time", newTime.ToString(CultureInfo.InvariantCulture))//time //}; var eventData = new EventData("UserEvent", _eventCount, newTime); var newEvent = new Event(EventTypes.UserEvent, TestId, eventData); UnitySingleton.Resolve <IBlackboardWrapper>().PublishEvent(newEvent); } finally { EventGenerationTimer1.Change(EventGenerationDelay1, EventGenerationDelay1); } }
public static Boolean DoesInstanceExist() { AudioController singleton = UnitySingleton <AudioController> .GetSingleton(false, false); return(!Object.Equals(singleton, null)); }
/// <summary> /// Activates the singleton instance. /// </summary> /// <remarks> /// Call this function if you set an singleton object inactive before ever accessing the <c>Instance</c>. This is /// required because Unity does not (yet) offer a way to find inactive game objects. /// </remarks> static public void ActivateSingletonInstance() // { UnitySingleton <T> .GetSingleton(true, true); }
void static Main(string[] args) { UnitySingleton.GetInstance(); }
/// <summary> /// Идентификатор хоста. /// </summary> Guid ISrvcBlackboard.GetHostID() { Logger.Debug("ISrvcBlackboard.GetHostID: Запросили HostId"); return(UnitySingleton.Resolve <ITransport>().HostID); }
/// <summary> /// Checks if an instance of this MonoBehaviour exists. /// </summary> /// <returns> /// A reference to the instance if it exists, otherwise <c>null</c> /// </returns> static public T DoesInstanceExist() { return(UnitySingleton <T> .GetSingleton(false, false)); }
private void OnEnable() { instance = this; text = "Hello World"; }
void Awake() { _instance = this; }
/// <summary> /// Checks if an instance of this MonoBehaviour exists. /// </summary> public static bool DoesInstanceExist( ) { return(UnitySingleton <T> .GetSingleton(false, null) != null); }
public void Awake() { UnitySingleton <FirstPersonEntity> .Register(this); }
public void Awake() { UnitySingleton <ProximityPlayer> .Register(this); }
protected virtual void Awake() // should be called in derived class { UnitySingleton <T> ._Awake((T)this); //Debug.Log( "Awake: " + this.GetType().Name ); }
public void Awake() { UnitySingleton <HUD> .Register(this); }