ParticleEffectForUGUI/Samples~/Demo/Scripts/CopyItemOnStart.cs

32 lines
806 B
C#
Raw Normal View History

2024-01-23 22:17:57 +08:00
using UnityEngine;
2023-08-17 08:43:02 +08:00
using UnityEngine.Serialization;
2022-06-09 00:50:36 +08:00
namespace Coffee.UIExtensions.Demo
{
public class CopyItemOnStart : MonoBehaviour
{
2023-08-17 08:43:02 +08:00
[FormerlySerializedAs("origin")]
[SerializeField]
private GameObject m_Origin;
[FormerlySerializedAs("count")]
[SerializeField]
private int m_Count;
2022-06-09 00:50:36 +08:00
private void Start()
{
2023-08-17 08:43:02 +08:00
if (!m_Origin) return;
m_Origin.SetActive(false);
2022-06-09 00:50:36 +08:00
2023-08-17 08:43:02 +08:00
var parent = m_Origin.transform.parent;
for (var i = 0; i < m_Count; i++)
2022-06-09 00:50:36 +08:00
{
2023-08-17 08:43:02 +08:00
var go = Instantiate(m_Origin, parent, false);
go.name = $"{m_Origin.name} {i + 1}";
2022-06-09 00:50:36 +08:00
go.hideFlags = HideFlags.DontSave;
go.SetActive(true);
}
}
}
2023-08-17 08:43:02 +08:00
}