Paint in 3D

Paint in 3D用于在游戏内和编辑器里绘制所有物体。所有功能已经过深度优化,在WebGL、移动端、VR 以及更多平台用起来都非常好用!

它支持标准管线,以及 LWRP、HDRP 和 URP。通过使用GPU 加速,你的物体将以难以置信的速度被绘制。代码还经过深度优化来防止GC,和将所有绘制操作一起批次完成。

跟贴图系统不同,它是一个纹理绘制解决方案。这意味着你可以绘制你的物体上百万次,还是无帧率丢失,让你创作难以想象的游戏。

它在Unity应用商店上的售价是60美元,地址:https://assetstore.unity.com/packages/tools/painting/paint-in-3d-26286

Photon

Photon中文翻译为“光子”,为有着15年服务器后端开发经验的德国Exit Games公司开发的高效,稳定,可拓展的网络引擎。为目前世界上用户最广泛,支持游戏类型最多的专业网络引擎之一,也是Unity应用商店里用户评价最高的网络组件。

世界多个知名游戏公司和工作室选用Photon作为其产品的网络支持引擎,其中包括WB华纳,Codemaster, 2K, Glu, 微软游戏工作室,史克威尔艾尼克斯,百代南梦宫,SandBox,雨神电竞等知名企业,也有许多工作室和新创企业正在了解和试用Photon之中。

它在Unity应用商店上有一个免费应用,地址:https://assetstore.unity.com/packages/tools/network/pun-2-free-119922

当然,Photon需要注册账号、创建应用等操作才能使用,还不了解的同学可以去官方网站查阅相关资料。

温馨提示:Photon的国外服务器在国内使用比较卡,所以最好去中国官网申请国内的服务器,申请地址:https://vibrantlink.com/chinacloudapply/

下面正式开始。

微信扫描二维码关注后回复「电子书」,获取12本Java必读技术书籍。

创建工程

使用Unity Hub创建一个3D项目,然后分别引入Paint in 3DPhoton Unity Networking 2,如下图:

温馨提示:在引入Photon Unity Networking 2后,记得配置AppId。

创建简易画板

为了方便演示,我们创建一个Quad作为画板,然后为其添加P3dPaintable、P3dMaterialCloner和P3dPaintableTexture组件,使用它们的默认配置即可,如下图:

然后,创建一个空的GameObject命名为OneMorePaint,然后向OneMorePaint添加P3dPaintSphere组件,修改P3dPaintSphere组件的Color为红色,其他配置保持默认不变,如下图:

再向OneMorePaint添加P3dHitScreen组件,勾选上P3dHitScreen组件的ConnectHits,其他配置保持默认不变,如下图:

这时候,创建简易画板就做好了,运行以后就可以画画了,如下图:

只不过,还是个单机版,我们加上实时在线功能。

微信扫描二维码关注后回复「电子书」,获取12本Java必读技术书籍。

连接PUN2服务器

创建一个C#脚本命名为Launcher,再创建一个空的GameObject命名为LauncherGameObject,把C#脚本Launcher添加到LauncherGameObject中。

编辑C#脚本Launcher为如下内容:

using Photon.Pun;
using Photon.Realtime;
using UnityEngine; namespace One.More
{
public class Launcher : MonoBehaviourPunCallbacks
{
#region Private Fields
/// <summary>
/// This client's version number. Users are separated from each other by gameVersion (which allows you to make breaking changes).
/// </summary>
string gameVersion = "1";
/// <summary>
/// Keep track of the current process. Since connection is asynchronous and is based on several callbacks from Photon,
/// we need to keep track of this to properly adjust the behavior when we receive call back by Photon.
/// Typically this is used for the OnConnectedToMaster() callback.
/// </summary>
bool isConnecting;
#endregion void Start()
{
this.Connect();
} #region MonoBehaviourPunCallbacks Callbacks
public override void OnConnectedToMaster()
{
Debug.Log("PUN Basics Tutorial/Launcher: OnConnectedToMaster() was called by PUN");
// we don't want to do anything if we are not attempting to join a room.
// this case where isConnecting is false is typically when you lost or quit the game, when this level is loaded, OnConnectedToMaster will be called, in that case
// we don't want to do anything.
if (isConnecting)
{
// #Critical: The first we try to do is to join a potential existing room. If there is, good, else, we'll be called back with OnJoinRandomFailed()
PhotonNetwork.JoinRandomRoom();
isConnecting = false;
}
}
public override void OnDisconnected(DisconnectCause cause)
{
Debug.LogWarningFormat("PUN Basics Tutorial/Launcher: OnDisconnected() was called by PUN with reason {0}", cause);
isConnecting = false;
}
public override void OnJoinRandomFailed(short returnCode, string message)
{
Debug.Log("PUN Basics Tutorial/Launcher:OnJoinRandomFailed() was called by PUN. No random room available, so we create one.\nCalling: PhotonNetwork.CreateRoom");
// #Critical: we failed to join a random room, maybe none exists or they are all full. No worries, we create a new room.
PhotonNetwork.CreateRoom(null, new RoomOptions());
}
public override void OnJoinedRoom()
{
Debug.Log("PUN Basics Tutorial/Launcher: OnJoinedRoom() called by PUN. Now this client is in a room.");
}
#endregion #region Public Methods
/// <summary>
/// Start the connection process.
/// - If already connected, we attempt joining a random room
/// - if not yet connected, Connect this application instance to Photon Cloud Network
/// </summary>
public void Connect()
{
// we check if we are connected or not, we join if we are , else we initiate the connection to the server.
if (PhotonNetwork.IsConnected)
{
// #Critical we need at this point to attempt joining a Random Room. If it fails, we'll get notified in OnJoinRandomFailed() and we'll create one.
PhotonNetwork.JoinRandomRoom();
}
else
{
// #Critical, we must first and foremost connect to Photon Online Server.
isConnecting = PhotonNetwork.ConnectUsingSettings();
PhotonNetwork.GameVersion = gameVersion;
}
}
#endregion
}
}

这时候,就可以连接到连接PUN2服务器了,运行以后我们可以看到如下日志:

微信扫描二维码关注后回复「电子书」,获取12本Java必读技术书籍。

实时在线同步

向之前创建的OneMorePaint添加PhotonView组件,使用默认配置即可,如下图:

创建一个C#脚本命名为OnlinePainting,把C#脚本OnlinePainting添加到OneMorePaint中。

编辑C#脚本OnlinePainting为如下内容:

using PaintIn3D;
using Photon.Pun;
using UnityEngine; namespace One.More
{
public class OnlinePainting : MonoBehaviour, IHitPoint, IHitLine
{
private PhotonView photonView;
private P3dPaintSphere paintSphere; void Start()
{
this.photonView = this.GetComponent<PhotonView>();
this.paintSphere = this.GetComponent<P3dPaintSphere>();
} public void HandleHitPoint(bool preview, int priority, float pressure, int seed, Vector3 position, Quaternion rotation)
{
if (preview)
{
return;
}
if (this.photonView == null)
{
Debug.LogError("PhotonView is not found.");
return;
}
this.photonView.RPC("HandleHitPointRpc", RpcTarget.Others, preview, priority, pressure, seed, position, rotation);
} public void HandleHitLine(bool preview, int priority, float pressure, int seed, Vector3 position, Vector3 endPosition, Quaternion rotation, bool clip)
{
if (preview)
{
return;
}
if (this.photonView == null)
{
Debug.LogError("PhotonView is not found.");
return;
}
this.photonView.RPC("HandleHitLinetRpc", RpcTarget.Others, preview, priority, pressure, seed, position, endPosition, rotation, clip);
} [PunRPC]
public void HandleHitPointRpc(bool preview, int priority, float pressure, int seed, Vector3 position, Quaternion rotation)
{
if (this.paintSphere == null)
{
Debug.LogError("P3dPaintSphere is not found.");
return;
}
this.paintSphere.HandleHitPoint(preview, priority, pressure, seed, position, rotation);
} [PunRPC]
public void HandleHitLinetRpc(bool preview, int priority, float pressure, int seed, Vector3 position, Vector3 endPosition, Quaternion rotation, bool clip)
{
if (this.paintSphere == null)
{
Debug.LogError("P3dPaintSphere is not found.");
return;
}
this.paintSphere.HandleHitLine(preview, priority, pressure, seed, position, endPosition, rotation, clip);
}
}
}

在线涂鸦画板就制作完成了,我们看看运行效果怎么样?

运行效果

构建以后,同时启动两个客户端,效果如下:

当然,这只是简单的在线涂鸦画板,你还可以再此基础上添加更丰富的功能,比如:修改画笔颜色、修改画笔大小等等。

微信扫描二维码关注后回复「电子书」,获取12本Java必读技术书籍。

最后,谢谢你这么帅,还给我点赞关注

手把手带你使用Paint in 3D和Photon撸一个在线涂鸦画板的更多相关文章

  1. 手把手带你做一个超炫酷loading成功动画view Android自定义view

    写在前面: 本篇可能是手把手自定义view系列最后一篇了,实际上我也是一周前才开始真正接触自定义view,通过这一周的练习,基本上已经熟练自定义view,能够应对一般的view需要,那么就以本篇来结尾 ...

  2. 手把手教你玩转 CSS3 3D 技术

    css3的3d起步 要玩转css3的3d,就必须了解几个词汇,便是透视(perspective).旋转(rotate)和移动(translate).透视即是以现实的视角来看屏幕上的2D事物,从而展现3 ...

  3. 手把手教你玩转CSS3 3D技术

    手把手教你玩转 CSS3 3D 技术   要玩转css3的3d,就必须了解几个词汇,便是透视(perspective).旋转(rotate)和移动(translate).透视即是以现实的视角来看屏幕上 ...

  4. [.Net] 手把手带你将自己打造的类库丢到 NuGet 上

    手把手带你将自己打造的类库丢到 NuGet 上 序 我们习惯了对项目右键点击“引用”,选择“管理NuGet 程序包”来下载第三方的类库,可曾想过有一天将自己的打造的类库放到 NuGet 上,让第三者下 ...

  5. Android性能优化:手把手带你全面实现内存优化

      前言 在 Android开发中,性能优化策略十分重要 本文主要讲解性能优化中的内存优化,希望你们会喜欢 目录   1. 定义 优化处理 应用程序的内存使用.空间占用 2. 作用 避免因不正确使用内 ...

  6. Android:手把手带你深入剖析 Retrofit 2.0 源码

    前言 在Andrroid开发中,网络请求十分常用 而在Android网络请求库中,Retrofit是当下最热的一个网络请求库 今天,我将手把手带你深入剖析Retrofit v2.0的源码,希望你们会喜 ...

  7. [转帖]从零开始入门 K8s | 手把手带你理解 etcd

    从零开始入门 K8s | 手把手带你理解 etcd https://zhuanlan.zhihu.com/p/96721097 导读:etcd 是用于共享配置和服务发现的分布式.一致性的 KV 存储系 ...

  8. 手把手带你阅读Mybatis源码(三)缓存篇

    前言 大家好,这一篇文章是MyBatis系列的最后一篇文章,前面两篇文章:手把手带你阅读Mybatis源码(一)构造篇 和 手把手带你阅读Mybatis源码(二)执行篇,主要说明了MyBatis是如何 ...

  9. GitHub 热点速览 Vol.26:手把手带你做数据库

    作者:HelloGitHub-小鱼干 摘要:手把手带你学知识,应该是学习新知识最友好的姿势了.toyDB 虽然作为一个"玩具"项目不能应用在实际开发中,但通过它你可以了解到如何制作 ...

随机推荐

  1. SpringBoot外部配置属性注入

    一.命令行参数配置 Spring Boot可以是基于jar包运行的,打成jar包的程序可以直接通过下面命令运行: java -jar xx.jar 那么就可以通过命令行改变相关配置参数.例如默认tom ...

  2. Redis 中 String 类型的内存开销比较大

    使用 String 类型内存开销大 1.简单动态字符串 2.RedisObject 3.全局哈希表 使用 Hash 来存储 总结 参考 使用 String 类型内存开销大 如果我们有大量的数据需要来保 ...

  3. web开发 小方法3-position

    值 描述 absolute 生成绝对定位的元素,相对于 static 定位以外的第一个父元素进行定位. 元素的位置通过 "left", "top", " ...

  4. 4.2 K8S超级完整安装配置

    前言: 采坑 k8s有3种安装方式,如下所示: minikube:这是一个k8s集群模拟器,只有一个节点的集群,只为了测试使用,master和node都在一台机器上 直接使用带有容器功能的云平台安装: ...

  5. kali系统语言设置

    一.背景信息在安装完 kali linux 2020.1 时,其操作系统默认语言为英文的,我们操作起来比较麻烦,为了以后操作方便起见,这边将其操作系统默认语言更改为中文.本篇文章将带领各位小伙伴们一起 ...

  6. BI企服界大众点评来袭!Smartbi入围36氪企服软件系列三大榜单!

    近日,36氪企服点评中国商业智能BI金榜揭晓.作为国产民族BI软件的领跑者,思迈特软件凭借深耕多年大数据BI领域中拥有过硬的产品实力与优质的服务,荣获"商业智能BI最佳软件总榜TOP10&q ...

  7. 学习OMO游戏管理驾驶舱的设计

    2019年第1季度,Smartbi帮助合作伙伴开发了一个销售管理沙盘游戏(OMO),在第一个版本中主要精力放在游戏的后台过程逻辑上(基于电子表格的报表和回写能力),并没有把Smartbi的最强项--数 ...

  8. 苹果如何控制android手机,安卓手机怎么控制苹果?

    小编经常通过手机远程控制别人手机,帮助他人解决一些电脑问题,另外还经常需要通过远程电脑控制服务器,管理脚本之家的服务器等等,可能这些对大家都没有什么诱惑,今天笔者为大家带来一个非常有趣的手机控制电脑的 ...

  9. MSBuild 和项目文件

    Microsoft 生成引擎(MSBuild)项目文件位于生成和部署过程的核心. 本主题以 MSBuild 和项目文件的概念性概述开头. 它介绍了在处理项目文件时将遇到的关键组件,并通过一个示例来演示 ...

  10. windows server 2012 r2 修改administrator密码

    转至:https://jingyan.baidu.com/article/b907e627b615b646e7891cbf.html 1.进入开始面板,点击"管理工具". 2.双击 ...