コード例 #1
0
    public static void BuildGrassLand()
    {
#if UNITY_EDITOR
        if (null == GrassMaterial)
        {
            GrassMaterial = AssetDatabase.LoadAssetAtPath <Material>("Assets/Shaders/Grasses/Mat/GrassMat.mat");
        }

        if (pointList.Count < 2)
        {
            EditorUtility.DisplayDialog("提示", "你还没有画好草地的范围", "ok");
        }
        List <Vector3> allPoint = AllPointIn(pointList);
        TextAsset      t        = Resources.Load <TextAsset>("Config/GrassesPos");
        string         json     = "";
        if (null != t)
        {
            json = t.text;
        }

        GrassPosConfig grassPosConfig = JsonConvert.DeserializeObject <GrassPosConfig>(json);

        if (null == grassPosConfig)
        {
            grassPosConfig = ScriptableObject.CreateInstance <GrassPosConfig>();
        }
        grassPosConfig.AddGrassPos(allPoint);


        json = JsonConvert.SerializeObject(grassPosConfig);
        File.WriteAllText(GrassPosConfigPath, json, Encoding.UTF8);

        pointList.Clear();
#endif
    }
コード例 #2
0
    public void Initialize()
    {
        TextAsset t    = Resources.Load <TextAsset>("Config/GrassesPos");
        string    json = "";

        if (t != null)
        {
            json = t.text;
        }
        else
        {
            Debug.LogError("无法加载草地配置信息");
        }

        GrassPosConfig grassPosConfig = JsonConvert.DeserializeObject <GrassPosConfig>(json);

        if (null == grassPosConfig)
        {
            return;
        }
        List <Vector3> GrassPosList = grassPosConfig.GetGrassPos();

        GrassPosList = GrassPosList.Distinct().ToList();

        foreach (Vector3 pos in GrassPosList)
        {
            GameEntity entity = _context.CreateEntity();

            ////草地位置稍有偏移
            //Vector3 grassPos = new Vector3(
            //    RandomService.game.Float(-0.1f, 0.1f) + pos.x,
            //    0f,
            //    RandomService.game.Float(-0.1f, 0.1f) + pos.z);

            entity.AddGrassPos(pos);
        }
    }