[Unity XLua]热更新XLua入门(二)-俄罗斯方块实例篇

前言

在xLua没出来之前,开源的lua框架基本都是以界面用Lua开发为主,核心战斗用C#开发,但xLua出来之后主推C#开发,Lua用作HotFix,这里我展示的第一个例子就是基于界面的经典2D小游戏——俄罗斯方块,界面逻辑是用C#写,启动加载逻辑是用lua,后面我会继续第二个同样的Demo,但是以纯Lua为主,这个案例明天更新。

效果图

由于我不会美术,所以这里使用的开源的游戏资源,感谢此作者。

游戏启动

C#启动Lua逻辑

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using XLua;
using System;

[LuaCallCSharp]
public class LuaRunningBehaviour : MonoBehaviour
{
    public TextAsset luaScript;

    internal static LuaEnv luaEnv = new LuaEnv(); //all lua behaviour shared one luaenv only!
    internal static float lastGCTime = 0;
    internal const float GCInterval = 1;//1 second 

    private Action luaStart;
    private Action luaUpdate;
    private Action luaOnDestroy;

    private LuaTable scriptEnv;

    void Awake()
    {
        scriptEnv = luaEnv.NewTable();

        LuaTable meta = luaEnv.NewTable();
        meta.Set("__index", luaEnv.Global);
        scriptEnv.SetMetaTable(meta);
        meta.Dispose();

        scriptEnv.Set("self", this);

        luaEnv.DoString(luaScript.text, "LuaBehaviour", scriptEnv);

        Action luaAwake = scriptEnv.Get<Action>("awake");
        scriptEnv.Get("start", out luaStart);
        scriptEnv.Get("update", out luaUpdate);
        scriptEnv.Get("ondestroy", out luaOnDestroy);

        if (luaAwake != null)
        {
            luaAwake();
        }
    }

    // Use this for initialization
    void Start()
    {
        if (luaStart != null)
        {
            luaStart();
        }
    }

    // Update is called once per frame
    void Update()
    {
        if (luaUpdate != null)
        {
            luaUpdate();
        }
        if (Time.time - LuaBehaviour.lastGCTime > GCInterval)
        {
            luaEnv.Tick();
            LuaBehaviour.lastGCTime = Time.time;
        }
    }

    void OnDestroy()
    {
        if (luaOnDestroy != null)
        {
            luaOnDestroy();
        }
        luaOnDestroy = null;
        luaUpdate = null;
        luaStart = null;
        scriptEnv.Dispose();
    }
}

Lua加载游戏界面预设逻辑


local util = require ‘xlua.util‘

local function initGamePanel()
    local obj = CS.UnityEngine.Resources.Load("TetrisPanelOne")
    local gamePanel = CS.UnityEngine.Object.Instantiate(obj.gameObject).transform
    gamePanel.name = "GamePanel"
    gamePanel.gameObject.name = "GamePanel"
    gamePanel:SetParent(self.transform)
    gamePanel.localPosition = CS.UnityEngine.Vector3.zero
    gamePanel.localScale = CS.UnityEngine.Vector3.one
end

function start()
    print("lua start, 游戏开始...")
    initGamePanel()
end

function ondestroy()
    print("lua destroy")
end

游戏主要界面对应的C#逻辑

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;

public class MainGameCSScript : MonoBehaviour
{
    const int cRow = 16;
    const int cCol = 10;
    List<int>[] aTable = new List<int>[cRow];
    int lineCount = 0;
    public Texture[] BoxTexture = new Texture[4];
    private string[] boxColors = new string[] { "eluosi_lan", "eluosi_zi", "eluosi_lv", "eluosi_hong" };

    public int LineCount
    {
        get { return lineCount; }
        set
        {
            lineCount = value;
            this.onLineCountChange();
        }
    }
    int score = 0;

    public int Score
    {
        get { return score; }
        set
        {
            score = value;
            this.onScoreChange();
        }
    }
    int nextCellID = 0;
    int curCellID = 0;

    float curSpeed = 1;
    float fCurSpeed = 1;
    float fDeltaTime = 0;
    bool bPause = false;

    bool bStart = false;
    bool bGameOver = false;

    public bool BGameOver
    {
        get { return bGameOver; }
        set
        {
            bGameOver = value;
            this.onGameOverChange(bGameOver);
        }
    }

    System.Random rdm = new System.Random();

    const int boxTop = 16;
    const int boxLeft = 290;
    /// <summary>
    /// 彩色砖块的宽度
    /// </summary>
    const int boxSize = 38;

    int[][] nextCell = null;
    int[][] curCell = null;
    int curCellCol = 0;
    int curCellRow = 0;

    public GameObject BtnUp, BtnDown, BtnLeft, BtnRight, BtnIsPause;
    public UILabel TimeLabel, ScoreLabel, LineCountLabel;

    private Action onScoreChange = null;
    private Action onLineCountChange = null;
    private Action<bool> onGameOverChange = null;
    public GameObject EndPanel, BtnRestart;
    public UISprite[] BoxSprites = null;

    void Start()
    {
        BoxSprites = new UISprite[4];
        for (int i = 0; i < 4; i++)
        {
            BoxTexture[i] = Resources.Load<Texture>(boxColors[i]);
        }
        this.onScoreChange = this.ScoreChange;
        this.onLineCountChange = this.LineCountChange;
        this.onGameOverChange = this.GameOverChange;
        TimeLabel = transform.Find("LeftNode/CutDownBG/CountLabel").GetComponent<UILabel>();
        LineCountLabel = transform.Find("ScoreNode/LineCount").GetComponent<UILabel>();
        ScoreLabel = transform.Find("ScoreNode/Score").GetComponent<UILabel>();
        BtnLeft = transform.Find("InputNode/Left").gameObject;
        BtnRight = transform.Find("InputNode/Right").gameObject;
        BtnUp = transform.Find("InputNode/Up").gameObject;
        BtnDown = transform.Find("InputNode/Down").gameObject;
        BtnIsPause = transform.Find("LeftNode/RestartBtn").gameObject;
        EndPanel = transform.Find("EndPanel").gameObject;
        BtnRestart = transform.Find("EndPanel/ReplayBtn").gameObject;

        for (int i = 1; i <= 4; i++)
        {
            var obj = transform.Find(string.Format("BlcokTop/Blocks/block{0}", i)).gameObject;
            var sprite = obj.GetComponent<UISprite>();
            BoxSprites[i - 1] = sprite;
        }

        UIEventListener.Get(BtnRestart).onClick = go =>
        {
            EndPanel.gameObject.SetActive(false);
            Debug.Log("重新开始");
            DoStart();
        };

        UIEventListener.Get(BtnIsPause).onClick = go =>
        {
            Debug.Log("开始/暂停");
            bPause = !bPause;
        };

        UIEventListener.Get(BtnUp).onClick = go =>
        {
            Debug.Log("上翻");
            DoTransform();
        };

        UIEventListener.Get(BtnDown).onPress = (go, state) =>
        {
            Debug.Log("下按");
            //state  true:按下   false:松开
            if (state)
                DoSpeedUp();
            else
                DoSpeedRestore();
        };

        UIEventListener.Get(BtnLeft).onClick = go =>
        {
            Debug.Log("左移");
            DoLeft();
        };

        UIEventListener.Get(BtnRight).onClick = go =>
        {
            Debug.Log("右移");
            DoRight();
        };

        this.DoStart();
    }

    void ScoreChange()
    {
        ScoreLabel.text = "获得积分:" + this.Score.ToString();
    }

    void LineCountChange()
    {
        LineCountLabel.text = "消灭行数:" + this.LineCount.ToString();
    }

    void GameOverChange(bool state)
    {
        if (state)
            EndPanel.SetActive(true);
    }

    /// <summary>
    /// 初始化10*16的格子
    /// </summary>
    void DoInit()
    {
        this.LineCount = 0;
        this.Score = 0;
        curSpeed = 1;

        for (int i = 0; i < aTable.Length; i++)
        {
            aTable[i] = new List<int>();
            for (int j = 0; j < cCol; j++)
                aTable[i].Add(0);
        }
    }

    void OnGUI()
    {
        if (!bStart)
            return;

        if (BGameOver)
        {
            return;
        }

        if (bPause)
        {
            return;
        }

        for (int i = 0; i < curCell.Length; i++)
        {
            for (int j = 0; j < curCell[i].Length; j++)
            {
                if (curCell[i][j] == 0)
                {
                    continue;
                }
                if (i + curCellRow < 0)
                {
                    continue;
                }
                GUI.DrawTexture(new Rect(boxLeft + boxSize * j + curCellCol * boxSize, boxTop + boxSize * i + curCellRow * boxSize, boxSize, boxSize), BoxTexture[0]);
            }
        }

        //背景图
        for (int i = 0; i < aTable.Length; i++)
        {
            for (int j = 0; j < cCol; j++)
            {
                if (aTable[i][j] == 0)
                {
                    continue;
                }
                GUI.DrawTexture(new Rect(boxLeft + boxSize * j, boxTop + boxSize * i, boxSize, boxSize), BoxTexture[aTable[i][j] - 1]);
            }
        }
    }

    string GetContent(int cellContent)
    {
        switch (cellContent)
        {
            case 0:
                return "";
            default:
                return cellContent.ToString();
        }
    }

    void DoStart()
    {
        DoInit();
        DoNextCell();

        bStart = true;
        BGameOver = false;
    }

    void DrawNextBox()
    {
        //绘制下一个图
        int boxIndex = 0;
        for (int i = 0; i < nextCell.Length; i++)
        {
            for (int j = 0; j < nextCell[i].Length; j++)
            {
                if (nextCell[i][j] == 0)
                {
                    continue;
                }
                BoxSprites[boxIndex++].transform.localPosition = new Vector3(j * 35, i * (-35), 0);
            }
        }
    }

    /// <summary>
    /// 随机生成下面一个模型
    /// </summary>
    void DoNextCell()
    {
        if (nextCell == null)
        {
            nextCellID = rdm.Next(aCells.Length);
            nextCell = aCells[nextCellID];
        }
        curCellCol = cCol / 2 - 2;
        curCellRow = -4;
        curCell = nextCell;
        curCellID = nextCellID;
        nextCellID = rdm.Next(aCells.Length);
        nextCell = aCells[nextCellID];

        DrawNextBox();

        DetectIsFail();
    }

    /// <summary>
    /// 放置当前的模型
    /// </summary>
    private void DoSetCurCellDown()
    {
        for (int i = 0; i < curCell.Length; i++)
        {
            for (int j = 0; j < curCell[i].Length; j++)
            {
                if (curCell[i][j] == 0)
                {
                    continue;
                }
                if (curCellRow + i < 0)
                {
                    BGameOver = true;
                    return;
                }
                aTable[curCellRow + i][curCellCol + j] = curCell[i][j];
            }
        }
        //速度重置
        DoSpeedRestore();
        //消除一行
        DoLine();
        //生成下一个模型
        DoNextCell();
    }

    void Update()
    {
        if (!bStart)
        {
            return;
        }

        if (BGameOver)
        {
            return;
        }

        if (bPause)
        {
            return;
        }

        //自动下滑
        fDeltaTime += Time.deltaTime;
        if (fDeltaTime > fCurSpeed)
        {
            fDeltaTime -= fCurSpeed;
            if (CanMoveTo(curCellCol, curCellRow + 1))
            {
                curCellRow++;
            }
            else
            {
                DoSetCurCellDown();
                return;
            }
        }

        if (BGameOver)
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow))  //左移
        {
            DoLeft();
        }
        if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow)) //右移
        {
            DoRight();
        }
        if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow))  //上翻
        {
            DoTransform();
        }
        if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow))  //按下快速下移
        {
            DoSpeedUp();
        }
        if (Input.GetKeyUp(KeyCode.S) || Input.GetKeyUp(KeyCode.DownArrow))  //按键取消 取消快速下移
        {
            DoSpeedRestore();
        }
    }

    /// <summary>
    /// 检测游戏是否结束
    /// </summary>
    private void DetectIsFail()
    {
        if (CanMoveTo(curCellCol, curCellRow))
        {
            return;
        }
        BGameOver = true;
    }

    /// <summary>
    /// 判断模型移动
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="cell"></param>
    /// <returns></returns>
    bool CanMoveTo(int x, int y, int[][] cell = null) // 3, -4
    {
        if (cell == null)
        {
            cell = curCell;
        }
        for (int i = 0; i < cell.Length; i++)
        {
            for (int j = 0; j < cell[i].Length; j++)
            {
                if (cell[i][j] == 0)
                {
                    continue;
                }
                if (x + j < 0 || x + j >= cCol)
                {
                    return false;
                }
                if (y + i >= cRow) //到顶了
                {
                    return false;
                }
                if (y + i < 0)
                {
                    continue;
                }
                if (aTable[i + y][j + x] != 0)
                {
                    return false;
                }
            }
        }
        return true;
    }

    private void DoSpeedRestore()
    {
        fCurSpeed = curSpeed;
    }

    //下移加速
    private void DoSpeedUp()
    {
        fCurSpeed = curSpeed / 8;
        fDeltaTime = fCurSpeed;
    }

    //右移
    private void DoRight()
    {
        if (CanMoveTo(curCellCol + 1, curCellRow))
        {
            curCellCol++;
        }
    }

    //左移
    private void DoLeft()
    {
        if (CanMoveTo(curCellCol - 1, curCellRow))
        {
            curCellCol--;
        }
    }

    //上翻
    private void DoTransform()
    {
        int transformedCellID = curCellID / 4 * 4 + (curCellID % 4 + 1) % 4;
        if (CanMoveTo(curCellCol, curCellRow, aCells[transformedCellID]))
        {
            curCellID = transformedCellID;
            curCell = aCells[transformedCellID];
        }
    }

    /// <summary>
    /// 消除一行
    /// </summary>
    private void DoLine()
    {
        List<int> fulledLines = new List<int>();
        for (int i = curCellRow; i < curCellRow + 4; i++)
        {
            if (i >= cRow)
            {
                continue;
            }
            if (i < 0)
            {
                BGameOver = true;
                return;
            }
            for (int j = 0; j < cCol; j++)
            {
                if (aTable[i][j] == 0)
                {
                    break;
                }
                if (j == cCol - 1)
                {
                    fulledLines.Add(i);
                }
            }
        }

        if (fulledLines.Count == 0)
        {
            return;
        }

        for (int i = 0; i < fulledLines.Count; i++)
        {
            for (int j = 0; j < cCol; j++)
            {
                aTable[fulledLines[i]][j] = 0;
            }
        }

        int ilastEmptyRow = fulledLines[fulledLines.Count - 1];
        int ilastNotEmptyRow = ilastEmptyRow - 1;
        while (true)
        {
            if (ilastNotEmptyRow < 0)
            {
                break;
            }

            if (!IsRowEmpty(ilastNotEmptyRow))
            {
                for (int j = 0; j < cCol; j++)
                {
                    aTable[ilastEmptyRow][j] = aTable[ilastNotEmptyRow][j];
                    aTable[ilastNotEmptyRow][j] = 0;
                }
                ilastEmptyRow--;
            }
            ilastNotEmptyRow--;
        }

        for (int i = 0; i < fulledLines.Count; i++)
        {
            for (int j = 0; j < cCol; j++)
            {
                aTable[i][j] = 0;
            }
        }
        //消除的行数
        LineCount += fulledLines.Count;
        //分数加成
        Score += fulledLines.Count * fulledLines.Count;

        curSpeed *= 0.99f;
    }

    bool IsRowEmpty(int irow)
    {
        for (int j = 0; j < cCol; j++)
        {
            if (aTable[irow][j] != 0)
            {
                return false;
            }
        }
        return true;
    }

    /// <summary>
    /// 各种形态的砖块  28个
    /// </summary>
    private int[][][] aCells = new int[][][]
        {
                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{0,1,1,0},
                        new int[]{0,1,1,0},
                        new int[]{0,0,0,0},
                },
                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{0,1,1,0},
                        new int[]{0,1,1,0},
                        new int[]{0,0,0,0},
                },
                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{0,1,1,0},
                        new int[]{0,1,1,0},
                        new int[]{0,0,0,0},
                },
                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{0,1,1,0},
                        new int[]{0,1,1,0},
                        new int[]{0,0,0,0},
                },

                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{0,0,1,1},
                        new int[]{0,1,1,0},
                        new int[]{0,0,0,0},
                },
                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{0,1,0,0},
                        new int[]{0,1,1,0},
                        new int[]{0,0,1,0},
                },
                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{0,0,1,1},
                        new int[]{0,1,1,0},
                        new int[]{0,0,0,0},
                },
                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{0,1,0,0},
                        new int[]{0,1,1,0},
                        new int[]{0,0,1,0},
                },

                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{1,1,0,0},
                        new int[]{0,1,1,0},
                        new int[]{0,0,0,0},
                },
                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{0,0,1,0},
                        new int[]{0,1,1,0},
                        new int[]{0,1,0,0},
                },
                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{1,1,0,0},
                        new int[]{0,1,1,0},
                        new int[]{0,0,0,0},
                },
                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{0,0,1,0},
                        new int[]{0,1,1,0},
                        new int[]{0,1,0,0},
                },

                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{1,1,1,1},
                        new int[]{0,0,0,0},
                        new int[]{0,0,0,0},
                },
                new int[][]
                {
                        new int[]{0,0,1,0},
                        new int[]{0,0,1,0},
                        new int[]{0,0,1,0},
                        new int[]{0,0,1,0},
                },
                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{1,1,1,1},
                        new int[]{0,0,0,0},
                        new int[]{0,0,0,0},
                },
                new int[][]
                {
                        new int[]{0,0,1,0},
                        new int[]{0,0,1,0},
                        new int[]{0,0,1,0},
                        new int[]{0,0,1,0},
                },

                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{0,1,0,0},
                        new int[]{1,1,1,0},
                        new int[]{0,0,0,0},
                },
                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{0,1,0,0},
                        new int[]{0,1,1,0},
                        new int[]{0,1,0,0},
                },
                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{0,0,0,0},
                        new int[]{1,1,1,0},
                        new int[]{0,1,0,0},
                },
                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{0,1,0,0},
                        new int[]{1,1,0,0},
                        new int[]{0,1,0,0},
                },

                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{0,1,1,0},
                        new int[]{0,0,1,0},
                        new int[]{0,0,1,0},
                },
                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{0,0,1,0},
                        new int[]{1,1,1,0},
                        new int[]{0,0,0,0},
                },
                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{0,1,0,0},
                        new int[]{0,1,0,0},
                        new int[]{0,1,1,0},
                },
                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{1,1,1,0},
                        new int[]{1,0,0,0},
                        new int[]{0,0,0,0},
                },

                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{0,1,1,0},
                        new int[]{0,1,0,0},
                        new int[]{0,1,0,0},
                },
                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{1,1,1,0},
                        new int[]{0,0,1,0},
                        new int[]{0,0,0,0},
                },
                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{0,0,1,0},
                        new int[]{0,0,1,0},
                        new int[]{0,1,1,0},
                },
                new int[][]
                {
                        new int[]{0,0,0,0},
                        new int[]{1,0,0,0},
                        new int[]{1,1,1,0},
                        new int[]{0,0,0,0},
                },
        };
}

欢迎加群交流

1.unity游戏开发群

2.专门探讨XLua的程序群:437645698


下载地址

https://git.oschina.net/dingxiaowei/Aladdin_XLua.git

Github同步:https://github.com/dingxiaowei/Aladdin_XLua

关注后续更新请点start或者fork,感谢!

时间: 2024-10-18 07:46:45

[Unity XLua]热更新XLua入门(二)-俄罗斯方块实例篇的相关文章

Unity3D|-XLua热更新用法的大致流程

xlua是由腾讯维护的一个开源项目,我们可以在github上下载这个开源项目并查看一些相关文档 官网:https://github.com/Tencent/xLua 配置文档:https://github.com/Tencent/xLua/blob/master/Assets/XLua/Doc/hotfix.md 常见问题解答:https://github.com/Tencent/xLua/blob/master/Assets/XLua/Doc/faq.md 接下来我们来走一遍使用xlua的大致

Unity3D热更新全书-脚本(二) 两级分化

上篇明确了我们探讨的脚本是什么:是写在文本文件里面的代码,可以作为资源加载,取得字符串再执行. 可是为什么世界上会有那么多的脚本?而其使用方法完全看起来不一样呢?这是因为每种脚本都有自己的定位,在不同的复杂度脚本将表现出完全不同的样貌,我们来看一下. 复杂度一:计算 执行字符串的核心函数应该是这样的 int i = Eval("1+2"); 我们有一套例子,本文最后有如何取得例子的说明. 程序里就可以通过执行字符串来执行逻辑,字符串的变更就可以得到逻辑的变更. 试想如果要做公式计算,他

Unity3D热更新全书-下载 唯一的一篇

下载在这个时代实在是太平常了,每个人都深刻的理解着下载到底是什么. 这一篇文字只是把下载的代码分享并介绍,而已. 首先,下载系统担负着几个使命. 第一.是保持客户端版本库的最新. 第二.是下载要能够比对并最少下载 第三.是要尽量快一些. 其实我们并没有写一个下载系统,因为实在没有几行代码.我们这里介绍的是一个 Http下载并保存缓存,首包从StreamingAssets读取,加载资源,三个功能在一起的模块 源码位置https://github.com/lightszero/easydown 保持

二、unity游戏热更新专题

第 1 章 : 热更新技术学习介绍 课时1:101-热更新技术学习介绍 11:55 什么是热更新? 举例来说 游戏上线后,玩家下载第一个版本(70M左右或者更大),在运营的过程中,如果需要更换UI显示,或者修改游戏的逻辑,这个时候,如果不使用热更新,就需要重新打包,然后让玩家重新下载(浪费流量和时间,体验不好). 热更新可以在不重新下载客户端的情况下,更新游戏的内容. 热更新一般应用在手机网游上. 为什么C#脚本不可以直接更新? C#是一门编程语言,它运行之前需要进行编译,而这个编译的过程在移动

Unity逻辑热更新

声明:原博链接: http://blog.csdn.net/janeky/article/details/17652021只是把自己研究实践的过程记录下来 先直接上代码:两个类,一个检测资源更新,有更新则下载到本地(ResUpdate),一个是逻辑热更新(LogicUpdate)一.资源对比更新并下载.资源是否更新了是通过比对服务器与客户端的 资源版本表: version.txt该文本文档内容为: Cube.assetbundle,78a6cd06388449d16aea5f6eae395abf

用ECMAScript4 ( ActionScript3) 实现Unity的热更新 -- 使用原型链和EventTrigger

原型链是JS的必备,作为ECMAScript4,原型链也是支持的. 特别说明,ActionScript3是支持完整的面向对象继承支持的,原型链只在某些非常特殊的情况下使用. 本文旨在介绍如何使用原型链. 任意对象类型都有一个prototype属性,包括导入的Unity的API也有.我们可以和JS一样的对这个prototype进行操作,比如动态的添加成员,添加方法等. 如果您决定使用原型链,那么必须舍弃编译时类型检查.如果使用强类型,则编译器会认为动态添加的成员不存在,而提示编译错误.解决办法为去

用ECMAScript4 ( ActionScript3) 实现Unity的热更新 -- 使用FairyGUI (一)

我们的热更新脚本在实际使用中,当然也要支持常用的第三方组件,例如这里介绍一个非常实用的第三方UI库:FairyGUI. 什么是FairyGUI 这里照搬FaiyGUI官网的介绍: 重新定义 UI 制作流程,全可视化,零代码,是一款同时适用于程序员.设计师和游戏策划的UI制作工具. 配合FairyGUI-SDK,在各个游戏引擎都能得到高效的渲染表现,独特的FairyBatching技术可自动优化复杂界面的DC数量. 我们这里自然是使用它的Unity组件啦. 我们这篇文章的主旨并非是介绍如何使用Fa

Android 美团Robust热更新 使用入门

Android热更新方案Robust 相信很多人都认识了解过 热修复.热更新.热补丁(对于这个技术也没有特别标准的一种叫法,下面我统一叫热更新),之后的一年里,各种热更新方案如雨后春笋般出现,比较耳熟能详的就有Nuwa.Tinker.Andfix 和 Dexposed 等等,他们之间的区别以及优缺点就不在这里讨论了,鉴于它们的实际使用和局限性,美团的开发团队就脑洞大开了. 就去年 Google 高调发布了 Android Studio 2.0,其中最重要的新特性Instant Run,实现了对代

Unity代码热更新方案 JSBinding + SharpKit 介绍

目前Unity的代码更新方案有很多,主要以lua为主. JSBinding + SharpKit 是一种新的技术,他做了两件事情: JSBinding将C#导出到JS中,让你可以用JS写代码,就好像 lua 一样 SharpKit(sharpkit.net)将C#代码翻译成JS代码. 因此,他可以让你使用C#编译代码,之后一键转换成JS代码并正常运行.如果你的项目已经使用C#开发并希望能够更新代码,欢迎尝试使用. 本文先做简介,后续本博客将做详细介绍. 完全支持序列化功能.即可以在 Inspec