added gameplay lifetimescope

This commit is contained in:
Savya Bikram Shah
2026-05-27 12:13:45 +05:45
parent 50ca3a0a0f
commit 442836ad89
28 changed files with 349 additions and 19 deletions

6
.idea/.idea.Colorbook/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -3,8 +3,10 @@ using UnityEngine;
using VContainer; using VContainer;
using VContainer.Unity; using VContainer.Unity;
public abstract class BaseLifetimeScope : LifetimeScope namespace Darkmatter.App.LifetimeScopes
{ {
public abstract class BaseLifetimeScope : LifetimeScope
{
[SerializeField] private MonoBehaviour[] serviceModules; [SerializeField] private MonoBehaviour[] serviceModules;
protected override void Configure(IContainerBuilder builder) protected override void Configure(IContainerBuilder builder)
@@ -15,4 +17,5 @@ public abstract class BaseLifetimeScope : LifetimeScope
serviceModule.Register(builder); serviceModule.Register(builder);
} }
} }
}
} }

View File

@@ -1,8 +1,11 @@
using VContainer; using VContainer;
public class GameLifetimeScope : BaseLifetimeScope namespace Darkmatter.App.LifetimeScopes
{ {
public class GameLifetimeScope : BaseLifetimeScope
{
protected override void Configure(IContainerBuilder builder) protected override void Configure(IContainerBuilder builder)
{ {
} }
}
} }

View File

@@ -0,0 +1,6 @@
namespace Darkmatter.App.LifetimeScopes
{
public class GameplayLifetimescope : BaseLifetimeScope
{
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b08651ebc7d8347b4957067e8be677bc

View File

@@ -1,9 +1,11 @@
using VContainer; using VContainer;
using VContainer.Unity;
public class RootLifetimeScope : BaseLifetimeScope namespace Darkmatter.App.LifetimeScopes
{ {
public class RootLifetimeScope : BaseLifetimeScope
{
protected override void Configure(IContainerBuilder builder) protected override void Configure(IContainerBuilder builder)
{ {
} }
}
} }

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2dcdc5f13849d4559b718fda525c6a65
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,10 @@
using UnityEngine;
namespace Darkmatter.Core
{
public interface ICommand
{
void Execute();
void Undo();
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 92465f7eb9c044c59b1046fccb01247c

View File

@@ -0,0 +1,12 @@
namespace Darkmatter.Core.Contracts.Features.History
{
public interface IUndoStack
{
bool CanUndo { get; }
bool CanRedo { get; }
void Push(ICommand cmd); // executes + appends
void Undo();
void Redo();
void Clear();
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e7b0a633ff0da42289a1ace00298f217

View File

@@ -5,9 +5,6 @@ namespace Darkmatter.Core.Contracts.Features.Paper
public interface IPaperRig public interface IPaperRig
{ {
Camera ArtCamera { get; } Camera ArtCamera { get; }
RenderTexture Surface { get; } RectTransform DisplayRect { get; }
Vector2Int SurfaceSize { get; }
float DesignHalfSize { get; }
Transform PaperRoot { get; }
} }
} }

View File

@@ -3,7 +3,6 @@ namespace Darkmatter.Core.Enums.Services.Camera
public enum CameraType public enum CameraType
{ {
MainCamera, MainCamera,
UICamera, UICamera
ArtCamera
} }
} }

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5aaa3a66fb83e44d7a2a762d88e4092b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f555e5ed9c45e44cd804a598d08efc6c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f26c384b6ed9f482b8b3f325ba5e06f5
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
using System;
using Darkmatter.Core.Contracts.Features.Paper;
using UnityEngine;
namespace Darkmatter.Features.PaperRig
{
[Serializable]
public class PaperRig : IPaperRig
{
[SerializeField] private Camera artCamera;
[SerializeField] private RectTransform displayRect;
public Camera ArtCamera => artCamera;
public RectTransform DisplayRect => displayRect;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: fd7db17694325451c8441d824b221199

View File

@@ -0,0 +1,18 @@
{
"name": "Features.PaperRig",
"rootNamespace": "Darkmatter.Features.PaperRig",
"references": [
"GUID:6a0a834eb41764f12ba55c3fb04a40cb",
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
"GUID:c1c03c0e5b2f4412b9f2be1c20d6a9b1"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c54b3e6267ecb41b68cc06079d4b39f2
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0156c96d959344bfbf0c1212ea68d473
timeCreated: 1779859615

View File

@@ -0,0 +1,45 @@
using Darkmatter.Core.Contracts.Features.Paper;
using Darkmatter.Core.Contracts.Services.Camera;
using UnityEngine;
using CameraType = Darkmatter.Core.Enums.Services.Camera.CameraType;
namespace Darkmatter.Features.PaperRig.Darkmatter.Code.Features.PaperRig.Input
{
public class ArtInputBridge : IArtInputBridge
{
private readonly IPaperRig _paperRig;
private ICameraService _cameraService;
public ArtInputBridge(IPaperRig paperRig, ICameraService cameraService)
{
_paperRig = paperRig;
_cameraService = cameraService;
}
public bool TryScreenToArtWorld(Vector2 screenPos, out Vector2 artWorldPos)
{
var rectT = _paperRig.DisplayRect;
var uiCamera = _cameraService.GetCamera(CameraType.UICamera);
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(
rectT, screenPos, uiCamera, out var local))
{
artWorldPos = default;
return false;
}
var rect = rectT.rect;
var uv = new Vector2(
(local.x - rect.xMin) / rect.width,
(local.y - rect.yMin) / rect.height);
if (uv.x < 0 || uv.x > 1 || uv.y < 0 || uv.y > 1)
{
artWorldPos = default;
return false;
}
artWorldPos = _paperRig.ArtCamera.ViewportToWorldPoint(uv);
return true;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0337c48e57934443887873de8e382d4e
timeCreated: 1779859625

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ecba85ae080a44ef9b1a1d55f3f86659
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
using Darkmatter.Core.Contracts.Features.Paper;
using Darkmatter.Features.PaperRig.Darkmatter.Code.Features.PaperRig.Input;
using Darkmatter.Libs.Installers;
using UnityEngine;
using VContainer;
using VContainer.Unity;
namespace Darkmatter.Features.PaperRig
{
public class PaperRigServiceModule : MonoBehaviour, IServiceModule
{
[SerializeField] private PaperRig paperRig;
public void Register(IContainerBuilder builder)
{
builder.RegisterComponent<IPaperRig>(paperRig);
builder.Register<IArtInputBridge, ArtInputBridge>(Lifetime.Singleton);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: ef7eaa67fc66d48c88c8ec12d27f9b14

View File

@@ -417,7 +417,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: Darkmatter.App::GameLifetimeScope m_EditorClassIdentifier: Darkmatter.App::GameLifetimeScope
parentReference: parentReference:
TypeName: TypeName: RootLifetimeScope
autoRun: 1 autoRun: 1
autoInjectGameObjects: [] autoInjectGameObjects: []
serviceModules: serviceModules:

View File

@@ -410,6 +410,136 @@ Transform:
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1224714931
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1224714932}
- component: {fileID: 1224714933}
m_Layer: 0
m_Name: GameplayLifetimeScope
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1224714932
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1224714931}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 1132.1088, y: 564.77155, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1965442263}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1224714933
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1224714931}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b08651ebc7d8347b4957067e8be677bc, type: 3}
m_Name:
m_EditorClassIdentifier: Darkmatter.App::Darkmatter.App.LifetimeScopes.GameplayLifetimescope
parentReference:
TypeName: Darkmatter.App.LifetimeScopes.GameLifetimeScope
autoRun: 1
autoInjectGameObjects: []
serviceModules:
- {fileID: 1594774441}
--- !u!1 &1594774439
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1594774440}
- component: {fileID: 1594774441}
m_Layer: 0
m_Name: PaperRigServiceModule
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1594774440
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1594774439}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1965442263}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1594774441
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1594774439}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ef7eaa67fc66d48c88c8ec12d27f9b14, type: 3}
m_Name:
m_EditorClassIdentifier: Features.PaperRig::Darkmatter.Features.PaperRig.PaperRigServiceModule
paperRig:
artCamera: {fileID: 942391591}
displayRect: {fileID: 2081960987}
--- !u!1 &1965442262
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1965442263}
m_Layer: 0
m_Name: ServiceModules
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1965442263
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1965442262}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1594774440}
m_Father: {fileID: 1224714932}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &2069155637 --- !u!1 &2069155637
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -593,3 +723,4 @@ SceneRoots:
- {fileID: 942391592} - {fileID: 942391592}
- {fileID: 2069155641} - {fileID: 2069155641}
- {fileID: 590523275} - {fileID: 590523275}
- {fileID: 1224714932}