Skip to content

Commit

Permalink
2020.3.33対応、中断に備える、キャンバスのスケーリング、コメント整備
Browse files Browse the repository at this point in the history
  • Loading branch information
tetr4lab committed Apr 10, 2022
1 parent 7e94c9e commit d4658c9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_UiScaleMode: 1
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
Expand Down
27 changes: 20 additions & 7 deletions Assets/Scripts/ManagedInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,23 @@ namespace Tetr4lab {
/// </summary>
public class ManagedInstance<T> : IDisposable where T : MonoBehaviour {

public int Count => Instances.Count; // インスタンス数
public int MaxInstances { get; protected set; } // 最大インスタンス数 (0で無制限)
public bool AutoDelete { get; protected set; } // 上限数を超えたら最古を破棄する
public List<T> Instances { get; protected set; } // インスタンス一覧
public T LastInstance => (Instances == null || Count <= 0) ? null : Instances [Count - 1]; // 最新のインスタンス
public bool OnMode { // ひとつ以上生成されている
/// <summary>インスタンス数</summary>
public int Count => Instances.Count;

/// <summary>最大インスタンス数 (0で無制限)</summary>
public int MaxInstances { get; protected set; }

/// <summary>上限数を超えたら最古を破棄する</summary>
public bool AutoDelete { get; protected set; }

/// <summary>インスタンス一覧</summary>
public List<T> Instances { get; protected set; }

/// <summary>最新のインスタンス</summary>
public T LastInstance => (Instances == null || Count <= 0) ? null : Instances [Count - 1];

/// <summary>ひとつ以上生成されている</summary>
public bool OnMode {
get { return (Instances != null && Count > 0); }
set {
if (!value) { // 全インスタンス破棄
Expand All @@ -45,7 +56,9 @@ public class ManagedInstance<T> : IDisposable where T : MonoBehaviour {
}
}
}
public async Task<GameObject> GetPrefabAsync () { // デフォルトプレハブ

/// <summary>デフォルトプレハブ</summary>
public async Task<GameObject> GetPrefabAsync () {
if (!prefab) {
prefab = await Addressables.LoadAssetAsync<GameObject> ($"Prefabs/{typeof (T).Name}.prefab").Task;
}
Expand Down
18 changes: 11 additions & 7 deletions Assets/Scripts/SampleMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@

public class SampleMain : MonoBehaviour {

private bool destroyed = false;

async void Start () {
// 生成1
await FlyText.CreateAsync (gameObject, "Ready?");
if (!destroyed) await FlyText.CreateAsync (gameObject, "Ready?");
// 消滅を待つ
await TaskEx.DelayWhile (() => FlyText.managedInstance.OnMode);
if (!destroyed) await TaskEx.DelayWhile (() => FlyText.managedInstance.OnMode);
// 生成2
await FlyText.CreateAsync (gameObject, "Start!");
if (!destroyed) await FlyText.CreateAsync (gameObject, "Start!");
// 消滅を待つ
await TaskEx.DelayWhile (() => FlyText.managedInstance.OnMode);
if (!destroyed) await TaskEx.DelayWhile (() => FlyText.managedInstance.OnMode);
// 3秒待つ
await Task.Delay (3000);
if (!destroyed) await Task.Delay (3000);
// 生成3
await FlyText.CreateAsync (gameObject, "End");
if (!destroyed) await FlyText.CreateAsync (gameObject, "End");
// 消滅を待つ
await TaskEx.DelayWhile (() => FlyText.managedInstance.OnMode);
if (!destroyed) await TaskEx.DelayWhile (() => FlyText.managedInstance.OnMode);
// 終了
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
Expand All @@ -29,4 +31,6 @@ public class SampleMain : MonoBehaviour {
#endif
}

private void OnDestroy () => destroyed = true;

}
6 changes: 3 additions & 3 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"dependencies": {
"com.unity.addressables": "1.18.19",
"com.unity.collab-proxy": "1.15.12",
"com.unity.collab-proxy": "1.15.15",
"com.unity.ide.rider": "2.0.7",
"com.unity.ide.visualstudio": "2.0.14",
"com.unity.ide.vscode": "1.2.4",
"com.unity.test-framework": "1.1.29",
"com.unity.ide.vscode": "1.2.5",
"com.unity.test-framework": "1.1.31",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.4.8",
"com.unity.ugui": "1.0.0",
Expand Down
6 changes: 3 additions & 3 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"url": "https://packages.unity.com"
},
"com.unity.collab-proxy": {
"version": "1.15.12",
"version": "1.15.15",
"depth": 0,
"source": "registry",
"dependencies": {
Expand Down Expand Up @@ -49,7 +49,7 @@
"url": "https://packages.unity.com"
},
"com.unity.ide.vscode": {
"version": "1.2.4",
"version": "1.2.5",
"depth": 0,
"source": "registry",
"dependencies": {},
Expand All @@ -72,7 +72,7 @@
"url": "https://packages.unity.com"
},
"com.unity.test-framework": {
"version": "1.1.29",
"version": "1.1.31",
"depth": 0,
"source": "registry",
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2020.3.30f1
m_EditorVersionWithRevision: 2020.3.30f1 (1fb1bf06830e)
m_EditorVersion: 2020.3.33f1
m_EditorVersionWithRevision: 2020.3.33f1 (915a7af8b0d5)

0 comments on commit d4658c9

Please sign in to comment.