├── .gitattributes ├── .github ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── ci.yml ├── .gitignore ├── .gitmodules ├── Altseed2.sln ├── Documents ├── HowToBuild_Ja.md ├── HowToDevelop_Ja.md └── HowToNugetUpdate.md ├── Engine ├── .editorconfig ├── AltseedContext.cs ├── AssemblyInfo.cs ├── AutoGeneratedCoreBindings.cs ├── Collection │ ├── ArrayBuffer.cs │ ├── DrawnCollection.cs │ ├── Registerable.cs │ ├── RegisterableCollection.cs │ └── RenderTextureCache.cs ├── Common │ └── ProfilerBlock.cs ├── CorePartial │ ├── Array.cs │ ├── Collider.cs │ ├── Configuration.cs │ ├── Font.cs │ ├── Graphics.cs │ ├── IO.cs │ ├── Joystick.cs │ ├── Material.cs │ ├── Rendered.cs │ ├── Shader.cs │ ├── Sound.cs │ ├── Texture.cs │ └── Tool.cs ├── Engine.cs ├── Engine.csproj ├── InternalHelper │ ├── CacheHelper.cs │ ├── IOHelper.cs │ └── SerializationHelper.cs ├── Math │ ├── Easing.cs │ ├── MathHelper.cs │ ├── Matrix33F.cs │ ├── Matrix33I.cs │ ├── Matrix44F.cs │ ├── Matrix44I.cs │ ├── RectF.cs │ ├── RectI.cs │ ├── Vector2F.cs │ ├── Vector2I.cs │ ├── Vector3F.cs │ ├── Vector3I.cs │ ├── Vector4F.cs │ └── Vector4I.cs ├── Node │ ├── AnchorTransformerNode.cs │ ├── AnchorTransformerNodeInfo.cs │ ├── CameraNode.cs │ ├── IDrawn.cs │ ├── Node.cs │ ├── PartsTree.cs │ ├── PartsTreeInstantiator.cs │ ├── Physics │ │ ├── CircleColliderNode.cs │ │ ├── ColliderNode.cs │ │ ├── ColliderVisualizeNodeFactory.cs │ │ ├── EdgeColliderNode.cs │ │ ├── PolygonColliderNode.cs │ │ └── RectangleColliderNode.cs │ ├── PolygonNode.cs │ ├── PostEffect │ │ ├── PostEffectGaussianBlurNode.cs │ │ ├── PostEffectGrayScaleNode.cs │ │ ├── PostEffectLightBloomNode.cs │ │ ├── PostEffectNode.cs │ │ └── PostEffectSepiaNode.cs │ ├── RootNode.cs │ ├── ShapeNodes │ │ ├── ArcNode.cs │ │ ├── CircleNode.cs │ │ ├── LineNode.cs │ │ ├── RectangleNode.cs │ │ ├── ShapeNode.cs │ │ └── TriangleNode.cs │ ├── SpriteNode.cs │ ├── TextNode.cs │ ├── TransformNode.cs │ ├── TransformNodeInfo.cs │ ├── TransformerNode.cs │ ├── TransformerNodeInfo.cs │ └── Transition │ │ ├── RuledTransitionNode.cs │ │ └── TransitionNode.cs └── Physics │ ├── Collider │ └── RectangleCollider.cs │ ├── CollisionCollection.cs │ ├── CollisionInfo.cs │ ├── CollisionManagerNode.cs │ ├── CollisionType.cs │ └── ICollisionEventReceiver.cs ├── NodeEditor.Test ├── Editor.cs ├── NodeEditor.Test.csproj └── NodeEditor │ └── ToolElementTreeFactoryTest.cs ├── NodeEditor ├── GuiTool │ ├── Attribute │ │ ├── ToolAttributeBase.cs │ │ ├── ToolAutoAttribute.cs │ │ ├── ToolBoolAttribute.cs │ │ ├── ToolButtonAttribute.cs │ │ ├── ToolColorAttribute.cs │ │ ├── ToolCommandAttributeBase.cs │ │ ├── ToolEnumAttribute.cs │ │ ├── ToolFloatAttribute.cs │ │ ├── ToolFontAttribute.cs │ │ ├── ToolGroupAttribute.cs │ │ ├── ToolHiddenAttribute.cs │ │ ├── ToolInputTextAttribute.cs │ │ ├── ToolIntAttribute.cs │ │ ├── ToolLabelAttribute.cs │ │ ├── ToolListAttribute.cs │ │ ├── ToolPathAttribute.cs │ │ ├── ToolTextureBaseAttribute.cs │ │ ├── ToolUserAttribute.cs │ │ └── ToolVector2FAttribute.cs │ ├── Element │ │ ├── BoolToolElement.cs │ │ ├── ButtonToolElement.cs │ │ ├── ColorToolElement.cs │ │ ├── EnumToolElement.cs │ │ ├── FloatToolElement.cs │ │ ├── FontToolElement.cs │ │ ├── GroupToolElement.cs │ │ ├── InputTextToolElement.cs │ │ ├── IntToolElement.cs │ │ ├── LabelToolElement.cs │ │ ├── ListToolElement.cs │ │ ├── PathToolElement.cs │ │ ├── TextureBaseToolElement.cs │ │ ├── ToolElement.cs │ │ ├── UserToolElement.cs │ │ └── Vector2FToolElement.cs │ ├── Factory │ │ ├── IToolElementTreeFactory.cs │ │ ├── ToolElementFactory.cs │ │ └── ToolElementTreeFactory.cs │ ├── MemberGuiInfo.cs │ └── Repository │ │ └── GuiInfoRepository.cs ├── IEditorPropertyAccessor.cs ├── Model │ └── NodeEditorModel.cs ├── NodeEditor.csproj ├── Program.cs ├── View │ ├── FontBrowserWindow.cs │ ├── NodeEditor.cs │ ├── NodeEditorHost.cs │ ├── NodeEditorPane.cs │ ├── NodeTreeWindow.cs │ ├── PreviewWindow.cs │ ├── SelectedNodeWindow.cs │ └── TextureBrowserWindow.cs └── ViewModel │ ├── FontBrowserViewModel.cs │ ├── NodeEditorViewModel.cs │ ├── NodeTreeViewModel.cs │ ├── PreviewViewModel.cs │ └── TextureBrowserViewModel.cs ├── Nuget ├── Altseed2.nuspec └── license.tools.txt ├── Readme.md ├── Samples ├── .editorconfig ├── Demonstration │ ├── AudioVisualizerDemonstration.cs │ └── CollisionDemonstration.cs ├── Engine │ └── Empty.cs ├── File │ ├── Package.cs │ ├── PackageFromZip.cs │ ├── PackageWithPassword.cs │ ├── StaticFile.cs │ └── StreamFile.cs ├── Graphics │ ├── Camera.cs │ ├── CustomPostEffect.cs │ ├── ImageText.cs │ ├── Material.cs │ ├── PostEffectGaussianBlur.cs │ ├── PostEffectGrayScale.cs │ ├── PostEffectLightBloom.cs │ ├── PostEffectSepia.cs │ ├── RenderTexture.cs │ ├── Sprite.cs │ └── Text.cs ├── Input │ ├── JoystickAxis.cs │ ├── JoystickButton.cs │ ├── Keyboard.cs │ ├── Mouse.cs │ └── MouseCursor.cs ├── Media │ └── Movie.cs ├── Physics │ ├── ColliderVisualization.cs │ └── Collision.cs ├── Sample.csproj ├── Sample.sln ├── Serialization │ └── Serialization.cs ├── ShapeNode │ └── ShapeNode.cs ├── Sound │ ├── BGM.cs │ ├── LoopingBGM.cs │ ├── SE.cs │ └── Spectrum.cs ├── Transition │ └── Transition.cs └── Viewer.cs ├── Test ├── .editorconfig ├── Async.cs ├── Camera.cs ├── Collider.cs ├── DrawnNode.cs ├── Engine.cs ├── Graphics.cs ├── IO.cs ├── Input.cs ├── Math.cs ├── Movie.cs ├── Node.cs ├── PartsTreeSystem.cs ├── PostEffectNode.cs ├── Profiler.cs ├── ReflectionSerialize.cs ├── ReflectionSources.cs ├── Serialization.cs ├── ShapeNodes.cs ├── Sound.cs ├── Test.csproj ├── TestCore.cs ├── Tool.cs └── Window.cs ├── TestForMacLinux ├── .editorconfig ├── Options.cs ├── Program.cs └── TestForMacLinux.csproj ├── TestSubstitute.sln ├── TestSubstitute ├── .editorconfig ├── Assert.cs ├── Log.txt ├── Program.cs └── TestSubstitute.csproj ├── Tool └── Altseed2.Tools │ ├── .editorconfig │ ├── Altseed2.Tools.csproj │ ├── FileCommand.cs │ ├── FontCommand.cs │ ├── GUI │ ├── FilePackageGenerator.cs │ ├── FontGenerator.cs │ └── IGuiApp.cs │ ├── GUICommand.cs │ ├── ISubCommand.cs │ ├── Program.cs │ └── SubCommandAttribute.cs └── scripts ├── BuildCore.bat ├── BuildCore_Mac.sh ├── ForcePull.bat ├── Pull.bat ├── Pull.sh ├── UpdateCore.bat ├── generate_bindings.py └── test_screenshot.py /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | * text eol=crlf encoding=utf-8 3 | *.nuspec text eol=crlf 4 | *.sh text eol=sh 5 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Changes/変更内容 2 | 3 | 4 | 5 | 6 | 7 | 8 | ## Issue 9 | 10 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Core"] 2 | path = Core 3 | url = https://github.com/altseed/altseed2.git 4 | [submodule "TestResult"] 5 | path = TestResult 6 | url = https://github.com/altseed/Altseed2-csharp-test-result.git 7 | [submodule "PartsTreeSystem"] 8 | path = PartsTreeSystem 9 | url = https://github.com/effekseer/PartsTreeSystem.git 10 | -------------------------------------------------------------------------------- /Documents/HowToBuild_Ja.md: -------------------------------------------------------------------------------- 1 | # ビルド手順 2 | 3 | ## 必須 4 | - [.NET Core SDK 3.1](https://dotnet.microsoft.com/download/dotnet-core/3.1) 5 | 6 | - その他: [Coreのdocument](../Core/documents/development/HowToBuild_Ja.md)を参照 7 | 8 | ## Build 9 | 10 | ### コアの取得 11 | 12 | - Windows の場合: `scripts/Pull.bat` を実行します。 13 | 14 | - Mac/Linux の場合: `scripts/Pull.sh` を実行します。 15 | 16 | ### コアをビルド 17 | 18 | 次のスクリプトを実行します。 19 | 20 | - Windows の場合: `scripts/BuildCore.bat` 21 | - Mac/Linux の場合: `scripts/BuildCore_Mac.sh` 22 | 23 | ### バインディングを生成 24 | 25 | スクリプト `scripts/generate_bindings.py` を実行します。 26 | 27 | ### エンジンをビルド 28 | 29 | #### Visual Studio 30 | `Alseed2.sln` を開き Engine をビルドします。 31 | 32 | #### CLI 33 | 34 | Debug 35 | ```shell 36 | dotnet build Altseed2.sln 37 | ``` 38 | Release 39 | ```shell 40 | dotnet build Altseed2.sln -c Release 41 | ``` 42 | detail: 43 | [dotnet build - Microsoft Docs](https://docs.microsoft.com/ja-jp/dotnet/core/tools/dotnet-build) 44 | -------------------------------------------------------------------------------- /Documents/HowToDevelop_Ja.md: -------------------------------------------------------------------------------- 1 | # 開発方法 2 | 3 | ## Core を実装 4 | 5 | まずは Core 側 に機能を実装します。 [この辺りを参考に](https://github.com/altseed/Altseed2/blob/master/documents/development/HowToDevelop_Ja.md)。 6 | 7 | ### Bindingを生成 8 | 9 | [やはりこの辺りを参考に](https://github.com/altseed/Altseed2/blob/master/documents/development/HowToDevelop_Ja.md) 、Engine側に公開するメソッドなどについて Binding 定義を追加します。 10 | 11 | 正しく追加できたかを確認するため、Wrapper を生成したうえで、再度 Core をビルドします。ここでビルドができたらコミットして次に進みます。 12 | 13 | ### Engine側に取り込み 14 | 15 | `git submodule update --init --force --merge --remote -- "Core"` などしてコアを取り込みます。ここで、このあとの記述と混ざらないようにするためいったんコミットしておきます。 16 | 17 | ### ビルド 18 | 19 | [ビルド手順](HowToBuild_Ja.md) を参考に、 20 | 21 | - Core のビルド 22 | - Binding の生成 23 | - Engine のビルド 24 | 25 | を行います。 26 | 27 | ### 動作チェック 28 | 29 | ここまでで追加したクラスやメソッドが IntelliSense から見えるか、実際にそれを呼び出すようなコードを書いてみて正常に実行できるかをチェックします。 30 | 31 | ### 単体テストの記述 32 | 33 | 既存のテストをマネしながら書く。 34 | 実行は `テストエクスプローラ` か `dotnet Test` で 35 | 36 | c.f.: 37 | - [テスト エクスプローラーを使用した単体テストの実行とデバッグ - Visual Studio](https://docs.microsoft.com/ja-jp/visualstudio/test/run-unit-tests-with-test-explorer?view=vs-2019) 38 | - [Exploring and Managing Unit Tests Using Test Explorer in Visual Studio - Daily .NET Tips](https://dailydotnettips.com/exploring-and-managing-unit-tests-using-test-explorer-in-visual-studio/) 39 | 40 | ### スクリーンショット比較 41 | 42 | Altseed2では、テストをスクリーンショットで比較しています。 43 | スクリーンショットによる比較の対象を追加する場合は、下記の手順を行います。 44 | 45 | 1. [Altseed2-csharp](https://github.com/altseed/Altseed2-csharp)の CIからtest-resultをダウンロードする。 46 | 47 | 2. ダウンロードしたファイルの中から比較したいスクリーンショットを取得する。 48 | 49 | 3. [TestResult](https://github.com/altseed/Altseed2-csharp-test-result)に比較したいスクリーンショットを追加する。 50 | 51 | 4. Altseed2-csharpのリポジトリのTestResultを更新する。 52 | 53 | 環境ごとにスクリーンショットは細かい部分で異なるので、CIからダウンロードする必要があります。 54 | 比較する場合、実行するたびに表示が変わる内容は実装してはいけません。 55 | 56 | 57 | -------------------------------------------------------------------------------- /Documents/HowToNugetUpdate.md: -------------------------------------------------------------------------------- 1 | # NuGet パッケージ更新方法 2 | 3 | # nuspec ファイルを更新しパッケージを取得 4 | 5 | `Nuget\Altseed2.nuspec` を開き、バージョン番号を更新する。 6 | 7 | ``` 8 | 9 | 10 | 11 | Altseed2 12 | 0.0.3-alpha // <- ココ! 13 | Altseed2 14 | Altseed 15 | ``` 16 | 17 | version の値は適切にインクリメントする。 18 | 19 | それを commit & push して CI でのパッケージ生成が完了するのを待って `nuget.zip` をダウンロードし解凍。 20 | 21 | # NuGet に提出 22 | 23 | 1. NuGet Gallery にログインする。 24 | 1. https://www.nuget.org/packages/manage/upload 25 | 1. `nuget.zip` の中の .nuget ファイルをアップロード 26 | 1. Submit !! 27 | -------------------------------------------------------------------------------- /Engine/.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | end_of_line = crlf 3 | charset = utf-8-bom 4 | insert_final_newline = false 5 | indent_size = 4 6 | indent_style = space 7 | trim_trailing_whitespace = true -------------------------------------------------------------------------------- /Engine/AltseedContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Threading; 4 | 5 | namespace Altseed2 6 | { 7 | /// 8 | /// Altseed2における 9 | /// 10 | internal class AltseedContext : SynchronizationContext 11 | { 12 | private readonly struct Entry 13 | { 14 | private readonly SendOrPostCallback d; 15 | private readonly object state; 16 | 17 | internal Entry(SendOrPostCallback d, object state) 18 | { 19 | this.d = d ?? throw new ArgumentNullException(nameof(d), "引数がnullです"); 20 | this.state = state; 21 | } 22 | 23 | internal void Invoke() 24 | { 25 | d.Invoke(state); 26 | } 27 | } 28 | 29 | private readonly ConcurrentQueue actions = new ConcurrentQueue(); 30 | 31 | /// 32 | /// 溜められた処理の個数を取得します。 33 | /// 34 | public int Count => actions.Count; 35 | 36 | /// 37 | /// 更新されるかどうかを取得または設定します。 38 | /// 39 | public bool IsUpdated { get; set; } = true; 40 | 41 | public override void Post(SendOrPostCallback d, object state) 42 | { 43 | actions.Enqueue(new Entry(d, state)); 44 | } 45 | 46 | /// 47 | /// 溜められた処理の実行を行います。 48 | /// 49 | public void Update() 50 | { 51 | if (!IsUpdated) return; 52 | 53 | var count = actions.Count; 54 | for (int i = 0; i < count; i++) 55 | { 56 | if (actions.TryDequeue(out var e)) e.Invoke(); 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Engine/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // The following GUID is for the ID of the typelib if this project is exposed to COM 6 | // [assembly: Guid("2ecbef6c-727d-414d-a3b3-28db476b1fdf")] 7 | 8 | // Version information for an assembly consists of the following four values: 9 | // 10 | // Major Version 11 | // Minor Version 12 | // Build Number 13 | // Revision 14 | // 15 | 16 | [assembly: InternalsVisibleTo("Test")] 17 | [assembly: InternalsVisibleTo("NodeEditor")] -------------------------------------------------------------------------------- /Engine/Collection/ArrayBuffer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Altseed2 3 | { 4 | sealed class ArrayBuffer 5 | { 6 | readonly int _Minimum; 7 | private T[] _Array; 8 | 9 | public ArrayBuffer(int minimum = 1) 10 | { 11 | _Minimum = minimum; 12 | } 13 | 14 | /// 15 | /// 長さ以上の配列を返す。 16 | /// 17 | /// 18 | /// 19 | public T[] GetAsArray(int length) 20 | { 21 | if (length < 1) 22 | { 23 | return _Array ??= new T[_Minimum]; 24 | } 25 | 26 | if (_Array is null) 27 | { 28 | int i = _Minimum; 29 | while (i < length) i *= 2; 30 | _Array = new T[i]; 31 | } 32 | else if (_Array.Length < length) 33 | { 34 | int i = _Array.Length * 2; 35 | while (i < length) i *= 2; 36 | _Array = new T[i]; 37 | } 38 | 39 | return _Array; 40 | } 41 | 42 | /// 43 | /// 長さのSpanを返す。 44 | /// 45 | /// 46 | /// 47 | public Span GetAsSpan(int length) 48 | { 49 | return GetAsArray(length).AsSpan(0, Math.Max(length, 0)); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Engine/Collection/Registerable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Altseed2 4 | { 5 | /// 6 | /// 登録状況を表します。 7 | /// 8 | [Serializable] 9 | public enum RegisteredStatus : int 10 | { 11 | /// 12 | /// 所属なし 13 | /// 14 | Free, 15 | 16 | /// 17 | /// 追加待ち 18 | /// 19 | WaitingAdded, 20 | 21 | /// 22 | /// 所属有り 23 | /// 24 | Registered, 25 | 26 | /// 27 | /// 削除待ち 28 | /// 29 | WaitingRemoved, 30 | } 31 | 32 | /// 33 | /// に登録や削除が可能な要素であることを表します。 34 | /// 35 | [Serializable] 36 | public abstract class Registerable 37 | where T : Registerable 38 | { 39 | /// 40 | /// の新しいインスタンスを生成します。 41 | /// 42 | protected Registerable() { } 43 | 44 | /// 45 | /// 要素がに登録されたとき実行します。 46 | /// 47 | /// 新たなオーナー 48 | internal abstract void Added(T owner); 49 | 50 | /// 51 | /// 要素が親要素から削除されたときに実行します。 52 | /// 53 | internal abstract void Removed(); 54 | 55 | /// 56 | /// 登録状況を取得します。 57 | /// 58 | public virtual RegisteredStatus Status { get; internal set; } = RegisteredStatus.Free; 59 | 60 | /// 61 | /// 親要素 62 | /// 63 | [NonSerialized] 64 | internal T _Parent; 65 | 66 | [NonSerialized] 67 | internal T _ParentReserved; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Engine/Common/ProfilerBlock.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System; 5 | using System.Diagnostics; 6 | using System.Runtime.CompilerServices; 7 | 8 | namespace Altseed2 9 | { 10 | /// 11 | /// プロファイラのブロックを簡単に使用できるようにするクラス 12 | /// 13 | public struct ProfilerBlock : IDisposable 14 | { 15 | /// 16 | /// 測定を開始する。 17 | /// 18 | /// 19 | /// 20 | /// 21 | /// 22 | public ProfilerBlock(string name, Color color, [CallerFilePath] string filepath = null, [CallerLineNumber] int line = 0) 23 | { 24 | if(!Engine.Profiler.IsProfilerRunning) 25 | { 26 | return; 27 | } 28 | 29 | Engine.Profiler.BeginBlock(name, filepath, line, color); 30 | } 31 | 32 | /// 33 | /// 測定を終了する。 34 | /// 35 | public void Dispose() 36 | { 37 | if (!Engine.Profiler.IsProfilerRunning) 38 | { 39 | return; 40 | } 41 | 42 | Engine.Profiler.EndBlock(); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Engine/CorePartial/Configuration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace Altseed2 5 | { 6 | public sealed partial class Configuration 7 | { 8 | #region SerializeName 9 | private const string S_VisibleTransformInfo = "S_VisibleTransformInfo"; 10 | #endregion 11 | 12 | /// 13 | /// 変形に関する情報の表示を取得または設定します。 14 | /// 15 | public bool VisibleTransformInfo 16 | { 17 | get 18 | { 19 | return _VisibleTransformInfo; 20 | } 21 | set 22 | { 23 | if (_VisibleTransformInfo == value) return; 24 | _VisibleTransformInfo = value; 25 | } 26 | } 27 | private bool _VisibleTransformInfo = false; 28 | 29 | /// 30 | /// の新しいインスタンスを生成します。 31 | /// 32 | public Configuration() 33 | { 34 | selfPtr = cbg_Configuration_Create(); 35 | } 36 | 37 | partial void Deserialize_GetPtr(ref IntPtr ptr, SerializationInfo info) 38 | { 39 | ptr = cbg_Configuration_Create(); 40 | } 41 | 42 | partial void OnDeserialize_Constructor(SerializationInfo info, StreamingContext context) 43 | { 44 | VisibleTransformInfo = info.GetBoolean(S_VisibleTransformInfo); 45 | } 46 | 47 | partial void OnGetObjectData(SerializationInfo info, StreamingContext context) 48 | { 49 | info.AddValue(S_VisibleTransformInfo, _VisibleTransformInfo); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Engine/CorePartial/Joystick.cs: -------------------------------------------------------------------------------- 1 | namespace Altseed2 2 | { 3 | public partial class Joystick 4 | { 5 | /// 6 | /// ジョイスティックの最大同時接続数を取得します。 7 | /// 8 | public int MaxCount { get; } = 16; 9 | 10 | /// 11 | /// ボタンの状態をインデックスで取得します。 12 | /// 13 | /// 検索するジョイスティックのインデックス 14 | /// 状態を検索するボタンのインデックス 15 | /// 指定インデックスのボタンの状態 16 | public ButtonState GetButtonState(int joystickIndex, int buttonIndex) 17 | => (ButtonState)cbg_Joystick_GetButtonStateByIndex(selfPtr, joystickIndex, buttonIndex); 18 | 19 | /// 20 | /// ボタンの状態を種類から取得します。 21 | /// 22 | /// 検索するジョイスティックのインデックス 23 | /// 状態を検索するボタンの種類 24 | /// 指定種類のボタンの状態 25 | public ButtonState GetButtonState(int joystickIndex, JoystickButton type) 26 | => (ButtonState)cbg_Joystick_GetButtonStateByType(selfPtr, joystickIndex, (int)type); 27 | 28 | /// 29 | /// 軸の状態をインデックスで取得します。 30 | /// 31 | /// 検索するジョイスティックのインデックス 32 | /// 状態を検索する軸のインデックス 33 | /// 指定インデックスの軸の状態 34 | public float GetAxisState(int joystickIndex, int axisIndex) 35 | => cbg_Joystick_GetAxisStateByIndex(selfPtr, joystickIndex, axisIndex); 36 | 37 | /// 38 | /// 軸の状態を軸の種類で取得します。 39 | /// 40 | /// 検索するジョイスティックのインデックス 41 | /// 状態を検索する軸の種類 42 | /// 指定種類の軸の状態 43 | public float GetAxisState(int joystickIndex, JoystickAxis type) 44 | => cbg_Joystick_GetAxisStateByType(selfPtr, joystickIndex, (int)type); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Engine/CorePartial/Rendered.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace Altseed2 5 | { 6 | internal partial class RenderedCamera 7 | { 8 | partial void OnGetObjectData(SerializationInfo info, StreamingContext context) 9 | { 10 | info.AddValue($"{S_RenderPassParameter}_Fix", RenderPassParameter); 11 | } 12 | 13 | partial void OnDeserialize_Constructor(SerializationInfo info, StreamingContext context) 14 | { 15 | RenderPassParameter = info.GetValue($"{S_RenderPassParameter}_Fix"); 16 | } 17 | 18 | partial void Deserialize_GetPtr(ref IntPtr ptr, SerializationInfo info) 19 | { 20 | ptr = cbg_RenderedCamera_Create(); 21 | } 22 | } 23 | 24 | internal partial class RenderedPolygon 25 | { 26 | /// 27 | /// インデックスバッファーを取得または設定します。 28 | /// 29 | /// 設定しようとした値がnull 30 | public Int32Array Buffers 31 | { 32 | get => _buffers ??= Int32Array.TryGetFromCache(cbg_RenderedPolygon_GetBuffers(selfPtr)); 33 | set 34 | { 35 | _buffers = value ?? throw new ArgumentNullException(nameof(value), "引数がnullです"); 36 | cbg_RenderedPolygon_SetBuffers(selfPtr, value.selfPtr); 37 | } 38 | } 39 | private Int32Array _buffers; 40 | 41 | /// 42 | /// インデックスバッファーを既定のもの設定します。 43 | /// 44 | public void SetDefaultIndexBuffer() 45 | { 46 | cbg_RenderedPolygon_SetDefaultIndexBuffer(selfPtr); 47 | _buffers = null; 48 | } 49 | 50 | partial void Deserialize_GetPtr(ref IntPtr ptr, SerializationInfo info) 51 | { 52 | ptr = cbg_RenderedPolygon_Create(); 53 | } 54 | } 55 | 56 | internal partial class RenderedSprite 57 | { 58 | partial void Deserialize_GetPtr(ref IntPtr ptr, SerializationInfo info) 59 | { 60 | ptr = cbg_RenderedSprite_Create(); 61 | } 62 | } 63 | 64 | internal partial class RenderedText 65 | { 66 | partial void Deserialize_GetPtr(ref IntPtr ptr, SerializationInfo info) 67 | { 68 | ptr = cbg_RenderedText_Create(); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Engine/CorePartial/Texture.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Runtime.Serialization; 4 | using System.Threading.Tasks; 5 | 6 | namespace Altseed2 7 | { 8 | public partial class Texture2D 9 | { 10 | partial void Deserialize_GetPtr(ref IntPtr ptr, SerializationInfo info) 11 | { 12 | Texture2D_Unsetter_Deserialize(info, out var path); 13 | ptr = cbg_Texture2D_Load(path); 14 | } 15 | 16 | /// 17 | /// 指定パスからテクスチャを読み込みます。 18 | /// 19 | /// 読み込むテクスチャのパス 20 | /// が空白文字のみからなる、または使用出来ない文字を含んでいる 21 | /// がnull 22 | /// で指定されたテクスチャが見つからない 23 | /// が指定するパスが見つからない 24 | /// テクスチャが破損または読み込みに失敗 25 | /// をパスに持つテクスチャのデータを格納したの新しいインスタンス 26 | public static Texture2D LoadStrict(string path) 27 | { 28 | var ex = IOHelper.CheckLoadPath(path); 29 | if (ex != null) throw ex; 30 | 31 | return Load(path) ?? throw new SystemException("ファイルが破損していたまたは読み込みに失敗しました"); 32 | } 33 | 34 | /// 35 | /// 非同期読み込みを行います。 36 | /// 37 | /// 読み込むパス 38 | /// がnull 39 | /// のファイルから読み込まれたテクスチャ 40 | public static async Task LoadAsync(string path) 41 | { 42 | return await Task.Run(() => Load(path)); 43 | } 44 | } 45 | 46 | public partial class RenderTexture 47 | { 48 | #region SerializeName 49 | private const string S_Size = "S_Size"; 50 | private const string S_Format = "S_Format"; 51 | #endregion 52 | 53 | partial void Deserialize_GetPtr(ref IntPtr ptr, SerializationInfo info) 54 | { 55 | ptr = cbg_RenderTexture_Create(info.GetValue(S_Size), info.GetValue(S_Format)); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Engine/InternalHelper/IOHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace Altseed2 5 | { 6 | internal static class IOHelper 7 | { 8 | private static char[] InvalidChars => _invalidChars ??= Path.GetInvalidPathChars(); 9 | private static char[] _invalidChars; 10 | /// 11 | /// 12 | /// 13 | /// 14 | /// 15 | /// 16 | internal static Exception CheckLoadPath(string path) 17 | { 18 | if (path == null) return new ArgumentNullException(nameof(path), "引数がnullです"); 19 | if (string.IsNullOrWhiteSpace(path)) return new ArgumentException("パスが空白文字のみからなります", nameof(path)); 20 | if (ContainsInvalidChar(path)) return new ArgumentException("パスに不正な文字が含まれています", nameof(path)); 21 | if (IsTooLongPath(path)) return new PathTooLongException("パスが長すぎます"); 22 | if (!Engine.File.Exists(path)) return new FileNotFoundException($"指定したパスのファイルが見つかりませんでした\nパス:{path}", path); 23 | return null; 24 | } 25 | /// 26 | /// 27 | /// 28 | /// 29 | /// 30 | /// 31 | internal static Exception CheckSavePath(string path) 32 | { 33 | if (path == null) return new ArgumentNullException(nameof(path), "引数がnullです"); 34 | if (string.IsNullOrWhiteSpace(path)) return new ArgumentException("パスが空白文字のみからなります", nameof(path)); 35 | if (ContainsInvalidChar(path)) return new ArgumentException("パスに不正な文字が含まれています", nameof(path)); 36 | if (IsTooLongPath(path)) return new PathTooLongException("パスが長すぎます"); 37 | if (!Directory.Exists(Path.GetDirectoryName(path))) return new DirectoryNotFoundException($"指定したパスのディレクトリが見つかりませんでした\nディレクトリ:{Path.GetDirectoryName(path)}"); 38 | return null; 39 | } 40 | internal static bool ContainsInvalidChar(string path) 41 | { 42 | if (path == null) throw new ArgumentNullException(nameof(path), "引数がnullです"); 43 | return path.IndexOfAny(InvalidChars) >= 0; 44 | } 45 | internal static bool IsTooLongPath(string path) 46 | { 47 | if (path == null) throw new ArgumentNullException(nameof(path), "引数がnullです"); 48 | if (path.Length >= 260) return true; 49 | return Path.GetFileName(path).Length >= 246; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Engine/InternalHelper/SerializationHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace Altseed2 5 | { 6 | internal static class SerializationHelper 7 | { 8 | /// 9 | /// から指定した名前を持つ要素を取得します。 10 | /// 11 | /// 取得する要素の型 12 | /// 要素を取り出すのインスタンス 13 | /// 取り出す要素の名前 14 | /// またはがnull 15 | /// 取り出した要素をにキャストできなかった 16 | /// を持つ要素が見つからなかった 17 | /// に格納されているを持つ要素 18 | internal static T GetValue(this SerializationInfo info, string name) 19 | { 20 | if (info == null) throw new ArgumentNullException(nameof(info), "引数がnullです"); 21 | return (T)info.GetValue(name, typeof(T)); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Engine/Node/IDrawn.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Altseed2 6 | { 7 | /// 8 | /// 描画ノードインターフェース 9 | /// 10 | public interface IDrawn 11 | { 12 | internal void Draw(); 13 | 14 | /// 15 | /// カメラグループを取得または設定します。 16 | /// 17 | ulong CameraGroup { get; set; } 18 | 19 | /// 20 | /// 描画時の重ね順を取得または設定します。 21 | /// 22 | int ZOrder { get; set; } 23 | } 24 | 25 | /// 26 | /// カリング対象ノードインターフェース 27 | /// 28 | public interface ICullableDrawn : IDrawn 29 | { 30 | internal Rendered Rendered { get; } 31 | 32 | internal int CullingId { get; } 33 | 34 | /// 35 | /// このノードを描画するかどうかを取得または設定します。 36 | /// 37 | bool IsDrawn { get; set; } 38 | 39 | /// 40 | /// 先祖のを考慮して、このノードを描画するかどうかを取得します。 41 | /// 42 | bool IsDrawnActually { get; internal set; } 43 | 44 | /// 45 | /// コンテンツのサイズを取得します。 46 | /// 47 | Vector2F ContentSize { get; } 48 | } 49 | 50 | internal static class DrawnExtension 51 | { 52 | /// 53 | /// 自身と子孫ノードの IsDrawnActually プロパティを更新します。 54 | /// 55 | internal static void UpdateIsDrawnActuallyOfDescendants(this T node) 56 | where T : Node, ICullableDrawn 57 | { 58 | static void UpdateRecursive(Node n, bool ancestorsIsDawnActually) 59 | { 60 | var isDrawnActually = ancestorsIsDawnActually; 61 | 62 | if (n is ICullableDrawn dn) 63 | { 64 | isDrawnActually = dn.IsDrawn && ancestorsIsDawnActually; 65 | dn.IsDrawnActually = isDrawnActually; 66 | } 67 | 68 | foreach (var child in n.Children) 69 | { 70 | UpdateRecursive(child, isDrawnActually); 71 | } 72 | } 73 | 74 | var ancestorsIsDrawnActually = node.GetAncestorSpecificNode()?.IsDrawnActually ?? true; 75 | UpdateRecursive(node, ancestorsIsDrawnActually); 76 | } 77 | 78 | internal static void UpdateIsDrawnActuallyFromAncestors(this T node) 79 | where T : Node, ICullableDrawn 80 | { 81 | var ancestorsIsDrawnActually = node.GetAncestorSpecificNode()?.IsDrawnActually ?? true; 82 | node.IsDrawnActually = ancestorsIsDrawnActually && node.IsDrawn; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Engine/Node/PartsTree.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Altseed2 8 | { 9 | /// 10 | /// エディタで編集したノードファイルのインスタンスを生成するシステムです。 11 | /// 12 | public class PartsTree where T : Node 13 | { 14 | enum PartsTreeOriginalType 15 | { 16 | File, 17 | Instance, 18 | } 19 | 20 | /// 21 | /// ノードファイルからを作成します。 22 | /// 23 | /// 24 | public PartsTree(string filepath) 25 | { 26 | nodeTreeGroup = PartsTreeInstantiator.LoadNodeTree(filepath); 27 | type = PartsTreeOriginalType.File; 28 | 29 | //Root node type check 30 | var node = Instantiate(); 31 | if (node.GetType() != typeof(T)) 32 | throw new Exception("This PartsTree's root node type is " + node.GetType().Name + ", not " + typeof(T).Name + "."); 33 | } 34 | 35 | /// 36 | /// ノードのインスタンスからを作成します。 37 | /// 38 | /// 39 | /// 40 | public PartsTree(Node original) 41 | { 42 | throw new NotImplementedException(); 43 | } 44 | 45 | /// 46 | /// 新しいインスタンスを生成し、エンジンに追加します。 47 | /// 48 | public T InstantiateAndAddToEngine() 49 | { 50 | var node = Instantiate(); 51 | Engine.AddNode(node); 52 | return node; 53 | } 54 | 55 | /// 56 | /// 新しいインスタンスを生成します。 57 | /// 58 | /// 59 | /// 60 | public T Instantiate() 61 | { 62 | switch (type) 63 | { 64 | case PartsTreeOriginalType.File: 65 | var node = PartsTreeInstantiator.Instantiate(nodeTreeGroup, environment); 66 | return node as T; 67 | 68 | case PartsTreeOriginalType.Instance: 69 | throw new NotImplementedException(); 70 | 71 | default: 72 | return null; 73 | } 74 | } 75 | 76 | private PartsTreeOriginalType type; 77 | private PartsTreeSystem.NodeTreeGroup nodeTreeGroup; 78 | private PartsTreeSystem.Environment environment = new(); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Engine/Node/PartsTreeInstantiator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Altseed2; 7 | using System.Reflection; 8 | 9 | namespace Altseed2 10 | { 11 | internal static class PartsTreeInstantiator 12 | { 13 | public static PartsTreeSystem.NodeTreeGroup LoadNodeTree(string path) 14 | { 15 | var text = System.IO.File.ReadAllText(path); 16 | var group = PartsTreeSystem.NodeTreeGroup.Deserialize(text); 17 | return group; 18 | } 19 | 20 | public static Node Instantiate(string path) 21 | { 22 | var group = LoadNodeTree(path); 23 | return Instantiate(group); 24 | } 25 | 26 | public static Node Instantiate(PartsTreeSystem.NodeTreeGroup nodeTreeGroup) 27 | { 28 | var env = new PartsTreeSystem.Environment(); 29 | return Instantiate(nodeTreeGroup, env); 30 | } 31 | 32 | public static Node Instantiate(PartsTreeSystem.NodeTreeGroup nodeTreeGroup, PartsTreeSystem.Environment environment) 33 | { 34 | var instance = PartsTreeSystem.Utility.CreateNodeFromNodeTreeGroup(nodeTreeGroup, environment); 35 | 36 | 37 | if (instance.Root is Node node) 38 | { 39 | return node; 40 | } 41 | else 42 | { 43 | throw new Exception(); 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Engine/Node/Physics/ColliderNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Altseed2 4 | { 5 | /// 6 | /// コライダを管理するノード 7 | /// 8 | [Serializable] 9 | public abstract class ColliderNode : TransformNode 10 | { 11 | /// 12 | /// コライダを取得します。 13 | /// 14 | internal abstract Collider Collider { get; } 15 | 16 | internal int _Version { get; private set; } 17 | 18 | /// 19 | /// の新しいインスタンスを生成します。 20 | /// 21 | private protected ColliderNode() { } 22 | 23 | private static CollisionManagerNode SearchManagerFromChildren(Node node) 24 | { 25 | if (node == null) return null; 26 | foreach (var current in node.Children) 27 | if (current is CollisionManagerNode m) 28 | return m; 29 | return null; 30 | } 31 | 32 | internal override void Added(Node owner) 33 | { 34 | base.Added(owner); 35 | SearchManagerFromChildren(owner.Parent)?.AddCollider(this); 36 | } 37 | 38 | private protected static Vector2F CalcScale(Matrix44F transform) 39 | { 40 | var sx = new Vector3F(transform[0, 0], transform[0, 1], transform[0, 2]).Length; 41 | var sy = new Vector3F(transform[1, 0], transform[1, 1], transform[1, 2]).Length; 42 | return new Vector2F(sx, sy); 43 | } 44 | 45 | internal override void Removed() 46 | { 47 | SearchManagerFromChildren(Parent.Parent)?.RemoveCollider(this); 48 | base.Removed(); 49 | } 50 | 51 | internal abstract void UpdateCollider(); 52 | 53 | private protected void UpdateVersion() 54 | { 55 | _Version++; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Engine/Node/Physics/ColliderVisualizeNodeFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Altseed2 4 | { 5 | /// 6 | /// の当たり判定範囲として描画されるノードを提供するクラス 7 | /// 8 | [Serializable] 9 | public static class ColliderVisualizeNodeFactory 10 | { 11 | internal readonly static int VertNum = 64; 12 | internal readonly static Color AreaColor = new Color(255, 100, 100, 100); 13 | 14 | /// 15 | /// 指定したの当たり判定領域を表示するノードを生成します。 16 | /// 17 | /// 使用するコライダノード 18 | /// 19 | /// の型がサポートされていない型である 20 | /// (若しくはそれらから派生した型ではない) 21 | /// 22 | /// Graphics機能が初期化されていない。 23 | /// がnull 24 | /// の当たり領域を表示するノード 25 | public static Node Create(ColliderNode colliderNode) 26 | { 27 | if (!Engine.Config.EnabledCoreModules.HasFlag(CoreModules.Graphics)) 28 | { 29 | throw new InvalidOperationException("Graphics機能が初期化されていません。"); 30 | } 31 | 32 | if (colliderNode == null) throw new ArgumentNullException(nameof(colliderNode), "引数がnullです"); 33 | 34 | return colliderNode switch 35 | { 36 | CircleColliderNode c => new CircleColliderVisualizeNode(c), 37 | PolygonColliderNode p => new PolygonColliderVisualizeNode(p), 38 | RectangleColliderNode r => new RectangleColliderVisualizeNode(r), 39 | EdgeColliderNode e => new EdgeColliderVisualizeNode(e), 40 | _ => throw new ArgumentException($"サポートされていない型です\n型:{colliderNode.GetType()}", nameof(colliderNode)) 41 | }; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Engine/Node/PostEffect/PostEffectGaussianBlurNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Altseed2 4 | { 5 | /// 6 | /// ガウスぼかしを適用するポストエフェクトのクラス 7 | /// 8 | public sealed class PostEffectGaussianBlurNode : PostEffectNode 9 | { 10 | private readonly Material materialX; 11 | private readonly Material materialY; 12 | 13 | private float intensity; 14 | 15 | /// 16 | /// ぼけの強さを取得または設定します。 17 | /// 18 | /// 値が大きいほど画面がぼけます。 19 | public float Intensity 20 | { 21 | get => intensity; 22 | set 23 | { 24 | if (intensity == value) return; 25 | 26 | intensity = value; 27 | 28 | float total = 0.0f; 29 | float dispersion = intensity * intensity; 30 | 31 | Span ws = stackalloc float[3]; 32 | 33 | for (int i = 0; i < 3; i++) 34 | { 35 | float pos = 1.0f + 2.0f * i; 36 | ws[i] = MathF.Exp(-0.5f * pos * pos / dispersion); 37 | total += ws[i] * 2.0f; 38 | } 39 | 40 | Vector4F weights = new Vector4F(ws[0], ws[1], ws[2], 0.0f) / total; 41 | 42 | materialX.SetVector4F("weight", weights); 43 | materialY.SetVector4F("weight", weights); 44 | } 45 | } 46 | 47 | /// 48 | /// の新しいインスタンスを生成します。 49 | /// 50 | public PostEffectGaussianBlurNode() 51 | { 52 | materialX = Material.Create(); 53 | materialY = Material.Create(); 54 | 55 | var baseCode = Engine.Graphics.BuiltinShader.GaussianBlurShader; 56 | 57 | materialX.SetShader(Shader.Create("GaussianBlurX", "#define BLUR_X\n" + baseCode, ShaderStage.Pixel)); 58 | materialY.SetShader(Shader.Create("GaussianBlurY", "#define BLUR_Y\n" + baseCode, ShaderStage.Pixel)); 59 | 60 | Intensity = 5.0f; 61 | } 62 | 63 | /// 64 | protected override void Draw(RenderTexture src, Color clearColor) 65 | { 66 | src.WrapMode = TextureWrapMode.Clamp; 67 | 68 | var buffer = GetBuffer(0, src.Size, src.Format); 69 | buffer.WrapMode = TextureWrapMode.Clamp; 70 | buffer.FilterType = TextureFilter.Linear; 71 | 72 | materialX.SetTexture("mainTex", src); 73 | Engine.Graphics.CommandList.RenderToRenderTexture(materialX, buffer, new RenderPassParameter(clearColor, true, true)); 74 | 75 | materialY.SetTexture("mainTex", buffer); 76 | Engine.Graphics.CommandList.RenderToRenderTarget(materialY); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Engine/Node/PostEffect/PostEffectGrayScaleNode.cs: -------------------------------------------------------------------------------- 1 | namespace Altseed2 2 | { 3 | /// 4 | /// グレースケール化を適用するポストエフェクトのクラス 5 | /// 6 | public sealed class PostEffectGrayScaleNode : PostEffectNode 7 | { 8 | readonly Material material; 9 | 10 | /// 11 | /// の新しいインスタンスを生成します。 12 | /// 13 | public PostEffectGrayScaleNode() 14 | { 15 | material = Material.Create(); 16 | var shader = Shader.Create("GrayScale", Engine.Graphics.BuiltinShader.GrayScaleShader, ShaderStage.Pixel); 17 | material.SetShader(shader); 18 | } 19 | 20 | /// 21 | protected override void Draw(RenderTexture src, Color clearColor) 22 | { 23 | material.SetTexture("mainTex", src); 24 | Engine.Graphics.CommandList.RenderToRenderTarget(material); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Engine/Node/PostEffect/PostEffectSepiaNode.cs: -------------------------------------------------------------------------------- 1 | namespace Altseed2 2 | { 3 | /// 4 | /// セピア調にするポストエフェクトのクラス 5 | /// 6 | public sealed class PostEffectSepiaNode : PostEffectNode 7 | { 8 | readonly Material material; 9 | 10 | /// 11 | /// の新しいインスタンスを生成します。 12 | /// 13 | public PostEffectSepiaNode() 14 | { 15 | material = Material.Create(); 16 | var shader = Shader.Create("Sepia", Engine.Graphics.BuiltinShader.SepiaShader, ShaderStage.Pixel); 17 | material.SetShader(shader); 18 | } 19 | 20 | /// 21 | protected override void Draw(RenderTexture src, Color clearColor) 22 | { 23 | material.SetTexture("mainTex", src); 24 | Engine.Graphics.CommandList.RenderToRenderTarget(material); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Engine/Node/RootNode.cs: -------------------------------------------------------------------------------- 1 | namespace Altseed2 2 | { 3 | internal sealed class RootNode : Node/*, ISized*/ 4 | { 5 | //public Vector2F Size => Engine.WindowSize; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Engine/Node/ShapeNodes/RectangleNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Altseed2 4 | { 5 | /// 6 | /// 短形を描画するノードのクラス 7 | /// 8 | [Serializable] 9 | public class RectangleNode : ShapeNode 10 | { 11 | private bool _RequireUpdateVertexes = true; 12 | 13 | /// 14 | /// 色を取得または設定します。 15 | /// 16 | [PartsTreeSystem.SerializeField] 17 | public Color Color 18 | { 19 | get => _Color; 20 | set 21 | { 22 | if (_Color == value) return; 23 | 24 | _Color = value; 25 | _RenderedPolygon.OverwriteVertexesColor(value); 26 | } 27 | } 28 | private Color _Color = new Color(255, 255, 255); 29 | 30 | /// 31 | /// 短形のサイズを取得または設定します。 32 | /// 33 | [PartsTreeSystem.SerializeField] 34 | public Vector2F RectangleSize 35 | { 36 | get => _RectangleSize; 37 | set 38 | { 39 | if (_RectangleSize == value) return; 40 | 41 | _RectangleSize = value; 42 | _RequireUpdateVertexes = true; 43 | } 44 | } 45 | private Vector2F _RectangleSize = new Vector2F(); 46 | 47 | /// 48 | /// の新しいインスタンスを生成します。 49 | /// 50 | public RectangleNode() { } 51 | 52 | private void UpdateVertexes() 53 | { 54 | Span positions = stackalloc Vector2F[4]; 55 | positions[0] = new Vector2F(0.0f, 0.0f); 56 | positions[1] = new Vector2F(0.0f, RectangleSize.Y); 57 | positions[2] = new Vector2F(RectangleSize.X, RectangleSize.Y); 58 | positions[3] = new Vector2F(RectangleSize.X, 0.0f); 59 | 60 | SetVertexes(positions, Color); 61 | } 62 | 63 | internal override void Update() 64 | { 65 | if (_RequireUpdateVertexes) 66 | { 67 | UpdateVertexes(); 68 | _RequireUpdateVertexes = false; 69 | } 70 | 71 | base.Update(); 72 | } 73 | 74 | internal override void ForceUpdate() 75 | { 76 | UpdateVertexes(); 77 | 78 | base.ForceUpdate(); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Engine/Node/TransformerNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Altseed2 6 | { 7 | /// 8 | /// 親ノードの座標変形を制御するノード 9 | /// 10 | [Serializable] 11 | public class TransformerNode : Node 12 | { 13 | /// 14 | /// 親ノードにおける変形行列を取得します。 15 | /// 16 | public virtual Matrix44F Transform { get; } = Matrix44F.Identity; 17 | 18 | /// 19 | /// 親ノードにおける先祖の変形を加味した変形行列を設定します。 20 | /// 21 | public virtual Matrix44F InheritedTransform { get; set; } = Matrix44F.Identity; 22 | 23 | /// 24 | /// 親ノードにおける先祖の変形およびへの変形を加味した最終的な変形行列を取得します。 25 | /// 26 | public virtual Matrix44F AbsoluteTransform { get; set; } = Matrix44F.Identity; 27 | 28 | /// 29 | /// Transformを再度計算するか 30 | /// 31 | protected internal virtual bool RequireCalcTransform { get; set; } = true; 32 | 33 | /// 34 | /// 情報表示 35 | /// 36 | internal protected TransformerNodeInfo TransformerNodeInfo { get; protected set; } 37 | 38 | internal override void Added(Node owner) 39 | { 40 | if (owner is TransformNode transformNode) 41 | { 42 | transformNode.Transfomer = this; 43 | } 44 | 45 | base.Added(owner); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Engine/Node/TransformerNodeInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Altseed2 6 | { 7 | [Serializable] 8 | public abstract class TransformerNodeInfo 9 | { 10 | protected TransformerNode _TransformerNode; 11 | 12 | public TransformerNodeInfo(TransformerNode transformerNode) 13 | { 14 | _TransformerNode = transformerNode; 15 | } 16 | 17 | internal protected virtual void Update() 18 | { 19 | 20 | } 21 | 22 | internal protected virtual void Draw() 23 | { 24 | 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Engine/Physics/CollisionInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Altseed2 4 | { 5 | /// 6 | /// 衝突判定に関する情報を格納したクラス 7 | /// 8 | [Serializable] 9 | public sealed class CollisionInfo 10 | { 11 | /// 12 | /// 衝突の種類を取得します。 13 | /// 14 | public CollisionType CollisionType { get; } 15 | 16 | /// 17 | /// 自身のを取得します。 18 | /// 19 | public ColliderNode SelfCollider { get; } 20 | 21 | /// 22 | /// 衝突相手のを取得します。 23 | /// 24 | public ColliderNode TheirsCollider { get; } 25 | 26 | internal CollisionInfo(ColliderNode selfCollider, ColliderNode theirsCollider, CollisionType type) 27 | { 28 | SelfCollider = selfCollider ?? throw new ArgumentNullException(nameof(selfCollider), "引数がnullです"); 29 | TheirsCollider = theirsCollider ?? throw new ArgumentNullException(nameof(theirsCollider), "引数がnullです"); 30 | CollisionType = type; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Engine/Physics/CollisionManagerNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Altseed2 5 | { 6 | /// 7 | /// 衝突判定を制御するノード 8 | /// 9 | [Serializable] 10 | public class CollisionManagerNode : Node 11 | { 12 | private readonly CollisionCollection collisionCollection = new CollisionCollection(); 13 | 14 | /// 15 | /// 格納されているコライダの個数を取得します。 16 | /// 17 | public int ColliderCount => collisionCollection.Count; 18 | 19 | /// 20 | /// 登録されているコライダを取得します。 21 | /// 22 | public IEnumerable Colliders => collisionCollection; 23 | 24 | /// 25 | /// の新しいインスタンスを生成します。 26 | /// 27 | public CollisionManagerNode() { } 28 | 29 | /// 30 | /// 指定したが格納されているかどうかを返します。 31 | /// 32 | /// 検索する 33 | /// が格納されていたらtrue,それ以外でfalse 34 | public bool ContainsCollider(ColliderNode node) => collisionCollection.Contains(node); 35 | 36 | internal static IEnumerable EnumerateColliderNodes(Node node) 37 | { 38 | foreach (var current in node.Children) 39 | if (current is ColliderNode n) 40 | yield return n; 41 | } 42 | 43 | internal void AddCollider(ColliderNode node) 44 | { 45 | collisionCollection.Add(node); 46 | } 47 | 48 | internal void RemoveCollider(ColliderNode node) 49 | { 50 | collisionCollection.Remove(node); 51 | } 52 | 53 | internal override void Added(Node owner) 54 | { 55 | foreach (var child in owner.Children) 56 | { 57 | if (child != this && child is CollisionManagerNode) throw new InvalidOperationException("既に衝突判定マネージャが格納されており,追加する事が出来ません"); 58 | foreach (var node in EnumerateColliderNodes(child)) 59 | AddCollider(node); 60 | } 61 | base.Added(owner); 62 | } 63 | 64 | internal override void Removed() 65 | { 66 | foreach (var child in Parent.Children) 67 | foreach (var node in EnumerateColliderNodes(child)) 68 | RemoveCollider(node); 69 | base.Removed(); 70 | } 71 | 72 | internal override void Update() 73 | { 74 | base.Update(); 75 | 76 | collisionCollection.Update(); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Engine/Physics/CollisionType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Altseed2 4 | { 5 | /// 6 | /// 衝突のタイプ 7 | /// 8 | [Serializable] 9 | public enum CollisionType : int 10 | { 11 | /// 12 | /// 前フレームでは衝突しておらず,このフレームで衝突している 13 | /// 14 | Enter, 15 | /// 16 | /// 前フレームでは衝突しており,このフレームでも衝突している 17 | /// 18 | Stay, 19 | /// 20 | /// 前フレームでは衝突しており,このフレームで衝突していない 21 | /// 22 | Exit 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Engine/Physics/ICollisionEventReceiver.cs: -------------------------------------------------------------------------------- 1 | namespace Altseed2 2 | { 3 | /// 4 | /// 衝突判定を感知するイベントを提供するインターフェイス 5 | /// 6 | public interface ICollisionEventReceiver 7 | { 8 | /// 9 | /// 衝突を開始した時に呼び出されます。 10 | /// 11 | /// 衝突に関する情報 12 | void OnCollisionEnter(CollisionInfo info); 13 | /// 14 | /// 衝突を終了した時に呼び出されます。 15 | /// 16 | /// 衝突に関する情報 17 | void OnCollisionExit(CollisionInfo info); 18 | /// 19 | /// 衝突が継続している時に呼び出されます。 20 | /// 21 | /// 衝突に関する情報 22 | void OnCollisionStay(CollisionInfo info); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /NodeEditor.Test/NodeEditor.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | Altseed2.NodeEditor.Test 6 | x64 7 | x64 8 | $(SolutionDir)Build\$(Configuration)\ 9 | false 10 | 11 | false 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Attribute/ToolAttributeBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Altseed2 4 | { 5 | [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] 6 | public abstract class ToolAttributeBase : Attribute 7 | { 8 | public string Name { get; } 9 | 10 | public ToolAttributeBase(string name) 11 | { 12 | Name = name; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Attribute/ToolAutoAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Altseed2 6 | { 7 | /// 8 | /// 9 | /// 10 | [System.AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)] 11 | public sealed class ToolAutoAttribute : System.Attribute 12 | { 13 | /// 14 | /// 15 | /// 16 | public ToolAutoAttribute() 17 | { 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Attribute/ToolBoolAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Altseed2 6 | { 7 | /// 8 | /// 9 | /// 10 | [System.AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = true)] 11 | public sealed class ToolBoolAttribute : ToolAttributeBase 12 | { 13 | /// 14 | /// 15 | /// 16 | /// 17 | public ToolBoolAttribute(string name = null) 18 | : base(name) 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Attribute/ToolButtonAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Altseed2 6 | { 7 | /// 8 | /// 9 | /// 10 | [System.AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = true)] 11 | public sealed class ToolButtonAttribute : ToolCommandAttributeBase 12 | { 13 | /// 14 | /// 15 | /// 16 | /// 17 | public ToolButtonAttribute(string name = null) 18 | : base(name) 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Attribute/ToolColorAttribute.cs: -------------------------------------------------------------------------------- 1 | using Altseed2; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Altseed2 7 | { 8 | /// 9 | /// 10 | /// 11 | [System.AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = true)] 12 | public sealed class ToolColorAttribute : ToolAttributeBase 13 | { 14 | /// 15 | /// 16 | /// 17 | public ToolColorEditFlags Flags { get; } 18 | 19 | /// 20 | /// 21 | /// 22 | /// 23 | /// 24 | public ToolColorAttribute(string name = null, ToolColorEditFlags flags = ToolColorEditFlags.AlphaBar) 25 | : base(name) 26 | { 27 | Flags = flags; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Attribute/ToolCommandAttributeBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Altseed2 6 | { 7 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] 8 | public abstract class ToolCommandAttributeBase : Attribute 9 | { 10 | public string Name { get; } 11 | 12 | public ToolCommandAttributeBase(string name = null) 13 | { 14 | Name = name; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Attribute/ToolEnumAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Altseed2 6 | { 7 | /// 8 | /// 9 | /// 10 | [System.AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = true)] 11 | public sealed class ToolEnumAttribute : ToolAttributeBase 12 | { 13 | /// 14 | /// 15 | /// 16 | /// 17 | public ToolEnumAttribute(string name = null) 18 | : base(name) 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Attribute/ToolFloatAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Altseed2 6 | { 7 | 8 | /// 9 | /// 10 | /// 11 | [System.AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = true)] 12 | public sealed class ToolFloatAttribute : ToolAttributeBase 13 | { 14 | /// 15 | /// 16 | /// 17 | public float Speed { get; } 18 | 19 | /// 20 | /// 21 | /// 22 | public float Min { get; } 23 | 24 | /// 25 | /// 26 | /// 27 | public float Max { get; } 28 | 29 | /// 30 | /// 31 | /// 32 | /// 33 | /// 34 | /// 35 | /// 36 | public ToolFloatAttribute(string name = null, float speed = 1, float min = -100, float max = 100) 37 | : base(name) 38 | { 39 | Speed = speed; 40 | Min = min; 41 | Max = max; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Attribute/ToolFontAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Altseed2 6 | { 7 | /// 8 | /// 9 | /// 10 | [System.AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = true)] 11 | public sealed class ToolFontAttribute : ToolAttributeBase 12 | { 13 | /// 14 | /// 15 | /// 16 | /// 17 | public ToolFontAttribute(string name = null) 18 | : base(name) 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Attribute/ToolGroupAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Altseed2 6 | { 7 | /// 8 | /// 9 | /// 10 | [System.AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = true)] 11 | public sealed class ToolGroupAttribute : ToolAttributeBase 12 | { 13 | /// 14 | /// 15 | /// 16 | /// 17 | public ToolGroupAttribute(string name = null) 18 | : base(name) 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Attribute/ToolHiddenAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Altseed2 6 | { 7 | /// 8 | /// 9 | /// 10 | [System.AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = true)] 11 | public sealed class ToolHiddenAttribute : System.Attribute 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Attribute/ToolInputTextAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Altseed2 6 | { 7 | /// 8 | /// 9 | /// 10 | [System.AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = true)] 11 | public sealed class ToolInputTextAttribute : ToolAttributeBase 12 | { 13 | /// 14 | /// 15 | /// 16 | public int MaxLength { get; } 17 | 18 | /// 19 | /// 20 | /// 21 | public bool IsMultiLine { get; } 22 | 23 | /// 24 | /// 25 | /// 26 | /// 27 | /// 28 | /// 29 | public ToolInputTextAttribute(string name = null, bool isMultiLine = false, int maxLength = 1024) 30 | : base(name) 31 | { 32 | IsMultiLine = isMultiLine; 33 | MaxLength = maxLength; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Attribute/ToolIntAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Altseed2 6 | { 7 | /// 8 | /// 9 | /// 10 | [System.AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = true)] 11 | public sealed class ToolIntAttribute : ToolAttributeBase 12 | { 13 | /// 14 | /// 15 | /// 16 | public float Speed { get; } 17 | 18 | /// 19 | /// 20 | /// 21 | public int Min { get; } 22 | 23 | /// 24 | /// 25 | /// 26 | public int Max { get; } 27 | 28 | /// 29 | /// 30 | /// 31 | /// 32 | /// 33 | /// 34 | /// 35 | public ToolIntAttribute(string name = null, float speed = 1, int min = -100, int max = 100) 36 | : base(name) 37 | { 38 | Speed = speed; 39 | Min = min; 40 | Max = max; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Attribute/ToolLabelAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Altseed2 6 | { 7 | /// 8 | /// 9 | /// 10 | [System.AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = true)] 11 | public sealed class ToolLabelAttribute : ToolAttributeBase 12 | { 13 | /// 14 | /// 15 | /// 16 | /// 17 | public ToolLabelAttribute(string name = null) 18 | : base(name) 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Attribute/ToolListAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Altseed2 6 | { 7 | /// 8 | /// 9 | /// 10 | [System.AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = true)] 11 | public sealed class ToolListAttribute : ToolAttributeBase 12 | { 13 | /// 14 | /// 15 | /// 16 | public string ListElementPropertyName { get; } 17 | 18 | /// 19 | /// 20 | /// 21 | public string SelectedItemPropertyName { get; } 22 | 23 | /// 24 | /// 25 | /// 26 | public string AddMethodName { get; } 27 | 28 | /// 29 | /// 30 | /// 31 | public string RemoveMethodName { get; } 32 | 33 | /// 34 | /// 35 | /// 36 | public string SelectedItemIndexPropertyName { get; } 37 | 38 | /// 39 | /// 40 | /// 41 | /// 42 | /// 43 | /// 44 | /// 45 | /// 46 | /// 47 | public ToolListAttribute(string name = null, string listElementPropertyName = null, string selectedItemPropertyName = null, string addMethodName = null, string removeMethodName = null, string selectedItemIndexPropertyName = null) 48 | : base(name) 49 | { 50 | ListElementPropertyName = listElementPropertyName; 51 | SelectedItemPropertyName = selectedItemPropertyName; 52 | AddMethodName = addMethodName; 53 | RemoveMethodName = removeMethodName; 54 | SelectedItemIndexPropertyName = selectedItemIndexPropertyName; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Attribute/ToolPathAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Altseed2 6 | { 7 | /// 8 | /// 9 | /// 10 | [System.AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = true)] 11 | public sealed class ToolPathAttribute : ToolAttributeBase 12 | { 13 | /// 14 | /// 15 | /// 16 | public int MaxLength { get; } 17 | 18 | /// 19 | /// 20 | /// 21 | public string Filter { get; } 22 | 23 | /// 24 | /// 25 | /// 26 | public string DefaultPath { get; } 27 | 28 | /// 29 | /// 30 | /// 31 | public bool IsDirectory { get; } 32 | 33 | /// 34 | /// 35 | /// 36 | public string RootDirectoryPathPropertyName { get; } 37 | 38 | /// 39 | /// 40 | /// 41 | /// 42 | /// 43 | /// 44 | /// 45 | /// 46 | /// 47 | public ToolPathAttribute(string name = null, bool isDirectory = false, string filter = "", string defaultPath = "", int maxLength = 1024, string rootDirectoryPathPropertyName = null) 48 | : base(name) 49 | { 50 | MaxLength = maxLength; 51 | Filter = filter; 52 | DefaultPath = defaultPath; 53 | IsDirectory = isDirectory; 54 | RootDirectoryPathPropertyName = rootDirectoryPathPropertyName; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Attribute/ToolTextureBaseAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Altseed2 6 | { 7 | /// 8 | /// 9 | /// 10 | [System.AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = true)] 11 | public sealed class ToolTextureBaseAttribute : ToolAttributeBase 12 | { 13 | /// 14 | /// 15 | /// 16 | /// 17 | public ToolTextureBaseAttribute(string name = null) 18 | : base(name) 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Attribute/ToolUserAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Altseed2 6 | { 7 | /// 8 | /// 9 | /// 10 | [System.AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = true)] 11 | public sealed class ToolUserAttribute : ToolCommandAttributeBase 12 | { 13 | /// 14 | /// 15 | /// 16 | /// 17 | public ToolUserAttribute(string name = null) 18 | : base(name) 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Attribute/ToolVector2FAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Altseed2 6 | { 7 | /// 8 | /// 9 | /// 10 | [System.AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = true)] 11 | public sealed class ToolVector2FAttribute : ToolAttributeBase 12 | { 13 | /// 14 | /// 15 | /// 16 | public float Speed { get; } 17 | 18 | /// 19 | /// 20 | /// 21 | public float Min { get; } 22 | 23 | /// 24 | /// 25 | /// 26 | public float Max { get; } 27 | 28 | /// 29 | /// 30 | /// 31 | /// 32 | /// 33 | /// 34 | /// 35 | public ToolVector2FAttribute(string name = null, float speed = 1, float min = -1000, float max = 1000) 36 | : base(name) 37 | { 38 | Speed = speed; 39 | Min = min; 40 | Max = max; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Element/BoolToolElement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Altseed2.NodeEditor.Model; 3 | 4 | namespace Altseed2 5 | { 6 | /// 7 | /// 向けチェックボックス 8 | /// 9 | public class BoolToolElement : ToolElement 10 | { 11 | /// 12 | /// インスタンスを作成します。 13 | /// 14 | /// 名前 15 | /// バインディング対象オブジェクト 16 | /// バインディング対象プロパティ名 17 | public BoolToolElement(string name, object source, string propertyName) : base(name, source, propertyName) 18 | { 19 | if (!typeof(bool).IsAssignableFrom(PropertyInfo?.PropertyType)) 20 | { 21 | throw new ArgumentException("参照先がbool型ではありません"); 22 | } 23 | } 24 | 25 | /// 26 | public override void Update(Node owner) 27 | { 28 | base.Update(owner); 29 | 30 | if (Source == null || PropertyInfo == null) return; 31 | 32 | bool flag = (bool)PropertyInfo.GetValue(Source); 33 | if (Engine.Tool.Checkbox(Name, ref flag)) 34 | { 35 | PropertyInfo.SetValue(Source, flag); 36 | NodeEditorModel.NotifyEditFields(owner); 37 | } 38 | } 39 | 40 | /// 41 | /// からを作成します。 42 | /// 43 | /// バインディング対象 44 | /// 45 | /// 46 | public static BoolToolElement Create(object source, MemberGuiInfo guiInfo) 47 | { 48 | return new BoolToolElement(guiInfo.Name, source, guiInfo.PropertyName); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Element/ButtonToolElement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using Altseed2.NodeEditor.Model; 4 | 5 | namespace Altseed2 6 | { 7 | /// 8 | /// メソッド実行ボタン 9 | /// 10 | public class ButtonToolElement : ToolElement 11 | { 12 | /// 13 | /// メソッド名 14 | /// 15 | public string MethodName { get; } 16 | 17 | /// 18 | /// MethodNameに対する 19 | /// 20 | public MethodInfo MethodInfo 21 | { 22 | get 23 | { 24 | try 25 | { 26 | return Source?.GetType().GetMethod(MethodName); 27 | } 28 | catch 29 | { 30 | return null; 31 | } 32 | } 33 | } 34 | 35 | /// 36 | /// インスタンスを作成します。 37 | /// 38 | /// 名前 39 | /// バインディング対象オブジェクト 40 | /// バインディング対象プロパティ名 41 | public ButtonToolElement(string name, object source, string methodName) : base(name, source, null) 42 | { 43 | MethodName = methodName; 44 | if (MethodInfo?.GetParameters().Length != 0) 45 | { 46 | throw new ArgumentException("参照するメソッドに引数を入れることはできません"); 47 | } 48 | } 49 | 50 | /// 51 | public override void Update(Node owner) 52 | { 53 | base.Update(owner); 54 | 55 | if (Source == null || MethodInfo == null) return; 56 | 57 | if (Engine.Tool.Button(Name)) 58 | { 59 | MethodInfo?.Invoke(Source, new object[] { }); 60 | NodeEditorModel.NotifyEditFields(owner); 61 | } 62 | } 63 | 64 | /// 65 | /// からを作成します。 66 | /// 67 | /// バインディング対象 68 | /// 69 | /// 70 | public static ButtonToolElement Create(object source, MemberGuiInfo guiInfo) 71 | { 72 | return new ButtonToolElement(guiInfo.Name, source, guiInfo.PropertyName); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Element/ColorToolElement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Altseed2 4 | { 5 | /// 6 | /// 向けUI 7 | /// 8 | public class ColorToolElement : ToolElement 9 | { 10 | /// 11 | ///  12 | /// 13 | public ToolColorEditFlags Flags { get; } 14 | 15 | /// 16 | /// インスタンスを作成します。 17 | /// 18 | /// 名前 19 | /// バインディング対象オブジェクト 20 | /// バインディング対象プロパティ名 21 | /// 22 | public ColorToolElement(string name, object source, string propertyName, ToolColorEditFlags flags = ToolColorEditFlags.AlphaBar) : base(name, source, propertyName) 23 | { 24 | Flags = flags; 25 | 26 | if (!typeof(Color).IsAssignableFrom(PropertyInfo?.PropertyType)) 27 | { 28 | throw new ArgumentException("参照先がColor型ではありません"); 29 | } 30 | } 31 | 32 | /// 33 | public override void Update(Node owner) 34 | { 35 | base.Update(owner); 36 | 37 | if (Source == null || PropertyInfo == null) return; 38 | 39 | Color color = (Color)PropertyInfo.GetValue(Source); 40 | if (Engine.Tool.ColorEdit4(Name, ref color, Flags)) 41 | { 42 | PropertyInfo.SetValue(Source, color); 43 | NodeEditor.Model.NodeEditorModel.NotifyEditFields(owner); 44 | } 45 | } 46 | 47 | /// 48 | /// からを作成します。 49 | /// 50 | /// バインディング対象 51 | /// 52 | /// 53 | public static ColorToolElement Create(object source, MemberGuiInfo guiInfo) 54 | { 55 | var flags = guiInfo.Options.ContainsKey("flags") ? (ToolColorEditFlags)guiInfo.Options["flags"] : ToolColorEditFlags.AlphaBar; 56 | return new ColorToolElement(guiInfo.Name, source, guiInfo.PropertyName, flags); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Element/EnumToolElement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Altseed2 4 | { 5 | /// 6 | /// 7 | /// 8 | public class EnumToolElement : ToolElement 9 | { 10 | /// 11 | /// 12 | /// 13 | /// 14 | /// 15 | /// 16 | public EnumToolElement(string name, object source, string propertyName) : base(name, source, propertyName) 17 | { 18 | if (!(PropertyInfo?.PropertyType.IsEnum ?? true)) 19 | { 20 | throw new ArgumentException("参照先がEnumではありません"); 21 | } 22 | } 23 | 24 | /// 25 | /// 26 | /// 27 | public override void Update(Node owner) 28 | { 29 | base.Update(owner); 30 | 31 | if (Source == null || PropertyInfo == null) return; 32 | 33 | int current = (int)PropertyInfo.GetValue(Source); 34 | if (Engine.Tool.Combo(Name, ref current, Enum.GetNames(PropertyInfo.PropertyType), -1)) 35 | { 36 | PropertyInfo.SetValue(Source, current); 37 | NodeEditor.Model.NodeEditorModel.NotifyEditFields(owner); 38 | } 39 | } 40 | 41 | /// 42 | /// 43 | /// 44 | /// 45 | /// 46 | /// 47 | public static EnumToolElement Create(object source, MemberGuiInfo guiInfo) 48 | { 49 | return new EnumToolElement(guiInfo.Name, source, guiInfo.PropertyName); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Element/FloatToolElement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Altseed2 4 | { 5 | /// 6 | /// 7 | /// 8 | public class FloatToolElement : ToolElement 9 | { 10 | /// 11 | /// 12 | /// 13 | public float Speed { get; } 14 | 15 | /// 16 | /// 17 | /// 18 | public float Min { get; } 19 | 20 | /// 21 | /// 22 | /// 23 | public float Max { get; } 24 | 25 | /// 26 | /// 27 | /// 28 | /// 29 | /// 30 | /// 31 | /// 32 | /// 33 | /// 34 | public FloatToolElement(string name, object source, string propertyName, float speed = 1, float min = -100, float max = 100) : base(name, source, propertyName) 35 | { 36 | Speed = speed; 37 | Min = min; 38 | Max = max; 39 | 40 | if (!typeof(float).IsAssignableFrom(PropertyInfo?.PropertyType)) 41 | { 42 | throw new ArgumentException("参照先がfloat型ではありません"); 43 | } 44 | } 45 | 46 | /// 47 | /// 48 | /// 49 | public override void Update(Node owner) 50 | { 51 | base.Update(owner); 52 | 53 | if (Source == null || PropertyInfo == null) return; 54 | 55 | float num = (float)PropertyInfo.GetValue(Source); 56 | if (Engine.Tool.DragFloat(Name, ref num, Speed, Min, Max, "%.1f", ToolSliderFlags.None)) 57 | { 58 | PropertyInfo.SetValue(Source, num); 59 | NodeEditor.Model.NodeEditorModel.NotifyEditFields(owner); 60 | } 61 | else 62 | { 63 | //huga 64 | } 65 | } 66 | 67 | /// 68 | /// 69 | /// 70 | /// 71 | /// 72 | /// 73 | public static FloatToolElement Create(object source, MemberGuiInfo guiInfo) 74 | { 75 | var speed = guiInfo.Options.ContainsKey("speed") ? (float)guiInfo.Options["speed"] : 1f; 76 | var min = guiInfo.Options.ContainsKey("min") ? (float)guiInfo.Options["min"] : -100f; 77 | var max = guiInfo.Options.ContainsKey("max") ? (float)guiInfo.Options["max"] : 100f; 78 | return new FloatToolElement(guiInfo.Name, source, guiInfo.PropertyName, speed, min, max); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Element/FontToolElement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Altseed2.NodeEditor.View; 3 | 4 | namespace Altseed2 5 | { 6 | /// 7 | /// 8 | /// 9 | public class FontToolElement : ToolElement 10 | { 11 | /// 12 | /// 13 | /// 14 | /// 15 | /// 16 | /// 17 | public FontToolElement(string name, object source, string propertyName) : base(name, source, propertyName) 18 | { 19 | if (!typeof(Font).IsAssignableFrom(PropertyInfo?.PropertyType)) 20 | { 21 | throw new ArgumentException("参照先がFont型ではありません"); 22 | } 23 | } 24 | 25 | /// 26 | /// 27 | /// 28 | public override void Update(Node owner) 29 | { 30 | base.Update(owner); 31 | 32 | if (Source == null || PropertyInfo == null) return; 33 | 34 | Font font = (Font)PropertyInfo.GetValue(Source); 35 | if (font != null) 36 | { 37 | var glyph = font.GetGlyph((int)'阿'); 38 | if (Engine.Tool.ImageButton(font.GetFontTexture(0), 39 | new Vector2I(80, 80), 40 | new Vector2F(0, 0), 41 | (glyph.Position + glyph.Size).To2F() / glyph.TextureSize, 42 | 5, 43 | new Color(), 44 | new Color(255, 255, 255, 255))) 45 | { 46 | NodeEditorHost.FontBrowserTarget = this; 47 | Engine.Tool.SetWindowFocus("Font Browser"); 48 | NodeEditor.Model.NodeEditorModel.NotifyEditFields(owner); 49 | } 50 | } 51 | else 52 | { 53 | if (Engine.Tool.Button("null")) 54 | { 55 | NodeEditorHost.FontBrowserTarget = this; 56 | Engine.Tool.SetWindowFocus("Font Browser"); 57 | NodeEditor.Model.NodeEditorModel.NotifyEditFields(owner); 58 | } 59 | } 60 | Engine.Tool.SameLine(0, -1); 61 | Engine.Tool.LabelText("Font", Name); 62 | } 63 | 64 | /// 65 | /// 66 | /// 67 | /// 68 | /// 69 | /// 70 | public static FontToolElement Create(object source, MemberGuiInfo guiInfo) 71 | { 72 | return new FontToolElement(guiInfo.Name, source, guiInfo.PropertyName); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Element/InputTextToolElement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Altseed2 4 | { 5 | /// 6 | /// 7 | /// 8 | public class InputTextToolElement : ToolElement 9 | { 10 | int MaxLength { get; } 11 | bool IsMultiLine { get; } 12 | 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | /// 20 | /// 21 | public InputTextToolElement(string name, object source, string propertyName, bool isMultiLine = false, int maxLength = 1024) : base(name, source, propertyName) 22 | { 23 | IsMultiLine = isMultiLine; 24 | MaxLength = maxLength; 25 | 26 | if (!typeof(string).IsAssignableFrom(PropertyInfo?.PropertyType)) 27 | { 28 | throw new ArgumentException("参照先がstring型ではありません"); 29 | } 30 | } 31 | 32 | /// 33 | /// 34 | /// 35 | public override void Update(Node owner) 36 | { 37 | base.Update(owner); 38 | 39 | if (Source == null || PropertyInfo == null) return; 40 | 41 | string text = (string)PropertyInfo.GetValue(Source); 42 | if (text == null) 43 | text = ""; 44 | string newStr; 45 | if (IsMultiLine) 46 | { 47 | if ((newStr = Engine.Tool.InputTextMultiline(Name, text, MaxLength, new Vector2F(-1, -1), ToolInputTextFlags.None)) != null) 48 | { 49 | PropertyInfo.SetValue(Source, newStr); 50 | NodeEditor.Model.NodeEditorModel.NotifyEditFields(owner); 51 | } 52 | } 53 | else if ((newStr = Engine.Tool.InputText(Name, text, MaxLength, ToolInputTextFlags.None)) != null) 54 | { 55 | PropertyInfo.SetValue(Source, newStr); 56 | NodeEditor.Model.NodeEditorModel.NotifyEditFields(owner); 57 | } 58 | } 59 | 60 | /// 61 | /// 62 | /// 63 | /// 64 | /// 65 | /// 66 | public static InputTextToolElement Create(object source, MemberGuiInfo guiInfo) 67 | { 68 | var isMultiLine = guiInfo.Options.ContainsKey("isMultiLine") ? (bool)guiInfo.Options["isMultiLine"] : false; 69 | var maxLength = guiInfo.Options.ContainsKey("maxLength") ? (int)guiInfo.Options["maxLength"] : 1024; 70 | return new InputTextToolElement(guiInfo.Name, source, guiInfo.PropertyName, isMultiLine, maxLength); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Element/IntToolElement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Altseed2 4 | { 5 | /// 6 | /// 7 | /// 8 | public class IntToolElement : ToolElement 9 | { 10 | /// 11 | /// 12 | /// 13 | public float Speed { get; } 14 | 15 | /// 16 | /// 17 | /// 18 | public int Min { get; } 19 | 20 | /// 21 | /// 22 | /// 23 | public int Max { get; } 24 | 25 | /// 26 | /// 27 | /// 28 | /// 29 | /// 30 | /// 31 | /// 32 | /// 33 | /// 34 | public IntToolElement(string name, object source, string propertyName, float speed = 1, int min = -100, int max = 100) : base(name, source, propertyName) 35 | { 36 | Speed = speed; 37 | Min = min; 38 | Max = max; 39 | 40 | if (!typeof(int).IsAssignableFrom(PropertyInfo?.PropertyType)) 41 | { 42 | throw new ArgumentException("参照先がint型ではありません"); 43 | } 44 | } 45 | 46 | /// 47 | /// 48 | /// 49 | public override void Update(Node owner) 50 | { 51 | base.Update(owner); 52 | 53 | if (Source == null || PropertyInfo == null) return; 54 | 55 | int num = (int)PropertyInfo.GetValue(Source); 56 | if (Engine.Tool.DragInt(Name, ref num, Speed, Min, Max, "%d", ToolSliderFlags.None)) 57 | { 58 | PropertyInfo.SetValue(Source, num); 59 | NodeEditor.Model.NodeEditorModel.NotifyEditFields(owner); 60 | } 61 | } 62 | 63 | /// 64 | /// 65 | /// 66 | /// 67 | /// 68 | /// 69 | public static IntToolElement Create(object source, MemberGuiInfo guiInfo) 70 | { 71 | var speed = guiInfo.Options.ContainsKey("speed") ? (float)guiInfo.Options["speed"] : 1; 72 | var min = guiInfo.Options.ContainsKey("min") ? (int)guiInfo.Options["min"] : -100; 73 | var max = guiInfo.Options.ContainsKey("max") ? (int)guiInfo.Options["max"] : 100; 74 | return new IntToolElement(guiInfo.Name, source, guiInfo.PropertyName, speed, min, max); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Element/LabelToolElement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Altseed2 4 | { 5 | /// 6 | /// 7 | /// 8 | public class LabelToolElement : ToolElement 9 | { 10 | /// 11 | /// 12 | /// 13 | /// 14 | /// 15 | /// 16 | public LabelToolElement(string name, object source, string propertyName) : base(name, source, propertyName) 17 | { 18 | if (!(PropertyInfo?.CanRead ?? false)) 19 | { 20 | throw new ArgumentException("参照先から読み取れません"); 21 | } 22 | } 23 | 24 | /// 25 | /// 26 | /// 27 | public override void Update(Node ownere) 28 | { 29 | base.Update(ownere); 30 | 31 | if (Source == null || PropertyInfo == null) return; 32 | 33 | string text = PropertyInfo.GetValue(Source)?.ToString() ?? "none"; 34 | Engine.Tool.LabelText(Name, text); 35 | } 36 | 37 | /// 38 | /// 39 | /// 40 | /// 41 | /// 42 | /// 43 | public static LabelToolElement Create(object source, MemberGuiInfo guiInfo) 44 | { 45 | return new LabelToolElement(guiInfo.Name, source, guiInfo.PropertyName); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Element/TextureBaseToolElement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Altseed2.NodeEditor.View; 3 | 4 | namespace Altseed2 5 | { 6 | /// 7 | /// 8 | /// 9 | public class TextureBaseToolElement : ToolElement 10 | { 11 | /// 12 | /// 13 | /// 14 | /// 15 | /// 16 | /// 17 | public TextureBaseToolElement(string name, object source, string propertyName) : base(name, source, propertyName) 18 | { 19 | if (!typeof(TextureBase).IsAssignableFrom(PropertyInfo?.PropertyType)) 20 | { 21 | throw new ArgumentException("参照先がTextureBase型ではありません"); 22 | } 23 | } 24 | 25 | /// 26 | /// 27 | /// 28 | public override void Update(Node owner) 29 | { 30 | base.Update(owner); 31 | 32 | if (Source == null || PropertyInfo == null) return; 33 | 34 | TextureBase texture = (TextureBase)PropertyInfo.GetValue(Source); 35 | if (texture != null) 36 | { 37 | if (Engine.Tool.ImageButton(texture, 38 | new Vector2I(80, 80), 39 | new Vector2F(0, 0), 40 | new Vector2F(1, 1), 41 | 5, 42 | new Color(), 43 | new Color(255, 255, 255, 255))) 44 | { 45 | NodeEditorHost.TextureBrowserTarget = this; 46 | Engine.Tool.SetWindowFocus("Texture Browser"); 47 | NodeEditor.Model.NodeEditorModel.NotifyEditFields(owner); 48 | } 49 | } 50 | else 51 | { 52 | if (Engine.Tool.Button("null")) 53 | { 54 | NodeEditorHost.TextureBrowserTarget = this; 55 | Engine.Tool.SetWindowFocus("Texture Browser"); 56 | NodeEditor.Model.NodeEditorModel.NotifyEditFields(owner); 57 | } 58 | } 59 | Engine.Tool.SameLine(0, -1); 60 | Engine.Tool.LabelText("Texture", Name); 61 | } 62 | 63 | /// 64 | /// 65 | /// 66 | /// 67 | /// 68 | /// 69 | public static TextureBaseToolElement Create(object source, MemberGuiInfo guiInfo) 70 | { 71 | return new TextureBaseToolElement(guiInfo.Name, source, guiInfo.PropertyName); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Element/ToolElement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Collections.Generic; 4 | 5 | namespace Altseed2 6 | { 7 | /// 8 | /// 9 | /// 10 | public abstract class ToolElement 11 | { 12 | private readonly WeakReference source; 13 | 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | /// 20 | public ToolElement(string name, object source, string propertyName) 21 | { 22 | Name = name; 23 | this.source = new WeakReference(source); 24 | PropertyName = propertyName; 25 | } 26 | 27 | /// 28 | /// 29 | /// 30 | public virtual void Update(Node owner) { } 31 | 32 | /// 33 | /// 34 | /// 35 | public object Source 36 | { 37 | get 38 | { 39 | if (source.TryGetTarget(out var res)) 40 | return res; 41 | return null; 42 | } 43 | } 44 | 45 | /// 46 | /// 47 | /// 48 | public string PropertyName { get; } 49 | 50 | /// 51 | /// 52 | /// 53 | public string Name { get; } 54 | 55 | /// 56 | /// 57 | /// 58 | public PropertyInfo PropertyInfo 59 | { 60 | get 61 | { 62 | try 63 | { 64 | return Source?.GetType().GetProperty(PropertyName); 65 | } 66 | catch 67 | { 68 | return null; 69 | } 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Element/UserToolElement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace Altseed2 5 | { 6 | /// 7 | /// 8 | /// 9 | public class UserToolElement : ToolElement 10 | { 11 | /// 12 | /// 13 | /// 14 | public string MethodName { get; } 15 | 16 | /// 17 | /// 18 | /// 19 | public MethodInfo MethodInfo 20 | { 21 | get 22 | { 23 | try 24 | { 25 | return Source?.GetType().GetMethod(MethodName); 26 | } 27 | catch 28 | { 29 | return null; 30 | } 31 | } 32 | } 33 | 34 | /// 35 | /// 36 | /// 37 | /// 38 | /// 39 | /// 40 | public UserToolElement(string name, object source, string methodName) : base(name, source, null) 41 | { 42 | MethodName = methodName; 43 | if (MethodInfo?.GetParameters().Length != 0) 44 | { 45 | throw new ArgumentException("参照するメソッドに引数を入れることはできません"); 46 | } 47 | } 48 | 49 | /// 50 | /// 51 | /// 52 | public override void Update(Node owner) 53 | { 54 | base.Update(owner); 55 | Engine.Tool.PushID(MethodInfo.GetHashCode()); 56 | MethodInfo?.Invoke(Source, new object[] { }); 57 | Engine.Tool.PopID(); 58 | } 59 | 60 | /// 61 | /// 62 | /// 63 | /// 64 | /// 65 | /// 66 | public static UserToolElement Create(object source, MemberGuiInfo guiInfo) 67 | { 68 | return new UserToolElement(guiInfo.Name, source, guiInfo.PropertyName); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Element/Vector2FToolElement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Altseed2 4 | { 5 | /// 6 | /// 7 | /// 8 | public class Vector2FToolElement : ToolElement 9 | { 10 | /// 11 | /// 12 | /// 13 | public float Speed { get; } 14 | 15 | /// 16 | /// 17 | /// 18 | public float Min { get; } 19 | 20 | /// 21 | /// 22 | /// 23 | public float Max { get; } 24 | 25 | /// 26 | /// 27 | /// 28 | /// 29 | /// 30 | /// 31 | /// 32 | /// 33 | /// 34 | public Vector2FToolElement(string name, object source, string propertyName, float speed = 1, float min = -1000, float max = 1000) : base(name, source, propertyName) 35 | { 36 | Speed = speed; 37 | Min = min; 38 | Max = max; 39 | 40 | if (!typeof(Vector2F).IsAssignableFrom(PropertyInfo?.PropertyType)) 41 | { 42 | throw new ArgumentException("参照先がVector2Fではありません"); 43 | } 44 | } 45 | 46 | /// 47 | /// 48 | /// 49 | public override void Update(Node owner) 50 | { 51 | base.Update(owner); 52 | 53 | if (Source == null || PropertyInfo == null) return; 54 | 55 | Vector2F vector = (Vector2F)PropertyInfo.GetValue(Source); 56 | float[] vectorArray = new float[2] { vector.X, vector.Y }; 57 | 58 | if (Engine.Tool.DragFloat2(Name, vectorArray, Speed, Min, Max, "%f", ToolSliderFlags.None)) 59 | { 60 | vector.X = vectorArray[0]; 61 | vector.Y = vectorArray[1]; 62 | PropertyInfo.SetValue(Source, vector); 63 | NodeEditor.Model.NodeEditorModel.NotifyEditFields(owner); 64 | } 65 | } 66 | 67 | /// 68 | /// 69 | /// 70 | /// 71 | /// 72 | /// 73 | public static Vector2FToolElement Create(object source, MemberGuiInfo guiInfo) 74 | { 75 | var speed = guiInfo.Options.ContainsKey("speed") ? (float)guiInfo.Options["speed"] : 1; 76 | var min = guiInfo.Options.ContainsKey("min") ? (float)guiInfo.Options["min"] : -1000; 77 | var max = guiInfo.Options.ContainsKey("max") ? (float)guiInfo.Options["max"] : 1000; 78 | return new Vector2FToolElement(guiInfo.Name, source, guiInfo.PropertyName, speed, min, max); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /NodeEditor/GuiTool/Factory/IToolElementTreeFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Altseed2.GuiTool.Repository; 3 | 4 | namespace Altseed2.GuiTool.Factory 5 | { 6 | public interface IToolElementTreeFactory 7 | { 8 | GuiInfoRepository GuiInfoRepository { get; } 9 | IEnumerable CreateToolElements(object source); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /NodeEditor/IEditorPropertyAccessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reactive; 3 | 4 | namespace Altseed2.NodeEditor 5 | { 6 | internal interface IEditorPropertyAccessor 7 | { 8 | Node Selected { get; set; } 9 | float MenuHeight { get; } 10 | 11 | IObservable OnSelectedNodeChanged { get; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NodeEditor/NodeEditor.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | WinExe 5 | net5.0 6 | Altseed2.NodeEditor 7 | x64 8 | x64 9 | $(SolutionDir)Build\$(Configuration)\ 10 | false 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /NodeEditor/Program.cs: -------------------------------------------------------------------------------- 1 | using Altseed2.NodeEditor.View; 2 | using System; 3 | 4 | namespace Altseed2.NodeEditor 5 | { 6 | class Program 7 | { 8 | [STAThread] 9 | static void Main(string[] args) 10 | { 11 | var config = new Configuration() 12 | { 13 | WaitVSync = true, 14 | }; 15 | 16 | NodeEditorHost.Initialize("AltseedEditor", 1280, 960, config); 17 | Engine.ForceNodeUpdate = true; 18 | 19 | while (Engine.DoEvents()) 20 | { 21 | NodeEditorHost.Update(); 22 | } 23 | 24 | NodeEditorHost.Terminate(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /NodeEditor/View/FontBrowserWindow.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Altseed2.NodeEditor.ViewModel; 3 | 4 | namespace Altseed2.NodeEditor.View 5 | { 6 | internal sealed class FontBrowserWindow 7 | { 8 | private readonly FontBrowserViewModel _viewModel; 9 | 10 | public FontBrowserWindow(FontBrowserViewModel viewModel) 11 | { 12 | _viewModel = viewModel; 13 | } 14 | 15 | public bool IsActive => _viewModel.Selected != null; 16 | 17 | public void UpdateFontBrowser() 18 | { 19 | bool pOpen = true; 20 | if (Engine.Tool.Begin("Font Browser", ref pOpen, ToolWindowFlags.None)) 21 | { 22 | Engine.Tool.PushID("Browser".GetHashCode()); 23 | 24 | Engine.Tool.InputInt("Sampling Size", ref _viewModel.SamplingSize, 1, 1, ToolInputTextFlags.None); 25 | Engine.Tool.SameLine(0, -1); 26 | if (Engine.Tool.Button("+")) 27 | { 28 | OpenFont(); 29 | } 30 | 31 | foreach (var item in _viewModel.Options) 32 | { 33 | RenderFontButton(item, () => _viewModel.SetSelection(item)); 34 | } 35 | 36 | if (Engine.Tool.Button("null")) 37 | { 38 | _viewModel.SetSelection(null); 39 | } 40 | 41 | Engine.Tool.PopID(); 42 | 43 | if (!Engine.Tool.IsWindowFocused(ToolFocusedFlags.None)) 44 | { 45 | _viewModel.Selected = null; 46 | } 47 | Engine.Tool.End(); 48 | } 49 | } 50 | 51 | private void OpenFont() 52 | { 53 | if (Engine.Tool.OpenDialog("ttf,otf", "") is { } path) 54 | { 55 | _viewModel.LoadFont(path); 56 | } 57 | } 58 | 59 | private void RenderFontButton(Font font, Action onClick) 60 | { 61 | var glyph = font.GetGlyph((int)'阿'); 62 | if (Engine.Tool.ImageButton(font.GetFontTexture(glyph.TextureIndex), 63 | new Vector2I(80, 80), 64 | new Vector2F(0, 0), 65 | (glyph.Position + glyph.Size).To2F() / glyph.TextureSize, 66 | 5, 67 | new Color(), 68 | new Color(255, 255, 255, 255))) 69 | { 70 | onClick(); 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /NodeEditor/View/NodeEditorPane.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Altseed2.NodeEditor.View 4 | { 5 | internal sealed class NodeEditorPane 6 | { 7 | private readonly string _name; 8 | 9 | private const ToolWindowFlags UiConfig = ToolWindowFlags.None; 10 | 11 | public NodeEditorPane(string name) 12 | { 13 | _name = name; 14 | } 15 | 16 | public void Render(Action onActive, ToolWindowFlags flags = UiConfig) 17 | { 18 | if (Engine.Tool.Begin(_name, flags)) 19 | { 20 | onActive(); 21 | } 22 | Engine.Tool.End(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /NodeEditor/View/PreviewWindow.cs: -------------------------------------------------------------------------------- 1 | using Altseed2.NodeEditor.ViewModel; 2 | 3 | namespace Altseed2.NodeEditor.View 4 | { 5 | internal sealed class PreviewWindow 6 | { 7 | private readonly IEditorPropertyAccessor _accessor; 8 | private readonly PreviewViewModel _viewModel; 9 | private readonly NodeEditorPane _pane = new NodeEditorPane("Main"); 10 | 11 | private Vector2I _latestWindowSize = Engine.WindowSize; 12 | 13 | public PreviewWindow(IEditorPropertyAccessor accessor, PreviewViewModel viewModel) 14 | { 15 | _accessor = accessor; 16 | _viewModel = viewModel; 17 | 18 | _viewModel.UpdateRenderTexture(true, 19 | RenderTexture.Create(Engine.WindowSize - new Vector2I(600, 18), TextureFormat.R8G8B8A8_UNORM)); 20 | } 21 | 22 | public void Render() 23 | { 24 | Engine.Tool.PushStyleVar(ToolStyleVar.WindowPadding, new Vector2F()); 25 | 26 | _pane.Render(() => 27 | { 28 | AdjustWindowSize(); 29 | _viewModel.IsMainWindowFocus = Engine.Tool.IsWindowFocused(ToolFocusedFlags.None); 30 | 31 | _viewModel.MousePosition = Engine.Mouse.Position + EditorWindowPosition() - (Engine.Tool.GetWindowContentRegionMin() + Engine.Tool.GetWindowPos()); 32 | 33 | Engine.Tool.Image(_viewModel.Main, _viewModel.Main.Size, default, 34 | new Vector2F(1, 1), new Color(255, 255, 255), new Color()); 35 | 36 | }, ToolWindowFlags.NoScrollbar); 37 | 38 | Engine.Tool.PopStyleVar(1); 39 | } 40 | 41 | private void AdjustWindowSize() 42 | { 43 | if (_latestWindowSize != Engine.Tool.GetWindowSize().To2I()) 44 | { 45 | Vector2I texSize = Engine.Tool.GetWindowSize().To2I(); 46 | 47 | _viewModel.UpdateRenderTexture(texSize.X > 0 && texSize.Y > 0, 48 | RenderTexture.Create(texSize, TextureFormat.R8G8B8A8_UNORM)); 49 | 50 | _latestWindowSize = texSize; 51 | } 52 | } 53 | 54 | private Vector2F EditorWindowPosition() 55 | { 56 | var pos = new Vector2F(0, 0); 57 | if (Engine.Tool.BeginMainMenuBar()) 58 | { 59 | pos = Engine.Tool.GetWindowPos(); 60 | Engine.Tool.EndMainMenuBar(); 61 | } 62 | return pos; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /NodeEditor/View/SelectedNodeWindow.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Altseed2.GuiTool.Factory; 4 | using Altseed2.NodeEditor.Model; 5 | 6 | namespace Altseed2.NodeEditor.View 7 | { 8 | internal sealed class SelectedNodeWindow : IDisposable 9 | { 10 | private readonly IEditorPropertyAccessor _accessor; 11 | private readonly IDisposable _subscription; 12 | private readonly NodeEditorPane _pane = new NodeEditorPane("Selected"); 13 | 14 | private IEnumerable _selectedToolElements; 15 | 16 | public SelectedNodeWindow(IEditorPropertyAccessor accessor, IToolElementTreeFactory toolElementTreeFactory) 17 | { 18 | _accessor = accessor; 19 | 20 | _subscription = accessor.OnSelectedNodeChanged.Subscribe( 21 | x => _selectedToolElements = toolElementTreeFactory.CreateToolElements(accessor.Selected)); 22 | } 23 | 24 | public void Render() 25 | { 26 | _pane.Render(() => 27 | { 28 | if(_accessor.Selected != null) 29 | NodeEditorModel.StartEditFields(_accessor.Selected); 30 | if (_selectedToolElements != null) 31 | { 32 | Engine.Tool.PushID("Selected".GetHashCode()); 33 | foreach (var toolElement in _selectedToolElements) 34 | { 35 | Engine.Tool.PushID(toolElement.GetHashCode()); 36 | toolElement.Update(_accessor.Selected); 37 | Engine.Tool.PopID(); 38 | } 39 | Engine.Tool.PopID(); 40 | 41 | } 42 | 43 | if (_accessor.Selected != null) 44 | NodeEditorModel.EndEditFields(_accessor.Selected); 45 | }); 46 | } 47 | 48 | public void Dispose() 49 | { 50 | _subscription.Dispose(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /NodeEditor/View/TextureBrowserWindow.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Altseed2.NodeEditor.ViewModel; 3 | 4 | namespace Altseed2.NodeEditor.View 5 | { 6 | internal sealed class TextureBrowserWindow 7 | { 8 | private readonly TextureBrowserViewModel _viewModel; 9 | 10 | public TextureBrowserWindow(TextureBrowserViewModel viewModel) 11 | { 12 | _viewModel = viewModel; 13 | } 14 | 15 | public bool IsActive => _viewModel.Selected != null; 16 | 17 | public void Render() 18 | { 19 | bool pOpen = true; 20 | if (Engine.Tool.Begin("Texture Browser", ref pOpen, ToolWindowFlags.None)) 21 | { 22 | Engine.Tool.PushID("Browser".GetHashCode()); 23 | if (Engine.Tool.Button("+")) 24 | { 25 | OpenImage(); 26 | } 27 | 28 | foreach (var item in _viewModel.Options) 29 | { 30 | RenderImageButton(item, () => _viewModel.SetSelection(item)); 31 | } 32 | 33 | if (Engine.Tool.Button("null")) 34 | { 35 | _viewModel.SetSelection(null); 36 | } 37 | 38 | Engine.Tool.PopID(); 39 | 40 | if (!Engine.Tool.IsWindowFocused(ToolFocusedFlags.None)) 41 | { 42 | _viewModel.Selected = null; 43 | } 44 | } 45 | Engine.Tool.End(); 46 | } 47 | 48 | private void OpenImage() 49 | { 50 | if (Engine.Tool.OpenDialog("png,jpg,jpeg,psd", "") is { } path) 51 | { 52 | _viewModel.LoadImage(path); 53 | } 54 | } 55 | 56 | private static void RenderImageButton(TextureBase image, Action onClick) 57 | { 58 | if (Engine.Tool.ImageButton(image, 59 | new Vector2F(80, 80), 60 | new Vector2F(0, 0), 61 | new Vector2F(1, 1), 62 | 5, 63 | new Color(), 64 | new Color(255, 255, 255, 255))) 65 | { 66 | onClick(); 67 | } 68 | } 69 | 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /NodeEditor/ViewModel/FontBrowserViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Altseed2.NodeEditor.ViewModel 4 | { 5 | internal sealed class FontBrowserViewModel 6 | { 7 | public List Options { get; } = new List(); 8 | public FontToolElement Selected { get; set; } 9 | public int SamplingSize; 10 | 11 | public void SetSelection(Font item) 12 | { 13 | Selected?.PropertyInfo.SetValue(Selected.Source, item); 14 | Selected = null; 15 | } 16 | 17 | public void LoadFont(string fontPath) 18 | { 19 | var font = Font.LoadDynamicFont(fontPath, SamplingSize); 20 | font.GetGlyph((int) 'a'); 21 | font.GetGlyph((int) 'あ'); 22 | font.GetGlyph((int) '阿'); 23 | Options.Add(font); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /NodeEditor/ViewModel/NodeEditorViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Altseed2.NodeEditor.ViewModel 4 | { 5 | internal sealed class NodeEditorViewModel 6 | { 7 | public NodeEditorViewModel() 8 | { 9 | TextureBrowserViewModel = new TextureBrowserViewModel(); 10 | FontBrowserViewModel = new FontBrowserViewModel(); 11 | PreviewViewModel = new PreviewViewModel(); 12 | } 13 | public TextureBrowserViewModel TextureBrowserViewModel { get; } 14 | public FontBrowserViewModel FontBrowserViewModel { get; } 15 | public PreviewViewModel PreviewViewModel { get; } 16 | 17 | public List TextureOptions => TextureBrowserViewModel.Options; 18 | public List Fonts => FontBrowserViewModel.Options; 19 | public Vector2F MousePosition => PreviewViewModel.MousePosition; 20 | public bool IsMainWindowFocus => PreviewViewModel.IsMainWindowFocus; 21 | 22 | public TextureBaseToolElement TextureBrowserTarget 23 | { 24 | get => TextureBrowserViewModel.Selected; 25 | set => TextureBrowserViewModel.Selected = value; 26 | } 27 | 28 | public FontToolElement FontBrowserTarget 29 | { 30 | get => FontBrowserViewModel.Selected; 31 | set => FontBrowserViewModel.Selected = value; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /NodeEditor/ViewModel/PreviewViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace Altseed2.NodeEditor.ViewModel 2 | { 3 | internal sealed class PreviewViewModel 4 | { 5 | public bool IsMainWindowFocus { get; set; } 6 | public Vector2F MousePosition { get; set; } 7 | public RenderTexture Main { get; set; } 8 | 9 | public void UpdateRenderTexture(bool condition, RenderTexture renderTexture) 10 | { 11 | if (condition) 12 | { 13 | Main = renderTexture; 14 | } 15 | 16 | Engine._DefaultCamera.TargetTexture = Main; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /NodeEditor/ViewModel/TextureBrowserViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Altseed2.NodeEditor.ViewModel 4 | { 5 | internal sealed class TextureBrowserViewModel 6 | { 7 | public List Options { get; } = new List(); 8 | public TextureBaseToolElement Selected { get; set; } 9 | 10 | public void SetSelection(TextureBase item) 11 | { 12 | Selected?.PropertyInfo.SetValue(Selected.Source, item); 13 | Selected = null; 14 | } 15 | 16 | public void LoadImage(string texturePath) 17 | { 18 | if (Texture2D.Load(texturePath) is {} newTexture) 19 | { 20 | Options.Add(newTexture); 21 | } 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Nuget/Altseed2.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Altseed2 5 | 2.2.2 6 | Altseed2 7 | Altseed 8 | LICENSE.txt 9 | https://github.com/altseed/Altseed2-csharp/ 10 | true 11 | Altseed2はマルチプラットフォームな和製ゲームエンジンです。オブジェクト指向を用いて効率的にゲームを組み立てることができます。このパッケージにはゲームエンジンのライブラリ部分のみが含まれます。 12 | Altseed2はマルチプラットフォームな和製ゲームエンジンです。 13 | Copyright (c) 2020 Altseed 14 | ja-JP 15 | Game 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Nuget/license.tools.txt: -------------------------------------------------------------------------------- 1 | --CommandLineParser-- 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2005 - 2015 Giacomo Stelluti Scala & Contributors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | ![Altseed](https://github.com/altseed/Altseed2-csharp/workflows/Altseed/badge.svg) 2 | 3 | # Altseed2-csharp 4 | 5 | ## Altseed2 6 | [Altseed](https://github.com/altseed/Altseed) の後継となるべく開発しているゲームエンジンです。 7 | 8 | [Nugetでインストール](https://www.nuget.org/packages/Altseed2) 9 | 10 | ## 関連リポジトリ 11 | * [altseed/LLGI](https://github.com/altseed/LLGI): C++による各種描画APIの抽象化 12 | * [altseed/Altseed2](https://github.com/altseed/Altseed2): C++による内部実装(Core) 13 | * [altseed/CppBindingGenerator](https://github.com/altseed/CppBindingGenerator): エンジンからCoreを呼び出すためのバインディングコードを自動生成するツール 14 | * [altseed/Altseed2-csharp](https://github.com/altseed/Altseed2-csharp): C#エンジン 15 | * [altseed/Altseed2-document](https://github.com/altseed/Altseed2-document): ウェブサイト用ドキュメント 16 | 17 | ## Issue 18 | 新しいissueは[Altseed2/issues](https://github.com/altseed/Altseed2/issues)に作成してください。 19 | 20 | ## 開発用ドキュメント 21 | 22 | * [ビルド方法](Documents/HowToBuild_Ja.md) 23 | 24 | -------------------------------------------------------------------------------- /Samples/.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | end_of_line = crlf 3 | charset = utf-8-bom 4 | insert_final_newline = false 5 | indent_size = 4 6 | indent_style = space 7 | trim_trailing_whitespace = true -------------------------------------------------------------------------------- /Samples/Demonstration/CollisionDemonstration.cs: -------------------------------------------------------------------------------- 1 | using Altseed2; 2 | 3 | namespace Collider 4 | { 5 | class CollisionDemonstration 6 | { 7 | static void Main(string[] args) 8 | { 9 | // Altseed を初期化します。 10 | Engine.Initialize("~ Altseed2 DEMO ~", 640, 480); 11 | 12 | // 移動するスプライトを作って、エンジンに登録します。 13 | var sprite1 = new CollidableSprite(); 14 | Engine.AddNode(sprite1); 15 | 16 | // 固定するスプライトを作って、エンジンに登録します。 17 | var sprite2 = new CollidableSprite(); 18 | sprite2.Position = new Vector2F(480, 320); 19 | Engine.AddNode(sprite2); 20 | 21 | // コライダを自動処理するノードをシーンに登録します。 22 | var collisionManager = new CollisionManagerNode(); 23 | Engine.AddNode(collisionManager); 24 | 25 | // メインループ。 26 | // Altseed のウインドウが閉じられると終了します。 27 | while (Engine.DoEvents()) 28 | { 29 | // スプライトの描画位置を更新します。 30 | sprite1.Position = Engine.Mouse.Position; 31 | 32 | // Altseed を更新します。 33 | Engine.Update(); 34 | } 35 | 36 | // Altseed の終了処理をします。 37 | Engine.Terminate(); 38 | } 39 | } 40 | 41 | // 衝突判定機能を持ったスプライトを描画するクラス 42 | class CollidableSprite : SpriteNode, ICollisionEventReceiver 43 | { 44 | public CollidableSprite() 45 | { 46 | // テクスチャ・大きさ・中心位置を設定します。 47 | Texture = Texture2D.Load(@"TestData/IO/AltseedPink256.png"); 48 | Scale = new Vector2F(0.4f, 0.4f); 49 | CenterPosition = Texture.Size.To2F() * 0.5f; 50 | 51 | // コライダを作成して子ノードとして登録します。 52 | var colliderNode = new CircleColliderNode(); 53 | colliderNode.Radius = Texture.Size.X * 0.5f; 54 | AddChildNode(colliderNode); 55 | } 56 | 57 | // 衝突が開始された時に実行されます。 58 | void ICollisionEventReceiver.OnCollisionEnter(CollisionInfo info) 59 | { 60 | Color = new Color(255, 50, 50); 61 | } 62 | 63 | // 衝突が継続している時に実行されます。 64 | void ICollisionEventReceiver.OnCollisionStay(CollisionInfo info) { } 65 | 66 | // 衝突が解除された時に実行されます。 67 | void ICollisionEventReceiver.OnCollisionExit(CollisionInfo info) 68 | { 69 | Color = new Color(255, 255, 255); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Samples/Engine/Empty.cs: -------------------------------------------------------------------------------- 1 | using Altseed2; 2 | 3 | class Empty 4 | { 5 | static void Main(string[] args) 6 | { 7 | // Altseed2 を起動する前にいくつかの設定ができます。 8 | var config = new Configuration() 9 | { 10 | // 垂直同期信号を待つかどうかを取得または設定します。 11 | WaitVSync = true, 12 | }; 13 | 14 | // Altseed2 を初期化します。 15 | Engine.Initialize("Empty", 640, 480, config); 16 | 17 | // ここで画像などのデータを読み込んだりノードツリーを作成したりすることができます。 18 | 19 | // メインループ。 20 | // Altseed のウインドウが閉じられると終了します。 21 | while (Engine.DoEvents()) 22 | { 23 | // ここに挙動をべた書きすることも可能です。 24 | 25 | // Altseed を更新します。 26 | Engine.Update(); 27 | } 28 | 29 | // Altseed の終了処理をします。 30 | Engine.Terminate(); 31 | } 32 | } -------------------------------------------------------------------------------- /Samples/File/Package.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | class Package 8 | { 9 | [STAThread] 10 | static void Main(string[] args) 11 | { 12 | // Altseed を初期化します。 13 | if (!Engine.Initialize("SpriteNode", 640, 480)) return; 14 | 15 | // TestData ディレクトリからファイルパッケージを生成します。 16 | Engine.File.Pack("TestData", "Package.pack"); 17 | 18 | // Package.pack をルートパッケージにします。 19 | Engine.File.AddRootPackage("Package.pack"); 20 | 21 | // パッケージに含まれる画像データをロードします。 22 | var texture = Texture2D.Load(@"TestData/IO/AltseedPink256.png"); 23 | 24 | // 画像を描画するノードを生成・登録します。 25 | var node = new SpriteNode(); 26 | node.Texture = texture; 27 | Engine.AddNode(node); 28 | 29 | // メインループ。 30 | // Altseed のウインドウが閉じられると終了します。 31 | while (Engine.DoEvents()) 32 | { 33 | // Altseed を更新します。 34 | Engine.Update(); 35 | } 36 | 37 | // Altseed の終了処理をします。 38 | Engine.Terminate(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Samples/File/PackageFromZip.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | class PackageFromZip 8 | { 9 | [STAThread] 10 | static void Main(string[] args) 11 | { 12 | // Altseed を初期化します。 13 | if (!Engine.Initialize("SpriteNode", 640, 480)) return; 14 | 15 | // Package.zip をルートパッケージにします。 16 | Engine.File.AddRootPackage("Package.zip"); 17 | 18 | // パッケージに含まれる画像データをロードします。 19 | var texture = Texture2D.Load(@"TestData/IO/AltseedPink256.png"); 20 | 21 | // 画像を描画するノードを生成・登録します。 22 | var node = new SpriteNode(); 23 | node.Texture = texture; 24 | Engine.AddNode(node); 25 | 26 | // メインループ。 27 | // Altseed のウインドウが閉じられると終了します。 28 | while (Engine.DoEvents()) 29 | { 30 | // Altseed を更新します。 31 | Engine.Update(); 32 | } 33 | 34 | // Altseed の終了処理をします。 35 | Engine.Terminate(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Samples/File/PackageWithPassword.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | class PackageWithPassword 8 | { 9 | [STAThread] 10 | static void Main(string[] args) 11 | { 12 | // Altseed を初期化します。 13 | if (!Engine.Initialize("SpriteNode", 640, 480)) return; 14 | 15 | // TestData ディレクトリからファイルパッケージを生成します。 16 | // パスワードを ALTSEED とします。 17 | Engine.File.PackWithPassword("TestData", "Package.pack", "ALTSEED"); 18 | 19 | // Package.pack をルートパッケージにします。 20 | Engine.File.AddRootPackageWithPassword("Package.pack", "ALTSEED"); 21 | 22 | // パッケージに含まれる画像データをロードします。 23 | var texture = Texture2D.Load(@"TestData/IO/AltseedPink256.png"); 24 | 25 | // 画像を描画するノードを生成・登録します。 26 | var node = new SpriteNode(); 27 | node.Texture = texture; 28 | Engine.AddNode(node); 29 | 30 | // メインループ。 31 | // Altseed のウインドウが閉じられると終了します。 32 | while (Engine.DoEvents()) 33 | { 34 | // Altseed を更新します。 35 | Engine.Update(); 36 | } 37 | 38 | // Altseed の終了処理をします。 39 | Engine.Terminate(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Samples/File/StaticFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | using Altseed2; 5 | 6 | namespace Sample 7 | { 8 | class FileStaticFile 9 | { 10 | [STAThread] 11 | static void Main(string[] args) 12 | { 13 | // Altseed2 を初期化します。 14 | if (!Engine.Initialize("StaticFile", 640, 480)) return; 15 | 16 | // ファイルを読み込みます。 17 | var staticFile = StaticFile.Create(@"TestData/IO/test.txt"); 18 | 19 | // バイト配列をUTF8として、string型に変換します。 20 | var text = Encoding.UTF8.GetString(staticFile.Buffer); 21 | 22 | // コンソールに出力します。 23 | Console.WriteLine(text); 24 | 25 | // Altseed の終了処理をします。 26 | Engine.Terminate(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Samples/File/StreamFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | using Altseed2; 5 | 6 | namespace Sample 7 | { 8 | class FileStreamFile 9 | { 10 | [STAThread] 11 | static void Main(string[] args) 12 | { 13 | // Altseed2 を初期化します。 14 | if (!Engine.Initialize("StaticFile", 640, 480)) return; 15 | 16 | // ファイルを読み込みます。 17 | var streamFile = StreamFile.Create(@"TestData/IO/test.txt"); 18 | 19 | // メインループ。 20 | // Altseed のウインドウが閉じられると終了します。 21 | while (Engine.DoEvents()) 22 | { 23 | // Altseedを更新します。 24 | Engine.Update(); 25 | 26 | // 1バイト読み込む 27 | var size = streamFile.Read(1); 28 | 29 | // バイト配列をUTF8として、string型に変換します。 30 | var text = Encoding.UTF8.GetString(streamFile.TempBuffer); 31 | 32 | // コンソールに出力します。 33 | Console.WriteLine(text); 34 | 35 | // 新たに読み込んだデータが0なら終了させます。 36 | if (size == 0) break; 37 | } 38 | 39 | // Altseed の終了処理をします。 40 | Engine.Terminate(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Samples/Graphics/Camera.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | class Camera 8 | { 9 | [STAThread] 10 | static void Main(string[] args) 11 | { 12 | const ulong cameraGroup = 0b1; 13 | 14 | // Altseed2 を初期化します。 15 | if (!Engine.Initialize("Camera", 640, 480)) return; 16 | 17 | // SpriteNode を作成します。 18 | // 詳しくは SpriteNode のサンプルを参照してください。 19 | var sprite = new SpriteNode(); 20 | // テクスチャを設定します。 21 | sprite.Texture = Texture2D.Load(@"TestData/IO/AltseedPink256.png"); 22 | sprite.CameraGroup = cameraGroup; 23 | Engine.AddNode(sprite); 24 | 25 | // sprite の座標を設定します。 26 | sprite.Position = new Vector2F(100, 100); 27 | 28 | // カメラノードを作成します。 29 | var camera = new CameraNode(); 30 | 31 | // カメラが映す対象とするグループを設定します。 32 | camera.Group = cameraGroup; 33 | 34 | // カメラが映す箇所の座標を設定します。 35 | camera.Position = new Vector2F(100, 100); 36 | 37 | // カメラノードを登録します。 38 | Engine.AddNode(camera); 39 | 40 | // メインループ。 41 | // Altseed のウインドウが閉じられると終了します。 42 | while (Engine.DoEvents()) 43 | { 44 | // Altseed を更新します。 45 | Engine.Update(); 46 | } 47 | 48 | // Altseed の終了処理をします。 49 | Engine.Terminate(); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Samples/Graphics/CustomPostEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | public class CustomPostEffect 8 | { 9 | [STAThread] 10 | static void Main(string[] args) 11 | { 12 | // Altseed2 を初期化します。 13 | if (!Engine.Initialize("PostEffect - Custom", 640, 480)) return; 14 | 15 | // 画像を表示するノードを作成して登録します。 16 | // 詳しくはSpriteのサンプルを参照してください。 17 | var node = new SpriteNode 18 | { 19 | Texture = Texture2D.Load(@"TestData/Graphics/flower.png"), 20 | Scale = new Vector2F(0.5f, 0.5f) 21 | }; 22 | 23 | Engine.AddNode(node); 24 | 25 | // 自作のポストエフェクトを描画するノードを作成して登録します。 26 | var postEffect = new MyPostEffectNode(); 27 | 28 | Engine.AddNode(postEffect); 29 | 30 | // メインループ。 31 | // Altseed のウインドウが閉じられると終了します。 32 | while (Engine.DoEvents()) 33 | { 34 | // Altseed を更新します。 35 | Engine.Update(); 36 | } 37 | 38 | // Altseed の終了処理をします。 39 | Engine.Terminate(); 40 | } 41 | 42 | class MyPostEffectNode : PostEffectNode 43 | { 44 | const string _HlslCode = @" 45 | struct PS_INPUT 46 | { 47 | float4 Position : SV_POSITION; 48 | float4 Color : COLOR0; 49 | float2 UV1 : UV0; 50 | float2 UV2 : UV1; 51 | }; 52 | 53 | Texture2D mainTex : register(t0); 54 | SamplerState mainSamp : register(s0); 55 | 56 | float4 main(PS_INPUT input) : SV_TARGET 57 | { 58 | // 入力画像のUV画像に対応するピクセルの色を取得します。 59 | float4 color = mainTex.Sample(mainSamp, input.UV1); 60 | 61 | // RGBの値を反転します。 62 | color.xyz = float3(1.0, 1.0, 1.0) - color.xyz; 63 | 64 | // 算出した値を返します。 65 | return color; 66 | }"; 67 | 68 | // ポストエフェクトに使用するマテリアル 69 | private readonly Material _Material; 70 | 71 | public MyPostEffectNode() 72 | { 73 | // マテリアルに使用するシェーダを作成します。 74 | var shader = Shader.Create("Negative", _HlslCode, ShaderStage.Pixel); 75 | 76 | // スプライトを描画するノードを作成します。 77 | _Material = Material.Create(); 78 | 79 | // マテリアルにシェーダを割り当てます。 80 | _Material.SetShader(shader); 81 | } 82 | 83 | protected override void Draw(RenderTexture src, Color clearColor) 84 | { 85 | // マテリアルを入力画像を設定します。 86 | _Material.SetTexture("mainTex", src); 87 | 88 | // マテリアルを適用します。 89 | Engine.Graphics.CommandList.RenderToRenderTarget(_Material); 90 | } 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Samples/Graphics/ImageText.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | public class ImageTextSample 8 | { 9 | [STAThread] 10 | static void Main(string[] args) 11 | { 12 | // Altseed2 を初期化します。 13 | if (!Engine.Initialize("TextNode", 640, 480)) return; 14 | 15 | // フォントファイルを読み込みます。 16 | var font = Font.LoadDynamicFont(@"TestData/Font/mplus-1m-regular.ttf", 64); 17 | 18 | // テクスチャ追加対応フォントを作成します。 19 | var imageFont = Font.CreateImageFont(font); 20 | 21 | // 絵文字にする画像を読み込みます。 22 | var textImage = Texture2D.Load(@"TestData/IO/AltseedPink.png"); 23 | 24 | // 特定の文字に対応する絵文字を登録します。 25 | imageFont.AddImageGlyph('○', textImage); 26 | 27 | // テキストを描画するノードを作成します。 28 | var node = new TextNode(); 29 | 30 | // フォントを設定します。 31 | node.Font = imageFont; 32 | 33 | // フォントのサイズを指定します。 34 | node.FontSize = 48; 35 | 36 | // 描画する文字列を設定します。 37 | node.Text = "Altseed2 ○ Altseed2"; 38 | 39 | // ノードを登録します。 40 | Engine.AddNode(node); 41 | 42 | // メインループ。 43 | // Altseed のウインドウが閉じられると終了します。 44 | while (Engine.DoEvents()) 45 | { 46 | // Altseed を更新します。 47 | Engine.Update(); 48 | } 49 | 50 | // Altseed の終了処理をします。 51 | Engine.Terminate(); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Samples/Graphics/Material.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | public class MaterialSample 8 | { 9 | const string _HlslCode = @" 10 | 11 | struct PS_INPUT 12 | { 13 | float4 Position : SV_POSITION; 14 | float4 Color : COLOR0; 15 | float2 UV1 : UV0; 16 | float2 UV2 : UV1; 17 | }; 18 | 19 | Texture2D mainTex : register(t0); 20 | SamplerState mainSamp : register(s0); 21 | 22 | float4 main(PS_INPUT input) : SV_TARGET 23 | { 24 | // 入力画像のUV画像に対応するピクセルの色を取得します。 25 | float4 color = mainTex.Sample(mainSamp, input.UV1); 26 | 27 | // RGBの値を反転します。 28 | color.xyz = float3(1.0) - color.xyz; 29 | 30 | // 算出した値を返します。 31 | return color; 32 | } 33 | 34 | "; 35 | 36 | [STAThread] 37 | static void Main(string[] args) 38 | { 39 | // Altseed2 を初期化します。 40 | if (!Engine.Initialize("TextNode", 640, 480)) return; 41 | 42 | // テクスチャを読み込みます。 43 | var texture = Texture2D.Load(@"TestData/IO/AltseedPink256.png"); 44 | 45 | // マテリアルを作成します。 46 | var material = Material.Create(); 47 | 48 | // マテリアルに使用するシェーダを作成します。 49 | var shader = Shader.Create("Negative", _HlslCode, ShaderStage.Pixel); 50 | 51 | // マテリアルにシェーダを割り当てます。 52 | material.SetShader(shader); 53 | 54 | // 必要な場合、アルファブレンドの種類を割り当てます。 55 | material.AlphaBlend = AlphaBlend.Normal; 56 | 57 | // スプライトを描画するノードを作成します。 58 | var node = new SpriteNode(); 59 | 60 | // テクスチャを設定します。 61 | node.Texture = texture; 62 | 63 | // マテリアルを設定します。 64 | node.Material = material; 65 | 66 | // ノードを登録します。 67 | Engine.AddNode(node); 68 | 69 | // メインループ。 70 | // Altseed のウインドウが閉じられると終了します。 71 | while (Engine.DoEvents()) 72 | { 73 | // Altseed を更新します。 74 | Engine.Update(); 75 | } 76 | 77 | // Altseed の終了処理をします。 78 | Engine.Terminate(); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Samples/Graphics/PostEffectGaussianBlur.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | public class PostEffectGaussianBlur 8 | { 9 | [STAThread] 10 | static void Main(string[] args) 11 | { 12 | // Altseed2 を初期化します。 13 | if (!Engine.Initialize("PostEffect - GaussianBur", 640, 480)) return; 14 | 15 | // 画像を表示するノードを作成して登録します。 16 | // 詳しくはSpriteのサンプルを参照してください。 17 | var node = new SpriteNode 18 | { 19 | Texture = Texture2D.Load(@"TestData/Graphics/flower.png"), 20 | Scale = new Vector2F(0.5f, 0.5f) 21 | }; 22 | 23 | Engine.AddNode(node); 24 | 25 | // ガウスぼかしを適用するポストエフェクトを作成して登録します。 26 | var postEffect = new PostEffectGaussianBlurNode 27 | { 28 | // ガウスぼかしの強さを設定します。 29 | Intensity = 3.0f 30 | }; 31 | 32 | Engine.AddNode(postEffect); 33 | 34 | // メインループ。 35 | // Altseed のウインドウが閉じられると終了します。 36 | while (Engine.DoEvents()) 37 | { 38 | // Altseed を更新します。 39 | Engine.Update(); 40 | } 41 | 42 | // Altseed の終了処理をします。 43 | Engine.Terminate(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Samples/Graphics/PostEffectGrayScale.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | public class PostEffectGrayScale 8 | { 9 | [STAThread] 10 | static void Main(string[] args) 11 | { 12 | // Altseed2 を初期化します。 13 | if (!Engine.Initialize("PostEffect - GrayScale", 640, 480)) return; 14 | 15 | // 画像を表示するノードを作成して登録します。 16 | // 詳しくはSpriteのサンプルを参照してください。 17 | var node = new SpriteNode 18 | { 19 | Texture = Texture2D.Load(@"TestData/Graphics/flower.png"), 20 | Scale = new Vector2F(0.5f, 0.5f) 21 | }; 22 | 23 | Engine.AddNode(node); 24 | 25 | // グレースケールを適用するポストエフェクトを作成して登録します。 26 | var postEffect = new PostEffectGrayScaleNode(); 27 | 28 | Engine.AddNode(postEffect); 29 | 30 | // メインループ。 31 | // Altseed のウインドウが閉じられると終了します。 32 | while (Engine.DoEvents()) 33 | { 34 | // Altseed を更新します。 35 | Engine.Update(); 36 | } 37 | 38 | // Altseed の終了処理をします。 39 | Engine.Terminate(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Samples/Graphics/PostEffectLightBloom.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | public class PostEffectLightBloom 8 | { 9 | [STAThread] 10 | static void Main(string[] args) 11 | { 12 | // Altseed2 を初期化します。 13 | if (!Engine.Initialize("PostEffect - LightBloom", 640, 480)) return; 14 | 15 | // 画像を表示するノードを作成して登録します。 16 | // 詳しくはSpriteのサンプルを参照してください。 17 | var node = new SpriteNode 18 | { 19 | Texture = Texture2D.Load(@"TestData/Graphics/flower.png"), 20 | Scale = new Vector2F(0.5f, 0.5f) 21 | }; 22 | 23 | Engine.AddNode(node); 24 | 25 | // ライトブルームを適用するポストエフェクトを作成して登録します。 26 | var postEffect = new PostEffectLightBloomNode 27 | { 28 | // ライトブルームの強さを設定します。 29 | Intensity = 5.0f, 30 | Threshold = 0.5f 31 | }; 32 | 33 | Engine.AddNode(postEffect); 34 | 35 | // メインループ。 36 | // Altseed のウインドウが閉じられると終了します。 37 | while (Engine.DoEvents()) 38 | { 39 | // Altseed を更新します。 40 | Engine.Update(); 41 | } 42 | 43 | // Altseed の終了処理をします。 44 | Engine.Terminate(); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Samples/Graphics/PostEffectSepia.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | public class PostEffectSepia 8 | { 9 | [STAThread] 10 | static void Main(string[] args) 11 | { 12 | // Altseed2 を初期化します。 13 | if (!Engine.Initialize("PostEffect - Sepia", 640, 480)) return; 14 | 15 | // 画像を表示するノードを作成して登録します。 16 | // 詳しくはSpriteのサンプルを参照してください。 17 | var node = new SpriteNode 18 | { 19 | Texture = Texture2D.Load(@"TestData/Graphics/flower.png"), 20 | Scale = new Vector2F(0.5f, 0.5f) 21 | }; 22 | 23 | Engine.AddNode(node); 24 | 25 | // セピアを適用するポストエフェクトを作成して登録します。 26 | var postEffect = new PostEffectSepiaNode(); 27 | 28 | Engine.AddNode(postEffect); 29 | 30 | // メインループ。 31 | // Altseed のウインドウが閉じられると終了します。 32 | while (Engine.DoEvents()) 33 | { 34 | // Altseed を更新します。 35 | Engine.Update(); 36 | } 37 | 38 | // Altseed の終了処理をします。 39 | Engine.Terminate(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Samples/Graphics/RenderTexture.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | class Camera_RenderTexture 8 | { 9 | [STAThread] 10 | static void Main(string[] args) 11 | { 12 | const ulong cameraGroup = 0b1; 13 | const ulong cameraGroup2 = 0b10; 14 | 15 | // Altseed2 を初期化します。 16 | if (!Engine.Initialize("RenderTexture", 640, 480)) return; 17 | 18 | // SpriteNode を作成します。 19 | // 詳しくは SpriteNode のサンプルを参照してください。 20 | var sprite = new SpriteNode(); 21 | sprite.Texture = Texture2D.Load(@"TestData/IO/AltseedPink256.png"); 22 | sprite.CameraGroup = cameraGroup; 23 | sprite.Scale = new Vector2F(200, 200) / sprite.Texture.Size; 24 | Engine.AddNode(sprite); 25 | 26 | // スクリーンのように描画先にできるテクスチャを作成します。 27 | var renderTexture = RenderTexture.Create(new Vector2I(200, 200), TextureFormat.R8G8B8A8_UNORM); 28 | 29 | // sprite を写してrenderTexture に出力する CameraNode を作成します。 30 | // 詳しくは CameraNode のサンプルを参照してください。 31 | var camera = new CameraNode(); 32 | camera.Group = cameraGroup; 33 | Engine.AddNode(camera); 34 | 35 | // カメラの描画先を設定します。 36 | // null のとき出力先はスクリーンになります。 37 | camera.TargetTexture = renderTexture; 38 | 39 | // 描画する前に TargetTexture を指定色で塗りつぶすかどうかを設定します。 40 | camera.IsColorCleared = true; 41 | 42 | // 塗りつぶす色を設定します。 43 | camera.ClearColor = new Color(100, 100, 100); 44 | 45 | // renderTexture をスクリーンに描画するための SpriteNode を作成します。 46 | var sprite2 = new SpriteNode(); 47 | sprite2.Texture = renderTexture; 48 | sprite2.CameraGroup = cameraGroup2; 49 | Engine.AddNode(sprite2); 50 | 51 | // sprite2 を写してスクリーンに出力するカメラを作成します。 52 | var camera2 = new CameraNode(); 53 | camera2.Group = cameraGroup2; 54 | Engine.AddNode(camera2); 55 | 56 | // メインループ。 57 | // Altseed のウインドウが閉じられると終了します。 58 | while (Engine.DoEvents()) 59 | { 60 | // Altseed を更新します。 61 | Engine.Update(); 62 | } 63 | 64 | // Altseed の終了処理をします。 65 | Engine.Terminate(); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Samples/Graphics/Sprite.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | class Sprite 8 | { 9 | [STAThread] 10 | static void Main(string[] args) 11 | { 12 | // Altseed2 を初期化します。 13 | if (!Engine.Initialize("SpriteNode", 640, 480)) return; 14 | 15 | // テクスチャを読み込みます。 16 | var texture = Texture2D.Load(@"TestData/IO/AltseedPink256.png"); 17 | 18 | // スプライトを描画するノードを作成します。 19 | var node = new SpriteNode(); 20 | 21 | // テクスチャを設定します。 22 | node.Texture = texture; 23 | 24 | // ノードを登録します。 25 | Engine.AddNode(node); 26 | 27 | // メインループ。 28 | // Altseed のウインドウが閉じられると終了します。 29 | while (Engine.DoEvents()) 30 | { 31 | // Altseed を更新します。 32 | Engine.Update(); 33 | } 34 | 35 | // Altseed の終了処理をします。 36 | Engine.Terminate(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Samples/Graphics/Text.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | public class TextSample 8 | { 9 | [STAThread] 10 | static void Main(string[] args) 11 | { 12 | // Altseed2 を初期化します。 13 | if (!Engine.Initialize("TextNode", 640, 480)) return; 14 | 15 | // フォントファイルを読み込みます。 16 | var font = Font.LoadDynamicFont(@"TestData/Font/mplus-1m-regular.ttf", 64); 17 | 18 | // テキストを描画するノードを作成します。 19 | var node = new TextNode(); 20 | 21 | // フォントを設定します。 22 | node.Font = font; 23 | 24 | // フォントサイズ 25 | node.FontSize = 48; 26 | 27 | // 描画する文字列を設定します。 28 | node.Text = "Hello World!"; 29 | 30 | // ノードを登録します。 31 | Engine.AddNode(node); 32 | 33 | // メインループ。 34 | // Altseed のウインドウが閉じられると終了します。 35 | while (Engine.DoEvents()) 36 | { 37 | // Altseed を更新します。 38 | Engine.Update(); 39 | } 40 | 41 | // Altseed の終了処理をします。 42 | Engine.Terminate(); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Samples/Input/Keyboard.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | class Keyboard 8 | { 9 | static void Main(string[] args) 10 | { 11 | // Altseed2 を初期化します。 12 | Engine.Initialize("Keyboard", 640, 480); 13 | 14 | // 状態を出力するための TextNode を作成します。 15 | // 詳細は TextNode のサンプルを参照してください。 16 | var font = Font.LoadDynamicFont("./mplus-1m-regular.ttf", 64); 17 | var textNode = new TextNode(); 18 | textNode.Font = font; 19 | textNode.FontSize = 40; 20 | 21 | while (Engine.DoEvents()) 22 | { 23 | var zState = Engine.Keyboard.GetKeyState(Key.Z); 24 | 25 | // Zキーが押されているかどうかを取得します。 26 | if (zState == ButtonState.Free) 27 | { 28 | textNode.Text = "Zキーを離しています。"; 29 | } 30 | else if (zState == ButtonState.Hold) 31 | { 32 | textNode.Text = "Zキーを押しています。"; 33 | } 34 | else if (zState == ButtonState.Push) 35 | { 36 | textNode.Text = "Zキーを押しました!"; 37 | } 38 | else if (zState == ButtonState.Release) 39 | { 40 | textNode.Text = "Zキーを離しました!"; 41 | } 42 | 43 | Engine.Update(); 44 | } 45 | 46 | Engine.Terminate(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Samples/Input/Mouse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | class Mouse 8 | { 9 | static void Main(string[] args) 10 | { 11 | // Altseed2 を初期化します。 12 | Engine.Initialize("Mouse", 640, 480); 13 | 14 | // 状態を出力するための TextNode を作成します。 15 | // 詳細は TextNode のサンプルを参照してください。 16 | var font = Font.LoadDynamicFont("./mplus-1m-regular.ttf", 64); 17 | var textNode = new TextNode(); 18 | textNode.Font = font; 19 | textNode.FontSize = 40; 20 | 21 | Engine.AddNode(textNode); 22 | 23 | while (Engine.DoEvents()) 24 | { 25 | // マウスの左ボタンが押されているかどうかを取得します。 26 | if (Engine.Mouse.GetMouseButtonState(MouseButton.ButtonLeft) == ButtonState.Hold) 27 | { 28 | textNode.Text = "左ボタンが押されています。"; 29 | } 30 | else 31 | { 32 | textNode.Text = "左ボタンが押されていません。"; 33 | } 34 | 35 | // マウスの座標を取得します。 36 | Vector2F position = Engine.Mouse.Position; 37 | textNode.Text += $"\nポジション(x/y): {position.X} / {position.Y}"; 38 | 39 | // マウスホイールの値を取得します。 40 | textNode.Text += $"\nホイール    : {Engine.Mouse.Wheel}"; 41 | 42 | // マウスモードを取得します。 43 | textNode.Text += $"\nモード     : {Engine.Mouse.CursorMode}"; 44 | 45 | Engine.Update(); 46 | } 47 | 48 | Engine.Terminate(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Samples/Input/MouseCursor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | class MouseCursor 8 | { 9 | static void Main(string[] args) 10 | { 11 | // Altseed2 を初期化します。 12 | Engine.Initialize("MouseCursor", 640, 480); 13 | 14 | // まず、カーソルオブジェクトを生成します。画像の読み込みに失敗するとnullが返ります。 15 | // 引数は、string(png画像のパス), Altseed2.Vector2I(クリック判定の相対座標) です。 16 | var cursor = Cursor.Create("../../Core/TestData/Input/altseed_logo.png", new Vector2I(16, 16)); 17 | 18 | if (cursor != null) 19 | { 20 | // マウスにカーソルをセットします。 21 | Engine.Mouse.CursorImage = cursor; 22 | } 23 | 24 | while (Engine.DoEvents()) 25 | { 26 | Engine.Update(); 27 | } 28 | 29 | Engine.Terminate(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Samples/Media/Movie.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | class Movie 8 | { 9 | [STAThread] 10 | static void Main(string[] args) 11 | { 12 | // Altseed2 を初期化します。 13 | if (!Engine.Initialize("Movie", 640, 480)) return; 14 | 15 | // 空のテクスチャを読み込みます。 16 | var texture = RenderTexture.Create(new Vector2I(640, 480), TextureFormat.R8G8B8A8_UNORM); 17 | 18 | // 映像を読み込みます。 19 | var mediaPlayer = MediaPlayer.Load(@"TestData/Movie/Test1.mp4"); 20 | 21 | // 映像を再生します。 22 | mediaPlayer.Play(false); 23 | 24 | // スプライトを描画するノードを作成します。 25 | var node = new SpriteNode(); 26 | 27 | // テクスチャを設定します。 28 | node.Texture = texture; 29 | 30 | // ノードを登録します。 31 | Engine.AddNode(node); 32 | 33 | // メインループ。 34 | // Altseed のウインドウが閉じられると終了します。 35 | while (Engine.DoEvents()) 36 | { 37 | // 現在の映像を画像に書き込みます。 38 | mediaPlayer.WriteToRenderTexture(texture); 39 | 40 | // Altseed を更新します。 41 | Engine.Update(); 42 | } 43 | 44 | // Altseed の終了処理をします。 45 | Engine.Terminate(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Samples/Physics/ColliderVisualization.cs: -------------------------------------------------------------------------------- 1 | using Altseed2; 2 | 3 | namespace Sample 4 | { 5 | class ColliderVisualization 6 | { 7 | static void Main(string[] args) 8 | { 9 | // Altseed2 を初期化します。 10 | Engine.Initialize("Collision", 640, 480); 11 | 12 | // 衝突判定が行われるノードの親ノードを作成します。 13 | var scene = new Node(); 14 | 15 | // コライダを自動処理するノードをシーンに登録します。 16 | scene.AddChildNode(new CollisionManagerNode()); 17 | 18 | 19 | // 衝突判定を持つSpriteNodeを生成します。 20 | var texture = Texture2D.Load(@"TestData/IO/AltseedPink256.png"); 21 | var sprite = new SpriteNode() 22 | { 23 | Position = new Vector2F(200f, 200f), 24 | Scale = new Vector2F(0.5f, 0.5f), 25 | Texture = texture, 26 | CenterPosition = texture.Size / 2, 27 | }; 28 | 29 | // 円形コライダノードを生成します。 30 | var collider = new CircleColliderNode() 31 | { 32 | Radius = texture.Size.X / 2, 33 | }; 34 | 35 | // colliderの衝突判定を視覚化できるノードを生成します。 36 | var visualizer = ColliderVisualizeNodeFactory.Create(collider); 37 | 38 | // エンジンにノードを追加します。 39 | scene.AddChildNode(sprite); 40 | sprite.AddChildNode(collider); 41 | collider.AddChildNode(visualizer); 42 | Engine.AddNode(scene); 43 | 44 | // メインループ。 45 | // Altseed のウインドウが閉じられると終了します。 46 | while (Engine.DoEvents()) 47 | { 48 | // Altseed を更新します。 49 | Engine.Update(); 50 | } 51 | 52 | // Altseed の終了処理をします。 53 | Engine.Terminate(); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /Samples/Physics/Collision.cs: -------------------------------------------------------------------------------- 1 | using Altseed2; 2 | 3 | using System; 4 | 5 | namespace Sample 6 | { 7 | class Collision 8 | { 9 | static void Main(string[] args) 10 | { 11 | // Altseed2 を初期化します。 12 | Engine.Initialize("Collision", 640, 480); 13 | 14 | // 衝突判定が行われるノードの親ノードを作成します。 15 | var scene = new Node(); 16 | 17 | // コライダを自動処理するノードをシーンに登録します。 18 | scene.AddChildNode(new CollisionManagerNode()); 19 | 20 | // 衝突判定を持つスプライトノードを生成します。 21 | var node1 = new CollidableSprite() 22 | { 23 | Position = new Vector2F(0, 100) 24 | }; 25 | 26 | // 衝突時のイベントを実行する衝突判定を持つスプライトノードを生成します。 27 | var node2 = new EventRaisedCollidableSprite() 28 | { 29 | Position = new Vector2F(300, 100) 30 | }; 31 | 32 | // エンジンにノードを追加します。 33 | scene.AddChildNode(node1); 34 | scene.AddChildNode(node2); 35 | Engine.AddNode(scene); 36 | 37 | // メインループ。 38 | // Altseed のウインドウが閉じられると終了します。 39 | while (Engine.DoEvents()) 40 | { 41 | // 右側に移動させる 42 | node1.Position += new Vector2F(5, 0); 43 | 44 | // Altseed を更新します。 45 | Engine.Update(); 46 | } 47 | 48 | // Altseed の終了処理をします。 49 | Engine.Terminate(); 50 | } 51 | } 52 | 53 | // 衝突判定が行われるノードのクラス 54 | class CollidableSprite : SpriteNode 55 | { 56 | // 円形コライダを持つノード 57 | private readonly CircleColliderNode colliderNode = new CircleColliderNode(); 58 | 59 | // コンストラクタ 60 | public CollidableSprite() 61 | { 62 | // テクスチャを読み込みます。 63 | Texture = Texture2D.Load(@"TestData/IO/AltseedPink256.png"); 64 | 65 | // 半径を設定します。 66 | colliderNode.Radius = Texture.Size.X / 2; 67 | 68 | // 中心を設定します。 69 | CenterPosition = Texture.Size / 2; 70 | 71 | // コライダを登録します。 72 | AddChildNode(colliderNode); 73 | } 74 | } 75 | 76 | // 衝突時の内容を実装できるクラス 77 | class EventRaisedCollidableSprite : CollidableSprite, ICollisionEventReceiver 78 | { 79 | // 衝突が開始された時に実行されます。 80 | void ICollisionEventReceiver.OnCollisionEnter(CollisionInfo info) 81 | { 82 | Color = new Color(255, 50, 50); 83 | } 84 | 85 | // 衝突が継続している時に実行されます。 86 | void ICollisionEventReceiver.OnCollisionStay(CollisionInfo info) 87 | { 88 | Angle++; 89 | } 90 | 91 | // 衝突が解除された時に実行されます。 92 | void ICollisionEventReceiver.OnCollisionExit(CollisionInfo info) 93 | { 94 | Color = new Color(255, 255, 255); 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /Samples/Sample.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net5.0 5 | Sample 6 | WinExe 7 | x64 8 | 9 | Sample.Viewer 10 | Sample 11 | $(SolutionDir)Build\$(Configuration)\ 12 | false 13 | 14 | 15 | 16 | x64 17 | 18 | 19 | 20 | x64 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | PreserveNewest 30 | 31 | 32 | 33 | 34 | PreserveNewest 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Samples/Sample.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "Sample.csproj", "{8C30DF2E-73C4-40AA-8F71-A1D6360E623C}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|x64 = Debug|x64 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {8C30DF2E-73C4-40AA-8F71-A1D6360E623C}.Debug|x64.ActiveCfg = Debug|x64 13 | {8C30DF2E-73C4-40AA-8F71-A1D6360E623C}.Debug|x64.Build.0 = Debug|x64 14 | {8C30DF2E-73C4-40AA-8F71-A1D6360E623C}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {8C30DF2E-73C4-40AA-8F71-A1D6360E623C}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | EndGlobal 18 | -------------------------------------------------------------------------------- /Samples/Serialization/Serialization.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Runtime.Serialization.Formatters.Binary; 4 | using System.Text; 5 | 6 | using Altseed2; 7 | 8 | namespace Sample 9 | { 10 | class Serialization 11 | { 12 | [STAThread] 13 | static void Main(string[] args) 14 | { 15 | // Altseed2 を初期化します。 16 | if (!Engine.Initialize("Serialization", 640, 480)) return; 17 | 18 | // シリアライズ結果を保存するファイルのパス 19 | var path = "SerializeSample.bin"; 20 | 21 | // StaticFileを生成。 22 | var file1 = StaticFile.Create(@"TestData/IO/test.txt"); 23 | 24 | // fileをシリアライズします。 25 | Serialize(path, file1); 26 | 27 | // シリアライズされたfileをデシリアライズします。 28 | var file2 = (StaticFile)DeSerialize(path); 29 | 30 | // バイト配列をUTF8として、string型に変換します。 31 | var text1 = Encoding.UTF8.GetString(file1.Buffer); 32 | var text2 = Encoding.UTF8.GetString(file2.Buffer); 33 | 34 | // テキストをコンソールに出力します。 35 | Console.WriteLine("text1 : {0}", text1); 36 | Console.WriteLine("text2 : {0}", text2); 37 | 38 | // Altseed の終了処理をします。 39 | Engine.Terminate(); 40 | } 41 | 42 | // シリアライズを行うメソッド 43 | static void Serialize(string path, object value) 44 | { 45 | // バイナリシリアライズに使用するフォーマッターを生成。 46 | var formatter = new BinaryFormatter(); 47 | 48 | // シリアライズに使用するストリームを生成。 49 | using var stream = new FileStream(path, FileMode.Create); 50 | 51 | // valueをシリアライズする。 52 | formatter.Serialize(stream, value); 53 | } 54 | 55 | // デシリアライズを行うメソッド 56 | static object DeSerialize(string path) 57 | { 58 | // バイナリデシリアライズに使用するフォーマッターを生成。 59 | var formatter = new BinaryFormatter(); 60 | 61 | // デシリアライズに使用するストリームを生成。 62 | using var stream = new FileStream(path, FileMode.Open); 63 | 64 | // デシリアライズを実行 65 | var result = formatter.Deserialize(stream); 66 | 67 | // デシリアライズの結果を返す。 68 | return result; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Samples/ShapeNode/ShapeNode.cs: -------------------------------------------------------------------------------- 1 | using Altseed2; 2 | 3 | namespace Sample 4 | { 5 | class ShapeNode 6 | { 7 | static void Main(string[] args) 8 | { 9 | // Altseed2 を初期化します。 10 | Engine.Initialize("ShapeNode", 640, 480); 11 | 12 | // 円を描画するノード 13 | var circle = new CircleNode() 14 | { 15 | Color = new Color(255, 100, 100), 16 | Radius = 30f, 17 | Position = new Vector2F(100f, 300f), 18 | VertNum = 30 19 | }; 20 | 21 | // 円弧を描画するノード 22 | var arc = new ArcNode() 23 | { 24 | Color = new Color(100, 255, 100), 25 | Radius = 25f, 26 | Position = new Vector2F(300f, 100f), 27 | StartDegree = 30f, 28 | EndDegree = 150f, 29 | VertNum = 30 30 | }; 31 | 32 | // 直線を描画するノード 33 | var line = new LineNode() 34 | { 35 | Color = new Color(100, 100, 255), 36 | Point1 = new Vector2F(200f, 150f), 37 | Point2 = new Vector2F(400f, 350f), 38 | Thickness = 5f 39 | }; 40 | 41 | // 短形を描画するノード 42 | var rectangle = new RectangleNode() 43 | { 44 | Color = new Color(255, 255, 100), 45 | Position = new Vector2F(300f, 400f), 46 | RectangleSize = new Vector2F(50f, 50f) 47 | }; 48 | 49 | // 三角形を描画するノード 50 | var triangle = new TriangleNode() 51 | { 52 | Color = new Color(255, 100, 255), 53 | Point1 = new Vector2F(50f, 50f), 54 | Point2 = new Vector2F(100f, 50f), 55 | Point3 = new Vector2F(50f, 100f), 56 | }; 57 | 58 | // エンジンにノードを追加します。 59 | Engine.AddNode(circle); 60 | Engine.AddNode(arc); 61 | Engine.AddNode(line); 62 | Engine.AddNode(rectangle); 63 | Engine.AddNode(triangle); 64 | 65 | // メインループ。 66 | // Altseed のウインドウが閉じられると終了します。 67 | while (Engine.DoEvents()) 68 | { 69 | // Altseed を更新します。 70 | Engine.Update(); 71 | } 72 | 73 | // Altseed の終了処理をします。 74 | Engine.Terminate(); 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /Samples/Sound/BGM.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | class SoundBGM 8 | { 9 | static void Main(string[] args) 10 | { 11 | // Altseed2 を初期化します。 12 | Engine.Initialize("Sound_BGM", 640, 480); 13 | 14 | // 音ファイルを読み込みます。 15 | // 効果音の場合は第2引数を true に設定して再生しながら解凍することが推奨されている。 16 | var bgm = Sound.Load(@"TestData\Sound\bgm1.ogg", false); 17 | 18 | // 音を再生します。 19 | var id = Engine.Sound.Play(bgm); 20 | 21 | // メインループ。 22 | // Altseed のウインドウが閉じられると終了します。 23 | while (Engine.DoEvents()) 24 | { 25 | // Altseedを更新します。 26 | Engine.Update(); 27 | 28 | // 音の再生が終了しているか調べる。 29 | if (!Engine.Sound.GetIsPlaying(id)) 30 | { 31 | break; 32 | } 33 | } 34 | 35 | // Altseed の終了処理をします。 36 | Engine.Terminate(); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Samples/Sound/LoopingBGM.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | class SoundLoop 8 | { 9 | static void Main(string[] args) 10 | { 11 | // Altseed2 を初期化します。 12 | Engine.Initialize("Sound_Loop", 640, 480); 13 | 14 | // 音ファイルを読み込みます。 15 | // 効果音の場合は第2引数を true に設定して再生しながら解凍することが推奨されている。 16 | var bgm = Sound.Load(@"TestData\Sound\bgm1.ogg", false); 17 | 18 | // 音のループモードを有効にします。 19 | bgm.IsLoopingMode = true; 20 | 21 | // ループの始端を1秒に、終端を2.5秒にします。 22 | bgm.LoopStartingPoint = 1.0f; 23 | bgm.LoopEndPoint = 2.5f; 24 | 25 | // 音を再生します。 26 | var id = Engine.Sound.Play(bgm); 27 | 28 | // メインループ。 29 | // Altseed のウインドウが閉じられると終了します。 30 | while (Engine.DoEvents()) 31 | { 32 | // Altseedを更新します。 33 | Engine.Update(); 34 | 35 | // 音の再生が終了しているか調べる。 36 | if (!Engine.Sound.GetIsPlaying(id)) 37 | { 38 | break; 39 | } 40 | } 41 | 42 | // Altseed の終了処理をします。 43 | Engine.Terminate(); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Samples/Sound/SE.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | class SoundSE 8 | { 9 | static void Main(string[] args) 10 | { 11 | // Altseed2 を初期化します。 12 | Engine.Initialize("Sound_SE", 640, 480); 13 | 14 | // 音ファイルを読み込みます。 15 | // 効果音の場合は第2引数を true に設定して事前にファイルを解凍することが推奨されている。 16 | var se = Sound.Load(@"TestData\Sound\se1.wav", true); 17 | 18 | // 音を再生します。 19 | var id = Engine.Sound.Play(se); 20 | 21 | // メインループ。 22 | // Altseed のウインドウが閉じられると終了します。 23 | while (Engine.DoEvents()) 24 | { 25 | // Altseedを更新します。 26 | Engine.Update(); 27 | 28 | // 音の再生が終了しているか調べる。 29 | if (!Engine.Sound.GetIsPlaying(id)) 30 | { 31 | break; 32 | } 33 | } 34 | 35 | // Altseed の終了処理をします。 36 | Engine.Terminate(); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Samples/Sound/Spectrum.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Sample 6 | { 7 | class SoundSpectrum 8 | { 9 | static void Main(string[] args) 10 | { 11 | // Altseed2 を初期化します。 12 | Engine.Initialize("Sound_BGM", 640, 480); 13 | 14 | // 音ファイルを読み込みます。 15 | // 効果音の場合は第2引数を true に設定して再生しながら解凍することが推奨されている。 16 | var bgm = Sound.Load(@"TestData\Sound\bgm1.ogg", false); 17 | 18 | // 音を再生します。 19 | var id = Engine.Sound.Play(bgm); 20 | 21 | // スペクトルバーのインスタンスを1024個作成します。 22 | var spectrumBars = new PolygonNode[1024]; 23 | for (int i = 0; i < 1024; ++i) 24 | { 25 | // ※ 640 / 1024 = 0.625 26 | var spectrumBar = new PolygonNode(); 27 | spectrumBar.Position = new Vector2F(i * 0.625f, 1.0f); 28 | Span vertexes = stackalloc Vector2F[4] { 29 | new Vector2F(0.0f, 480.0f), 30 | new Vector2F(0.0f, 480.0f), 31 | new Vector2F(0.625f, 480.0f), 32 | new Vector2F(0.625f, 480.0f), 33 | }; 34 | spectrumBar.SetVertexes(vertexes, new Color(255, 255, 255)); 35 | spectrumBars[i] = spectrumBar; 36 | Engine.AddNode(spectrumBar); 37 | } 38 | 39 | // メインループ。 40 | // Altseed のウインドウが閉じられると終了します。 41 | while (Engine.DoEvents()) 42 | { 43 | // Altseedを更新します。 44 | Engine.Update(); 45 | 46 | // 再生されている音のスペクトル情報を取得します。 47 | // データの長さは2のn乗でなくてはなりません。 48 | var spectrum = Engine.Sound.GetSpectrum(id, 1024, FFTWindow.Rectangular); 49 | 50 | // 取得したスペクトル情報をスペクトルバーに反映させます。 51 | for (int i = 0; i < 1024; ++i) 52 | { 53 | Span vertexes = stackalloc Vector2F[] 54 | { 55 | new Vector2F(0.0f, 480.0f), 56 | new Vector2F(0.0f, 480.0f - spectrum[i]), 57 | new Vector2F(0.625f, 480.0f - spectrum[i]), 58 | new Vector2F(0.625f, 480.0f), 59 | }; 60 | spectrumBars[i].SetVertexes(vertexes, new Color(255, 255, 255)); 61 | } 62 | 63 | // 音の再生が終了しているか調べる。 64 | if (!Engine.Sound.GetIsPlaying(id)) 65 | { 66 | break; 67 | } 68 | } 69 | 70 | // Altseed の終了処理をします。 71 | Engine.Terminate(); 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /Test/.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | end_of_line = crlf 3 | charset = utf-8-bom 4 | insert_final_newline = false 5 | indent_size = 4 6 | indent_style = space 7 | trim_trailing_whitespace = true -------------------------------------------------------------------------------- /Test/Camera.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading; 5 | 6 | using NUnit.Framework; 7 | 8 | namespace Altseed2.Test 9 | { 10 | [TestFixture] 11 | class Camera 12 | { 13 | [Test, Apartment(ApartmentState.STA)] 14 | public void NoRenderTexture() 15 | { 16 | var tc = new TestCore(); 17 | tc.Init(); 18 | 19 | var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png"); 20 | Assert.NotNull(texture); 21 | 22 | var node = new SpriteNode(); 23 | node.Texture = texture; 24 | node.CenterPosition = texture.Size / 2; 25 | node.CameraGroup = 0b1; 26 | Engine.AddNode(node); 27 | 28 | var camera = new CameraNode(); 29 | camera.Position = new Vector2F(100, 0); 30 | camera.Scale = new Vector2F(2, 2); 31 | camera.Group = 0b1; 32 | Engine.AddNode(camera); 33 | 34 | tc.LoopBody(c => 35 | { 36 | node.Angle++; 37 | } 38 | , null); 39 | 40 | tc.End(); 41 | } 42 | 43 | [Test, Apartment(ApartmentState.STA)] 44 | public void _RenderTexture() 45 | { 46 | var tc = new TestCore(); 47 | tc.Init(); 48 | 49 | var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png"); 50 | Assert.NotNull(texture); 51 | 52 | var node = new SpriteNode(); 53 | node.Texture = texture; 54 | node.CenterPosition = texture.Size / 2; 55 | node.Scale = new Vector2F(0.5f, 0.5f); 56 | node.CameraGroup = 0b1; 57 | Engine.AddNode(node); 58 | 59 | var renderTexture = RenderTexture.Create(new Vector2I(200, 200), TextureFormat.R8G8B8A8_UNORM); 60 | var camera = new CameraNode(); 61 | camera.Group = 0b1; 62 | camera.TargetTexture = renderTexture; 63 | Engine.AddNode(camera); 64 | 65 | var node2 = new SpriteNode(); 66 | node2.CameraGroup = 0b10; 67 | node2.Texture = renderTexture; 68 | node2.Position = new Vector2F(300, 300); 69 | Engine.AddNode(node2); 70 | 71 | var camera2 = new CameraNode(); 72 | camera2.Group = 0b10; 73 | Engine.AddNode(camera2); 74 | 75 | tc.LoopBody(c => 76 | { 77 | } 78 | , null); 79 | 80 | tc.End(); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Test/Movie.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.IO; 4 | using NUnit.Framework; 5 | 6 | namespace Altseed2.Test 7 | { 8 | [TestFixture] 9 | public class Movie 10 | { 11 | [Test, Apartment(ApartmentState.STA)] 12 | public void Basic() 13 | { 14 | var tc = new TestCore(); 15 | tc.Init(); 16 | 17 | var texture = RenderTexture.Create(new Vector2I(640, 480), TextureFormat.R8G8B8A8_UNORM); 18 | Assert.NotNull(texture); 19 | 20 | var node = new SpriteNode(); 21 | node.Texture = texture; 22 | Engine.AddNode(node); 23 | 24 | var mp = MediaPlayer.Load(@"TestData/Movie/Test1.mp4"); 25 | mp.Play(false); 26 | 27 | tc.LoopBody(c => 28 | { 29 | mp.WriteToRenderTexture(texture); 30 | } 31 | , null); 32 | 33 | tc.End(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Test/PartsTreeSystem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Threading; 7 | using NUnit.Framework; 8 | using System.Reflection; 9 | 10 | namespace Altseed2.Test 11 | { 12 | [TestFixture] 13 | class PartsTreeSystem 14 | { 15 | [Test, Apartment(ApartmentState.STA)] 16 | public void Instantiate() 17 | { 18 | var tc = new TestCore(); 19 | tc.Init(); 20 | 21 | for(var i = 0; i < 10; i++) 22 | { 23 | var node = PartsTreeInstantiator.Instantiate("TestData/PartsTreeSystem/Parts.nodes"); 24 | Engine.AddNode(node); 25 | } 26 | 27 | tc.LoopBody(null, null); 28 | 29 | tc.End(); 30 | } 31 | 32 | [Test, Apartment (ApartmentState.STA)] 33 | public void PartsTree() 34 | { 35 | var tc = new TestCore(); 36 | tc.Init(); 37 | 38 | var partstree = new PartsTree("TestData/PartsTreeSystem/Parts.nodes"); 39 | 40 | tc.Duration = 200; 41 | Altseed2.Node added = new Altseed2.Node(); 42 | tc.LoopBody( 43 | (_) => 44 | { 45 | added = partstree.InstantiateAndAddToEngine(); 46 | }, 47 | (_) => 48 | { 49 | foreach(var c in added.Children) 50 | { 51 | if (c is TransformNode tc) 52 | tc.Position += new Vector2F(_ * 2f, _ * 2f); 53 | } 54 | } 55 | ); 56 | tc.End(); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Test/Profiler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.IO; 4 | using NUnit.Framework; 5 | 6 | namespace Altseed2.Test 7 | { 8 | [TestFixture] 9 | public class Profiler 10 | { 11 | [Test, Apartment(ApartmentState.STA)] 12 | public void Basic() 13 | { 14 | var tc = new TestCore(); 15 | tc.Init(); 16 | 17 | Engine.Profiler.StartCapture(); 18 | 19 | { 20 | using var block1 = new ProfilerBlock("Block1", new Color(255, 0, 0)); 21 | System.Threading.Thread.Sleep(500); 22 | { 23 | using var block2 = new ProfilerBlock("Block2", new Color(0, 255, 0)); 24 | System.Threading.Thread.Sleep(500); 25 | } 26 | } 27 | 28 | Engine.Profiler.DumpToFileAndStopCapture("Profiler.prof"); 29 | 30 | tc.End(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Test/Sound.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.IO; 4 | using NUnit.Framework; 5 | 6 | namespace Altseed2.Test 7 | { 8 | [TestFixture] 9 | public class Sound 10 | { 11 | [Test, Apartment(ApartmentState.STA)] 12 | public void Play() 13 | { 14 | var tc = new TestCore(); 15 | tc.Init(); 16 | 17 | var bgm = Altseed2.Sound.Load(@"TestData/Sound/bgm1.ogg", false); 18 | var se = Altseed2.Sound.Load(@"TestData/Sound/se1.wav", true); 19 | 20 | Assert.NotNull(bgm); 21 | Assert.NotNull(se); 22 | 23 | var bgm_id = Engine.Sound.Play(bgm); 24 | var se_id = Engine.Sound.Play(se); 25 | 26 | tc.LoopBody(null, null); 27 | 28 | Engine.Sound.StopAll(); 29 | 30 | tc.End(); 31 | } 32 | 33 | [Test, Apartment(ApartmentState.STA)] 34 | public void Loop() 35 | { 36 | var tc = new TestCore(); 37 | tc.Init(); 38 | 39 | var bgm = Altseed2.Sound.Load(@"TestData/Sound/bgm1.ogg", false); 40 | Assert.NotNull(bgm); 41 | 42 | bgm.IsLoopingMode = true; 43 | bgm.LoopStartingPoint = 1f; 44 | bgm.LoopEndPoint = 2.5f; 45 | 46 | var bgm_id = Engine.Sound.Play(bgm); 47 | 48 | tc.LoopBody(null, null); 49 | 50 | Engine.Sound.StopAll(); 51 | 52 | tc.End(); 53 | } 54 | 55 | [Test, Apartment(ApartmentState.STA)] 56 | public void GetPosition() 57 | { 58 | var tc = new TestCore(); 59 | tc.Init(); 60 | 61 | var bgm = Altseed2.Sound.Load(@"TestData/Sound/bgm1.ogg", false); 62 | Assert.NotNull(bgm); 63 | 64 | int bgm_id = Engine.Sound.Play(bgm); 65 | 66 | var font = Font.LoadDynamicFont("TestData/Font/mplus-1m-regular.ttf", 100); 67 | Assert.NotNull(font); 68 | 69 | var textNode = new TextNode(); 70 | textNode.Font = font; 71 | 72 | Engine.AddNode(textNode); 73 | 74 | tc.LoopBody(c => 75 | { 76 | textNode.Text = $"{Engine.Sound.GetPlaybackPosition(bgm_id)}"; 77 | }, null); 78 | 79 | Engine.Sound.StopAll(); 80 | 81 | tc.End(); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Test/Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net5.0 5 | Altseed2.Test 6 | x64 7 | Debug;Release;CI 8 | $(SolutionDir)Build\$(Configuration)\ 9 | false 10 | 11 | 12 | 13 | x64 14 | 15 | 16 | 17 | x64 18 | 19 | 20 | 21 | x64 22 | true 23 | TRACE;CI;NET;NET5_0;NETCOREAPP 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Test/TestCore.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Linq; 4 | using NUnit.Framework; 5 | 6 | namespace Altseed2.Test 7 | { 8 | class TestCore 9 | { 10 | public int Duration { get; set; } = 200; 11 | private string _TestName; 12 | private Configuration _Config; 13 | 14 | public TestCore(Configuration config = null) 15 | { 16 | if (config != null) 17 | { 18 | config.FileLoggingEnabled = true; 19 | config.LogFileName = "log.txt"; 20 | config.ConsoleLoggingEnabled = true; 21 | } 22 | _Config = config ?? new Configuration() 23 | { 24 | FileLoggingEnabled = true, 25 | LogFileName = "log.txt", 26 | ConsoleLoggingEnabled = true, 27 | }; 28 | } 29 | 30 | public void Init([CallerMemberName] string testName = "") 31 | { 32 | _TestName = testName; 33 | Assert.True(Engine.Initialize($"Altseed2 C# EngineTest:{testName}", 800, 600, _Config)); 34 | Engine.FramerateMode = FramerateMode.Variable; 35 | Engine.TargetFPS = 60; 36 | } 37 | 38 | public void LoopBody(Action beforeUpdateAction, Action afterUpdateAction) 39 | { 40 | #if CI 41 | Duration = 20; 42 | #endif 43 | int count = 0; 44 | while (Engine.DoEvents() && count++ < Duration) 45 | { 46 | Engine.WindowTitle = $"Altseed2 C# EngineTest:{_TestName} ({count:D3}/{Duration:D3}) FPS:{Engine.CurrentFPS}"; 47 | beforeUpdateAction?.Invoke(count); 48 | 49 | Assert.True(Engine.Update()); 50 | 51 | afterUpdateAction?.Invoke(count); 52 | 53 | if(count == Duration / 2 && !string.IsNullOrEmpty(_TestName)) 54 | { 55 | Engine.Graphics.SaveScreenshot(_TestName + ".png"); 56 | } 57 | } 58 | } 59 | 60 | public void End() 61 | { 62 | Engine.Terminate(); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Test/Window.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.IO; 4 | using NUnit.Framework; 5 | 6 | namespace Altseed2.Test 7 | { 8 | [TestFixture] 9 | public class Window 10 | { 11 | [Test, Apartment(ApartmentState.STA)] 12 | public void Base() 13 | { 14 | var tc = new TestCore(); 15 | tc.Init(); 16 | 17 | tc.LoopBody(null, null); 18 | 19 | tc.End(); 20 | } 21 | 22 | [Test, Apartment(ApartmentState.STA)] 23 | public void FullScreen() 24 | { 25 | var tc = new TestCore(new Configuration() { IsFullscreen = true }); 26 | tc.Init(); 27 | 28 | tc.LoopBody(null, null); 29 | 30 | tc.End(); 31 | } 32 | 33 | [Test, Apartment(ApartmentState.STA)] 34 | public void ReSize() 35 | { 36 | var tc = new TestCore(); 37 | tc.Init(); 38 | 39 | tc.LoopBody(null, x => 40 | { 41 | if (x < 100) Engine.Window.Size += new Vector2I(1, 1); 42 | else Engine.Window.Size -= new Vector2I(1, 1); 43 | }); 44 | 45 | tc.End(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /TestForMacLinux/.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | end_of_line = crlf 3 | charset = utf-8-bom 4 | insert_final_newline = false 5 | indent_size = 4 6 | indent_style = space 7 | trim_trailing_whitespace = true -------------------------------------------------------------------------------- /TestForMacLinux/Options.cs: -------------------------------------------------------------------------------- 1 | using CommandLine; 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Altseed2.TestForMacLinux 8 | { 9 | public class Options 10 | { 11 | [Option('f', "filter", Separator = ',', Required = false)] 12 | public IEnumerable Filter { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /TestForMacLinux/TestForMacLinux.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net5.0 6 | Altseed2.TestForMacLinux 7 | x64 8 | Debug;Release;CI 9 | $(SolutionDir)Build\$(Configuration)\ 10 | false 11 | 12 | 13 | 14 | x64 15 | 16 | 17 | 18 | x64 19 | 20 | 21 | 22 | x64 23 | true 24 | TRACE;CI;NET;NET5_0;NETCOREAPP 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | PreserveNewest 39 | 40 | 41 | 42 | 43 | PreserveNewest 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /TestSubstitute.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29418.71 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Engine", "Engine\Engine.csproj", "{222E571D-A955-4025-9DAB-75528D7EDAE5}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestSubstitute", "TestSubstitute\TestSubstitute.csproj", "{DDDEE94A-6429-43B1-AFBD-9DF1641E45AC}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|x64 = Debug|x64 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {222E571D-A955-4025-9DAB-75528D7EDAE5}.Debug|x64.ActiveCfg = Debug|x64 17 | {222E571D-A955-4025-9DAB-75528D7EDAE5}.Debug|x64.Build.0 = Debug|x64 18 | {222E571D-A955-4025-9DAB-75528D7EDAE5}.Release|x64.ActiveCfg = Release|x64 19 | {222E571D-A955-4025-9DAB-75528D7EDAE5}.Release|x64.Build.0 = Release|x64 20 | {DDDEE94A-6429-43B1-AFBD-9DF1641E45AC}.Debug|x64.ActiveCfg = Debug|x64 21 | {DDDEE94A-6429-43B1-AFBD-9DF1641E45AC}.Debug|x64.Build.0 = Debug|x64 22 | {DDDEE94A-6429-43B1-AFBD-9DF1641E45AC}.Release|x64.ActiveCfg = Release|x64 23 | {DDDEE94A-6429-43B1-AFBD-9DF1641E45AC}.Release|x64.Build.0 = Release|x64 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {6FA63A05-B09B-41FA-A5E2-13BF921E490A} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /TestSubstitute/.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | end_of_line = crlf 3 | charset = utf-8-bom 4 | insert_final_newline = false 5 | indent_size = 4 6 | indent_style = space 7 | trim_trailing_whitespace = true -------------------------------------------------------------------------------- /TestSubstitute/Assert.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Altseed.Test 4 | { 5 | public static class Assert 6 | { 7 | public static void True(bool condition) 8 | { 9 | if (!condition) 10 | Console.WriteLine("Not True・I"); 11 | } 12 | 13 | public static void False(bool condition) 14 | { 15 | if (condition) 16 | Console.WriteLine("Not False・I"); 17 | } 18 | 19 | public static void NotNull(object obj) 20 | { 21 | if (obj == null) 22 | Console.WriteLine("Null・I"); 23 | } 24 | 25 | public static void AreEqual(double expected, double actual, double delta) 26 | { 27 | if (Math.Abs(expected - actual) > delta) 28 | Console.WriteLine("Not Equal・I"); 29 | } 30 | 31 | public static void AreEqual(object expected, object actual) 32 | { 33 | if (expected != actual) 34 | Console.WriteLine("Not Equal・I"); 35 | } 36 | 37 | public static void AreNotEqual(double expected, double actual, double delta) 38 | { 39 | if (Math.Abs(expected - actual) < delta) 40 | Console.WriteLine("Equal・I"); 41 | } 42 | 43 | public static void AreNotEqual(object expected, object actual) 44 | { 45 | if (expected == actual) 46 | Console.WriteLine("Equal・I"); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /TestSubstitute/Log.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altseed/Altseed2-csharp/17c20c9bf4fa741bbd0beb8a0a855c840e50bec1/TestSubstitute/Log.txt -------------------------------------------------------------------------------- /TestSubstitute/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Altseed.Test 4 | { 5 | class Program 6 | { 7 | [STAThread] 8 | static void Main(string[] args) 9 | { 10 | var dn = new Test.DrawnNode(); 11 | dn.SpriteNode(); 12 | dn.TextNode(); 13 | 14 | Console.ReadLine(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /TestSubstitute/TestSubstitute.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | Altseed.Test 6 | Exe 7 | x64 8 | $(SolutionDir)Build\$(Configuration)\ 9 | false 10 | 11 | 12 | 13 | x64 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Tool/Altseed2.Tools/.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | end_of_line = crlf 3 | charset = utf-8-bom 4 | insert_final_newline = false 5 | indent_size = 4 6 | indent_style = space 7 | trim_trailing_whitespace = true -------------------------------------------------------------------------------- /Tool/Altseed2.Tools/Altseed2.Tools.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | true 8 | altseed2 9 | 10 | x64 11 | x64 12 | $(SolutionDir)Build\$(Configuration)\ 13 | false 14 | 15 | Altseed2.Tools 16 | Copyright © 2021 Altseed 17 | 2.2.2 18 | 2.2.2.0 19 | 2.2.2.0 20 | 2.2.2 21 | 22 | 23 | 24 | true 25 | LICENSE.txt 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | PreserveNewest 40 | Always 41 | 42 | 43 | 44 | PreserveNewest 45 | Always 46 | 47 | 48 | 49 | PreserveNewest 50 | Always 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /Tool/Altseed2.Tools/FileCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using CommandLine; 3 | 4 | namespace Altseed2.Tools 5 | { 6 | [Verb("file")] 7 | [SubCommand(1, 1, CoreModules.File)] 8 | class FileCommand : ISubCommand 9 | { 10 | [Option('s', "src", HelpText = "Source Directory", Required = true)] 11 | public string SrcPath { get; set; } 12 | 13 | [Option('o', "output", HelpText = "Target Package Path", Required = true)] 14 | public string DstPath { get; set; } 15 | 16 | [Option('p', "password", HelpText = "Password (Optional)", Required = false, Default = null)] 17 | public string Password { get; set; } 18 | 19 | void ISubCommand.Run() 20 | { 21 | if (!System.IO.Directory.Exists(SrcPath)) 22 | { 23 | throw new Exception($"Directory {SrcPath} is not found."); 24 | } 25 | 26 | 27 | if (DstPath is null || DstPath == "") 28 | { 29 | throw new Exception($"Output '{DstPath}' is invalid."); 30 | } 31 | 32 | 33 | var dst = DstPath.EndsWith(".pack") ? DstPath : $"{DstPath}.pack"; 34 | 35 | if (Password is null) 36 | { 37 | if (!Engine.File.Pack(SrcPath, dst)) 38 | { 39 | throw new Exception($"Failed to pack '{SrcPath}' to '{dst}'."); 40 | } 41 | } 42 | else 43 | { 44 | if (!Engine.File.PackWithPassword(SrcPath, dst, Password)) 45 | { 46 | throw new Exception($"Failed to pack '{SrcPath}' to '{dst}' with password."); 47 | } 48 | } 49 | } 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Tool/Altseed2.Tools/FontCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using CommandLine; 4 | 5 | namespace Altseed2.Tools 6 | { 7 | [Verb("font")] 8 | [SubCommand(1, 1, CoreModules.Graphics | CoreModules.File)] 9 | public class FontCommand : ISubCommand 10 | { 11 | [Option('s', "src", HelpText = "Source Font File", Required = true)] 12 | public string SrcPath { get; set; } 13 | 14 | [Option('o', "output", HelpText = "Target a2f Path", Required = true)] 15 | public string DstPath { get; set; } 16 | 17 | [Option('c', "chars", HelpText = "Characters to Generate", Required = true)] 18 | public string Characters { get; set; } 19 | 20 | [Option("size", Default = Font.DefaultSamplingSize, HelpText = "Sampling Size", Required = false)] 21 | public int SamplingSize { get; set; } 22 | 23 | void ISubCommand.Run() 24 | { 25 | if (!System.IO.File.Exists(SrcPath)) 26 | { 27 | throw new Exception($"File {SrcPath} is not found."); 28 | } 29 | 30 | if (DstPath is null || DstPath == "") 31 | { 32 | throw new Exception($"Output '{DstPath}' is invalid."); 33 | } 34 | 35 | var dst = DstPath.EndsWith(".a2f") ? DstPath : $"{DstPath}.a2f"; 36 | 37 | if (!Font.GenerateFontFile(SrcPath, dst, Characters, SamplingSize)) 38 | { 39 | throw new Exception($"Failed to generate font file from '{SrcPath}' to '{dst}'"); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Tool/Altseed2.Tools/GUI/FilePackageGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Altseed2.Tools.GUI 3 | { 4 | public class FilePackageGenerator : IGuiApp 5 | { 6 | string input = ""; 7 | string password = ""; 8 | string msg = ""; 9 | 10 | public FilePackageGenerator() { } 11 | 12 | string IGuiApp.Msg => msg; 13 | 14 | void IGuiApp.DrawImGui() 15 | { 16 | var tmp = Engine.Tool.InputText("Source Directory", input, 2048, ToolInputTextFlags.None); 17 | if (tmp != null) 18 | { 19 | input = tmp; 20 | } 21 | 22 | if (Engine.Tool.SmallButton("Open Directory")) 23 | { 24 | input = Engine.Tool.PickFolder("") ?? ""; 25 | } 26 | 27 | tmp = Engine.Tool.InputText("Input Password", password, 128, ToolInputTextFlags.None); 28 | if (tmp != null) 29 | { 30 | password = tmp; 31 | } 32 | 33 | if (Engine.Tool.Button("Pack", new Vector2F())) 34 | { 35 | if (!System.IO.Directory.Exists(input)) 36 | { 37 | msg = $"Source directory '{input}' not found."; 38 | return; 39 | } 40 | 41 | var output = Engine.Tool.SaveDialog("pack", ""); 42 | 43 | if (output != "") 44 | { 45 | if (!output.EndsWith(".pack")) 46 | { 47 | output += ".pack"; 48 | } 49 | 50 | bool res; 51 | if (password == "") 52 | { 53 | res = Engine.File.Pack(input, output); 54 | } 55 | else 56 | { 57 | res = Engine.File.PackWithPassword(input, output, password); 58 | } 59 | 60 | msg = res ? "Success!" : "Fail to generate package file"; 61 | } 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Tool/Altseed2.Tools/GUI/FontGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Altseed2.Tools.GUI 3 | { 4 | public class FontGenerator : IGuiApp 5 | { 6 | string input = ""; 7 | int samplingSize = Font.DefaultSamplingSize; 8 | string charactersTextFilePath = ""; 9 | string msg = ""; 10 | 11 | public FontGenerator() { } 12 | 13 | string IGuiApp.Msg => msg; 14 | 15 | void IGuiApp.DrawImGui() 16 | { 17 | var tmp = Engine.Tool.InputText("Input Font File", input, 2048, ToolInputTextFlags.None); 18 | if (tmp != null) input = tmp; 19 | 20 | if (Engine.Tool.SmallButton("Open Font File")) 21 | { 22 | input = Engine.Tool.OpenDialog("ttf,otf", "") ?? ""; 23 | } 24 | 25 | Engine.Tool.SliderInt("Sampling Size", ref samplingSize, 1, 1024, "%d", ToolSliderFlags.None); 26 | 27 | tmp = Engine.Tool.InputText("Characters Text File", charactersTextFilePath, 2048, ToolInputTextFlags.None); 28 | if (tmp != null) 29 | { 30 | charactersTextFilePath = tmp; 31 | } 32 | 33 | if (Engine.Tool.SmallButton("Open Characters Text File")) 34 | { 35 | charactersTextFilePath = Engine.Tool.OpenDialog("txt", "") ?? ""; 36 | } 37 | 38 | if (Engine.Tool.Button("Save A2F File", new Vector2F())) 39 | { 40 | if (!System.IO.File.Exists(input)) 41 | { 42 | msg = $"Font file '{input}' not found."; 43 | return; 44 | } 45 | 46 | if (!System.IO.File.Exists(charactersTextFilePath)) 47 | { 48 | msg = $"Characters text file '{charactersTextFilePath}' not found."; 49 | return; 50 | } 51 | 52 | var output = Engine.Tool.SaveDialog("a2f", "") ?? ""; 53 | 54 | if (output != "") 55 | { 56 | if (!output.EndsWith(".a2f")) output += ".a2f"; 57 | 58 | var characters = System.IO.File.ReadAllText(charactersTextFilePath); 59 | var res = Font.GenerateFontFile(input, output, characters, samplingSize); 60 | 61 | msg = res ?$"Success!" : $"Fail to generate A2F file"; 62 | } 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Tool/Altseed2.Tools/GUI/IGuiApp.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Altseed2.Tools.GUI 4 | { 5 | interface IGuiApp 6 | { 7 | void DrawImGui(); 8 | string Msg { get; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Tool/Altseed2.Tools/GUICommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | using CommandLine; 6 | 7 | namespace Altseed2.Tools 8 | { 9 | [Verb("gui")] 10 | [SubCommand(600, 600, CoreModules.Default | CoreModules.Tool)] 11 | public class GUICommand : ISubCommand 12 | { 13 | void ISubCommand.Run() 14 | { 15 | var apps = new List<(string, GUI.IGuiApp)> { 16 | ("font", new GUI.FontGenerator()), 17 | ("file", new GUI.FilePackageGenerator()), 18 | }; 19 | 20 | var current = 0; 21 | 22 | while(Engine.DoEvents()) 23 | { 24 | var app = apps[current].Item2; 25 | 26 | if (Engine.Tool.BeginFullScreen(0)) 27 | { 28 | if (Engine.Tool.BeginTabBar("Apps", ToolTabBarFlags.None)) 29 | { 30 | for (int i = 0; i < apps.Count; i++) 31 | { 32 | if (Engine.Tool.BeginTabItem(apps[i].Item1, ToolTabItemFlags.None)) 33 | { 34 | current = i; 35 | Engine.Tool.EndTabItem(); 36 | } 37 | } 38 | 39 | Engine.Tool.EndTabBar(); 40 | } 41 | 42 | 43 | app.DrawImGui(); 44 | 45 | Engine.Tool.Text(app.Msg); 46 | 47 | Engine.Tool.End(); 48 | } 49 | 50 | Engine.Update(); 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Tool/Altseed2.Tools/ISubCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Altseed2; 4 | 5 | namespace Altseed2.Tools 6 | { 7 | interface ISubCommand 8 | { 9 | void Run(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Tool/Altseed2.Tools/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using CommandLine; 4 | 5 | namespace Altseed2.Tools 6 | { 7 | class Program 8 | { 9 | static void RunSubCommand(T cmd) 10 | where T : class, ISubCommand 11 | { 12 | var provider = (System.Reflection.ICustomAttributeProvider)typeof(T); 13 | var attrs = provider.GetCustomAttributes(typeof(SubCommandAttribute), false) as SubCommandAttribute[]; 14 | 15 | if (attrs is null || attrs.Length == 0) 16 | { 17 | throw new Exception($"SubCommandAttribute needed"); 18 | } 19 | 20 | var attr = attrs[0]; 21 | 22 | if (!Engine.Initialize("Altseed2.Tool", attr.Width, attr.Height, new Configuration { EnabledCoreModules = attr.CoreModules, ToolSettingFileName = null })) 23 | { 24 | throw new Exception("Failed to initialize the Engine"); 25 | } 26 | 27 | cmd.Run(); 28 | 29 | Engine.Terminate(); 30 | } 31 | 32 | [STAThread] 33 | static void Main(string[] args) 34 | { 35 | Parser.Default.ParseArguments(args) 36 | .WithParsed(RunSubCommand) 37 | .WithParsed(RunSubCommand) 38 | .WithParsed(RunSubCommand) 39 | .WithNotParsed(er => { 40 | Console.WriteLine("Failed to parse arguments"); 41 | }); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Tool/Altseed2.Tools/SubCommandAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Altseed2.Tools 3 | { 4 | [AttributeUsage(AttributeTargets.Class)] 5 | class SubCommandAttribute : Attribute 6 | { 7 | public int Width { get; private set; } 8 | public int Height { get; private set; } 9 | public CoreModules CoreModules { get; private set; } 10 | 11 | public SubCommandAttribute(int width, int height, CoreModules modules) 12 | { 13 | Width = width; 14 | Height = height; 15 | CoreModules = modules; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /scripts/BuildCore.bat: -------------------------------------------------------------------------------- 1 | echo set current directory 2 | cd /d %~dp0 3 | 4 | mkdir ..\Core\build 5 | 6 | cd /d ..\Core\build 7 | 8 | cmake -A x64 -D BUILD_TEST=OFF USE_MSVC_RUNTIME_LIBRARY_DLL=OFF ../ 9 | 10 | cmake --build . --config Debug 11 | 12 | cmake --build . --config Release 13 | 14 | pause -------------------------------------------------------------------------------- /scripts/BuildCore_Mac.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo set current directory 4 | cd `dirname $0` 5 | 6 | mkdir ../Core/build 7 | 8 | cd ../Core/build 9 | 10 | cmake -D BUILD_TEST=OFF ../ -G "Xcode" 11 | 12 | cmake --build . --config Debug 13 | 14 | cmake --build . --config Release 15 | -------------------------------------------------------------------------------- /scripts/ForcePull.bat: -------------------------------------------------------------------------------- 1 | echo set current directory 2 | cd /d %~dp0 3 | 4 | cd .. 5 | git fetch 6 | git reset --hard origin/master 7 | git submodule update 8 | 9 | cd Core 10 | git reset --hard ORIG_HEAD 11 | pause -------------------------------------------------------------------------------- /scripts/Pull.bat: -------------------------------------------------------------------------------- 1 | echo set current directory 2 | cd /d %~dp0 3 | 4 | cd .. 5 | git pull 6 | git submodule update --init 7 | 8 | cd Core 9 | 10 | git submodule update --init 11 | 12 | cd thirdparty/LLGI 13 | git submodule update --init 14 | 15 | pause -------------------------------------------------------------------------------- /scripts/Pull.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo set current directory 4 | cd `dirname $0` 5 | 6 | cd .. 7 | git pull 8 | git submodule update --init 9 | 10 | cd Core 11 | 12 | git submodule update --init 13 | 14 | cd thirdparty/LLGI 15 | git submodule update --init -------------------------------------------------------------------------------- /scripts/UpdateCore.bat: -------------------------------------------------------------------------------- 1 | echo set current directory 2 | cd /d %~dp0 3 | 4 | cd .. 5 | git pull 6 | git submodule update --init 7 | git submodule update --remote -- "Core" 8 | 9 | cd Core 10 | git submodule update --init 11 | 12 | pause -------------------------------------------------------------------------------- /scripts/generate_bindings.py: -------------------------------------------------------------------------------- 1 | import os, shutil, ntpath, glob, sys 2 | 3 | # move to source directory 4 | os.chdir(os.path.dirname(os.path.abspath(__file__))) 5 | 6 | # copy C++ Binding Generator scripts 7 | targetPath = '../Core/scripts/bindings' 8 | outputPath = "./Bindings" 9 | 10 | if os.path.exists(outputPath): 11 | print('Directory {} exists'.format(outputPath)) 12 | shutil.rmtree(outputPath) 13 | print('Removed directory {}'.format(outputPath)) 14 | 15 | shutil.copytree(targetPath, outputPath) 16 | print('Copied directory {} to {}'.format(targetPath, outputPath)) 17 | 18 | 19 | from Bindings import define 20 | from Bindings import auto_generate_define 21 | from Bindings.CppBindingGenerator import BindingGeneratorCSharp 22 | 23 | # generate C# binding 24 | args = sys.argv 25 | lang = 'ja' 26 | if len(args) >= 3 and args[1] == '-lang': 27 | if args[2] in ['ja', 'en']: 28 | lang = args[2] 29 | else: 30 | print('python csharp.py -lang [ja|en]') 31 | 32 | define.load_text_from_json_file('Bindings/desc.json') 33 | define.load_text_from_json_file('Bindings/desc_profiler.json') 34 | define.load_text_from_json_file('Bindings/desc_media.json') 35 | 36 | bindingGenerator = BindingGeneratorCSharp(define, [], lang) 37 | bindingGenerator.output_path = '../Engine/AutoGeneratedCoreBindings.cs' 38 | bindingGenerator.dll_name = 'Altseed2_Core' 39 | bindingGenerator.namespace = 'Altseed2' 40 | bindingGenerator.generate() 41 | -------------------------------------------------------------------------------- /scripts/test_screenshot.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import os 3 | import time 4 | import shutil 5 | import filecmp 6 | import base64 7 | import glob 8 | import json 9 | 10 | class ScreenShotTest(unittest.TestCase): 11 | def test_screenshots(self): 12 | generated_file_paths = glob.glob('../TestResult/*.png') 13 | 14 | for path in generated_file_paths: 15 | name = os.path.basename(path) 16 | self.assertTrue(filecmp.cmp('../test-windows/CI/net5.0/' + name, path), name + ' is not equal') 17 | 18 | if __name__ == '__main__': 19 | unittest.main() 20 | 21 | --------------------------------------------------------------------------------