Skip to content

Commit

Permalink
prefab mode issue fixed & bad inject issue fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Saeed Barari committed Jul 30, 2023
1 parent 1bbcc5f commit 8163560
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions BContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ void SaveLastHierarchyState() {
void ReportSceneChangeOrRemoveFromManagerIfPossible() {
var sceneHandle = new SceneHandle( gameObject.scene );
if (_lastSceneHandle.Value != sceneHandle.Value) { // scene changed
if (sceneHandle.Value == 0) { // invalid scene
if (sceneHandle.Value == 0 || !gameObject.scene.isLoaded) { // invalid scene
BinjectManager.RemoveContext( this, sceneHandle );
_addedToManager = false;
} else {
Expand All @@ -289,7 +289,7 @@ void ReportSceneChangeOrRemoveFromManagerIfPossible() {
/// </summary>
[MethodImpl( MethodImplOptions.AggressiveInlining )]
void AddToManagerIfNotAddedTo() {
if (_lastSceneHandle.Value != 0 && !_addedToManager) {
if (_lastSceneHandle.Value != 0 && gameObject.scene.isLoaded && !_addedToManager) {
BinjectManager.AddContext( this, _lastSceneHandle );
_addedToManager = true;
}
Expand Down
21 changes: 13 additions & 8 deletions BinjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,14 @@ public static BContext FindNearestContext(Transform transform, ushort groupNumbe
var originalTransform = transform;
// parents
while (transform is not null) {
for (int i = 0; i < contextsInScene.Count; i++)
if (isCorrectGroup( contextsInScene[i], groupNumber ) && ReferenceEquals( transform, contextsInScene[i].transform )) {
for (int i = 0; i < contextsInScene.Count; i++) {
var context = contextsInScene[i];
if (isCorrectGroup( context, groupNumber ) && ReferenceEquals( transform, context.transform )) {
contextsInScene.AddPoint( i );
return contextsInScene[i];
return context;
}
}

transform = transform.parent;
}

Expand Down Expand Up @@ -119,7 +122,7 @@ public static BContext FindContext<T>(Transform transform, ushort groupNumber =
// find
for (int i = 0; i < contextsInScene.Count; i++) {
var context = contextsInScene[i];
if (isCorrectGroup( context, groupNumber ) && ReferenceEquals( context.transform, transform )) {
if (isCorrectGroup( context, groupNumber ) && context.transform == transform ) {
if (context.HasDependency<T>()) {
contextsInScene.AddPoint( i );
return context;
Expand All @@ -145,11 +148,13 @@ public static BContext FindContext<T>(Transform transform, ushort groupNumber =

// check grouped contexts from any scene
if (_groupedContexts.TryGetValue( groupNumber, out var list ) && list.Count > 0) {
for (int i = 0; i < list.Count; i++)
if (list[i].HasDependency<T>()) {
for (int i = 0; i < list.Count; i++) {
var context = list[i];
if (context.HasDependency<T>()) {
list.AddPoint( i );
return list[i];
return context;
}
}
}

#if WARN
Expand Down Expand Up @@ -185,7 +190,7 @@ internal static void AddContext(BContext context, SceneHandle sceneHandle) {
/// </summary>
internal static void RemoveContext(BContext context, SceneHandle sceneHandle) {
#if B_DEBUG
Debug.Log( $"removing {(context ? $"{context.name}({context.gameObject.scene.name})" : "null")}. all: {CreateStringListOfAllContexts()}" );
Debug.Log( $"removing {(context ? $"{context.name}({context.gameObject.scene.name})" : "null")}. all: {CreateStringListOfAllContexts()}", context );
#endif
bool changed = false;

Expand Down

0 comments on commit 8163560

Please sign in to comment.