static public void DropDownMenu(Rect rect, TC_Layer layer) { if (TD.ClickRect(rect) != 1) { return; } GenericMenu menu = new GenericMenu(); // menu.AddItem(new GUIContent("Add Layer"), false, LeftClickMenu, "Add Layer"); string instanceID = layer.GetInstanceID().ToString(); if (layer.maskNodeGroup.itemList.Count == 0) { menu.AddItem(new GUIContent("Add Mask"), false, LeftClickMenu, instanceID + ":Add Mask"); menu.AddSeparator(""); } menu.AddItem(new GUIContent("Add Layer"), false, LeftClickMenu, instanceID + ":Add Layer"); menu.AddItem(new GUIContent("Duplicate Layer"), false, LeftClickMenu, instanceID + ":Duplicate Layer"); if (layer.level > 1) { menu.AddSeparator(""); menu.AddItem(new GUIContent("Add Layer Group"), false, LeftClickMenu, instanceID + ":Add LayerGroup"); } menu.AddSeparator(""); menu.AddItem(new GUIContent("Erase Layer"), false, LeftClickMenu, instanceID + ":Erase Layer"); menu.ShowAsContext(); }
static public void LeftClickMenu(object obj) { int instanceID; string command = TD.ObjectToCommandAndInstanceID(obj, out instanceID); TC_Layer layer = EditorUtility.InstanceIDToObject(instanceID) as TC_Layer; if (layer != null) { if (command == "Add Mask") { layer.maskNodeGroup.Add <TC_Node>("", false, false, true); } else if (command == "Add Layer") { layer.Add <TC_Layer>("", true, false, true); } else if (command == "Duplicate Layer") { layer.Duplicate(layer.t.parent); } else if (command == "Add LayerGroup") { layer.Add <TC_LayerGroup>("", true, false, true); } else if (command == "Erase Layer") { layer.DestroyMe(true); } } }
// public float barX; static public void Draw(TC_Layer layer, ref Vector2 startOffset, float activeMulti, bool drawMethod, bool isFirst, bool isLast) { TC_GlobalSettings g = TC_Settings.instance.global; bool isCulled = false; TC_LayerGroupGUI.DrawLayerOrLayerGroup(layer, ref startOffset, g.colLayer, ref isCulled, activeMulti, drawMethod, isFirst, isLast); if (!layer.active) { activeMulti *= 0.75f; } // DropDownMenu(rect, layer); bool hideSelectNodes = false; if (layer.outputId != TC.heightOutput) { if (layer.selectItemGroup.totalActive <= 1) { hideSelectNodes = true; } } TC_NodeGroupGUI.Draw(layer.maskNodeGroup, ref startOffset, g.colMaskNodeGroup, g.colMaskNode, g.colLayer, activeMulti, layer.nodeFoldout, false, false, false); if (!hideSelectNodes) { TC_NodeGroupGUI.Draw(layer.selectNodeGroup, ref startOffset, g.colSelectNodeGroup, g.colSelectNode, g.colLayer, activeMulti, layer.nodeFoldout, false, layer.outputId != TC.heightOutput, hideSelectNodes); } if (layer.selectItemGroup != null && layer.outputId != TC.heightOutput) { TC_SelectItemGroupGUI.Draw(layer.selectItemGroup, ref startOffset, TC_Settings.instance.global.colSelectItemGroup, TC_Settings.instance.global.colSelectItem, g.colLayer, activeMulti); } }
public void AddLayerNodeGroups(TC_Layer layer) { layer.Add <TC_NodeGroup>("Mask Group", false); TC_NodeGroup selectNodeGroup = (TC_NodeGroup)layer.Add <TC_NodeGroup>("Select Group", false); selectNodeGroup.Add <TC_Node>("", false, false, false); layer.Add <TC_SelectItemGroup>("", false); }
public void ResetObjects() { for (int i = 0; i < itemList.Count; i++) { TC_Layer layer = itemList[i] as TC_Layer; if (layer != null) { layer.ResetObjects(); } else { TC_LayerGroup layerGroup = itemList[i] as TC_LayerGroup; if (layerGroup != null) { layerGroup.ResetObjects(); } } } }
public int CalcPlaced() { int placed = 0; for (int i = 0; i < itemList.Count; i++) { TC_Layer layer = itemList[i] as TC_Layer; if (layer != null) { placed += layer.CalcPlaced(); } else { TC_LayerGroup layerGroup = itemList[i] as TC_LayerGroup; if (layerGroup != null) { placed += layerGroup.CalcPlaced(); } } } return(placed); }
public void LinkClone(TC_LayerGroupResult resultLayerGroupS) { preview = resultLayerGroupS.preview; for (int i = 0; i < itemList.Count; i++) { TC_Layer layer = itemList[i] as TC_Layer; if (layer != null) { TC_Layer layerS = resultLayerGroupS.itemList[i] as TC_Layer; layer.LinkClone(layerS); } else { TC_LayerGroup layerGroup = itemList[i] as TC_LayerGroup; if (layerGroup != null) { TC_LayerGroup layerGroupS = resultLayerGroupS.itemList[i] as TC_LayerGroup; layerGroup.LinkClone(layerGroupS); } } } }
static public void Draw(TC_LayerGroup layerGroup, bool drawMethod, ref Vector2 pos, float activeMulti, bool isFirst, bool isLast, ref float shelfLineVerticalStartY) { TC_GlobalSettings g = TC_Settings.instance.global; if (layerGroup.level == 0) { pos.x -= TD.texShelfStartOutput.width; } float posOldX = pos.x; bool isCulled = false; layerGroup.nodePos = pos - new Vector2(0, TD.cardHeight); Rect rect = DrawLayerOrLayerGroup(layerGroup, ref pos, g.colLayerGroup, ref isCulled, activeMulti, drawMethod, isFirst, isLast); activeMulti = layerGroup.active ? activeMulti : activeMulti * 0.75f; // Rect rectFoldout = TD.GetRectScaled(pos.x + 240, pos.y + 43 + (layerGroup.nodeFoldout ? TD.cardHeight : 32), 20, 20); // if (GUI.Button(rectFoldout, "")) layerGroup.foldout = !layerGroup.foldout; shelfLineVerticalStartY = pos.y + (layerGroup.nodeFoldout ? TD.texShelfLayerStart1.height : TD.texShelfLayerCollapsed.height) - TD.shelfOffsetY; DropDownMenu(rect, layerGroup); Vector2 bar2 = pos; bar2.x -= TD.texCardBody.width * 1.5f; bar2.y += TD.cardHeight; TC_NodeGroupGUI.Draw(layerGroup.maskNodeGroup, ref pos, g.colMaskNodeGroup, g.colMaskNode, g.colLayerGroup, activeMulti, layerGroup.nodeFoldout, false, false, false); // if (startOffsetXMax > startOffset.x) startOffsetXMax = startOffset.x; // Draw Result Node TC_LayerGroupResultGUI.Draw(layerGroup, ref pos, posOldX, activeMulti, layerGroup.nodeFoldout); int layerGroupCount = 0; int layerCount = 0; float lineOffsetX; if (layerGroup.maskNodeGroup.itemList.Count > 0) { lineOffsetX = 2.5f; } else { lineOffsetX = 0; } bool m_isFirst, m_isLast; float m_shelfLineVerticalStartY = 0; pos.y += layerGroup.nodeFoldout ? (TD.cardHeight) : 32; if (layerGroup.foldout == 2) { for (int i = layerGroup.groupResult.itemList.Count - 1; i >= 0; --i) { pos.x = posOldX;// - lineOffsetX ; pos.x -= g.layerHSpace; TC_LayerGroup layerGroupChild = layerGroup.groupResult.itemList[i] as TC_LayerGroup; m_isLast = (i == 0); m_isFirst = (i == layerGroup.groupResult.itemList.Count - 1); if (layerGroupChild != null) { Draw(layerGroupChild, i != 0, ref pos, activeMulti, m_isFirst, m_isLast, ref m_shelfLineVerticalStartY); if (!m_isLast) { pos.y += layerGroupChild.nodeFoldout ? 0 : 32; TD.DrawTextureScaledV(pos.x + 64, m_shelfLineVerticalStartY, (pos.y - m_shelfLineVerticalStartY) + 16, TD.texShelfLinesVertical, Color.white); TD.DrawTextureScaledV(pos.x + 64, m_shelfLineVerticalStartY, (pos.y - m_shelfLineVerticalStartY) + 16, TD.texLineVertical, g.colLayer * activeMulti); } ++layerGroupCount; } else { TC_Layer layer = layerGroup.groupResult.itemList[i] as TC_Layer; if (layer == null) { continue; } TC_LayerGUI.Draw(layer, ref pos, activeMulti, i != 0, m_isFirst, m_isLast); pos.y += layer.nodeFoldout ? TD.cardHeight : 32; ++layerCount; } } } pos.y += 64; Rect clickRect = TD.GetRectScaled(new Rect(bar2.x + (TD.texCardBody.width * 1.5f) - (2.5f + lineOffsetX), bar2.y - 5f, 10, 10)); if (TD.ClickRect(clickRect, 0)) { if (layerGroup.foldout == 0) { layerGroup.foldout = 2; } else { layerGroup.foldout = 0; } } pos.x = posOldX; }
static public Rect DrawLayerOrLayerGroup(TC_ItemBehaviour item, ref Vector2 pos, Color color, ref bool isCulled, float activeMulti, bool drawMethod, bool isFirst, bool isLast) { TC_GlobalSettings g = TC_Settings.instance.global; // TODO: Make global static and init TC_LayerGroup layerGroup = item as TC_LayerGroup; TC_Layer layer = item as TC_Layer; bool nodeFoldout = (layerGroup != null) ? layerGroup.nodeFoldout : layer.nodeFoldout; if (isFirst) { pos.y += TD.shelfOffsetY; TD.DrawTextureScaled(pos.x, pos.y, TD.texShelfLinesConnectDown, Color.white); TD.DrawTextureScaled(pos.x, pos.y, TD.texLineConnectDown, g.colLayer * activeMulti); pos.y += TD.texShelfLinesConnectDown.height; } else if (item.level == 0) { TD.DrawTextureScaled(pos.x + 64, pos.y, TD.texShelfStartConnect, Color.white); } else { pos.y += 15; } Texture texShelf; Texture texLine = null; if (item.level == 0) { if (nodeFoldout) { texShelf = TD.texShelfStartOutput; } else { texShelf = TD.texShelfStartOutputCollapsed; } } else if (isLast) { if (nodeFoldout) { texShelf = TD.texShelfLayerStart2; texLine = TD.texLineLayerStart2; } else { texShelf = TD.texShelfLayerCollapsedStart2; texLine = TD.texLineLayerStart2; } } else { if (nodeFoldout) { texShelf = TD.texShelfLayerStart1; texLine = TD.texLineLayerStart1; } else { texShelf = TD.texShelfLayerCollapsedStart1; texLine = TD.texLineLayerCollapsedStart1; } } TD.DrawTextureScaled(pos.x, pos.y, texShelf, Color.white); if (item.level > 0) { TD.DrawTextureScaled(pos.x, pos.y, texLine, g.colLayer * activeMulti); } TD.DrawTextureScaled(pos.x - TD.texShelfStartOutput.width, pos.y, nodeFoldout ? TD.texShelfLayer : TD.texShelfLayerCollapsed, Color.white, false, StretchMode.Left); pos.y += TD.shelfOffsetY; pos.x -= TD.texCardBody.width - (item.level == 0 ? 20 : 34); isCulled = false; Rect nodeRect = TD.DrawNode(item, pos, color, Color.white, ref isCulled, activeMulti, nodeFoldout, drawMethod); if (isCulled) { return(nodeRect); } int mouseButton = TD.Button(new Rect(pos.x + 245.1f, pos.y + 6.5f, 20, 20), TD.texFoldout, true, new Color(1, 1, 1, 0.25f), Color.white, Color.white, true); if (mouseButton >= 0) { if (layerGroup != null) { layerGroup.nodeFoldout = !layerGroup.nodeFoldout; if (mouseButton == 0) { layerGroup.foldout = layerGroup.nodeFoldout ? 2 : 0; } } else { layer.nodeFoldout = !layer.nodeFoldout; } Event.current.Use(); } //if (GUI.Button(TD.GetRectScaled(pos.x + 225, pos.y + 2, 40, 25), "")) //{ // if (layerGroup != null) layerGroup.nodeFoldout = !layerGroup.nodeFoldout; // else layer.nodeFoldout = !layer.nodeFoldout; //} if (item.method == Method.Lerp && drawMethod) { // TD.DrawSlider(startOffset, ref item.overlay, 0, 1); // if (GUI.changed) TC_Generate.singleton.AutoGenerate(); } if (item.level > 0) { DrawConnectionIndicator(item, new Vector2(pos.x + 289, pos.y - 27), false, true); if (isLast) { DrawConnectionIndicator(item, new Vector2(pos.x + 289, pos.y + TD.cardHeight + 4), true, nodeFoldout); } } return(nodeRect); }
public override void GetItems(bool refresh, bool rebuildGlobalLists, bool resetTextures) { if (resetTextures) { DisposeTextures(); } active = visible; itemList.Clear(); firstActive = lastActive = -1; totalActive = 0; bool newBounds = true; int listIndex = 0; // Debug.Log(name + " GetItems"); for (int i = t.childCount - 1; i >= 0; i--) { Transform child = transform.GetChild(i); TC_Layer layer = child.GetComponent <TC_Layer>(); if (layer != null) { layer.SetParameters(this, listIndex); layer.GetItems(refresh, rebuildGlobalLists, resetTextures); if (layer.active) { ++totalActive; lastActive = listIndex; if (firstActive == -1) { firstActive = lastActive; } } itemList.Add(layer); ++listIndex; if (newBounds) { bounds = layer.bounds; newBounds = false; } else { bounds.Encapsulate(layer.bounds); } } else { TC_LayerGroup layerGroup = child.GetComponent <TC_LayerGroup>(); if (layerGroup == null) { TC.MoveToDustbin(child); } else { layerGroup.SetParameters(this, listIndex); layerGroup.GetItems(refresh, rebuildGlobalLists, resetTextures); if (layerGroup.active) { ++totalActive; lastActive = listIndex; if (firstActive == -1) { firstActive = lastActive; } } if (layerGroup.groupResult == null) { TC.MoveToDustbin(child); } else { itemList.Add(layerGroup); listIndex++; } if (newBounds) { bounds = layerGroup.bounds; newBounds = false; } else { bounds.Encapsulate(layerGroup.bounds); } } } } TC_Reporter.Log(TC.outputNames[outputId] + " Level " + level + " activeTotal " + totalActive); if (!active) { totalActive = 0; } else if (totalActive == 0) { active = false; } }
// Compute height, trees and objects public ComputeBuffer ComputeSingle(float seedParent, bool first = false) { TC_Compute compute = TC_Compute.instance; ComputeBuffer totalBuffer = null; ComputeBuffer layerBuffer = null; ComputeBuffer layerMaskBuffer = null; RenderTexture[] rtsPreview = null; RenderTexture rtRightPreview = null; RenderTexture rtLeftPreview = null; if (outputId != TC.heightOutput) { rtsPreview = new RenderTexture[2]; } SetPreviewTextureBefore(); int even = 0; float seedTotal = seed + seedParent; for (int i = 0; i < itemList.Count; i++) { TC_Layer layer = itemList[i] as TC_Layer; if (layer != null) { if (!layer.active) { TC_Reporter.Log("Inactive layer " + i); continue; } if (totalBuffer == null) { if (outputId == TC.heightOutput) { layer.ComputeHeight(ref totalBuffer, ref layerMaskBuffer, seedTotal, i == firstActive); } else { layer.ComputeItem(ref totalBuffer, ref layerMaskBuffer, seedTotal, i == firstActive); if (totalBuffer != null) { rtLeftPreview = layer.rtDisplay; } } TC_Area2D.current.layerGroupBuffer = totalBuffer; // Portal compute.DisposeBuffer(ref layerMaskBuffer); } else { if (outputId == TC.heightOutput) { layer.ComputeHeight(ref layerBuffer, ref layerMaskBuffer, seedTotal); } else { layer.ComputeItem(ref layerBuffer, ref layerMaskBuffer, seedTotal); } if (layerBuffer != null) { if (outputId == TC.heightOutput) { compute.RunComputeMethod(this, layer, totalBuffer, ref layerBuffer, totalActive, i == lastActive ? rtPreview : null, layerMaskBuffer); } else { rtRightPreview = layer.rtDisplay; compute.RunComputeObjectMethod(this, layer, totalBuffer, ref layerBuffer, layerMaskBuffer, rtPreview, ref rtsPreview[even++ % 2], ref rtLeftPreview, rtRightPreview); } TC_Area2D.current.layerGroupBuffer = totalBuffer; } compute.DisposeBuffer(ref layerMaskBuffer); } } else { TC_LayerGroup layerGroup = itemList[i] as TC_LayerGroup; if (layerGroup == null) { continue; } if (!layerGroup.active) { continue; } if (totalBuffer == null) { layerMaskBuffer = layerGroup.ComputeSingle(ref totalBuffer, seedTotal, i == firstActive); if (totalBuffer != null) { rtLeftPreview = layerGroup.rtDisplay; } TC_Area2D.current.layerGroupBuffer = totalBuffer; compute.DisposeBuffer(ref layerMaskBuffer); } else { layerMaskBuffer = layerGroup.ComputeSingle(ref layerBuffer, seedTotal); if (layerBuffer != null) { if (outputId == TC.heightOutput) { compute.RunComputeMethod(this, layerGroup, totalBuffer, ref layerBuffer, totalActive, i == lastActive ? rtPreview : null, layerMaskBuffer); } else { rtRightPreview = layerGroup.rtDisplay; compute.RunComputeObjectMethod(this, layerGroup, totalBuffer, ref layerBuffer, layerMaskBuffer, rtPreview, ref rtsPreview[even++ % 2], ref rtLeftPreview, rtRightPreview); } TC_Area2D.current.layerGroupBuffer = totalBuffer; } compute.DisposeBuffer(ref layerMaskBuffer); } } } SetPreviewTextureAfter(); if (outputId != TC.heightOutput) { TC_Compute.DisposeRenderTextures(ref rtsPreview); } compute.DisposeBuffer(ref layerMaskBuffer); if (totalBuffer == null) { TC_Reporter.Log("Layer buffer null"); } return(totalBuffer); }
public void LinkClone(TC_Layer layerS) { preview = layerS.preview; maskNodeGroup.LinkClone(layerS.maskNodeGroup); selectNodeGroup.LinkClone(layerS.selectNodeGroup); }