小编use*_*261的帖子

从另一个Thread使用Unity API或调用主Thread中的函数

我的问题是我尝试使用Unity套接字来实现一些东西.每次,当我收到新消息时,我需要将其更新为updattext(它是Unity Text).但是,当我执行以下代码时,void update不会每次都调用.

我没有包含updatetext.GetComponent<Text>().text = "From server: "+tempMesg;在void getInformation中的原因是这个函数在线程中,当我在getInformation()中包含它时会出现错误:

getcomponentfastpath can only be called from the main thread

我认为问题是我不知道如何在C#中运行主线程和子线程?或者可能还有其他问题...希望有人可以提供帮助..有我的代码:

using UnityEngine;
using System.Collections;
using System;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using UnityEngine.UI;


public class Client : MonoBehaviour {

    System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient();
    private Thread oThread;

//  for UI update
    public GameObject updatetext;
    String tempMesg = "Waiting...";

    // Use this for initialization
    void Start () {
        updatetext.GetComponent<Text>().text = "Waiting...";
        clientSocket.Connect("10.132.198.29", 8888);
        oThread = new Thread (new ThreadStart …
Run Code Online (Sandbox Code Playgroud)

c# multithreading unity-game-engine

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

在python中读取csv文件两次

这是我的Python代码:

import csv

# Reading
ordersFile = open('orders.csv', 'rb')
ordersR = csv.reader(ordersFile, delimiter=',')

# Find order employeeID=5, shipCountry="Brazil"
print "Find order employeeID=5, shipCountry=\"Brazil\""
for order in ordersR:
    if order[2] == '5' and order[13] == 'Brazil':
        print order
# Find order employeeID=5
print "Find order employeeID=5"
for order in ordersR:
    if order[2] == '5':
        print order
ordersFile.close()
Run Code Online (Sandbox Code Playgroud)

我可以打印“#查找订单employeeID = 5,shipCountry =“巴西”“,但是对于#查找订单employeeID = 5我什么也没得到。我在想如何多次读取(选择)同一csv文件中的行。

python csv python-2.7

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

Java通过引用传递与listNode问题

我有一堂课:

class ListNode {
     int val;
     ListNode next;
     ListNode(int x) { val = x; }
}
Run Code Online (Sandbox Code Playgroud)

打印LinkedList的函数是:

public static void printLinkedNode(ListNode l){
        while(l != null){
            System.out.print(l.val+" ");
            l = l.next;
        }
        System.out.println(" ");
    }
Run Code Online (Sandbox Code Playgroud)

在我的主要功能中,我创建了一个名为test的ListNode:

ListNode test = new ListNode(1);
head.next = new ListNode(2);
head.next.next = new ListNode(3);
head.next.next.next = new ListNode(4);
Run Code Online (Sandbox Code Playgroud)

如果我做答:

ListNode fast = head, slow = head;
fast = fast.next.next;
printLinkedNode(head); // I get 1->2->3->4
Run Code Online (Sandbox Code Playgroud)

如果我做B:

ListNode fast = head, slow = head;
fast.next = fast.next.next;
printLinkedNode(head); …
Run Code Online (Sandbox Code Playgroud)

java assign

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

标签 统计

assign ×1

c# ×1

csv ×1

java ×1

multithreading ×1

python ×1

python-2.7 ×1

unity-game-engine ×1