Ejemplo n.º 1
0
    public void MovePointMarker(int pointID, Vector3 pos)
    {
        //issue : don't move the head point
        oldPos   = listPoint[listPoint.Count - 1].transform.position;
        lineType = dicPointType[pointID];
        //Debug.LogWarning("dd; " + lineType);

        //editable none type
        switch (lineType)
        {
        case lineTypeList.straight:
            if (pointID == 0)
            {
                EditStraitghtCurve(pos, listPoint[pointID + 1].transform.position);
            }
            else
            {
                EditStraitghtCurve(listPoint[pointID - 1].transform.position, pos);
            }
            break;

        case lineTypeList.curve:
            if (pointID == 0)     //start point
            {
                EditSingleCurve(pos, listPoint[pointID + 1].transform.position, pointID, listControlPoint[pointID]);
            }
            else if (pointID == (listPoint.Count - 1))    //end point
            {
                EditSingleCurve(listPoint[pointID - 1].transform.position, pos, pointID - 1, listControlPoint[pointID - 1]);
            }
            else     //middle point
            {
                EditSingleCurve(listPoint[pointID - 1].transform.position, pos, pointID - 1, listControlPoint[pointID - 1]);
                EditSingleCurve(pos, listPoint[pointID + 1].transform.position, pointID, listControlPoint[pointID]);
            }
            break;

        case lineTypeList.bezier:
            if (pointID == 0)     //start point
            {
                EditBezierCurve(pos, listPoint[pointID + 1].transform.position, pointID, listControlPoint[0], listControlPoint[1]);
            }
            else if (pointID == (listPoint.Count - 1))     //end point
            {
                EditBezierCurve(listPoint[pointID - 1].transform.position, pos, pointID - 1, listControlPoint[(pointID - 1) * 2], listControlPoint[(pointID - 1) * 2 + 1]);
            }
            else     //middle point
            {
                EditBezierCurve(listPoint[pointID - 1].transform.position, pos, pointID - 1, listControlPoint[(pointID - 1) * 2], listControlPoint[(pointID - 1) * 2 + 1]);
                EditBezierCurve(pos, listPoint[pointID + 1].transform.position, pointID, listControlPoint[pointID * 2], listControlPoint[pointID * 2 + 1]);
            }
            break;
        }
        //Debug.Log("MovePointMarker : " + id + " / " + pos);
    }
Ejemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        pos = new Vector3[maxpoints];

        //lineType = lineTypeList.none;
        lineType = lineTypeList.curve;

        lineRenderer.positionCount = 0;
        lineRenderer.startWidth    = 0.1f;
        lineRenderer.endWidth      = 0.1f;

        cam = Camera.main;

        GetComponentInParent <DrawManager>().BezierIdx = transform.GetSiblingIndex();
        Debug.LogWarning("dd : " + GetComponentInParent <DrawManager>().BezierIdx);
    }
Ejemplo n.º 3
0
    public void SetLineType(int type)
    {
        switch (type)
        {
        case 1:
            lineType = lineTypeList.straight;
            break;

        case 2:
            lineType = lineTypeList.curve;
            break;

        case 3:
            lineType = lineTypeList.bezier;
            break;
        }

        //GameObject.Find("/Script").GetComponent<TestScript>().SetIndicator(type);
    }
Ejemplo n.º 4
0
    public void ResetStatus()
    {
        lineType  = lineTypeList.none;
        addWeight = 0;
        cntDraw   = 0;

        listPoint.Clear();
        listControlPoint.Clear();
        dicPointType.Clear();

        pos = null;
        pos = new Vector3[maxpoints];

        lineRenderer.positionCount = 0;

        for (int i = 0; i < this.transform.childCount; i++)
        {
            Destroy(this.transform.GetChild(i).gameObject);
        }
    }
Ejemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        //Debug.DrawRay(ray.origin, ray.direction * 1000f, Color.red, 2f);

        if (Input.GetKeyDown(KeyCode.Space))
        {
            //for dev
            foreach (KeyValuePair <int, lineTypeList> abc in dicPointType)
            {
                Debug.Log("a : " + abc.Key + " / " + abc.Value);
            }
        }
        else if (Input.GetMouseButtonDown(0) && Input.GetKey(KeyCode.LeftShift))
        {
            if (lineType == lineTypeList.none)
            {
                return;
            }

            //newPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); //orthographic cam only
            //newPos = Camera.main.ScreenPointToRay(Input.mousePosition).GetPoint(Mathf.Abs(cam.transform.localPosition.z)); //perspective cam only

            if (Physics.Raycast(ray, out hit, Mathf.Infinity))
            {
                //Debug.Log("hit posi " + hit.point);
                newPos = hit.point;

                //GameObject abc = GameObject.CreatePrimitive(PrimitiveType.Cube);
                //abc.transform.localPosition = hit.point;
            }

            if (Common.ISDRAWORTHO)
            {
                newPos.z = 0; //when use for customize
            }
            //Debug.Log("created point posi : " + newPos);

            if (dicPointType.Count == 0) //head point
            {
                Common.Instance.DebugPrint('c', "create new header", "create new header");
                dicPointType.Add(cntDraw, lineType);
            }

            if (CreatePointMarker(newPos) > 1)
            {
                Common.Instance.DebugPrint('c', "create new point", "create new point");
                //add lineType on hashmap
                cntDraw++;
                dicPointType.Add(cntDraw, lineType);
                //end

                switch (lineType)
                {
                case lineTypeList.straight:
                    //DrawStraitghtCurve(oldPos, newPos);
                    break;

                case lineTypeList.curve:
                    DrawSingleCurve(oldPos, newPos);
                    break;

                case lineTypeList.bezier:
                    DrawBezierCurve(oldPos, newPos);
                    break;
                }

                if (lineType != lineTypeList.straight)
                {
                    addWeight += numpos; //eg 0, 20, 40 ...
                }
                else
                {
                    addWeight += 2; //eg 2, 4, 6 ...
                }
            }
            oldPos = newPos;
        }
        else if (Input.GetMouseButtonDown(1)) //end draw line
        {
            lineType = lineTypeList.none;
            pos.Initialize();

            transform.GetComponentInParent <DrawManager>().BezierIdx = -1;
            transform.GetComponentInParent <DrawManager>().RefBezier = null; //release
        }
    }