VS Code 擴充功能推薦 CodeCursor


建立時間: 2023年4月12日 14:33
更新時間: 2023年5月22日 12:52

免費版跑不動,已棄用

最近使用 CodeCursor 聊天功能都沒有回應,所以忍痛刪除,不過文章還是留著分享給大家。

介紹

這是一款 AI 生成程式碼的擴充功能,跟 ChatGPT 不一樣的地方是它會分析專案現有的程式碼,再給出建議,功能強大到超乎我的想像,如同之前傳言的:人類寫程式的時代已經結束。

Preview

安裝

在 Visual Studio Code 安裝完 CodeCursor 後就可使用

使用方式

使用方式主要有兩種

1. 程式碼生成

在指令面板輸入 CodeCursor 選擇 Generate Code,然後會出現提示框,在提示框中輸入要生成的程式碼,比較適合簡短的描述。

Code Generation

後續生成程式碼後再決定是否採用

Code Generation Completed

2. 聊天

聊天就像 ChatGPT 一樣,出現一個對話框讓你輸入你的需求,開啟方式在左側的 Icon 按鈕中找到 CodeCursor Icon 點擊即可。

Chat

實際演練

這裡將提供一個 Unity C# 腳本的聊天過程

需求如下:
Unity 請參考現有的 Effect 類別,我打算建立子類別 ThreeBallsEffect 和 BallSplittingEffect 原有的碰撞處理功能都一樣,唯一的差異是,ThreeBallsEffect 一樣處理 ServeThreeBalls 而 BallSplittingEffect 則變成處理球原處分裂,也就是 Clone 一顆,他的 velicity 我還沒決定,幫我留個位置讓我之後可以設定,請用中文回答

這是一個比較複雜的需求,將上述的內容貼在 CodeCursor 聊天對話中,它回覆給我的程式碼如下

using UnityEngine;

public class ThreeBallsEffect : Effect
{
    protected override void TriggerEffect()
    {
        ServeThreeBalls();
    }

    private void ServeThreeBalls()
    {
        Paddle paddle = FindObjectOfType<Paddle>();

        Vector2[] directions = {
            new Vector2(-1, 1),
            Vector2.up,
            new Vector2(1, 1)
        };

        foreach (Vector2 direction in directions)
        {
            GameObject ballGameObject = GameManager.CreateOneBall(paddle.transform.position);
            Ball ball = ballGameObject.GetComponent<Ball>();
            ball.Go(direction);
        }
    }
}

public class BallSplittingEffect : Effect
{
    protected override void TriggerEffect()
    {
        SplitBalls();
    }

    private void SplitBalls()
    {
        Ball[] balls = FindObjectsOfType<Ball>();

        foreach (Ball ball in balls)
        {
            Vector2 direction = ball.Rigidbody2D.velocity.normalized;
            Vector2 perpendicularDirection = new Vector2(direction.y, -direction.x);
            Vector2[] directions = {
                direction + perpendicularDirection,
                direction - perpendicularDirection
            };

            foreach (Vector2 splitDirection in directions)
            {
                GameObject ballGameObject = GameManager.CreateOneBall(ball.transform.position);
                Ball newBall = ballGameObject.GetComponent<Ball>();
                newBall.Rigidbody2D.velocity = splitDirection;
            }
        }
    }
}

基本上這段程式碼有幫我分好子類別,但實際上我還是需要稍微修改一下,CodeCursor 幫我寫好了 SplitBalls(),而且還會利用我已經寫好的程式碼 GameManager.CreateOneBall(),基本上只需稍微修改一下就可以用了,在子類別中提示我要繼承 Effect 類別,雖然 protected override void TriggerEffect() 並沒有設計的很洽當,應該是要在 Effect 類別的 private void OnTriggerEnter2D(Collider2D other) 改成 protected 然後其他關鍵字,但這已經幫助我很多靈感。

結論

使用 CodeCursor 後可以知道,AI 生成的程式碼可讀性、可維護性都相當不錯,未來只會越來越強,這樣我們學習程式時可以把時間投入在理解語法上,在未來也許 AI 精通所有的設計模式、無瑕的程式碼開發守則、所有程式設計的優良習慣,在這樣的情況下我們只需把想法告訴 AI 再稍微修改就可以用了。

參考

觀看次數: 2332
AIaicodecodecursorcursorstudiovisual
按讚追蹤 Enjoy 軟體 Facebook 粉絲專頁
每週分享資訊技術

一杯咖啡的力量,勝過千言萬語的感謝。

支持我一杯咖啡,讓我繼續創作優質內容,與您分享更多知識與樂趣!