private void CreateBrush(Texture2D texture) { Texture2D brushTexture = new Texture2D(texture.width + 2, texture.height + 2, TextureFormat.ARGB32, false); brushTexture.wrapMode = TextureWrapMode.Clamp; Color32[] pixels = brushTexture.GetPixels32(); Color32 c = new Color32(255, 255, 255, 0); for (int i = 0; i < pixels.Length; ++i) { pixels[i] = c; } brushTexture.SetPixels32(pixels); Graphics.CopyTexture(texture, 0, 0, 0, 0, texture.width, texture.height, brushTexture, 0, 0, 1, 1); pixels = brushTexture.GetPixels32(); for (int i = 0; i < pixels.Length; ++i) { byte a = pixels[i].a; pixels[i] = new Color32(255, 255, 255, a); } brushTexture.SetPixels32(pixels); brushTexture.Apply(); Sprite sprite = Sprite.Create(brushTexture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f)); m_source.UserBrushes.Add(sprite); m_brushesList.Add(sprite); m_brushesList.SelectedItem = sprite; m_brushesList.ScrollIntoView(sprite); }
private void OnTextureSelected(Texture2D texture, bool create) { TerrainLayer layer; if (create) { layer = new TerrainLayer() { name = "TerrainLayer" }; layer.diffuseTexture = texture; List <TerrainLayer> layers = TerrainData.terrainLayers.ToList(); layers.Add(layer); TerrainData.terrainLayers = layers.ToArray(); m_layersList.Add(layer); } else { layer = (TerrainLayer)m_layersList.SelectedItem; layer.diffuseTexture = texture; m_layersList.DataBindItem(layer); } }
protected virtual void OnObjectAwaked(ExposeToEditor obj) { if (!m_isSpawningPrefab) { if (!obj.MarkAsDestroyed && m_treeView.IndexOf(obj) == -1) { if (IsFilterEmpty) { ExposeToEditor parent = obj.GetParent(); m_treeView.AddChild(parent, obj); } else { if (Filter(obj)) { m_treeView.Add(obj); } } } } }
private void OnTextureSelected(Texture2D texture, bool create) { float[,,] oldAlphamaps = GetAlphamaps(); TerrainLayer[] oldLayers = TerrainData.terrainLayers.ToArray(); TerrainLayer layer; if (create) { layer = new TerrainLayer() { name = "TerrainLayer" }; layer.diffuseTexture = texture; List <TerrainLayer> layers = TerrainData.terrainLayers.ToList(); layers.Add(layer); TerrainData.terrainLayers = layers.ToArray(); m_layersList.Add(layer); if (layers.Count == 1) { float[,,] alphaMaps = TerrainData.GetAlphamaps(0, 0, TerrainData.alphamapWidth, TerrainData.alphamapHeight); int amapY = alphaMaps.GetLength(0); int amapX = alphaMaps.GetLength(1); for (int y = 0; y < amapY; y++) { for (int x = 0; x < amapX; x++) { alphaMaps[y, x, 0] = 1; } } TerrainData.SetAlphamaps(0, 0, alphaMaps); } } else { layer = (TerrainLayer)m_layersList.SelectedItem; layer.diffuseTexture = texture; m_layersList.DataBindItem(layer); } RecordState(oldAlphamaps, oldLayers); }
private void OnCreateTree() { TreePrototype[] oldTrees = TerrainData.treePrototypes.ToArray(); TreePrototype tree = new TreePrototype(); tree.prefab = Resources.Load <GameObject>("Tree/RTT_DefaultTree"); List <TreePrototype> newTrees = TerrainData.treePrototypes.ToList(); newTrees.Add(tree); TerrainData.treePrototypes = newTrees.ToArray(); m_treeList.Add(tree); m_treeList.SelectedItem = tree; RecordState(oldTrees); }
private void OnMessageAdded(IRuntimeConsole console, ConsoleLogEntry logEntry) { bool scroll = false; if (m_scrollRect.Index + m_scrollRect.VisibleItemsCount == m_scrollRect.ItemsCount) { scroll = true; } if (CanAdd(logEntry.LogType)) { m_treeView.Add(logEntry); } UpdateCounters(); if (scroll) { m_scrollRect.verticalNormalizedPosition = 0; } }
private void OnCreateDetail() { DetailPrototype[] oldDetails = TerrainData.detailPrototypes.ToArray(); DetailPrototype detail = new DetailPrototype(); detail.renderMode = DetailRenderMode.Grass; detail.dryColor = Color.white; detail.healthyColor = Color.white; List <DetailPrototype> newDetails = TerrainData.detailPrototypes.ToList(); newDetails.Add(detail); TerrainData.detailPrototypes = newDetails.ToArray(); DetailPrototypeWrapper wrapper = new DetailPrototypeWrapper(detail); m_detailsList.Add(wrapper); m_detailsList.SelectedItem = wrapper; RecordState(oldDetails); }
private void OnAssetItemsLoaded(Object[] objects, ExposeToEditor dropTarget, VirtualizingTreeViewItem treeViewItem) { GameObject[] createdObjects = new GameObject[objects.Length]; for (int i = 0; i < objects.Length; ++i) { GameObject prefab = (GameObject)objects[i]; bool wasPrefabEnabled = prefab.activeSelf; prefab.SetActive(false); GameObject prefabInstance = InstantiatePrefab(prefab); prefab.SetActive(wasPrefabEnabled); ExposeToEditor exposeToEditor = prefabInstance.GetComponent <ExposeToEditor>(); if (exposeToEditor == null) { exposeToEditor = prefabInstance.AddComponent <ExposeToEditor>(); } exposeToEditor.SetName(prefab.name); if (dropTarget == null) { exposeToEditor.transform.SetParent(null); m_treeView.Add(exposeToEditor); } else { if (m_treeView.DropAction == ItemDropAction.SetLastChild) { exposeToEditor.transform.SetParent(dropTarget.transform); m_treeView.AddChild(dropTarget, exposeToEditor); treeViewItem.CanExpand = true; treeViewItem.IsExpanded = true; } if (m_lastDropAction != ItemDropAction.None) { int index; int siblingIndex; if (m_lastDropAction == ItemDropAction.SetNextSibling) { index = m_treeView.IndexOf(dropTarget) + 1; siblingIndex = dropTarget.transform.GetSiblingIndex() + 1; } else { index = m_treeView.IndexOf(dropTarget); siblingIndex = dropTarget.transform.GetSiblingIndex(); } exposeToEditor.transform.SetParent(dropTarget.transform.parent != null ? dropTarget.transform.parent : null); exposeToEditor.transform.SetSiblingIndex(siblingIndex); TreeViewItemContainerData newTreeViewItemData = (TreeViewItemContainerData)m_treeView.Insert(index, exposeToEditor); VirtualizingTreeViewItem newTreeViewItem = m_treeView.GetTreeViewItem(exposeToEditor); if (newTreeViewItem != null) { newTreeViewItem.Parent = treeViewItem.Parent; } else { newTreeViewItemData.Parent = treeViewItem.Parent; } } } OnActivatePrefabInstance(prefabInstance); createdObjects[i] = prefabInstance; } if (createdObjects.Length > 0) { IRuntimeEditor editor = IOC.Resolve <IRuntimeEditor>(); editor.RegisterCreatedObjects(createdObjects); } m_treeView.ExternalItemDrop(); m_isSpawningPrefab = false; }
public override void Drop(object[] dragObjects, PointerEventData pointerEventData) { base.Drop(dragObjects, pointerEventData); if (CanDrop(dragObjects)) { ExposeToEditor dropTarget = (ExposeToEditor)m_treeView.DropTarget; VirtualizingTreeViewItem treeViewItem = null; if (dropTarget != null) { treeViewItem = m_treeView.GetTreeViewItem(m_treeView.DropTarget); } AssetItem[] loadAssetItems = dragObjects.Where(o => o is AssetItem && m_project.ToType((AssetItem)o) == typeof(GameObject)).Select(o => (AssetItem)o).ToArray(); if (loadAssetItems.Length > 0) { m_isSpawningPrefab = true; Editor.IsBusy = true; m_project.Load(loadAssetItems, (error, objects) => { Editor.IsBusy = false; if (error.HasError) { IWindowManager wm = IOC.Resolve <IWindowManager>(); wm.MessageBox("Unable to load asset items.", error.ErrorText); return; } GameObject[] createdObjects = new GameObject[objects.Length]; for (int i = 0; i < objects.Length; ++i) { GameObject prefab = (GameObject)objects[i]; bool wasPrefabEnabled = prefab.activeSelf; prefab.SetActive(false); GameObject prefabInstance = Instantiate(prefab, Vector3.zero, Quaternion.identity); prefab.SetActive(wasPrefabEnabled); ExposeToEditor exposeToEditor = prefabInstance.GetComponent <ExposeToEditor>(); if (exposeToEditor == null) { exposeToEditor = prefabInstance.AddComponent <ExposeToEditor>(); } exposeToEditor.SetName(prefab.name); if (dropTarget == null) { exposeToEditor.transform.SetParent(null); m_treeView.Add(exposeToEditor); } else { if (m_treeView.DropAction == ItemDropAction.SetLastChild) { exposeToEditor.transform.SetParent(dropTarget.transform); m_treeView.AddChild(dropTarget, exposeToEditor); treeViewItem.CanExpand = true; treeViewItem.IsExpanded = true; } else if (m_treeView.DropAction != ItemDropAction.None) { int index; int siblingIndex; if (m_treeView.DropAction == ItemDropAction.SetNextSibling) { index = m_treeView.IndexOf(dropTarget) + 1; siblingIndex = dropTarget.transform.GetSiblingIndex() + 1; } else { index = m_treeView.IndexOf(dropTarget); siblingIndex = dropTarget.transform.GetSiblingIndex(); } exposeToEditor.transform.SetParent(dropTarget.transform.parent != null ? dropTarget.transform.parent : null); exposeToEditor.transform.SetSiblingIndex(siblingIndex); TreeViewItemContainerData newTreeViewItemData = (TreeViewItemContainerData)m_treeView.Insert(index, exposeToEditor); VirtualizingTreeViewItem newTreeViewItem = m_treeView.GetTreeViewItem(exposeToEditor); if (newTreeViewItem != null) { newTreeViewItem.Parent = treeViewItem.Parent; } else { newTreeViewItemData.Parent = treeViewItem.Parent; } } } prefabInstance.SetActive(true); createdObjects[i] = prefabInstance; } if (createdObjects.Length > 0) { IRuntimeEditor editor = IOC.Resolve <IRuntimeEditor>(); editor.RegisterCreatedObjects(createdObjects); } m_treeView.ExternalItemDrop(); m_isSpawningPrefab = false; }); } else { m_treeView.ExternalItemDrop(); } } else { m_treeView.ExternalItemDrop(); } }