Teach you how to use Unity to build a simple image server

Table of contents

introduction

server

Introduction to WAMP

Configuration and use of WAMP

The main WAMP integration environments are:

text

1. External tools & material preparation

First download and install WAMP 

image path setting

2. Create a Unity project

Load the image into the Unity project:

code block

The operation effect is as follows:


introduction

server

In online games, the construction of the server is particularly important. Whether it is an authorized server or an unauthorized server, it is responsible for a large part of data processing. Today, I will share with you an intermediate and advanced small server construction, which of course is also implemented on Unity, which can be migrated to services, external programs, etc. The serialization and deserialization of objects, the packaging and unpacking of data packets are added, and there is a unique taste when you taste it carefully. For example, ProtoBuf is cross-platform and can transfer objects across platforms. This article uses the transport layer protocol, and interested students can use the network layer protocol Socket to implement.

This article only involves using WAMP to build a simple image server, which is easy to use, let's do it together.

WAMP (Windows + Apache + Mysql + PHP), a group of open source software commonly used to build dynamic websites or servers, are independent programs themselves. Because they are often used together, they form a powerful web development platform.

Introduction to WAMP

Configuration and use of WAMP

There are a lot of AMP (Apache\MySQL\PHP) integrated software, which allows us to install and set it up at one time. This has many benefits for users unfamiliar with AMP.


The main WAMP integration environments are:

1. WampServer Wamp is the Windows Apache Mysql PHP integrated installation environment, that is, the server software of apache, php and mysql under the window . PHP extension, Apache module, you can turn it on/off with a few clicks of the mouse, and you don't have to modify the configuration file yourself, WAMP will do it. There is no need to ask about the installation of php everywhere, everything is done with WAMP, and this software is used more on the win platform.

2、XAMPP

XAMPP is a full-featured integrated environment with Chinese instructions. XAMPP is not just for Windows, but an easy-to-install Apache distribution for Linux, Windows, Mac OS X and Solaris. The package includes Apache server, MySQL, SQLite, PHP, Perl, FileZilla FTP Server, Tomcat, and more. The default installation opens all functions, and there are security problems, which require additional security settings.

3、AppServ

It integrates Apache, PHP, MySQL, and phpMyAdmin, which is relatively lightweight, and the version has not been updated for a long time.

In general, the above WAMP environments can basically meet the needs of beginners to configure WAMP environments. For example, XAMPP and AppServ have various components, but they also feel that the file composition is more complicated, and beginners can't understand it at once. , like Digast Wamp Server, because it is a brand-new integrated environment, the program file configuration is more rigorous, the environment program size is moderate, and any directory can be customized, and the system will automatically configure parameters, which is especially suitable for beginners.

4、phpStudy

phpStudy supports 22 combinations to switch freely. This package integrates the latest Apache+Nginx+LightTPD+PHP+MySQL+phpMyAdmin+Zend Optimizer+Zend Loader. It is a one-time installation and can be used without configuration. It is a very convenient and easy-to-use PHP debugging environment. The program is only 35M green, small and simple, and has a special control panel. In short, learning PHP only requires one package.


text

1. External tools & material preparation

First download and install WAMP 

It is installed under the D:\Work\wamp\wamp directory. After the installation is complete, there will be an icon in the taskbar, click it and the following content:

image path setting

Then put the pictures you need to use in the folder of the web page (the changed directory will be created when installing WAMP):

Enter the corresponding path in the browser to open to view the picture, as shown in the following figure:


2. Create a Unity project

Load the image into the Unity project:

The project structure is as follows:

code block

The code in WAMPServerTest.cs is as follows:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WAMPServerTest : MonoBehaviour
{
    [SerializeField]
    UITexture tex;
    [SerializeField]
    GameObject btnGetImage;

    string path = "http://localhost/test.png"; //设置路径
    WWW myWWW = null;

    void Awake()
    {
        UIEventListener.Get(btnGetImage).onClick = OnClickGetImageBtn;
    }

    void OnClickGetImageBtn(GameObject go)
    {
        StartCoroutine(GetImage());
    }

    IEnumerator GetImage()
    {
        if (null == myWWW)
            myWWW = new WWW(path);
        yield return myWWW;
        tex.mainTexture = myWWW.texture;
        tex.MakePixelPerfect();
    }
}

The operation effect is as follows:

Guess you like

Origin blog.csdn.net/flyTie/article/details/127165534