예제 #1
0
    public void EditorRefreshData()
    {
        MPDataCreator creator = gameObject.GetComponent <MPDataCreator>();

        if (creator == null)
        {
            return;
        }
        string     path = string.Format("{0}/MightyPillar/Resources/{1}.bytes", Application.dataPath, creator.DataName);
        PillarData data = MPFileUtil.LoadData(path, creator.DataName);

        //create display data
        mSlices.Clear();
        mCubes.Clear();
        Handles.color = Color.green;
        List <DisplaySlice> lSlices  = new List <DisplaySlice>();
        Vector3             startPos = new Vector3(data.setting.center[0], data.setting.center[1], data.setting.center[2]);

        startPos.x -= data.setting.maxX * data.setting.sliceSize[0] * 0.5f;
        startPos.y -= (data.setting.heightValRange[1] - data.setting.heightValRange[0]) * 0.5f;
        startPos.z -= data.setting.maxZ * data.setting.sliceSize[1] * 0.5f;
        for (int x = 0; x < data.setting.maxX; ++x)
        {
            for (int z = 0; z < data.setting.maxZ; ++z)
            {
                data.GetDisplaySlice(startPos.x, startPos.z, x, z, lSlices);
            }
        }
        for (int s = 0; s < lSlices.Count; ++s)
        {
            DisplaySlice slice = lSlices[s];
            if (slice.flag > 0 && s + 1 < lSlices.Count)
            {
                MyDisplayCube cube = new MyDisplayCube();
                Vector3       c0   = slice.min[0] * Vector3.right + slice.min[1] * Vector3.forward + slice.height * Vector3.up;
                DisplaySlice  next = lSlices[s + 1];
                Vector3       c1   = next.max[0] * Vector3.right + next.max[1] * Vector3.forward + next.height * Vector3.up;
                cube.center = 0.5f * (c0 + c1);
                cube.size   = c1 - c0;
                mCubes.Add(cube);
            }
            else
            {
                MyDisplaySlice myslice = new MyDisplaySlice();
                myslice.verts = new Vector3[]
                {
                    slice.min[0] * Vector3.right + slice.min[1] * Vector3.forward + slice.height * Vector3.up,
                    slice.min[0] * Vector3.right + slice.max[1] * Vector3.forward + slice.height * Vector3.up,
                    slice.max[0] * Vector3.right + slice.max[1] * Vector3.forward + slice.height * Vector3.up,
                    slice.max[0] * Vector3.right + slice.min[1] * Vector3.forward + slice.height * Vector3.up,
                };
                mSlices.Add(myslice);
            }
        }
    }
예제 #2
0
    // Start is called before the first frame update
    void Start()
    {
        MPDataCreator creator = gameObject.GetComponent <MPDataCreator>();

        if (creator != null)
        {
            string     path = string.Format("{0}/MightyPillar/Resources/{1}.bytes", Application.dataPath, creator.DataName);
            PillarData data = MPFileUtil.LoadData(path, creator.DataName);
            data.setting.boundHeight    = BoundHeight;
            data.setting.jumpableHeight = JumpableHeight;
            mPathPinder = new MPUnityAStar(data);
        }
    }