示例#1
0
        public override void OnInspectorGUI()
        {
            //Create a target to grab data from
            PointContainer myTarget = (PointContainer)target;

            //This makes sure that the active id is not out of bounds of the points array
            if (myTarget.activeId >= myTarget.points.Count)
            {
                myTarget.activeId = Mathf.Clamp(myTarget.points.Count - 1, 0, myTarget.points.Count);
            }

            GUILayout.Label("Tools");
            EditorGUILayout.BeginVertical("box");

            if (GUILayout.Button("Add New Point"))
            {
                Vector3 startPoint = (myTarget.points.Count > 0) ? myTarget.points[myTarget.activeId].LocalPosition : Vector3.zero;

                myTarget.AddPoint(1, startPoint);
                myTarget.activeId = myTarget.points.Count;
            }

            if (GUILayout.Button("Snap All To Ground"))
            {
                for (int i = 0; i < myTarget.points.Count; i++)
                {
                    myTarget.SnapToGround(i);
                }
            }

            //Change colour of points based on selected point
            GUI.color = (Tools.current == Tool.None) ? Color.red : Color.green;

            GUI.color = Color.white;

            EditorGUILayout.EndVertical();

            GUILayout.Label("Points");
            EditorGUILayout.BeginVertical("box");

            //If we have active points then update the UI with their editors
            if (myTarget.points.Count > 0)
            {
                for (int i = 0; i < myTarget.points.Count; i++)
                {
                    DrawPoint(i, myTarget);
                }
            }

            EditorGUILayout.EndVertical();
        }
示例#2
0
    private void NewDot(Vector3 mousePosition)
    {
        mousePosition.z = gameObject.transform.position.z;
        GameObject point =
            Instantiate(PointPrefab, Camera.main.ScreenToWorldPoint(mousePosition), Quaternion.identity);

        point.transform.position = mousePosition;
        point.transform.parent   = PointContainer.transform;

        if (_isInsert && _pointContainer.selectedPoint != null)
        {
            _pointContainer.Insert(point.transform, _pointContainer.Points.IndexOf(_pointContainer.selectedPoint.transform) + 1);
        }
        else
        {
            _pointContainer.AddPoint(point.transform);
        }
    }