static public TC_ItemBehaviour AddItem(TC_ItemBehaviour item, bool clone, bool addNodeGroup = false) { TC_ItemBehaviour itemToDrop = null; if (!clone) { if (item.GetType() == typeof(TC_Node)) { if (addNodeGroup) { itemToDrop = (TC_ItemBehaviour)item.Add <TC_NodeGroup>("Node Group", true); } else { itemToDrop = (TC_ItemBehaviour)item.Add <TC_Node>("", true); } } else if (item.GetType() == typeof(TC_SelectItem)) { itemToDrop = (TC_ItemBehaviour)item.Add <TC_SelectItem>("", true); TC_SelectItem newSelectItem = (TC_SelectItem)itemToDrop; TC_SelectItem selectItem = (TC_SelectItem)item; if (selectItem.dropPosition == DropPosition.Right) { newSelectItem.selectIndex = Mathf.Min(selectItem.selectIndex + 1, Mathf.Max(0, newSelectItem.GetItemTotalFromTerrain() - 1)); } else { newSelectItem.selectIndex = Mathf.Max(selectItem.selectIndex - 1, 0); } } Undo.RegisterCreatedObjectUndo(item.gameObject, "Created " + item.name); } else { itemToDrop = item; } itemToDrop = TD.DropItemSameLevel(item, itemToDrop, clone, false); Selection.activeTransform = itemToDrop.t; return(itemToDrop); }
static void DrawConnectionIndicator(TC_ItemBehaviour item, Vector2 pos, bool addBefore, bool nodeFoldout) { if (!nodeFoldout) { pos.y -= 351; } //if (TD.startDrag) //{ // Rect dropRect = TD.GetRectScaled(new Rect(pos.x, pos.y, TD.texConnectionIndicator.width, TD.texConnectionIndicator.height)); // // TD.DragDropNode(item, dropRect); // DrawTextureCommand.Add(pos, TD.texConnectionIndicator, Color.white); //} //else //{ TC_GlobalSettings g = TC_Settings.instance.global; pos -= new Vector2(2.5f, 2.5f); Rect rect = new Rect(pos.x + g.rect4.x, pos.y + g.rect4.y, g.rect4.width, g.rect4.width); // DrawTextureCommand.Add(rect, TD.texCardCounter, TD.g.colLayer * 0.25f); int clickedButton = TD.Button(rect, TD.texAddFirstCard, true, new Color(1, 1, 1, 0.25f), Color.white, Color.white, true, true); // tooltip //Vector2 mousePosition = Event.current.mousePosition; //if (rectScaled.Contains(mousePosition)) //{ // DrawCommand.Add(mousePosition + new Vector2(9, 19), 65, "Left Click", "-> Add a new Layer", Color.white); // DrawCommand.Add(mousePosition + new Vector2(9, 19 + TD.labelHeight), 65, "Right Click","-> Add a new Layer Group", Color.white); // TD.repaintNodeWindow = true; //} if (clickedButton == 0) { Undo.RegisterCreatedObjectUndo(item.Add <TC_Layer>("", true, addBefore, true).gameObject, "Created Layer"); } else if (clickedButton == 1) { Undo.RegisterCreatedObjectUndo(item.Add <TC_LayerGroup>("", true, addBefore, true).gameObject, "Created GameObject"); } //} }
public virtual MonoBehaviour Add <T>(string label, bool addSameLevel, bool addBefore = false, bool makeSelection = false, int startIndex = 1) where T : TC_ItemBehaviour { GameObject newItemGo = new GameObject(); Transform newItemT = newItemGo.transform; Type type = typeof(T); if (label == "") { if (type == typeof(TC_LayerGroup)) { label = "Layer Group"; } else if (type == typeof(TC_Layer)) { label = "Layer"; } else if (type == typeof(TC_Node)) { label = "Node"; } else if (type == typeof(TC_SelectItem)) { label = "Item"; } else if (type == typeof(TC_SelectItemGroup)) { label = "ItemGroup"; } } // Debug.Log("Add " + label); newItemT.name = label; #if UNITY_EDITOR if (makeSelection) { UnityEditor.Selection.activeTransform = newItemT; } #endif int index; TC_ItemBehaviour item = newItemGo.AddComponent <T>(); // Version number item.SetVersionNumber(); item.outputId = outputId; if (addSameLevel) { newItemT.parent = t.parent; index = t.GetSiblingIndex() + (addBefore ? 1 : 0); newItemT.SetSiblingIndex(index); } else { if (type == typeof(TC_SelectItemGroup)) { startIndex = 2; } newItemT.parent = t; newItemT.SetSiblingIndex(index = startIndex); } if (newItemT.parent != null) { newItemT.localPosition = Vector3.zero; } if (type == typeof(TC_Node)) { ((TC_Node)item).SetDefaultSettings(); } else if (type == typeof(TC_LayerGroup)) { if (outputId != TC.heightOutput && outputId != TC.grassOutput) { item.method = Method.Lerp; } item.Add <TC_NodeGroup>("Mask Group", false); item.Add <TC_LayerGroupResult>("Result", false); } else if (type == typeof(TC_Layer)) { if (outputId != TC.heightOutput && outputId != TC.grassOutput) { item.method = Method.Lerp; } AddLayerNodeGroups((TC_Layer)item); } return(item); }