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 3D游戏开始界面GUI美化

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

【Unity】Unity中开场动画设置

using System.Collections; public class Test: MonoBehaviour { // 电影纹理 public MovieTexture movTex...
  • sinat_20559947
  • sinat_20559947
  • 2015年07月16日 09:52
  • 3604

【Unity3D】公告栏与开始界面的布置

开始界面是一个游戏最常见的元素,作品或大或少都会有这些东西。下面里面4.6之后Unity3D自带的UGUI,实现一个公告栏和开始界面,以此说明Unity3D中是怎么布置游戏UI的。如下图所示,开始游戏...
  • yongh701
  • yongh701
  • 2017年04月14日 11:06
  • 2173

【Unity3D入门教程】Unity3D界面介绍及游戏对象基本操作

本文介绍了Unity3D界面及游戏对象基本操作。
  • zzlyw
  • zzlyw
  • 2017年01月06日 17:16
  • 7706

【Unity3D】场景切换、UGUI组件事件、开始游戏与关闭游戏

在《【Unity3D】公告栏与开始界面的布置》(点击打开链接)我曾经简单地提到UGUI是怎么布置与使用的,但这根本不完整,就像单身狗缺个另一半永远只能被喂狗粮似的,组件也因为事件的存在才能够精彩。因此...
  • yongh701
  • yongh701
  • 2017年04月15日 11:27
  • 3525

unity3d界面设计教程

  • 2013年12月12日 15:56
  • 1.19MB
  • 下载

Unity3D——异步加载游戏场景loading界面的开发!

最近在开始研究整个项目的开发!毕竟
  • lmzqm
  • lmzqm
  • 2014年06月18日 11:02
  • 4193

【Unity3D】场景切换、UGUI组件事件、开始游戏与关闭游戏

在《【Unity3D】公告栏与开始界面的布置》(点击打开链接)我曾经简单地提到UGUI是怎么布置与使用的,但这根本不完整,就像单身狗缺个另一半永远只能被喂狗粮似的,组件也因为事件的存在才能够精彩。因此...
  • yongh701
  • yongh701
  • 2017年04月15日 11:27
  • 3525

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

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

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

猴子原创,欢迎转载。转载请注明: 转载自Cocos2D开发网–Cocos2Dev.com,谢谢!原文地址: http://www.cocos2dev.com/?p=553今天看了个Demo,发现它的游...
  • yanghuiliu
  • yanghuiliu
  • 2014年06月01日 23:45
  • 4017
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:unity 3D游戏开场画面隐退实现
举报原因:
原因补充:

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