美文网首页
Unity3D-阴阳师画符

Unity3D-阴阳师画符

作者: BugUnknown | 来源:发表于2018-09-05 17:21 被阅读235次

前言

众所周知,2016年对“陰陽師”而言是不一样的一年。作为网易在第三季度推出的新游,创新地将原汁原味的和风美学体验带给用户,获得了超出预期的市场反应。9月2日首发当天即获App Store编辑选荐,更在12月发布的App Annie中国区2016年度十佳游戏中占据一席之地。10月初,其中文版在全球多个国家的苹果应用商店上架,根据11月11日首部资料片上线时的App Annie数据,《阴阳师》获得极具突破的瞩目和成绩:中国免费榜第1、畅销榜第1,加拿大畅销榜第1,澳大利亚畅销榜第1,新西兰畅销榜第1,英国畅销榜第8,美国畅销榜第10等等傲人的成绩。

2016年度十佳游戏

作为其中的核心玩法-画符,是其受到众多玩家青睐的重大原因,本篇将告诉您怎么在Unity3D中怎么实现这一原理。

思路?

如何实现在屏幕上画东西?

  1. Unity内置的LineRenderer
  2. Shader
  • 这里我们选择用OpenGL。
    在官方帮助文档里面,我们可以找到GL这个API

代码

using System.Collections.Generic;
using UnityEngine;

public class Test : MonoBehaviour
{
    public void GenerateText()
    {
        Texture2D tmpTex = new Texture2D(300,400);

        for (int i = 1; i < allPoints.Count; i++)
        {
            Vector2 tmpFront = allPoints[i - 1];
            Vector2 tmpBack = allPoints[i];

            for (int j = 1; j < 100; j++)
            {
                int xx = (int)(Mathf.Lerp(tmpFront.x * tmpTex.width, tmpBack.x*tmpTex.width, j / 100f));
                int yy = (int)(Mathf.Lerp(tmpFront.y * tmpTex.height, tmpBack.y * tmpTex.height, j / 100f));
                tmpTex.SetPixel(xx, yy, Color.yellow);
            }
        }

        tmpTex.Apply();

        GetComponent<Renderer>().material.mainTexture = tmpTex;

    }


    static Material lineMaterial;
    static void CreateLineMaterial()
    {
        if (!lineMaterial)
        {
            // Unity has a built-in shader that is useful for drawing
            // simple colored things.
            Shader shader = Shader.Find("Hidden/Internal-Colored");
            lineMaterial = new Material(shader);
            lineMaterial.hideFlags = HideFlags.HideAndDontSave;
            // Turn on alpha blending
            lineMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
            lineMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
            // Turn backface culling off
            lineMaterial.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off);
            // Turn off depth writes
            lineMaterial.SetInt("_ZWrite", 0);
        }
    }

    // Will be called after all regular rendering is done
    public void OnRenderObject()
    {
        CreateLineMaterial();
        // Apply the line material
        lineMaterial.SetPass(0);

        GL.PushMatrix();
        // Set transformation matrix for drawing to
        // match our transform
        GL.MultMatrix(transform.localToWorldMatrix);

        // Draw lines
        GL.Begin(GL.LINES);

        // 将透视投影变成正交投影
        GL.LoadOrtho();

        GL.Color(Color.yellow);

        for (int i = 1; i < allPoints.Count; i++)
        {
            Vector2 tmpFront = allPoints[i-1];
            Vector2 tmpBack = allPoints[i];

            GL.Vertex3(tmpFront.x, tmpFront.y, 0);
            GL.Vertex3(tmpBack.x, tmpBack.y, 0);
        }

        GL.End();
        GL.PopMatrix();
    }

    List<Vector2> allPoints = new List<Vector2>();

    private void Update()
    {
        if (Input.GetMouseButton(0))
        {
            Vector2 tmpPos = Camera.main.ScreenToViewportPoint(Input.mousePosition);

            allPoints.Add(tmpPos);
        }

        if (Input.GetMouseButtonUp(0))
        {
            GenerateText();
            //清空屏幕上的点
            allPoints.Clear();
        }
    }
}

效果

画符.gif

相关文章

  • Unity3D-阴阳师画符

    前言 众所周知,2016年对“陰陽師”而言是不一样的一年。作为网易在第三季度推出的新游,创新地将原汁原味的和风美学...

  • 异界阴阳师

    阴阳师,是掌握着阴阳道,懂得观星宿、相人面,还会测方位、知灾异,画符念咒、施行幻术的一种巫师。阴阳师主要职责便...

  • 阴阳师:这些强力的SSR式神永不过时,很适合培养!

    阴阳师是由网易推出的一款和风RPG手游,游戏为我们讲述了人鬼共生时代的晴明等人的故事,而游戏最大的乐趣就是画符召唤...

  • 跟着阴阳师学画符——五芒星

    五芒星(Pentacle)在古埃及被作为冥界子宫的符号 而在古代巴比伦则被作为女神伊修塔尔的孪生姐姐尼斐提斯(冥界...

  • 【虫二组】第四次作业

    阴阳师之非酋歌 法师法师画符, 召来一只山兔。 山兔出来跳舞, 召来一只铁鼠。 铁鼠出来撒土, 召来一只姑姑。 姑...

  • 我愿护你周全——阴阳师同人

    写在前面: 1,以晴明大人为第一人称,记录我的网易阴阳师历程。 2,画符的小童子是我自己加的人物,剧情需要。 3,...

  • 画符

    天空对大地放电 暴雨放低了它的泪点 一路穿越山峦 吃的是烛光晚宴 今夜,我终于来到了歙县 没有胡先生的歙县 文气萎...

  • 画符

    周末,连襟老大给孙子摆满月酒。大姨姐早早打来电话,让回去给帮忙。受宠若惊并满口答应之下,问具体什么分工。“记账”...

  • 画符

    画符 作者:散人 有一个大户人家,五短身材,又有钱,又情人多。其中一个情人生了一个儿子,一岁时突乱到夜里就哭啼,找...

  • 《画符》

    以前练符,将骰子符画了放在身上,不可告诉他人。之后叫对方掷骰子,这样你叫多少点数,对方也就掷出同样点数,神奇呀! ...

网友评论

      本文标题:Unity3D-阴阳师画符

      本文链接:https://www.haomeiwen.com/subject/zknawftx.html