public List <GameObject> InitLine(bool isLGraph, Vector3 positionFirst, Vector3 positionSecond, bool isDirected, Color32 color, string _name, Transform parent = null, bool isSimple = false, bool isLastPart = true) { Transform parentUse = parent ?? parentStandart; List <GameObject> gameObjects = new List <GameObject>(); if (!isSimple) { GameObject sphereFirst = Instantiate(resourceM.GetPrefab("SpherePrefab"), positionFirst, Quaternion.identity, parentUse); sphereFirst.transform.localScale = (isLGraph) ? scaleLGraph : scaleLink; sphereFirst.GetComponent <Renderer>().material.color = new Color32(color.r, color.g, color.b, color.a); gameObjects.Add(sphereFirst); TooltipText tT = sphereFirst.GetComponent <TooltipText>(); tT.text = _name; GameObject selectMarker = Instantiate(prefabSelectedContainer, sphereFirst.transform); selectMarker.transform.localScale = new Vector3(3f, 3f, 3f); tT.selectedContainer = selectMarker; tT.sizeSelectMarker = defaultScaleSelectorMarker; GameObject sphereSecond = Instantiate(resourceM.GetPrefab("SpherePrefab"), positionSecond, Quaternion.identity, parentUse); sphereSecond.transform.localScale = (isLGraph) ? scaleLGraph : scaleLink; sphereSecond.GetComponent <Renderer>().material.color = new Color32(color.r, color.g, color.b, color.a); gameObjects.Add(sphereSecond); } GameObject line = Instantiate(resourceM.GetPrefab("LinePrefab"), Vector3.zero, Quaternion.identity, parentUse); line.transform.localScale = (isLGraph) ? scaleLGraph : scaleLink; line.GetComponent <Renderer>().material.color = new Color32(color.r, color.g, color.b, color.a); Vector3 offset = positionSecond - positionFirst; Vector3 position = positionFirst + (offset / 2.0f); line.transform.position = position; line.transform.LookAt(positionFirst); Vector3 localScale = line.transform.localScale; localScale.z = (positionSecond - positionFirst).magnitude; line.transform.localScale = localScale; gameObjects.Add(line); // Если это последний участок, то разрешаем создать стрелку, если нужно. if (isDirected && isLastPart) { GameObject array = Instantiate(resourceM.GetPrefab("Arrow"), positionSecond, Quaternion.identity, parentUse); array.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f); array.transform.localRotation = line.transform.localRotation; array.transform.Rotate(new Vector3(-90f, 0, 0)); array.transform.position = GetPositionBetween(positionFirst, positionSecond, 0.35f); array.GetComponent <Renderer>().material.color = new Color32(color.r, color.g, color.b, color.a); gameObjects.Add(array); } foreach (var part in gameObjects) { part.name = _name; part.GetComponent <TooltipText>().text = _name; } return(gameObjects); }
public GameObject InitGraph(Vector3 position, Vector3 _scale, Color32 _color, string _name, string _nameModel, float _scaleSelectMarker, Transform parent = null) { Transform parentUse = parent ?? parentStandart; //string namePrefabObject = (Style3D) ? "GraphPrefab" : "2DVertexPrefab"; GameObject objectVar = Instantiate(resourceM.GetPrefab("GraphPrefab"), position, Quaternion.identity, parentUse).gameObject; objectVar.transform.localScale = _scale; objectVar.GetComponent <Renderer>().material.color = _color; objectVar.name = _name; TooltipText tT = objectVar.GetComponent <TooltipText>(); tT.text = _name; tT.selectedContainer = Instantiate(prefabSelectedContainer, objectVar.transform); tT.sizeSelectMarker = _scaleSelectMarker; if (_nameModel != null) { string _path; if (LoadSaveDialog.GetInstance().fileName != "") { _path = Path.GetDirectoryName(LoadSaveDialog.GetInstance().fileName); } else { _path = Application.dataPath + "/MetagraphEditorTemp"; } objectVar.GetComponent <DemoLoadObj>().LoadModel(_path, _nameModel); } objectVar.GetComponentInChildren <TextMesh>().text = _name; // Расчёт степени контрастности и соответствующего цвета. objectVar.GetComponentInChildren <TextMesh>().color = (_color.r * 0.299 + _color.g * 0.587 + _color.b * 0.114 <= 140) ? Color.white : Color.black; return(objectVar); }
private void LateUpdate() { bool show = false; boxText.fontSize = fontSize; RaycastHit hit; Ray ray = _camera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { if (hit.transform.GetComponent <TooltipText>()) { TooltipText tooltiptext = hit.transform.GetComponent <TooltipText>(); text = tooltiptext.text; arrayShow = tooltiptext.arrayShow; show = true; } } boxText.text = text; arrow.SetActive(arrayShow); float width = maxWidth; if (boxText.preferredWidth <= maxWidth - borderAround) { width = boxText.preferredWidth + borderAround; } // Ограничиватель. width = Mathf.Clamp(width, minWidth, maxWidth); boxRT.sizeDelta = new Vector2(width, boxText.preferredHeight + borderAround); if ((show || isUI) && !freeCamera.m_inputCaptured && !editorMenu.menuActive) { arrowPositionY = 0; arrowPositionX = 0; currentZ = 0; right = false; curY = Input.mousePosition.y + boxRT.sizeDelta.y + arrowRT.sizeDelta.y / 4f; curX = Input.mousePosition.x + boxRT.sizeDelta.x + arrowRT.sizeDelta.x / 4f; // Если Tooltip выходит за рамки экрана по ширине. if (curX > Screen.width) { right = true; arrowPositionX = boxRT.sizeDelta.x; } // Если Tooltip выходит за рамки экрана по высоте. if (curY > Screen.height) { arrowPositionY = boxRT.sizeDelta.y; if (right) { // Верхний правый currentZ = 315f; curX -= (boxRT.sizeDelta.x + boxRT.sizeDelta.x / 2f + arrowRT.sizeDelta.x / 2f); curY -= (boxRT.sizeDelta.y + boxRT.sizeDelta.y / 2f + arrowRT.sizeDelta.y / 2f); } else { // Верхний левый currentZ = 45f; curX -= boxRT.sizeDelta.x / 2f; curY -= (boxRT.sizeDelta.y + boxRT.sizeDelta.y / 2f + arrowRT.sizeDelta.y / 2f); } } else { if (right) { // Нижний правый currentZ = 225f; curX -= (boxRT.sizeDelta.x + boxRT.sizeDelta.x / 2f + arrowRT.sizeDelta.x / 2f); curY -= boxRT.sizeDelta.y / 2f; } else { // Нижний левый currentZ = 135f; curX -= boxRT.sizeDelta.x / 2f; curY -= boxRT.sizeDelta.y / 2f; } } boxRT.anchoredPosition = new Vector2(curX, curY); arrowRT.anchoredPosition = new Vector2(arrowPositionX, arrowPositionY); arrowRT.localRotation = Quaternion.Euler(0f, 0f, currentZ); // Появиться. foreach (Image bg in img) { bg.color = Color.Lerp(bg.color, BGColor, speed * Time.deltaTime); } boxText.color = Color.Lerp(boxText.color, textColor, speed * Time.deltaTime); } else { // Исчезнуть. foreach (Image bg in img) { bg.color = Color.Lerp(bg.color, BGColorFade, speed * Time.deltaTime); } boxText.color = Color.Lerp(boxText.color, textColorFade, speed * Time.deltaTime); } }