斜方向分割二维数组(lua简易实现)

分析规律(下图为11行-5列示例)

  • 同颜色数字相差值为列数-1
  • 可以产生(行数+列数-1)组数字(如图是15)
  • 每组数字中,每一行最多只有一个(同行号应舍去)

function formatVal(val)
    if val < 10 then return " " .. tostring(val) end
    return tostring(val)
end

local cols = 5
local rows = 11
local t = {}
local gap = " "
for r = 1, rows do
    local line = ""
    for c = 1, cols do
        local val = (r - 1) * cols + c
        table.insert(t, val, val)
        line = line .. " " .. formatVal(val)
    end
    print(line)
end

function SplitBySlash(t, cols, rows)
    local arr2 = {}
    local offset = cols - 1
    for c = 1, rows + cols - 1 do
        local arr = {}
        for r = 1, rows do
            local n = c + (r - 1) * offset
            local fakeR = math.ceil(n / cols)
            if fakeR == r then
                table.insert(arr, n)
                print(n, r, fakeR)
            end

        end
        print("================")
        table.insert(arr2, arr)
    end
    return arr2
end

local function __dump(var, level)
    local rval = {}
    table.insert(rval, "{")
    for k, v in pairs(var) do
        if type(v) == "table" and getmetatable(var) ~= v then
            if k ~= "__base" then
                table.insert(rval, string.format("%s%s=%s",
                                                 string.rep("    ", level), k,
                                                 __dump(v, level + 1)))
            end
        elseif type(v) ~= "function" then
            table.insert(rval, string.format("%s%s=%s",
                                             string.rep("    ", level), k,
                                             tostring(v)))
        end
    end
    table.insert(rval, string.format("%s}", string.rep("    ", level - 1)))
    return table.concat(rval, "\n")
end

local function log(inst)
    if inst == nil then
        print(nil)
        return
    end
    print(__dump(inst, 1))
end

local array2 = SplitBySlash(t, cols, rows)
log(array2)

最终效果

C# 使用LINQ比较两个数组的差异

string[] arrRate = new string[] { "a", "b", "c", "d" };//A
string[] arrTemp = new string[] { "c", "d", "e" };//B

string[] arrUpd = arrRate.Intersect(arrTemp).ToArray();//相同的数据 (结果:c,d)
string[] arrAdd = arrRate.Except(arrTemp).ToArray();//A中有B中没有的 (结果:a,b)
string[] arrNew = arrTemp.Except(arrRate).ToArray();//B中有A中没有的 (结果:e)

关于bash:在sed命令中转义正斜杠

  1. 如果replace内容不包含/这种写法没问题sed"s/regex/replace/" file
  2. 如果replace内容包含/,则改变分割符号为|,完整写法为 sed"s|regex|replace|" file ,这样就不用为\写转义了

常用模拟器adb连接端口

::夜神安卓模拟器 62001
::逍遥安卓模拟器  21503
::蓝叠安卓模拟器  5555
::雷电安卓模拟器 5555
::天天安卓模拟器  5037
::网易MuMu模拟器  7555
::安卓模拟器大师  54001
::腾讯手游助手   5555

adb connect 127.0.0.1:62001
adb logcat -s Unity

导航报错SetDestination() can only be called on an active agent that has been placed on a NavMesh

原因:初始化导航组件NavMeshAgent 的时候,agent 离navmesh太远。isOnNavMesh属性为false;

解决办法: 在初始化预制体的时候,传入诞生点位置和旋转信息。

GameObject.Instantiate(m_shooter, m_currBirthPoint.transform.position,m_currBirthPoint.transform.rotation) as GameObject;

而不是直接初始化,后设置诞生点位置。

GameObject.Instantiate(m_shooter);
shooter.transform.position = m_currBirthPoint.transform.position;

另外:在重新使用SetActive(true);的时候,也要确保agent 离navmesh足够近。 建议在设置SetActive(false);的时候,就不要改变位置信息,以免重新激活时离导航网格太远。