Permalink
Browse files

AddTo(gameObject) doesn't dispose when ObservableTrigger is not activ…

…ated. close #144
  • Loading branch information...
1 parent 0859caf commit 43b8d46a471364cb9f6afce963317aea13d4e3f3 @neuecc committed Jun 6, 2016
@@ -1,22 +0,0 @@
-fileFormatVersion: 2
-guid: 11188de2b6632fa4486c470af4b55fa0
-PluginImporter:
- serializedVersion: 1
- iconMap: {}
- executionOrder: {}
- isPreloaded: 0
- platformData:
- Any:
- enabled: 0
- settings: {}
- Editor:
- enabled: 1
- settings:
- DefaultValueInitialized: true
- WindowsStoreApps:
- enabled: 0
- settings:
- CPU: AnyCPU
- userData:
- assetBundleName:
- assetBundleVariant:
@@ -1,22 +0,0 @@
-fileFormatVersion: 2
-guid: e35231d99115e9e4c8cb29414445831f
-PluginImporter:
- serializedVersion: 1
- iconMap: {}
- executionOrder: {}
- isPreloaded: 0
- platformData:
- Any:
- enabled: 0
- settings: {}
- Editor:
- enabled: 1
- settings:
- DefaultValueInitialized: true
- WindowsStoreApps:
- enabled: 0
- settings:
- CPU: AnyCPU
- userData:
- assetBundleName:
- assetBundleVariant:
@@ -1,4 +1,5 @@
using System;
+using System.Collections;
using System.Collections.Generic;
using UniRx.Triggers;
using UnityEngine;
@@ -23,10 +24,37 @@ public static T AddTo<T>(this T disposable, GameObject gameObject)
trigger = gameObject.AddComponent<ObservableDestroyTrigger>();
}
+#pragma warning disable CS0618
+
+ // If gameObject is deactive, does not raise OnDestroy, watch and invoke trigger.
+ if (!trigger.IsActivated && !trigger.IsMonitoredActivate && !trigger.gameObject.activeInHierarchy)
+ {
+ trigger.IsMonitoredActivate = true;
+ MainThreadDispatcher.StartEndOfFrameMicroCoroutine(MonitorTriggerHealth(trigger));
+ }
+
+#pragma warning restore CS0618
+
trigger.OnDestroyAsObservable().SubscribeWithState(disposable, (_, d) => d.Dispose());
return disposable;
}
+ static IEnumerator MonitorTriggerHealth(ObservableDestroyTrigger trigger)
+ {
+ var go = trigger.gameObject;
+ while (true)
+ {
+ yield return null;
+ if (trigger.IsActivated) yield break;
+
+ if (go == null) // isDestroy
+ {
+ trigger.ForceRaiseOnDestroy(); // Force publish OnDestroy
+ yield break;
+ }
+ }
+ }
+
/// <summary>Dispose self on target gameObject has been destroyed. Return value is self disposable.</summary>
public static T AddTo<T>(this T disposable, Component gameObjectComponent)
where T : IDisposable
@@ -9,11 +9,24 @@ public class ObservableDestroyTrigger : MonoBehaviour
bool calledDestroy = false;
Subject<Unit> onDestroy;
+ [Obsolete("Internal Use.")]
+ internal bool IsMonitoredActivate { get; set; }
+
+ public bool IsActivated { get; private set; }
+
+ void Awake()
+ {
+ IsActivated = true;
+ }
+
/// <summary>This function is called when the MonoBehaviour will be destroyed.</summary>
void OnDestroy()
{
- calledDestroy = true;
- if (onDestroy != null) { onDestroy.OnNext(Unit.Default); onDestroy.OnCompleted(); }
+ if (!calledDestroy)
+ {
+ calledDestroy = true;
+ if (onDestroy != null) { onDestroy.OnNext(Unit.Default); onDestroy.OnCompleted(); }
+ }
}
/// <summary>This function is called when the MonoBehaviour will be destroyed.</summary>
@@ -23,5 +36,11 @@ public IObservable<Unit> OnDestroyAsObservable()
if (calledDestroy) return Observable.Return(Unit.Default);
return onDestroy ?? (onDestroy = new Subject<Unit>());
}
+
+ /// <summary>Invoke OnDestroy, this method is used on internal.</summary>
+ public void ForceRaiseOnDestroy()
+ {
+ OnDestroy();
+ }
}
}
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 78d631aad21b470469bd6214ff1f673e
-timeCreated: 1455438477
-licenseType: Pro
-DefaultImporter:
- userData:
- assetBundleName:
- assetBundleVariant:
@@ -68,6 +68,7 @@ PlayerSettings:
n3dsEnableSharedListOpt: 1
n3dsEnableVSync: 0
uiUse16BitDepthBuffer: 0
+ ignoreAlphaClear: 0
xboxOneResolution: 0
ps3SplashScreen: {fileID: 0}
videoMemoryForVertexBuffers: 0
@@ -133,6 +134,9 @@ PlayerSettings:
iPadLandscapeSplashScreen: {fileID: 0}
iPadHighResLandscapeSplashScreen: {fileID: 0}
appleTVSplashScreen: {fileID: 0}
+ tvOSSmallIconLayers: []
+ tvOSLargeIconLayers: []
+ tvOSTopShelfImageLayers: []
iOSLaunchScreenType: 0
iOSLaunchScreenPortrait: {fileID: 0}
iOSLaunchScreenLandscape: {fileID: 0}
@@ -1,2 +1,2 @@
-m_EditorVersion: 5.3.0f4
+m_EditorVersion: 5.3.4p1
m_StandardAssetsVersion: 0
@@ -16,9 +16,9 @@
<CompilerResponseFile>Assets\smcs.rsp</CompilerResponseFile>
<UnityProjectType>GamePlugins:3</UnityProjectType>
<UnityBuildTarget>StandaloneWindows:5</UnityBuildTarget>
- <UnityVersion>5.3.0f4</UnityVersion>
- <RootNamespace>
- </RootNamespace>
+ <UnityVersion>5.3.4p1</UnityVersion>
+ <RootNamespace></RootNamespace>
+ <LangVersion Condition=" '$(VisualStudioVersion)' != '10.0' ">4</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -27,7 +27,7 @@
<IntermediateOutputPath>Temp\UnityVS_obj\Debug\</IntermediateOutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
- <DefineConstants>DEBUG;TRACE;UNITY_5_3_0;UNITY_5_3;UNITY_5;ENABLE_NEW_BUGREPORTER;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_FRAME_DEBUGGER;ENABLE_GENERICS;ENABLE_HOME_SCREEN;ENABLE_IMAGEEFFECTS;ENABLE_LIGHT_PROBES_LEGACY;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_PLUGIN_INSPECTOR;ENABLE_SHADOWS;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_SPRITE_POLYGON;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_UNITYEVENTS;ENABLE_VR;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;INCLUDE_IL2CPP;INCLUDE_DIRECTX12;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;ENABLE_LOCALIZATION;ENABLE_ANDROID_ATLAS_ETC1_COMPRESSION;ENABLE_EDITOR_TESTS_RUNNER;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_TEXTUREID_MAP;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_LOG_MIXED_STACKTRACE;ENABLE_UNITYWEBREQUEST;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;UNITY_TEAM_LICENSE;UNITY_PRO_LICENSE;</DefineConstants>
+ <DefineConstants>DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_3_4;UNITY_5_3;UNITY_5;ENABLE_NEW_BUGREPORTER;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_FRAME_DEBUGGER;ENABLE_GENERICS;ENABLE_HOME_SCREEN;ENABLE_IMAGEEFFECTS;ENABLE_LIGHT_PROBES_LEGACY;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_PLUGIN_INSPECTOR;ENABLE_SHADOWS;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_SPRITE_POLYGON;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_UNITYEVENTS;ENABLE_VR;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;INCLUDE_IL2CPP;INCLUDE_DIRECTX12;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;ENABLE_LOCALIZATION;ENABLE_ANDROID_ATLAS_ETC1_COMPRESSION;ENABLE_EDITOR_TESTS_RUNNER;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_TEXTUREID_MAP;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_LOG_MIXED_STACKTRACE;ENABLE_UNITYWEBREQUEST;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;UNITY_TEAM_LICENSE;UNITY_PRO_LICENSE;</DefineConstants>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
@@ -37,7 +37,7 @@
<IntermediateOutputPath>Temp\UnityVS_obj\Release\</IntermediateOutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
- <DefineConstants>TRACE;UNITY_5_3_0;UNITY_5_3;UNITY_5;ENABLE_NEW_BUGREPORTER;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_FRAME_DEBUGGER;ENABLE_GENERICS;ENABLE_HOME_SCREEN;ENABLE_IMAGEEFFECTS;ENABLE_LIGHT_PROBES_LEGACY;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_PLUGIN_INSPECTOR;ENABLE_SHADOWS;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_SPRITE_POLYGON;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_UNITYEVENTS;ENABLE_VR;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;INCLUDE_IL2CPP;INCLUDE_DIRECTX12;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;ENABLE_LOCALIZATION;ENABLE_ANDROID_ATLAS_ETC1_COMPRESSION;ENABLE_EDITOR_TESTS_RUNNER;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_TEXTUREID_MAP;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_LOG_MIXED_STACKTRACE;ENABLE_UNITYWEBREQUEST;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;UNITY_TEAM_LICENSE;UNITY_PRO_LICENSE;</DefineConstants>
+ <DefineConstants>TRACE;UNITY_5_3_OR_NEWER;UNITY_5_3_4;UNITY_5_3;UNITY_5;ENABLE_NEW_BUGREPORTER;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_FRAME_DEBUGGER;ENABLE_GENERICS;ENABLE_HOME_SCREEN;ENABLE_IMAGEEFFECTS;ENABLE_LIGHT_PROBES_LEGACY;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_PLUGIN_INSPECTOR;ENABLE_SHADOWS;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_SPRITE_POLYGON;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_UNITYEVENTS;ENABLE_VR;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;INCLUDE_IL2CPP;INCLUDE_DIRECTX12;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;ENABLE_LOCALIZATION;ENABLE_ANDROID_ATLAS_ETC1_COMPRESSION;ENABLE_EDITOR_TESTS_RUNNER;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_TEXTUREID_MAP;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_LOG_MIXED_STACKTRACE;ENABLE_UNITYWEBREQUEST;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;UNITY_TEAM_LICENSE;UNITY_PRO_LICENSE;</DefineConstants>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
@@ -58,21 +58,15 @@
<Reference Include="UnityEngine.Networking">
<HintPath>Library\UnityAssemblies\UnityEngine.Networking.dll</HintPath>
</Reference>
- <Reference Include="UnityEngine.Networking">
- <HintPath>Library\UnityAssemblies\UnityEngine.Networking.dll</HintPath>
- </Reference>
- <Reference Include="UnityEngine.UI">
- <HintPath>Library\UnityAssemblies\UnityEngine.UI.dll</HintPath>
- </Reference>
<Reference Include="UnityEditor">
<HintPath>Library\UnityAssemblies\UnityEditor.dll</HintPath>
</Reference>
- <Reference Include="Mono.Cecil">
- <HintPath>Library\UnityAssemblies\Mono.Cecil.dll</HintPath>
- </Reference>
<Reference Include="UnityEditor.iOS.Extensions.Xcode">
<HintPath>Library\UnityAssemblies\UnityEditor.iOS.Extensions.Xcode.dll</HintPath>
</Reference>
+ <Reference Include="UnityEditor.iOS.Extensions.Common">
+ <HintPath>Library\UnityAssemblies\UnityEditor.iOS.Extensions.Common.dll</HintPath>
+ </Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Assets\Plugins\UniRx\Examples\Sample01_ObservableWWW.cs" />
@@ -136,6 +130,7 @@
<Compile Include="Assets\Plugins\UniRx\Scripts\Operators\Aggregate.cs" />
<Compile Include="Assets\Plugins\UniRx\Scripts\Operators\Amb.cs" />
<Compile Include="Assets\Plugins\UniRx\Scripts\Operators\AsObservable.cs" />
+ <Compile Include="Assets\Plugins\UniRx\Scripts\Operators\AsSingleUnitObservable.cs" />
<Compile Include="Assets\Plugins\UniRx\Scripts\Operators\AsUnitObservable.cs" />
<Compile Include="Assets\Plugins\UniRx\Scripts\Operators\Buffer.cs" />
<Compile Include="Assets\Plugins\UniRx\Scripts\Operators\Cast.cs" />
@@ -155,7 +150,6 @@
<Compile Include="Assets\Plugins\UniRx\Scripts\Operators\Empty.cs" />
<Compile Include="Assets\Plugins\UniRx\Scripts\Operators\Finally.cs" />
<Compile Include="Assets\Plugins\UniRx\Scripts\Operators\First.cs" />
- <Compile Include="Assets\Plugins\UniRx\Scripts\Operators\AsSingleUnitObservable.cs" />
<Compile Include="Assets\Plugins\UniRx\Scripts\Operators\ForEachAsync.cs" />
<Compile Include="Assets\Plugins\UniRx\Scripts\Operators\FromEvent.cs" />
<Compile Include="Assets\Plugins\UniRx\Scripts\Operators\GroupBy.cs" />
@@ -312,4 +306,4 @@
<None Include="Assets\Plugins\UniRx\ReadMe.txt" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\SyntaxTree\UnityVS\2015\UnityVS.CSharp.targets" />
-</Project>
+</Project>
Oops, something went wrong.

0 comments on commit 43b8d46

Please sign in to comment.