Windows11でSimCity2000をしたい(フロッピー4枚組)

CD版SimCity2000を動かす方法は、

sc2.s27.xrea.com

にあるが、こちらの手元には、元フロッピー4枚組をHDDにコピーしたもの。DISK1,2,3,4 にSETUP.EXEが入っている。幸い、まだ3.5Inchフロッピーが使える時代にHDDにコピーしていたもの。


SimCity2000 on Win11

【概要】
Oracle VM VirtualBox 7.0でWindowsXPを動かして、DISK1のSETUP.EXEでインストールしたらSimCity2000が動いた。

【用意するもの】
Oracle VM VirtualBox 7.0
WindowsXPインストールCD
・SimCity2000のフロッピーのコピー(DISK1,2,3,4)
・USBストレージ(Win11からWinXPへコピー用)

【手順】
(特にハマることなしに動きました)
1. WindowsXPの仮想実行環境を準備(なお、VirtualBox 6だとWin11で動かないので、VirtualBox 7にすること)
kuukaix.hatenablog.com
2. SimCity2000のフロッピーのコピー(DISK1,2,3,4)をUSBストレージにコピー(SimCity2000/DISK1とかの名前にする)
3. 仮想WinXPを起動→「デバイス」→「USB」→「USBストレージ」を選択してチェックを入れる
(Win11のホストPCからUSBデバイスが見えなくって、WinXPの方のマイコンピュータのドライブとしてアクセスできる)
4. SimCity2000/DISK1/SETUP.EXEを実行してWinXPにインストールする
5. SimCity2000を実行する

Windows98をWindows10環境で動かす(2023年版)

CPUをSandy Bridge(第2世代)からAlder Lake(第12世代)に変えたら仮想環境が動かなくなったので 修復しました。

これは以前の環境で動かした方法(VirtualBoxをバージョン7にすれば使えるはず。試してません)
https://kuukaix.hatenablog.com/entry/2022/09/17/223721

【やったこと】
1. VirtualBoxのバージョンアップ(旧6.1.38→新7.0.4)
これだけでWinXPは動くようになった
2. Win98SEをsafe modeで起動して「32ビット プロテクト モードのディスク ドライバを使用しない」にチェック
これでWin98SEも動くようになった

【詳細】
1. VirtualBoxのバージョンアップ
https://www.virtualbox.org/wiki/Downloads
から最新バージョン(Windows hosts)をダウンロードして、インストールすればOK

2. Win98SEは仮想環境のものを起動すると
 「SHELL32.DLL ファイルは欠落エクスポート GDI32.DLL:リンクされてます」というエラーが  でてエクスプローラーが起動しないので、手も足も出ない状態になる。
 Win98SEをいったん強制シャットダウンして、VirtualBoxからWin98SEを再起動中にCtrlキーを押しっぱなしにして、  safe modeでWin98SEを起動するとエクスプローラーが使える。

 「コントロールパネル」→「システム」→「パフォーマンス」→「ファイルシステム」→「トラブルシューティング」とすすんで、「32ビット プロテクト モードのディスク ドライバを使用しない」にチェックを入れて、「OK」
 Win98SEを再起動すれば解決。

Draw a line on Canvas with Unity

I pasted an Image on Canvas in Unity, so I want to draw a line on it. This is surprisingly difficult and there is no function that can be used easily like draw.line(). If it's a triangle, it's easy to draw, so draw two long triangles to make it look like a straight line.

1. Click Canvas in Hierarchy, press the + button on the upper left of (1), select Create Empty Child, and add a GameObject.
2. Click on the GameObject to show the Inspector.
3. Click (2) and select Bottom, left while holding down the Shift key (the options change). Set Pos X,Y,Z to 0.
4. Click (3) Assets in Project, press the + button on the upper left of Assets, select C# Script, and add NewBehaviourScript.
5. Move the (4) slider to the leftmost (I want to see all the characters in NewBehaviourScript)
6. Double-click NewBehaviourScript to start Visual Studio 2022 and display NewBehaviourScript.cs.
7. We will not use the code that is automatically created, so delete all of them, rewrite the following and save.
8. Return to the Unity edit screen, click the (5) "Add Component" button, and select the magnifying glass (search) field. Enter "Canvas Renderer" and add " Canvas Renderer" that appears in the options .
9. Drag NewBehaviourScript(6) in Assets and drop it on GameObject(7) in Hierarchy.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class NewBehaviourScript : MaskableGraphic
{
    Static NewBehaviourScript self;

    NewBehaviourScript()
    {
        self = this;
    }

    // To redraw from outside this class, call NewBehaviourScript.redraw()
    static public void redraw()
    {
        print("redraw");
        self.SetAllDirty(); 
    }

    protected override void OnPopulateMesh(VertexHelper vh)
    {
        vh.Clear();
        UIVertex vertex = UIVertex.simpleVert;
        vertex.color = Color.red;

        // draw a diagonal red line from bottom left to top right

        // first triangle
        vertex.position = new Vector2(0, 0); // lower left position 
        vh.AddVert(vertex);
        vertex.position = new Vector2(canvas.pixelRect.width+2, canvas.pixelRect.height);
        vh.AddVert(vertex);
        vertex.position = new Vector2(canvas.pixelRect.width-2, canvas.pixelRect.height); 
        vh.AddVert(vertex);

        // second triangle
        vertex.position = new Vector2(2, 0);
        vh.AddVert(vertex);
        vertex.position = new Vector2(-2, 0);
        vh.AddVert(vertex);
        vertex.position = new Vector2(canvas.pixelRect.width, canvas.pixelRect.height); // position it on the upper right.
        vh.AddVert(vertex);

        // draw two elongated triangles to form a straight line
        vh.AddTriangle(0, 1, 2); // only triangles can be drawn
        vh.AddTriangle(3, 4, 5); // only triangles can be drawn
    }
}

.
10. click on GameObject in the Hierarchy to display the Inspector and confirm that the New Behaviour Script (Script) has been added under Canvas Renderer.
11. Run the application by pressing ▶ (Run button) at the top center of the screen and confirm that a diagonal red line appears on the desired image.
.
12. in the Solution Explorer of Visual Studio 2022, right-click NewBehaviourScript.cs and select Rename.
13. change it to RedLineOnCanvas.cs and confirm with Enter." Do you want to rename for all references?" You will be asked "Yes". Select "Yes" when asked.
14. All references are now renamed, even the C# class names, including the Unity code.

15. Click on GameObject in the hierarchy, press the + button a little above left of (1), select UI -> Legacy -> Text then Text(Legacy) is added.
16. hold down Shift and click (2)→select Bottom, Left.
17. set PosX, PosY, and PosZ in (3) to all 0.
18. set the "Font Style" in (4) to "Bold" (it will be easier to see that the text is above the line).
19. Press ▶ (Run button) at the top center of the screen to run the application and confirm that the white text "New Text" appears above the diagonal red line.
.

UnityでCanvasに線を描く(Unity draw line on canvas)

UnityでCanvasにImageを張り付けたので、その上に線を描きたい。 これが意外と大変でdraw.line()みたいな簡単に使える関数がない。三角形なら簡単にかけるので、細長い三角形を2つ書いて直線っぽくする。




1. HierarchyにあるCanvasをクリック、①のちょっと左上にある+ボタンを押して、Create Empty Child を選んで、GameObjectを追加する。
2. GameObjectをクリックして、Inspectorを表示。
3. ②をクリックして、Shiftキーを押しながら(選択肢が変わる)Bottom, leftを選ぶ。Pos X,Y,Z を0にする。
4. Projectにある③Assetsをクリック、Assetsのちょっと左上にある+ボタンを押して、C# Script を選んで、NewBehaviourScriptを追加する。
5. ④のスライダーを一番左にする(NewBehaviourScriptの文字を全部見たい)
6. NewBehaviourScriptをダブルクリックして、Visual Studio 2022を起動して、NewBehaviourScript.csを表示する。
7. 自動で作られるコードは使わないので、全部消して、以下に書き換えて保存する。
8. Unityの編集画面に戻って、⑤の「Add Component」ボタンをクリック、虫眼鏡(検索)の欄にCanvas Rendererと入れて、選択肢に出る「Canvas Renderer」を追加する。
9. AssetsにあるNewBehaviourScript⑥をドラッグして、HierarchyにあるGameObject⑦にドロップする。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class NewBehaviourScript : MaskableGraphic
{
    static NewBehaviourScript self;

    NewBehaviourScript()
    {
        self = this;
    }

    // このクラスの外から再描画したい場合はNewBehaviourScript.redraw()を呼び出す
    static public void redraw()
    {
        print("redraw");
        self.SetAllDirty();
    }

    protected override void OnPopulateMesh(VertexHelper vh)
    {
        vh.Clear();
        UIVertex vertex = UIVertex.simpleVert;
        vertex.color = Color.red;

        // 左下から、右上に斜めの赤い線を書く

        // 1番目の三角形
        vertex.position = new Vector2(0, 0); // 左下 
        vh.AddVert(vertex);
        vertex.position = new Vector2(canvas.pixelRect.width+2, canvas.pixelRect.height);
        vh.AddVert(vertex);
        vertex.position = new Vector2(canvas.pixelRect.width-2, canvas.pixelRect.height);
        vh.AddVert(vertex);

        // 2番目の三角形
        vertex.position = new Vector2(2, 0);
        vh.AddVert(vertex);
        vertex.position = new Vector2(-2, 0);
        vh.AddVert(vertex);
        vertex.position = new Vector2(canvas.pixelRect.width, canvas.pixelRect.height); // 右上
        vh.AddVert(vertex);

        // 細長い三角形を2つ書いて直線にする
        vh.AddTriangle(0, 1, 2); // 三角形しか書けない
        vh.AddTriangle(3, 4, 5); // 三角形しか書けない
    }
}

10. HierarchyにあるGameObjectをクリックして、Inspectorを表示すると、Canvas Rendererの下にNew Behaviour Script (Script)が追加されているのを確認する。
11. 画面中央の上にある▶(実行ボタン)を押して、アプリを実行して、目的の画像に斜めの赤い線が表示されるのを確認する。
12. Visual Studio 2022 のソリューション エクスプローラーで、NewBehaviourScript.csを右クリックして、名前の変更を選ぶ。
13. RedLineOnCanvas.csに変更して、Enterで確定する。「すべての参照に対して、名前を変更しますか?」と問われるので、「はい」を選ぶ。
14. これでUnity側のコードも含めて、C#クラス名まで全部の名前が変更される。
15. HierarchyにあるGameObjectをクリックして、①のちょっと左上にある+ボタンを押して、UI→Legacy→Textを選択する→Text(Legacy)が追加される。
16. ②をShiftを押しながらクリック→bottom, leftを選ぶ。
17. ③のPosX, PosY, Pos Zをすべて0にする 。 18. ④のFont StyleをBoldにする(ラインの上に文字があることが分かりやすくなる)。
19. 画面中央の上にある▶(実行ボタン)を押して、アプリを実行して、斜めの赤い線の上に白文字のNew Textが表示されるのを確認する。

UnityでCanvasに画像を表示する

Unityで画像を画面いっぱいに表示したい。普通のWindowアプリみたいにしたい。
【目的】画像を表示する
【結論】画像を張るだけでも色々設定しないといけない。面倒!
【詳細・やり方】
1. ①のちょっと左上にある+ボタンを押して、UIからCanvasとUIからImageを追加する。Canvasの中にImageが来るようマウスでドラッグして、調整する。
2. ②のAssetsの中に表示したい画像をファイルマネージャー(エクスプローラー)を使ってからドラッグ&ドロップして入れる。入れた画像をクリックする。
3. 右にInspectorが表示されるので、③にあるように、Texture Typeを「Sprite(2D and UI)」に、Sprite Modeを「Single」に変更する。
4. ④のGenerate Mip Mapのチェックを外す。
5. 左上①のImageをクリックして、右にInspectorを表示する。
6. ②をクリックして、左右、上下ともstretchになっている箱をクリックする。
7. ③のLeft,Top,Pos Z, Right, Bottomを全部0にする。
8. ④のSource Imageの右の◎をクリックして、表示される一覧から目的の画像を設定する。
9. 画面中央の上にある▶(実行ボタン)を押して、アプリを実行して、目的の画像が画面いっぱいに表示されるのを確認する。

AI画像作成で遊んでみた(stable diffusion)

stable diffusionというAI画像作成アプリをPCにインストールして使ってみました。 参考にしたサイトは、以下。サイトに従って環境構築すれば動きました。

gigazine.net ↑ GFPGANフォルダーは、GFPGANv1.3.pthに変更する必要がある

note.com

UnityでVisual Studio 2022でデバッグできないを対策する

Unity 2021.3.10f1を使って新しくプロジェクトを作って、C#スクリプトVisual Studio 2022で作成して、ブレイクポイントを設定してもきかない。原因は、Unity側に少しだけ設定が必要だった
【目的】Visual Studio 2022でデバッグしたい
【結論】UnityのトップメニューからEdit→Preferences→External Toolsで EditorにVisual Studioを設定して、Player projectsのチェックを入れる
【詳細・やり方】
1. Unityを起動して、適当なC#スクリプトを含むアプリを作る("unity hello world"で検索すればよさげなサンプルが見つかる)
2.UnityのトップメニューからEdit→Preferences→External Toolsで EditorにVisual Studioを設定して、Player projectsのチェックを入れる

Unity preferences
3.UnityとVisual Studioをいったん終了する
4.Unityを再起動して、先ほどのサンプルを読み込む
5.C#スクリプトをダブルクリックして、Visual StudioC#スクリプトを表示する
6.Visual Studioのコードが表示されている行の一番左をクリックして赤い丸を表示
(これがブレイクポイント。Debug.Log()のある行の左にブレイクポイントを設定するとわかりやすい)
7.Visual Studioのトップメニューの「▶Unityにアタッチ」をクリック
8.Unityに戻って、実行ボタン(上の方にある ▶)を押す
9.Visual Studioの画面が出て、ブレイクポイントを設定した行が黄色になれば、 そこで実行が中断されている
10.あとは変数を見たり、続行ボタンを押したり、ステップ実行(1行ずつ進める)するなり、詳細にデバッグする