public static ItemDescriptor CreateItemDescriptor(SceneItem item) { ItemDescriptor itemDescriptor = new ItemDescriptor(); itemDescriptor.name = item.gameObject.name; if (string.IsNullOrEmpty(item.DisplayName.Trim())) { itemDescriptor.displayName = SceneDescriptorsHelper.ToDisplayName(item.gameObject.name); } else { itemDescriptor.displayName = item.DisplayName.Trim(); } if (item.Silhouette != null) { itemDescriptor.displayImage = CreateImageDescriptor(item.Silhouette); } itemDescriptor.placeHolders = GetItemPlaceHolders(item); return(itemDescriptor); }
private void AttachSceneItemComponents(Dictionary <string, Item> items) { if (items == null) { #if DEBUG_SCENE_GENERATION Debug.LogError("AttachSceneItemComponents: Error: items is null"); #endif return; } foreach (var item in items) { Transform sceneItem = null; SceneItem sceneItemComponent = null; foreach (var placeHolder in item.Value.placeHolders) { if (placeHolder.Value.itemImage == null) { foreach (var patch in placeHolder.Value.patches) { patch.gameObject.transform.SetParent(GetErrorFolder()); } foreach (var shadow in placeHolder.Value.shadows) { shadow.gameObject.transform.SetParent(GetErrorFolder()); } } else { Transform parent = null; if (sceneItem == null) { sceneItem = new GameObject(item.Key).transform; sceneItem.SetParent(scene_folder); sceneItemComponent = sceneItem.gameObject.AddComponent <SceneItem>(); sceneItemComponent.DisplayName = SceneDescriptorsHelper.ToDisplayName(item.Key); if (item.Value.displayImage != null) { sceneItemComponent.Silhouette = item.Value.displayImage.sprite; // destroy silhouette object GameObject.DestroyImmediate(item.Value.displayImage.gameObject); } } placeHolder.Value.itemImage.gameObject.transform.SetParent(sceneItem); parent = placeHolder.Value.itemImage.gameObject.transform; foreach (var patch in placeHolder.Value.patches) { var component = patch.gameObject.AddComponent <SceneItemChildLayer>(); component.Type = SceneItemChildLayer.LayerType.Patch; if (sceneItemComponent) { sceneItemComponent.ChildLayers.Add(component); } patch.gameObject.transform.SetParent(parent); } foreach (var shadow in placeHolder.Value.shadows) { var component = shadow.gameObject.AddComponent <SceneItemChildLayer>(); component.Type = SceneItemChildLayer.LayerType.Shadow; if (sceneItemComponent) { sceneItemComponent.ChildLayers.Add(component); } shadow.gameObject.transform.SetParent(parent); } } } } }