问题列表 - 第318055页

如何将类列表从一个脚本复制到另一个包含相同类的脚本

脚本A

public class ScriptA: MonoBehaviour{

public List<LootItemsList> _lootItemsListToUse;

[System.Serializable]
public class LootItemsList
{
    public GameObject _lootItem;
    public Vector3 _lootItemOrigin;
    public float _lootColliderActivationTime = 0.5f;
}}
Run Code Online (Sandbox Code Playgroud)

脚本B

 public class ScriptB: MonoBehaviour{

public List<LootItemsList> _lootItemsListToUse;

[System.Serializable]
public class LootItemsList
{
    public GameObject _lootItem;
    public Vector3 _lootItemOrigin;
    public float _lootColliderActivationTime = 0.5f;
}

void Start(){
ScriptA scriptA = ObjA.GetComponent<ScriptA>();
    _lootItemsListToUse = scriptA._lootItemsListToUse;
}}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:错误 CS0029 无法将类型“System.Collections.Generic.List<ScriptB.LootItemsList>”隐式转换为“System.Collections.Generic.List<ScriptA.LootItemsList>”

我也尝试过这个

_lootItemsListToUse  = new List<ScriptA.LootItemsList>((IEnumerable<ScriptA.LootItemsList>)script._lootItemsList);
Run Code Online (Sandbox Code Playgroud)

MS studio 中没有错误,但我在播放时遇到此错误:InvalidCastException:指定的演员无效。(包装类型转换)System.Object.__castclass_with_cache(object,intptr,intptr)

请有人帮我找到复制此列表的正确方法吗?谢谢

c# unity-game-engine

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

require 表达式的隐式可复制要求

以下代码是否需要 T 的隐式复制构造函数,因为参数是按值传递的?或者它的行为类似于 decltype 并且不涉及真正的构造?

template<typename T>
concept Addable = requires (T a, T b){ a + b; };
Run Code Online (Sandbox Code Playgroud)

c++ c++-concepts c++20 requires-expression

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

使用像素 8 进行颤振调试开始显示 E/lutter_progetto(5180): PIXEL: ioctl err: 1

我正在开发一个带有 flutter 的应用程序,今天突然当我使用物理设备(pixel 8)进行调试测试时,我在每次交互时都会在控制台中收到以下错误。

我做一些研究没有发现任何类似的东西,它突然开始出现,我不知道原因,也无法猜测原因是什么。我在 Pixel 8 上启动的每个应用程序都有这个问题。我有第二个设备,没有电话 1,但这种情况不会发生。

此外,当启动每个应用程序时,这些字符串会出现(黄色的字符串不止一行),这是我以前从未见过的(总是且仅在像素 8 上)。

我想了解发生了什么事,有人可以帮助我吗?

我尝试用 flutter clean 清理 flutter 文件夹,但没有得到任何结果。我重新启动 Pixel 8,但没有得到任何结果。

flutter flutter-debug

7
推荐指数
0
解决办法
315
查看次数

在JDK 1.8源码中,为什么用AB&gt;0来判断哪一个更大,而不是A&gt;B呢?

作为一个初学者,最近阅读了JDK1.8的源码。我面临的问题是为什么用AB>0来判断哪个更大,而不是A>B?

下面的代码在java/util/ArrayList.java:236中

private void ensureExplicitCapacity(int minCapacity) {
    modCount++;

    // overflow-conscious code
    if (minCapacity - elementData.length > 0)
        grow(minCapacity);
}
Run Code Online (Sandbox Code Playgroud)

我无法理解 的代码minCapacity - elementData.length > 0。为什么不使用 minCapacity > elementData.length。

java java-8

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

获取python中搜索字符串后的值

我需要从包含类似以下格式的行的日志中检索值,因为我的输入行如下所示:

line = "(last_bytes wrote 66560002, cur_bytes read 33280206, curr_bytes wrote 66560002, blks read 103335128)"
    
Run Code Online (Sandbox Code Playgroud)

我需要根据我的搜索字符串获取值

Ex: search(last_bytes wrote)  =  66560002
    search(cur_bytes read)  = 33280206
Run Code Online (Sandbox Code Playgroud)

我曾尝试在写入/读取后分割行并搜索下一个字符串,但这似乎确实返回了意外的值。

有没有办法在 python 中获取这些值?

python string split

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

加速模拟

我有以下情况:

如果该马尔可夫链从位置 = 5 开始,则变量在 prob=0.5 时移动 +1,在 prob=-0.5 时移动 -1

  • 情况 1:变量首次达到位置 = 0 的预期时间是多少?
  • 情况 2:变量在至少一次达到position=10 后首次达到position=0 的预期时间是多少?

我尝试按如下方式执行此操作(我创建了一个跟踪变量来查看模拟卡在哪里):

# the simulations can take a long time to run, I interrupted them

library(ggplot2)
library(gridExtra)

n_sims <- 100
times_to_end_0 <- numeric(n_sims)
times_to_end_0_after_10 <- numeric(n_sims)
paths_0 <- vector("list", n_sims)
paths_0_after_10 <- vector("list", n_sims)

for (i in 1:n_sims) {
    print(paste("Running simulation", i, "for situation 1..."))
    y <- 5
    time <- 0
    path_0 <- c(y)

    while(y > 0) {
        step <- sample(c(-1, …
Run Code Online (Sandbox Code Playgroud)

algorithm performance r random-walk

9
推荐指数
3
解决办法
326
查看次数

如何在flutter中制作底部标签栏PlayStation风格?

import 'package:flutter/material.dart';

class BottomBarClipper extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    Path path = Path();
    
    final notchRadius = 25.0;

    path.lineTo(size.width / 2 - notchRadius * 2, 0);
    path.relativeArcToPoint(
      Offset(notchRadius * 2, notchRadius),
      radius: Radius.circular(notchRadius),
      clockwise: false,
    );
    path.lineTo(size.width / 2 + notchRadius * 2, 0);
    path.lineTo(size.width, 0);
    path.lineTo(size.width, size.height);
    path.lineTo(0, size.height);
    path.close();

    return path;
  }

  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}
Run Code Online (Sandbox Code Playgroud)

我不确定如何修改 CustomClipper 中底部NavigationBar 的自定义形状。

这就是我所期望的 .gif 中的内容

在此输入图像描述

dart flutter

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

GCC 出于什么目的创建应用于移位项的单独位掩码?

以下是一个最小的可重现代码示例,我必须uint_fast64_t在给定的八叉树分支x z和y位置中生成 3D 坐标的“数组”(其 1 字节元素被打包到结果中):

#include <stdint.h>
void test(uint_fast64_t *const coord, const uint_fast8_t x, const uint_fast8_t z, const uint_fast8_t y) {
    static const uint_fast64_t m = 0x2040810204081ULL, a = 0x101010101010101ULL;
    *coord = (x * m & a) | (z * m & a) << 1 | (y * m & a) << 2;
}
Run Code Online (Sandbox Code Playgroud)

从汇编来看,GCC 似乎只生成常量的一个“变体” m,但生成了三个variants常量a,包括0x404040404040404和0x202020202020202。

test:
        movabs  rax, 567382630219905 ; 0x2040810204081 …
Run Code Online (Sandbox Code Playgroud)

c assembly gcc compiler-optimization constantfolding

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

为什么我没有获得返回函数的唯一指针?

func creator(v string) func() string {
    return func() string {
        return v
    }
}

func getters(runID string) []func() string {
    return []func() string{
        creator(runID),
    }
}

func TestPtrs(t *testing.T) {
    var allVals []func() string
    for i := 0; i < 20; i++ {
        vals := getters(fmt.Sprintf("run-%d", i))
        for j := range vals {
            fmt.Printf("[%d] Valueof %v pointer: %d\n", i, reflect.ValueOf(vals[j]), reflect.ValueOf(vals[j]).Pointer())
        }
        allVals = append(allVals, vals...)
    }

    for i := range allVals {
        fmt.Printf("[%d] %s\n", i, allVals[i]()) // Works as …
Run Code Online (Sandbox Code Playgroud)

go

6
推荐指数
0
解决办法
123
查看次数

List.getFirst() 上的编译错误:找不到符号?

您能检测到编译问题吗?它在本地编译没有任何错误。但是,当使用我无法影响的远程自动编码服务编译它时,它会失败。

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /tmp/builds/autocode_133386/src/main/java/com/classes/ArrayRectangles.java:[76,46] cannot find symbol
  symbol:   method getFirst()
  location: variable perimeters of type java.util.List<java.lang.Double>
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.849 s
[INFO] Finished at: 2024-01-17T07:57:25Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project Classes: Compilation failure
[ERROR] /tmp/builds/autocode_133386/src/main/java/com/classes/ArrayRectangles.java:[76,46] cannot find symbol
[ERROR]   symbol:   method getFirst()
[ERROR]   location: variable perimeters of type java.util.List<java.lang.Double>
Run Code Online (Sandbox Code Playgroud)

我的代码

List<Double> perimeters = new ArrayList<>();
...
double …
Run Code Online (Sandbox Code Playgroud)

java

-3
推荐指数
1
解决办法
902
查看次数