示例#1
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();


        MapLinePointView view = (MapLinePointView)target;

        if (view.gameObject.transform.hasChanged)
        {
            Vector3  pos   = view.gameObject.transform.localPosition;
            IntPoint logic = PathUtilEdit.Real2Logic(pos);
            if (logic.x != propX.intValue || logic.y != propY.intValue)
            {
                pos = PathUtilEdit.LogicCenter2Real(logic);
                //Debug.Log("npc pos changed:" + logic.x + " != " + propX.intValue + "," + logic.y+" != "+propY.intValue);
                if (EditorData.terrainMan != null)
                {
                    pos.y = EditorData.terrainMan.GetHeight(pos.x, pos.z);
                    view.gameObject.transform.localPosition = pos;
                }
            }
            propX.intValue = logic.x;
            propY.intValue = logic.y;
        }
        EditorGUILayout.LabelField("X:\t" + propX.intValue);
        EditorGUILayout.LabelField("Y:\t" + propY.intValue);
        serializedObject.ApplyModifiedProperties();
    }
示例#2
0
    void updateMesh(int width, int height)
    {
        MapLinePointView view = (MapLinePointView)target;
        MeshFilter       mf   = view.gameObject.GetComponent <MeshFilter>();
        Mesh             mesh = mf.sharedMesh;

        float          x     = PathUtilEdit.Logic2RealLen(width / 2f);
        float          z     = PathUtilEdit.Logic2RealLen(height / 2f);
        List <Vector3> verts = new List <Vector3>();

        verts.Add(new Vector3(-x, 0, z));
        verts.Add(new Vector3(x, 0, z));
        verts.Add(new Vector3(x, 0, -z));
        verts.Add(new Vector3(-x, 0, -z));

        mesh.vertices = verts.ToArray();
    }
示例#3
0
    public GameObject AddLine(MapLine line)
    {
        string    subpath     = "line";
        Transform parentTrans = getRoot().FindChild(subpath);

        if (parentTrans == null)
        {
            GameObject subroot = new GameObject(subpath);
            subroot.transform.SetParent(getRoot());
            parentTrans = subroot.transform;
        }

        string     thirdpath        = "mapline_" + line.starobjid;
        Transform  grandParentTrans = getRoot().FindChild(thirdpath);
        GameObject thirdroot;

        if (grandParentTrans == null)
        {
            thirdroot = new GameObject(thirdpath);
            MapLineView view = thirdroot.AddComponent <MapLineView>();
            view.data = line;
            thirdroot.transform.SetParent(parentTrans);
            grandParentTrans = thirdroot.transform;
        }
        else
        {
            thirdroot = grandParentTrans.gameObject;
        }

        for (int i = 0; i < line.linepts.Count; i++)
        {
            if (grandParentTrans.FindChild("points" + (i + 1)))
            {
                continue;
            }


            GameObject       go        = new GameObject("points" + (i + 1));
            MeshFilter       mf        = go.AddComponent <MeshFilter>();
            MeshRenderer     mr        = go.AddComponent <MeshRenderer>();
            MapLinePointView pointView = go.AddComponent <MapLinePointView>();
            pointView.data   = line.linepts[i];
            pointView.target = go;
            Mesh           mesh  = new Mesh();
            List <Vector3> verts = new List <Vector3>();

            float x = 0.5f;
            float z = 0.5f;

            verts.Add(new Vector3(-x, 0, z));
            verts.Add(new Vector3(x, 0, z));
            verts.Add(new Vector3(x, 0, -z));
            verts.Add(new Vector3(-x, 0, -z));
            mesh.vertices = verts.ToArray();


            mesh.SetTriangles(new int[] { 0, 1, 2, 0, 2, 3 }, 0);
            Color cl = new Color(0, 1, 1);
            mesh.colors = new Color[] { cl, cl, cl, cl };

            mr.material = Resources.Load("Materials/Ground_tile_material") as Material;
            mf.mesh     = mesh;

            go.transform.SetParent(grandParentTrans);
            Vector2 real_pos = PathUtilEdit.logicCenter2Real((int)line.linepts[i].x, (int)line.linepts[i].y);
            float   h1       = EditorData.terrainMan.GetHeight(real_pos.x, real_pos.y) + 0.1f;
            Vector3 tempPos  = new Vector3(real_pos.x, h1, real_pos.y);
            go.transform.localPosition = tempPos;
        }



        line.target = thirdroot;
        return(thirdroot);
    }