コード例 #1
0
        public void Create(ItemTemplateId templateId, Vector3 position, Quaternion rotation)
        {
            if (!itemTemplates.TryGetValue(templateId, out var itemTemplate))
            {
                return;
            }
            if (itemTemplate.gameObject == null)
            {
                return;
            }
            var createdGameObject = GameObject.Instantiate(itemTemplate.gameObject, position, rotation);
            var createdItem       = createdGameObject.GetComponent <IItem>();

            createdItem.Id = ItemId.Create(); // todo: 重複チェック
            OnCreate?.Invoke(createdItem);
            OnCreateCompleted?.Invoke(createdItem);
        }
コード例 #2
0
        public static void AssignItemId()
        {
            var scene       = SceneManager.GetActiveScene();
            var rootObjects = scene.GetRootGameObjects();
            var hashSet     = new HashSet <ItemId>();

            foreach (var item in rootObjects.SelectMany(o => o.GetComponentsInChildren <Item.Implements.Item>(true)))
            {
                while (item.Id.Value == 0 || hashSet.Contains(item.Id))
                {
                    var id = ItemId.Create();
                    item.Id = id;
                    if (!Application.isPlaying)
                    {
                        EditorUtility.SetDirty(item);
                        EditorSceneManager.MarkSceneDirty(scene);
                    }
                }
                hashSet.Add(item.Id);
            }
        }