服务器内网地址 写在其上一个txt文档里 Unity读取该地址

原理和目的:resPath.txt写有服务器内网地址,它放在服务器存有Unity WebGL包里三个文件的同级目录下(“三个文件”指Build、TemplateData、index),在Unity里写脚本读取它——这样做的目的是,再去部署新服务器时,只需更改resPath.txt里服务器地址,省去了在Unity代码里修改服务器地址,又得重新打包的麻烦

1、resPath.txt文件(注意最后的竖杠是光标,实际是没有东西的)
在这里插入图片描述

2、以上txt文件的在服务器中的位置
下图品红色框
在这里插入图片描述

3、Unity里读取以上txt文件的脚本("Application.pathData"路径此处指向,存放webGL包三个文件的父文件夹,也可认为是Unity打出WebGL包)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Text;
using System;


public class WebUtil : MonoBehaviour
{
    public static WebUtil Instance = null;

    /// <summary>
    /// 从服务器获取到的资源路径
    /// </summary>
    private string path_Resource = string.Empty;

    private void Awake() {
        Instance = this;
    }

    // Start is called before the first frame update
    void Start()
    {
        StartCoroutine(readAddress());
    }

    public string GetResourcePath() {
       return  path_Resource;
    }


    /// <summary>
    /// 从网页Index的同层级获取到tex配置文件 得到文件中的网址
    /// </summary>
    /// <returns></returns>
    private IEnumerator readAddress() {
        string _path = Application.dataPath + "/resPath.txt";

        WWW www = new WWW(_path);

        yield return www;

        if (www.isDone)
        {
            path_Resource = Encoding.UTF8.GetString(www.bytes);
            Debug.Log("获取到的地址为:"+ path_Resource);
        }

    }

————————————————人肉分割线——————————————————

以下是我这边的WebGL包在服务器的部署,只做自己备忘无参考价值
1/服务器inetpub文件夹
在这里插入图片描述

2/wwwroot文件夹
在这里插入图片描述

3/DR和WebGL文件夹
在这里插入图片描述

4/DR文件夹
在这里插入图片描述

5/WebGL文件夹
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值