unity 3D游戏开场画面隐退实现

原创 2015年07月07日 14:20:25

//////////////2015/07/07//////////

/////////////by xbw/////////////////

////////////环境 unity 4.6.1////


今天实现了游戏欢迎界面的制作,先上效果图,

想必大家都玩过游戏,经过一个欢迎界面后会进入游戏,这就是我们今天要实现的;

、、、、、

这个我把他新建了一个场景,可以不用新建场景,直接把代码挂载到主摄像机上,下面直接上代码吧;

用的Java语言;

welcome代码

var renderOverlay : DisplayTextureFullScreen;


function Start() {

    renderOverlay = GetComponent(DisplayTextureFullScreen);
    renderOverlay.setStartColor(Color.white);
    renderOverlay.setDelay(2.0);
}

function Update () {

    if (renderOverlay.GUIColor.a > 0) {
        renderOverlay.AlphaDown(Time.deltaTime);
    } 
}



DisplayTextureFullScreen代码

var graphic = TextureGUI(); //(28,23);
var GUIColor:Color;

function OnGUI() {
    GUI.color = GUIColor;
    if (graphic.texture) {
        GUI.DrawTexture(Rect(graphic.offset.x,graphic.offset.y,
						Screen.width,Screen.height),
						graphic.texture,ScaleMode.StretchToFill,true);
    }
}

function AlphaUp(change:float) {
    GUIColor.a += change;
}

    function setStartColor(color:Color) {
        GUIColor = color;
    }


        function setDelay(delay:float) {
            if (GUIColor.a > .5) {
                GUIColor.a += delay;
            } else {
                GUIColor.a -= delay;
            }
        }

            function AlphaDown(change:float) {
                GUIColor.a -= change;
            }



这两个代码需要一个类库,

class类;

import System.Collections.Generic;


// TextureGUI Class: create a basic class for creating and placing GUI elements
// texture = the texture to display
// offset = pixel offset from top left corner, can be modified for easy positioning

class TextureGUI {
    var texture:Texture; //useful: texture.width, texture.height
    var offset:Vector2; // .x and .y
    private var originalOffset:Vector2; //store the original to correctly reset anchor point
	enum Point { TopLeft, TopRight, BottomLeft, BottomRight, Center} //what part of texture to position around?
	
    var anchorPoint = Point.TopLeft; // Unity default is from top left corner of texture
		
    function setAnchor() { // meant to be run ONCE at Start.
        originalOffset = offset;
        if (texture) { // check for null texture
            switch(anchorPoint) { //depending on where we want to center our offsets
                case anchorPoint.TopLeft: // Unity default, do nothing
                    break;
                case anchorPoint.TopRight: // Take the offset and go to the top right corner
                    offset.x = originalOffset.x - texture.width;
                    break;
					
                case anchorPoint.BottomLeft: // bottom left corner of texture
                    offset.y = originalOffset.y - texture.height;
                    break;
					
                case anchorPoint.BottomRight: //bottom right corner of texture
                    offset.x = originalOffset.x - texture.width;
                    offset.y = originalOffset.y - texture.height;
                    break;
					
                case anchorPoint.Center: //and the center of the texture (useful for screen center textures)
                    offset.x = originalOffset.x - texture.width/2;
                    offset.y = originalOffset.y - texture.height/2;
                    break;
            }
        }
    }	
}

//Timer Class:
	
	
class TimerGUI extends TextureGUI { // Extend functionality from TextureGUI for a depreciating timer graphic
    var textureLEnd:Texture; // left side of full texture (non stretching part)
    var offsetLEnd:Vector2; // left side of full texture (non stretching part) start position
    var textureCenter:Texture; // center of timer (will be stretched across width)
    var offsetCenter:Vector2; 
    var textureREnd:Texture;
    var offsetREnd:Vector2;
    var timerPerct:float = 1; // percentage (0 to 1) this stretches the center
    var desiredWidth:float = 403; // max width of the timer in pixels
	
    function setTime(newTime:float) {
        timerPerct = newTime; // sets the percent based on value
    }
    }

    // SwitchGUI Class: Extends the TextureGUI to be able to load in multiple textures and switch between them
class SwitchGUI extends TextureGUI {
    var switchableTextures = new List.<Texture>();
    var currentTexture:int = 0;
    function Start() {
        if (switchableTextures.Count > 0) {
            texture = switchableTextures[currentTexture];
        }
    }
    function changeTexture(switchTo:int) {
        if (switchTo < switchableTextures.Count && switchTo >= 0) {
            texture = switchableTextures[switchTo];
            currentTexture = switchTo;
        } else {
            //Debug.Log( this + ": tried to call invalid part of switchTextures array!");
        }
    }
	
        function up() {
            if ((currentTexture+1) < switchableTextures.Count) {
                ++currentTexture;
                texture = switchableTextures[currentTexture];
            } else {
                //Debug.Log( this + ": at the top!");
            }
        }
	
        function nextTexture() {
            if ((currentTexture+1) < switchableTextures.Count) { // if we are at the end of the array
                ++currentTexture;
                texture = switchableTextures[currentTexture];
            } else {// loop to the beginning
                currentTexture = 0;
                texture = switchableTextures[currentTexture];
            }
        }
	
        function down() {
            if ((currentTexture-1) >= 0) {
                --currentTexture;
                texture = switchableTextures[currentTexture];
            } else {
                //Debug.Log( this + ": at the bottom!");
            }
        }

    }

    // Location class: 


class Location {
	enum Point { TopLeft, TopRight, BottomLeft, BottomRight, Center}
	
    var pointLocation = Point.TopLeft;
    var offset:Vector2;
	
		
    function updateLocation() {
        switch(pointLocation) {
            case pointLocation.TopLeft:
                offset = Vector2(0,0);
                break;
            case pointLocation.TopRight:
                offset = Vector2(Screen.width,0);
                break;
				
            case pointLocation.BottomLeft:
                offset = Vector2(0,Screen.height);
                break;
				
            case pointLocation.BottomRight:
                offset = Vector2(Screen.width,Screen.height);
                break;
				
            case pointLocation.Center:
                offset = Vector2(Screen.width/2,Screen.height/2);
                break;
        }		
    }
}

class TextureAnchor {
	enum Point { TopLeft, TopRight, BottomLeft, BottomRight, Center}
	
    var anchorPoint = Point.TopLeft;
    var offset:Vector2;
	
    function update() {
        switch(anchorPoint) {
            case anchorPoint.TopLeft:
                offset = Vector2(0,0);
                break;
            case anchorPoint.TopRight:
                offset = Vector2(Screen.width,0);
                break;
				
            case anchorPoint.BottomLeft:
                offset = Vector2(0,Screen.height);
                break;
				
            case anchorPoint.BottomRight:
                offset = Vector2(Screen.width,Screen.height);
                break;
				
            case anchorPoint.Center:
                offset = Vector2(Screen.width/2,Screen.height/2);
                break;
        }		
    }
}



class类不需要挂载,两外两个代码挂载到主摄像机,

红色圈中为需要设置的贴图,即欢迎图片;;;,

试一下效果吧;;;

这是在同一个场景中的,我见了两个场景,这就需要场景转换了,

下节介绍,,欢迎同学互相学习交流,


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

unity项目去除unity开始动画和发布设置

Unity 工程发布设置,主要有去除官方开始动画,窗口拖动,分辨率,图标等内容。...

unity 3D游戏开始界面GUI美化

////////////////2015/07/07//////////// ///////////////by xbw/////////////////// //////////////环境 u...
  • xbw12138
  • xbw12138
  • 2015年07月07日 23:29
  • 23903

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

Ugui游戏开始界面 设置界面弹出

using UnityEngine; using System.Collections; using UnityEngine.UI; public class gamestart01 : MonoB...

unity3d学习笔记(十五)--利用Loading界面异步过渡游戏场景

前一篇文章介绍了游戏开始场景的制作,可还没有任何交互,按理说,我的设计是点击界面然后直接到游戏场景,但看到了雨松的这篇文章--Unity3D研究院之异步加载游戏场景与异步加载游戏资源进度条后,决定尝试...
  • lzhq1982
  • lzhq1982
  • 2013年10月22日 16:07
  • 18363

【Unity Shaders】游戏性和画面特效——创建一个老电影式的画面特效

本系列主要参考《Unity Shaders and Effects Cookbook》一书(感谢原书作者),同时会加上一点个人理解或拓展。这里是本书所有的插图。这里是本书所需的代码和资源(当然你也可以...

游戏开场镜头拉近(Unity3D开发之四)

猴子原创,欢迎转载。转载请注明: 转载自Cocos2D开发网–Cocos2Dev.com,谢谢!原文地址: http://www.cocos2dev.com/?p=553今天看了个Demo,发现它的游...

Unity_2D游戏实例从零讲起(2)——手游开场动画的实现

一个酷炫的开场动画多多少少可以让游戏高大上起来(对于外行来说…)不管怎么说,我们发现基本上任何一款游戏都有自己独特的开场动画用来显示自己的品牌logo。所以 接着我们上次教程,开始和大家分享如何制作出...

Unity3D 游戏画面像素与单位关系,简介。

1.游戏画面像素-》Unity3D单位(Unit) 可以看到屏幕中,正交相机的视口高度,刚好可以填满一个单位的cube,注意2点 1.图中cube 的缩放xyz设置的都是1,这样cub...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:unity 3D游戏开场画面隐退实现
举报原因:
原因补充:

(最多只允许输入30个字)