Exemplo n.º 1
0
    public void addPointAtPosition(Vector3 position)
    {
        GameObject        gameObject = new GameObject("point " + index.ToString());
        CurvedGroundPoint point      = gameObject.AddComponent <CurvedGroundPoint>();

        point.transform.parent = transform;
        point.position         = position;
        point.curve            = this;
        anchorPoints.Add(point);
        index++;
    }
Exemplo n.º 2
0
    bool drawPointInInspector(CurvedGroundPoint point)
    {
        EditorGUILayout.BeginVertical();
        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("X", GUILayout.Width(20)))
        {
            return(true);
        }


        EditorGUILayout.ObjectField(point.gameObject, typeof(GameObject), true);

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndVertical();
        return(false);
    }
Exemplo n.º 3
0
    public override void OnInspectorGUI()
    {
        bool render = false;

        int selection = EditorGUILayout.Popup("type", selectedType, types);

        if (selection != selectedType)
        {
            selectedType = selection;
            render       = true;

            if (selectedType == 0)
            {
                curve.type = CurvedGround.curveType.Bezier;
            }
            else
            {
                curve.type = CurvedGround.curveType.Lagrange;
            }
        }

        curve.precision = 1 / EditorGUILayout.FloatField("precision", 1 / curve.precision);
        curve.yheight   = EditorGUILayout.FloatField("y-height", curve.yheight);


        if (curve.GetType() == typeof(CurvedGround3D))
        {
            CurvedGround3D c = (CurvedGround3D)curve;
            c.zdepth = EditorGUILayout.FloatField("z-depth", c.zdepth);
        }
        CurvedGroundPoint toDelete = null;

        foreach (CurvedGroundPoint point in curve.anchorPoints)
        {
            if (drawPointInInspector(point))
            {
                toDelete = point;
            }
        }

        if (toDelete != null)
        {
            curve.anchorPoints.Remove(toDelete);
            DestroyImmediate(toDelete.gameObject);
        }



        if (GUILayout.Button("add point"))
        {
            Vector3 point = new Vector3(0, 0, 0);
            if (curve.anchorPoints.Count > 0)
            {
                Vector3 lastPoint = curve.anchorPoints[curve.anchorPoints.Count - 1].position;
                point.x = lastPoint.x + 5;
                point.y = lastPoint.y;
                point.z = 0;
            }
            curve.addPointAtPosition(point);
        }

        if (GUILayout.Button("update"))
        {
            render = true;
        }


        if (render)
        {
            curve.renderCurveMesh();
        }
    }
 private void OnEnable()
 {
     point = (CurvedGroundPoint)target;
 }