这仅用于编辑编辑器中的对象吗?如果是这样,那么听起来预制件是要走的路;您可以直接编辑预制件,它在场景中的所有“克隆”都将进行所有更改,包括所有单体行为、变换以及未复制到预制件的内容。
如果您需要它在运行时工作,那么您可能需要一些代码来为您执行此操作。您还没有对您到底想要做什么提供足够的说明,因此对于下面的示例,我假设您有一个带有网格或精灵组件的游戏对象,并希望它的大小/比例与它的所有“一起修改”克隆”;
using UnityEngine;
using System.Collections.Generic;
public class ShapeClone : MonoBehaviour
{
//This will hold references to the other "clone" gameobjects.
public List<GameObject> otherClones = new List<GameObject>();
//All the "clones" in the list otherClones will have their scale matched to this gameobject's scale
public bool leader;
private void Update()
{
if (leader) //Only change other clones' scales if marked as leader, to avoid every single clone
//overriding each other's scale every single frame, which could be rather chaotic
{
for (int i = 0; i < otherClones.Count; i++)
{
//setting each of the other clones' scale to that of this object.
otherClones[i].transform.localScale = this.transform.localScale;
}
}
}
}
上面是一个简短的例子,给你一个想法,绝不是广泛的,但你应该能够将它应用到你正在尝试做的事情中;例如,如果您想在游戏对象之间复制精灵的颜色,您可以修改otherClones
为Sprite
引用列表,而不是在更新中设置比例,您可以将每个 Sprite 组件的颜色设置为这个对象。
但是,如果您只在编辑器中而不是在运行时需要此功能 - 我强烈建议您使用预制件的第一个选项,因为它会以一小部分成本和性能为您提供更多功能。