Example #1
0
    public override void OnInspectorGUI()
    {
        MapWayPoint mapWayPoint = target as MapWayPoint;

        EditorGUILayout.PropertyField(serializedObject.FindProperty("pointList"), true);

        if (GUILayout.Button("+"))
        {
            Transform[] child = mapWayPoint.transform.GetComponentsInChildren <Transform>();
            int         count = 1;
            //if (child.Length == 1)
            //    count = 2;
            //else
            //    count = 1;

            for (int i = 0; i < count; ++i)
            {
                GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                cube.name = "point_" + (child.Length - 1);
                mapWayPoint.AddPoint(cube);
                cube.transform.position = child[child.Length - 1].position;
            }
        }
    }
Example #2
0
    public static void LoadPath()
    {
        List <GameObject> delarr   = new List <GameObject>();
        GameObject        WayPoint = null;

        foreach (GameObject sceneObject in Object.FindObjectsOfType(typeof(GameObject)))
        {
            if (sceneObject.name == mParentName)
            {
                WayPoint = sceneObject;
                break;
            }
        }

        if (WayPoint == null)
        {
            GameObject tGO = new GameObject(mParentName);
            tGO.AddComponent <MapDraw>();
            WayPoint = tGO;
        }

        //读取文件
        byte[] pointData = Util.ReadByteToFile(Util.GetDataFilePath(mapname + ".text"));

        if (pointData == null)
        {
            return;
        }

        foreach (Transform child in WayPoint.transform)
        {
            delarr.Add(child.gameObject);
        }
        //删除旧物体
        foreach (GameObject obj in delarr)
        {
            DestroyImmediate(obj);
        }

        string str = System.Text.Encoding.Default.GetString(pointData);

        Debug.Log(str);
        Dictionary <string, List <string> > post = JsonMapper.ToObject <Dictionary <string, List <string> > >(str);

        Dictionary <string, MapWayPoint> temp = new Dictionary <string, MapWayPoint>();

        foreach (KeyValuePair <string, List <string> > pair in post)
        {
            List <string> list        = pair.Value;
            GameObject    go          = new GameObject();
            MapWayPoint   mapWayPoint = go.GetOrAddComponent <MapWayPoint>();
            go.name = pair.Key;
            go.transform.SetParent(WayPoint.transform);
            int pointCount = int.Parse(list[0]);
            for (int i = 0; i < pointCount; ++i)
            {
                GameObject point = GameObject.CreatePrimitive(PrimitiveType.Cube);
                point.name = "point_" + i;
                point.transform.SetParent(go.transform);
                point.transform.localScale = Vector3.one;
                point.transform.position   = Util.StrintToVector3(list[i + 1]);
                mapWayPoint.AddPoint(point);
            }
        }
    }