示例#1
0
        void Randomize()
        {
            if (r == null || item == null)
            {
                return;
            }

            int amount = Random.Range(r.amount.x, r.amount.y);

            for (int i = 0; i < amount; i++)
            {
                Vector3 pos    = new Vector3(Random.Range(r.posX.x, r.posX.y), 0, Random.Range(r.posZ.x, r.posZ.y));
                float   rotY   = Random.Range(r.rotY.x, r.rotY.y);
                float   scaleX = Random.Range(r.scaleX.x, r.scaleX.y);
                Vector3 scale  = new Vector3(scaleX, Random.Range(r.scaleY.x, r.scaleY.y), scaleX);

                TC_ItemBehaviour newItem = item.Duplicate(item.t.parent);
                newItem.t.position   = pos;
                newItem.t.rotation   = Quaternion.Euler(0, rotY, 0);
                newItem.t.localScale = scale;
                newItem.method       = Method.Max;
            }

            TC.AutoGenerate();
        }
示例#2
0
        public bool hasChanged(TC_ItemBehaviour item)
        {
            // Debug.Log(item.posY + " " + posYOld);
            if (position.x != item.t.position.x || position.z != item.t.position.z || item.posY != positionYOld)
            {
                // if (position.x != item.t.position.x) Debug.Log("x " + position.x + ", " + item.t.position.x);
                // if (position.y != item.t.position.y) Debug.Log("y " + position.y + ", " + item.t.position.y);
                // if (position.z != item.t.position.z) Debug.Log("z " + position.z + ", " + item.t.position.z);

                // if (positionYOld != item.positionY) Debug.Log("posY " + positionYOld + ", " + item.positionY);
                // Debug.Log(TC.outputNames[item.outputId]);
                return(true);
            }
            // if (position != item.t.position) return false;
            if (rotation != item.t.rotation)
            {
                return(true);
            }
            if (scale != item.t.lossyScale)
            {
                return(true);
            }

            return(false);
        }
 public void SetParameters(TC_ItemBehaviour parentItem, int index)
 {
     this.parentItem = parentItem;
     level           = parentItem.level + 1;
     outputId        = parentItem.outputId;
     listIndex       = index;
 }
        public TC_ItemBehaviour Duplicate(Transform parent)
        {
            // Debug.Log("Duplicate");
            GameObject newGo = (GameObject)Instantiate(gameObject, t.position, t.rotation);
            Transform  newT  = newGo.transform;

            newT.parent = parent;
            if (dropPosition == DropPosition.Left)
            {
                newT.SetSiblingIndex(t.GetSiblingIndex() - 1);
            }
            else
            {
                newT.SetSiblingIndex(t.GetSiblingIndex());
            }
            newT.localScale = t.localScale;
            TC_ItemBehaviour item = newGo.GetComponent <TC_ItemBehaviour>();

            #if UNITY_EDITOR
            UnityEditor.Selection.activeObject = newGo;
            UnityEditor.Undo.RegisterCreatedObjectUndo(newGo, "Duplicate " + newGo.name);
            #endif

            return(item);
        }
示例#5
0
 public void Copy(TC_ItemBehaviour item)
 {
     position.x   = item.t.position.x;
     position.z   = item.t.position.z;
     posOffset    = item.posOffset;
     rotation     = item.t.rotation;
     scale        = item.t.lossyScale;
     positionYOld = item.posY;
 }
 void Start()
 {
     t = transform;
     if (target != null)
     {
         targetItem = target.GetComponent <TC_ItemBehaviour>();
     }
     item = GetComponent <TC_ItemBehaviour>();
 }
 void OnEnable()
 {
     t = transform;
     if (target != null)
     {
         targetItem = target.GetComponent <TC_ItemBehaviour>();
     }
     item = GetComponent <TC_ItemBehaviour>();
     UnityEditor.EditorApplication.update += Update;
 }
示例#8
0
        static public void DuplicateKey()
        {
            Transform[] transforms = (Transform[])Selection.transforms.Clone();

            if (transforms != null)
            {
                List <GameObject> gos = new List <GameObject>();

                for (int i = 0; i < transforms.Length; i++)
                {
                    Transform t = transforms[i];

                    TC_LayerGroup       layerGroup      = t.GetComponent <TC_LayerGroup>();
                    TC_LayerGroupResult groupResult     = t.GetComponent <TC_LayerGroupResult>();
                    TC_SelectItemGroup  selectItemGroup = t.GetComponent <TC_SelectItemGroup>();
                    TC_NodeGroup        nodeGroup       = t.GetComponent <TC_NodeGroup>();

                    if (layerGroup != null)
                    {
                        if (layerGroup.level == 0)
                        {
                            TC.AddMessage("The main " + TC.outputNames[layerGroup.outputId] + " Output Layer Group cannot be duplicated."); continue;
                        }
                    }
                    else if (groupResult != null)
                    {
                        TC.AddMessage("A Result Node cannot be duplicated."); continue;
                    }
                    else if (selectItemGroup != null)
                    {
                        TC.AddMessage("A " + TC.outputNames[selectItemGroup.outputId] + " Group cannot be directly duplicated.\n\nDrag & drop works with it, while dropping hold the alt key to duplicate it."); continue;
                    }
                    else if (nodeGroup != null)
                    {
                        TC.AddMessage("A " + nodeGroup.type.ToString() + " Group cannot be directly duplicated.\n\nDrag & drop works with it, while dropping hold the alt key to duplicate it."); continue;
                    }

                    TC_ItemBehaviour item = t.GetComponent <TC_ItemBehaviour>();
                    if (item != null)
                    {
                        gos.Add(item.Duplicate(item.transform.parent).gameObject);
                    }
                }
                if (gos.Count > 0)
                {
                    Selection.objects = gos.ToArray();
                }
            }
        }
示例#9
0
        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);
        }
示例#10
0
        static public bool VerifyPortal(TC_ItemBehaviour item)
        {
            if (item == null)
            {
                return(false);
            }
            if (item.outputId == heightOutput)
            {
                return(true);
            }
            if (item is TC_Node || item is TC_NodeGroup)
            {
                return(true);
            }

            AddMessage("This node cannot be used as a portal. All nodes in Height output can be used. And for the rest of the outputs only Nodes and NodeGroups can be used.");
            return(false);
        }
示例#11
0
        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");
            }
            //}
        }
示例#12
0
        public void Clear(bool undo)
        {
            int index = 0;

            int length = t.childCount;

            for (int i = 0; i < length; i++)
            {
                Transform        child = t.GetChild(index);
                TC_ItemBehaviour item  = child.GetComponent <TC_ItemBehaviour>();
                if (item != null)
                {
                    item.DestroyMe(undo);
                }
                else
                {
                    index++;
                }
            }
        }
示例#13
0
        static public void DrawAddItem(Rect rect, Vector2 pos, TC_ItemBehaviour item)
        {
            Event eventCurrent = Event.current;

            if (DragAndDrop.objectReferences.Length > 0)
            {
                return;
            }

            Vector2 posMouse = eventCurrent.mousePosition;

            if (rect.Contains(posMouse))
            {
                if (eventCurrent.alt && !eventCurrent.control)
                {
                    if (posMouse.x < rect.x + ((TD.texCardHeader.width / 2) * TD.scale))
                    {
                        item.dropPosition = DropPosition.Left;
                    }
                    else
                    {
                        item.dropPosition = DropPosition.Right;
                    }

                    if (eventCurrent.type == EventType.MouseDown && eventCurrent.button == 0 && eventCurrent.clickCount == 2)
                    {
                        AddItem(item, eventCurrent.shift);
                        eventCurrent.Use();
                    }

                    TC.repaintNodeWindow = true;
                }
                else
                {
                    item.dropPosition = DropPosition.None;
                }
            }
        }
示例#14
0
        static public void LeftClickMenu(object obj)
        {
            int    instanceID;
            string command = TD.ObjectToCommandAndInstanceID(obj, out instanceID);

            TC_ItemBehaviour item = EditorUtility.InstanceIDToObject(instanceID) as TC_ItemBehaviour;

            if (item != null)
            {
                // if (command == "Add Node ") node.Add<TC_Node>("", true, false, true);
                // else if (command == "Duplicate Node") node.Duplicate(node.t.parent);
                if (command.Contains("Right"))
                {
                    item.dropPosition = DropPosition.Right;
                }
                else if (command.Contains("Left"))
                {
                    item.dropPosition = DropPosition.Left;
                }

                bool addNodeGroup = command.Contains("NodeGroup");

                bool clone;
                if (command.Contains("Duplicate"))
                {
                    clone = true;
                }
                else
                {
                    clone = false;
                }

                AddItem(item, clone, addNodeGroup);

                item.dropPosition = DropPosition.None;
                // else if (command == "Erase Node") node.Destroy(true);
            }
        }
示例#15
0
        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);
        }
 void Start()
 {
     item = GetComponent <TC_ItemBehaviour>();
 }
示例#17
0
        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);
        }
示例#18
0
 public void CopyTransform(TC_ItemBehaviour item)
 {
     t.position   = item.t.position;
     t.rotation   = item.t.rotation;
     t.localScale = item.t.localScale;
 }
示例#19
0
 public void SetPreview(TC_ItemBehaviour item)
 {
     matProjector.SetTexture("_MainTex", item.rtDisplay);
 }
示例#20
0
        public void CopySpecial(TC_ItemBehaviour item)
        {
            TC_Node node = item as TC_Node;

            bool maskNode = false;

            if (node != null)
            {
                if (node.nodeType == NodeGroupType.Mask)
                {
                    maskNode = true;
                }
            }

            posOffset = item.posOffset;

            bool lockPosParent = item.lockPosParent;

            if (item.lockTransform || lockPosParent)
            {
                Vector3    posTemp = Vector3.zero;
                Quaternion rotTemp;
                Vector3    scaleTemp = Vector3.zero;

                if (!(item.lockPosX || lockPosParent))
                {
                    posTemp.x = item.t.position.x;
                }
                else
                {
                    posTemp.x = position.x;
                }
                if (!(item.lockPosY || lockPosParent))
                {
                    posTemp.y = item.posY * scale.y;
                }
                else
                {
                    posTemp.y = position.y;
                }
                if (!(item.lockPosZ || lockPosParent))
                {
                    posTemp.z = item.t.position.z;
                }
                else
                {
                    posTemp.z = position.z;
                }

                if (!(item.lockRotY && item.lockTransform))
                {
                    rotTemp = Quaternion.Euler(0, item.t.eulerAngles.y, 0);
                }
                else
                {
                    rotTemp = rotation;
                }

                if (!(item.lockScaleX && item.lockTransform))
                {
                    scaleTemp.x = item.t.lossyScale.x;
                }
                else
                {
                    scaleTemp.x = scale.x;
                }
                if (!(item.lockScaleY && item.lockTransform))
                {
                    if (maskNode)
                    {
                        scaleTemp.y = item.t.localScale.y;
                    }
                    else
                    {
                        scaleTemp.y = item.t.lossyScale.y * item.opacity;
                    }
                }
                else
                {
                    scaleTemp.y = scale.y;
                }
                if (!(item.lockScaleZ && item.lockTransform))
                {
                    scaleTemp.z = item.t.lossyScale.z;
                }
                else
                {
                    scaleTemp.z = scale.z;
                }

                position = posTemp;
                rotation = rotTemp;
                scale    = scaleTemp;

                if (item.t.position != position)
                {
                    item.t.position = position;
                }
                if (item.t.rotation != rotation)
                {
                    item.t.rotation = rotation;
                }

                item.t.hasChanged = false;
            }
            else
            {
                rotation = Quaternion.Euler(0, item.t.eulerAngles.y, 0);
                scale.x  = item.t.lossyScale.x;
                scale.z  = item.t.lossyScale.z;

                if (maskNode)
                {
                    scale.y = item.t.localScale.y;
                }
                else
                {
                    scale.y = item.t.lossyScale.y;
                }

                scale.y   *= item.opacity;
                position   = item.t.position;
                position.y = item.posY * scale.y;
            }

            // if (scale.x == 0) scale.x = 1;
            // if (scale.y == 0) scale.y = 1;
            // if (scale.z == 0) scale.z = 1;
        }
示例#21
0
 void Awake()
 {
     item = GetComponent <TC_ItemBehaviour>();
 }
示例#22
0
        static public void LeftClickMenu(Rect rect, TC_ItemBehaviour item)
        {
            if (TD.ClickRect(rect) != 1)
            {
                return;
            }

            string itemText = "";

            if (item.GetType() == typeof(TC_SelectItem))
            {
                itemText = "Item";
            }
            else
            {
                itemText = "Node";
            }

            GenericMenu menu = new GenericMenu();

            string instanceID = item.GetInstanceID().ToString();

            if (Event.current.mousePosition.x < rect.x + ((TD.texCardHeader.width / 2) * TD.scale))
            {
                menu.AddItem(new GUIContent("<-- Add " + itemText), false, LeftClickMenu, instanceID + ":Add Left");
                //if (itemText == "Node")
                //{
                //    menu.AddItem(new GUIContent("<-- Add Node Group"), false, LeftClickMenu, instanceID + ":Add NodeGroup Left");
                //    menu.AddSeparator("");
                //}
                menu.AddItem(new GUIContent("<-- Duplicate " + itemText), false, LeftClickMenu, instanceID + ":Duplicate Left");
            }
            else
            {
                menu.AddItem(new GUIContent("--> Add " + itemText), false, LeftClickMenu, instanceID + ":Add Right");
                //if (itemText == "Node")
                //{
                //    menu.AddItem(new GUIContent("--> Add Node Group"), false, LeftClickMenu, instanceID + ":Add NodeGroup Right");
                //    menu.AddSeparator("");
                //}
                menu.AddItem(new GUIContent("--> Duplicate " + itemText), false, LeftClickMenu, instanceID + ":Duplicate Right");
            }

            // bool eraseNodeMenu = true;

            //if (node.nodeType == NodeType.Select)
            //{
            //    TC_NodeGroup nodeGroup = node.t.parent.GetComponent<TC_NodeGroup>();
            //    if (nodeGroup != null)
            //    {
            //        if (nodeGroup.itemList.Count == 1) eraseNodeMenu = false;
            //    }
            //}

            //if (eraseNodeMenu) {
            //    menu.AddSeparator("");
            //    menu.AddItem(new GUIContent("Erase Node"), false, LeftClickMenu, instanceID + ":Erase Node");
            //}

            menu.ShowAsContext();
        }