Exemplo n.º 1
0
    public void CreateAndAddControlPt(LineInspectorInfo lineInfo, int inspectionIndex, Vector3 pos)
    {
        var controlPtsTB = lineInfo.controlPtsTB;
        var controlPts   = lineInfo.controlPts;

        Vector3 screenPos = Camera.main.WorldToScreenPoint(pos);

        controlPtsTB.Add(GameObject.Instantiate(endPtPrefab, screenPos, Quaternion.identity));
        int cpIndex = controlPtsTB.Count - 1;

        controlPtsTB[cpIndex].transform.SetParent(lineInfo.lineInspection);
        controlPtsTB[cpIndex].name = ((cpIndex == 0) ? "StartPt" : "EndPt") + createdLineInspectionCount.ToString();

        controlPtsTB[cpIndex].GetComponent <Image>().raycastTarget = true;

        Coordinate coord = map.GetCoordinatesFromUnits(pos.x, pos.z);

        lineInfo.coords.Add(coord);
        var cp = controlPtsTB[cpIndex].GetComponent <ControlPt>();

        controlPts.Add(cp);
        cp.InspectionIndex   = inspectionIndex;
        cp.ControlPointIndex = cpIndex;
        cp.LineInfo          = lineInfo;
        cp.SetCoord(coord);
    }
Exemplo n.º 2
0
    public void CreateLineInspectionMidPoint(LineInspectorInfo lineInfo, float midPtOffset)
    {
        Vector3 startPt = lineInfo.controlPtsTB[StartPtIndex].transform.localPosition;
        Vector3 endPt   = lineInfo.controlPtsTB[EndPtIndex].transform.localPosition;
        Vector3 midPt   = (startPt + endPt) * 0.5f;

        Quaternion rot    = Quaternion.FromToRotation(Vector2.right, (endPt - startPt).normalized);
        Vector3    offset = rot * (Vector3.down * midPtOffset);

        lineInfo.controlPtsTB.Add(GameObject.Instantiate(midPtPrefab, midPt, Quaternion.identity));
        lineInfo.controlPtsTB[MidPtIndex].transform.SetParent(lineInfo.lineInspection);
        lineInfo.controlPtsTB[MidPtIndex].name = "MidPt" + createdLineInspectionCount.ToString();

        var cp2 = lineInfo.controlPtsTB[MidPtIndex].GetComponent <ControlPt>();

        lineInfo.controlPts.Add(cp2);
        cp2.ControlPointIndex = lineInfo.controlPtsTB.Count - 1;
        cp2.LineInfo          = lineInfo;

        Vector3 newMidPtPos = midPt + offset;

        lineInfo.controlPtsTB[MidPtIndex].transform.localPosition = newMidPtPos;
        Coordinate coordMid = map.GetCoordinatesFromUnits(newMidPtPos.x, newMidPtPos.y);

        lineInfo.coords.Add(coordMid);
        cp2.SetCoord(coordMid);

        foreach (var controlPtTB in lineInfo.controlPtsTB)
        {
            controlPtTB.GetComponent <Image>().raycastTarget = true;
        }
    }
Exemplo n.º 3
0
    public void UpdateInspectionDelete(LineInspectorInfo lineInfo)
    {
        // Compute midpt
        Vector3 startPt = lineInfo.controlPtsTB[StartPtIndex].transform.localPosition;
        Vector3 endPt   = lineInfo.controlPtsTB[EndPtIndex].transform.localPosition;
        Vector3 midPt   = (startPt + endPt) * 0.5f;

        lineInfo.inspectionDelete.UpdatePosition(midPt);
    }
Exemplo n.º 4
0
 public void CreateLineInspection(LineInspectorInfo lineInfo, int count, RectTransform lineInspectionPrefab, RectTransform inspectorContainer)
 {
     if (lineInfo.lineInspection == null)
     {
         lineInfo.lineInspection = GameObject.Instantiate(lineInspectionPrefab);
         lineInfo.lineInspection.SetParent(inspectorContainer);
         lineInfo.lineInspection.name = "InspectionLine" + count.ToString();
         lineInfo.scaleFactor         = canvas.scaleFactor;
     }
 }
Exemplo n.º 5
0
    public void UpdateLineEndPtFromWorldPos(LineInspectorInfo lineInfo, int controlPtIndex, Vector3 worldPos)
    {
        // Update control point currently being dragged then update position of endpoint of line
        lineInfo.line.SetPosition(controlPtIndex, worldPos);

        Coordinate endPtCoord = map.GetCoordinatesFromUnits(worldPos.x, worldPos.z);

        lineInfo.coords[controlPtIndex] = endPtCoord;
        lineInfo.controlPts[controlPtIndex].SetCoord(endPtCoord);
    }
Exemplo n.º 6
0
 public void CreateLine(LineInspectorInfo lineInfo, int count, LineRenderer linePrefab)
 {
     // Init line prefab
     if (lineInfo.line == null)
     {
         lineInfo.line = GameObject.Instantiate(linePrefab);
         lineInfo.line.transform.SetParent(lineInfo.lineInspection);
         lineInfo.line.name      = "Line" + count.ToString();
         lineInfo.inspectionLine = lineInfo.line.GetComponent <InspectionLine>();
         lineInfo.inspectionLine.SetLineInfo(lineInfo);
     }
 }
Exemplo n.º 7
0
    public void UpdateMidPtPos(LineInspectorInfo lineInfo)
    {
        Vector3 screenPos = Input.mousePosition;

        // Update position of control pts of line taking into account of screen size
        lineInfo.controlPtsTB[MidPtIndex].transform.localPosition = lineInfo.mapViewAreaChanged ?
                                                                    (
            !lineInfo.scaleFactor.Equals(1.0f) ? screenPos * lineInfo.scaleFactor :
            screenPos / canvas.scaleFactor
                                                                    )
                                                                                                                                        : screenPos;
    }
Exemplo n.º 8
0
    public void CreateInspectorDeleteButton(LineInspectorInfo lineInfo)
    {
        Vector3 startPt = lineInfo.controlPtsTB[StartPtIndex].transform.localPosition;
        Vector3 endPt   = lineInfo.controlPtsTB[EndPtIndex].transform.localPosition;
        Vector3 midPt   = (startPt + endPt) * 0.5f;

        ToggleButton insspectionDelTB = GameObject.Instantiate(inspectionDelPrefab, midPt, Quaternion.identity);

        lineInfo.inspectionDelete = insspectionDelTB.GetComponent <InspectionDelete>();

        lineInfo.inspectionDelete.transform.SetParent(lineInfo.lineInspection);
        lineInfo.inspectionDelete.transform.name = "InspectionDel" + createdLineInspectionCount.ToString();

        lineInfo.inspectionDelete.SetLineInfo(lineInfo);
    }
Exemplo n.º 9
0
    public bool IsCursorNearLine(LineInspectorInfo lineInfo, Vector3 cursorPos, float range)
    {
        Vector3 startPt = Camera.main.WorldToScreenPoint(lineInfo.line.GetPosition(StartPtIndex));
        Vector3 endPt   = Camera.main.WorldToScreenPoint(lineInfo.line.GetPosition(EndPtIndex));

        float lineLength = (endPt - startPt).magnitude;

        Vector3 lineDir         = (endPt - startPt).normalized;
        Vector3 startPtToCursor = cursorPos - startPt;
        float   cursorProjLine  = Vector3.Dot(startPtToCursor, lineDir);
        float   offsetDist      = (startPtToCursor - lineDir * cursorProjLine).magnitude;

        bool isCursorNearLine = (offsetDist <= range * canvas.scaleFactor && cursorProjLine > (0.025f * lineLength) && cursorProjLine <= (0.975f * lineLength));

        return(isCursorNearLine);
    }
Exemplo n.º 10
0
    public void RemoveLineInspectorInfoProperties(LineInspectorInfo lineInfo)
    {
        // Remove map layer
        if (lineInfo.mapLayer != null)
        {
            toolLayers.Remove(lineInfo.mapLayer);
            if (lineInfo.mapLayer.grids.Count > 0)
            {
                lineInspectorGrids.AddRange(lineInfo.mapLayer.grids);
                lineInfo.mapLayer.Clear();
            }
            GameObject.Destroy(lineInfo.mapLayer.gameObject);
            lineInfo.mapLayer = null;
        }

        // Remove line inspection delete
        if (lineInfo.inspectionDelete)
        {
            GameObject.Destroy(lineInfo.inspectionDelete.gameObject);
            lineInfo.inspectionDelete = null;
        }

        // Remove control points
        foreach (var controlPtTB in lineInfo.controlPtsTB)
        {
            GameObject.Destroy(controlPtTB.gameObject);
        }
        lineInfo.controlPtsTB.Clear();
        lineInfo.controlPts.Clear();
        lineInfo.coords.Clear();

        // Remove line renderer
        if (lineInfo.line)
        {
            GameObject.Destroy(lineInfo.line.gameObject);
            lineInfo.line = null;
        }

        // Remove line inspection
        if (lineInfo.lineInspection != null)
        {
            GameObject.Destroy(lineInfo.lineInspection.gameObject);
            lineInfo.lineInspection = null;
        }

        lineInfo.mapViewAreaChanged = false;
    }
Exemplo n.º 11
0
    public void UpdateLineMidPt(LineInspectorInfo lineInfo, float midPtOffset)
    {
        // Update midPt position (screen pos)
        Vector3 startPt = lineInfo.controlPtsTB[StartPtIndex].transform.localPosition;
        Vector3 endPt   = lineInfo.controlPtsTB[EndPtIndex].transform.localPosition;
        Vector3 midPt   = (startPt + endPt) * 0.5f;

        Quaternion rot    = Quaternion.FromToRotation(Vector2.right, (endPt - startPt).normalized);
        Vector3    offset = rot * (Vector3.down * midPtOffset);

        Vector3 newMidPtPos = midPt + offset;

        lineInfo.controlPtsTB[MidPtIndex].transform.localPosition = newMidPtPos;

        inputHandler.GetWorldPoint(newMidPtPos, out Vector3 newMidPtWorldPos);

        Coordinate midPtCoord = map.GetCoordinatesFromUnits(newMidPtWorldPos.x, newMidPtWorldPos.z);

        lineInfo.coords[MidPtIndex] = midPtCoord;
        lineInfo.controlPts[MidPtIndex].SetCoord(midPtCoord);
    }
Exemplo n.º 12
0
 public void CreateLineMapLayer(LineInspectorInfo lineInfo, LineInspectionMapLayer lineInspectionMapLayerPrefab)
 {
     lineInfo.mapLayer = toolLayers.CreateMapLayer(lineInspectionMapLayerPrefab, "LineInspectionLayer" + createdLineInspectionCount.ToString());
     lineInfo.mapLayer.Init(lineInfo.coords);
     lineInfo.mapLayer.ShowTransect(false);
 }
Exemplo n.º 13
0
 public void UpdateLineEndPtPosition(LineInspectorInfo lineInfo, int index, Vector3 pos)
 {
     lineInfo.line.positionCount++;
     lineInfo.line.SetPosition(index, pos);
 }