小编Jim*_*Jim的帖子

将列表传递给方法,在方法内修改列表,而不会影响“原始”

抱歉,如果该主题含糊不清,我会尽可能地总结一下,而不知道要达到的确切术语。

本质上我有一个列表,然后调用一个方法

public List<int> myList;

void Start () {
    myList = new List<int>();
    myList.Add (1);
    myList.Add (2);

    doSomething(myList);

    foreach (int i in myList){
        print (i);
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的方法中,我想这样做(例如)

public void doSomething (List<int> myPassedList) 
{

    int A = 5;
    myPassList.Add (A);
    //... And then some other cool code with this modified list
}
Run Code Online (Sandbox Code Playgroud)

但是,我不想更改原始列表,我希望它保持原样。本质上,当我将列表传递给方法时,我想要列表的副本,然后在每次调用该方法时将其复制。

我想看到控制台打印“ 1”然后是“ 2”

但会显示“ 1”,“ 2”和“ 5”

希望这一切都有道理!非常感谢您的任何帮助

吉姆

.net c# list

4
推荐指数
2
解决办法
3888
查看次数

检查UI元素/ RectTransform是否重叠

我想知道如何检查Unity Canvas上的两个UI面板是否相互重叠。

目前,我正在通过比较画布元素Rects来做到这一点

画布设置

  • 渲染模式:屏幕空间-相机
  • 像素完美:[是]
  • 渲染相机:主相机
  • 平面距离:100
  • 排序层:默认
  • 图层顺序:0

画布缩放器设置

  • UI缩放模式:恒定像素大小
  • 比例因子:1
  • 每单位参考像素:100

我正在检查的代码

[Header("Check For Overlap")]
public RectTransform PlayerBar;
public RectTransform LeftBar;
public Rect RectOne;
public Rect RectTwo;
public bool overlapping;

//Check if the two canvas element Rects overlap each other

public void CheckForOverlap()
{
    overlapping = false;
    // Convert Canvas RectTransforms to World Rects
    RectOne = GetWorldRect(LeftBar);
    RectTwo = GetWorldRect(PlayerBar);

    if (RectOne.Overlaps(RectTwo))
    {
        overlapping = true;
    }
}


public Rect GetWorldRect(RectTransform rt)
{
    //  Get World corners, …
Run Code Online (Sandbox Code Playgroud)

c# user-interface rect unity-game-engine

4
推荐指数
2
解决办法
6486
查看次数

如何在Unity中实现和使用低级键盘钩子来禁用Windows快捷方式?

我的问题

如何在Unity中实现和使用低级键盘钩子来禁用Windows快捷方式?

我想通过意外使用Windows密钥来防止用户失去我的游戏焦点.这是因为我的应用程序是专为可以随机按键盘的幼儿设计的.

搜索堆栈溢出看来,我需要实现一个低级键盘钩子.

我试过了什么

以下内容已在Unity中实施.当按下打印屏幕按钮时,它应该将我的应用程序的背景颜色变为黑色,证明我已正确实现它.但是,在测试时,看看我是否可以使用此捕获键盘输入,我发现了这段代码

        Debug.Log("Print Screen");
        Camera cam = FindObjectOfType<Camera>();
        cam.backgroundColor = Color.black; 
Run Code Online (Sandbox Code Playgroud)

没有被调用,背景颜色不会变为黑色.

代码

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace SnagFree.TrayApp.Core
{
    class GlobalKeyboardHookEventArgs : HandledEventArgs
    {
        public GlobalKeyboardHook.KeyboardState KeyboardState { get; private set; }
        public GlobalKeyboardHook.LowLevelKeyboardInputEvent KeyboardData { get; private set; }

        public GlobalKeyboardHookEventArgs(
            GlobalKeyboardHook.LowLevelKeyboardInputEvent keyboardData,
            GlobalKeyboardHook.KeyboardState keyboardState)
        {
            KeyboardData = keyboardData;
            KeyboardState = keyboardState;
        }
    }

    //Based on https://gist.github.com/Stasonix
    class GlobalKeyboardHook : IDisposable
    {
        public event EventHandler<GlobalKeyboardHookEventArgs> KeyboardPressed;

        public GlobalKeyboardHook() …
Run Code Online (Sandbox Code Playgroud)

c# windows unity-game-engine

4
推荐指数
1
解决办法
339
查看次数

Maya Python:如何获取场景名称,但不能获取路径或扩展名

我只想获取当前打开的文件的场景名称。不是路径或扩展名。

cmds.file(q=True, sn=True)
Run Code Online (Sandbox Code Playgroud)

我不能使用上述内容,因为它会返回完整路径。

谢谢

python maya

2
推荐指数
1
解决办法
5677
查看次数

如何修改 Bresenham 的线算法以保持顺序?

我一直在努力尝试用粘在网格上的鼠标画一条线。我正在使用 Bresenhams 线算法。

但是我需要它来保留顺序,因此如果用户向左绘制,它将按该顺序给我点数。

WorldTile 是一个在网格上充当节点的类。

WorldBoard 是一组 WorldTiles。

private static void Swap<T>(ref T lhs, ref T rhs) 
{
    T temp; 
    temp = lhs; 
    lhs = rhs; 
    rhs = temp; 
}

public static IEnumerable<WorldTile> GetWorldTilesOnLine(int x0, int y0, int x1, int y1)
{


    bool steep = Mathf.Abs(y1 - y0) > Mathf.Abs(x1 - x0);

    if (steep)
    { 
        Swap<int>(ref x0, ref y0); // find out how this works
        Swap<int>(ref x1, ref y1); 
    }

    if (x0 > x1)
    {
        Swap<int>(ref x0, ref x1); …
Run Code Online (Sandbox Code Playgroud)

c# algorithm rasterizing unity-game-engine

1
推荐指数
1
解决办法
591
查看次数

npm install --save express@4.10.2 是什么意思,我该如何使用它?

我对 Node.JS 非常陌生(如果可以帮助您进行任何比较,我的背景是 Unity C#)。

我在 Socket.IO 的聊天教程

http://socket.io/get-started/chat/

我不明白这是什么意思

First let’s create a package.json manifest file that describes our project. 
I recommend you place it in a dedicated empty directory (I’ll call mine   
chat-example).

{
  "name": "socket-chat-example",
  "version": "0.0.1",
  "description": "my first socket.io app",
  "dependencies": {}
}

Now, in order to easily populate the dependencies with the things we need, we’ll 

npm install --save express@4.10.2
Run Code Online (Sandbox Code Playgroud)
  1. 什么是“保存”?
  2. 这是否意味着在安装了 Node.JS 的服务器上的命令提示符下使用?

javascript node.js express socket.io

1
推荐指数
1
解决办法
1423
查看次数

如何使用Newtonsoft.JSON和C#迭代嵌套的JSON字段(并且不使用动态关键字)

以下JSON文件包含字段' tileproperties '.在tileproperties中,有0到19 之间的数字.

在这种特殊情况下,数字量不固定,JSON文件可能包含更多.

在这些数字的每个下面都有字段名称TileType,带有字符串值(例如"river01","river02"等).

我想阅读这个JSON文件并创建一个字典.关键是数字,值是TileType.特别是我想使用Newtonsoft.JSON,C#,我无法使用dynamic关键字(如堆栈溢出中的类似问题所示)

我不确定如何遍历tileproperties字段,因为它似乎没有被格式化为数组(如数据字段).

    { "height":2,
 "infinite":false,
 "layers":[
        {
         "data":[1, 2, 11, 12, 1, 2, 6, 7, 16, 17, 6, 7],
         "height":2,
         "name":"Tile Layer 1",
         "opacity":1,
         "type":"tilelayer",
         "visible":true,
         "width":6,
         "x":0,
         "y":0
        }],
 "nextobjectid":1,
 "orientation":"orthogonal",
 "renderorder":"right-up",
 "tiledversion":"1.1.2",
 "tileheight":512,
 "tilesets":[
        {
         "columns":5,
         "firstgid":1,
         "image":"..\/Art\/Sprites\/PrototypeTileSheet.png",
         "imageheight":2048,
         "imagewidth":2560,
         "margin":0,
         "name":"prototypeTiles",
         "spacing":0,
         "tilecount":20,
         "tileheight":512,
         "tileproperties":
            {
             "0":
                {
                 "TileType":"river01"
                },
             "1":
                {
                 "TileType":"river02"
                },
             "10":
                {
                 "TileType":"start01" …
Run Code Online (Sandbox Code Playgroud)

c# json unity-game-engine

0
推荐指数
1
解决办法
336
查看次数