玲珑杯Unity开发心得——欢迎界面淡出并且转场景



///////////2015/08/04///////////

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

///////////环境 unity4.6///////

直接贴代码了,挂在给主摄像机就好了,其中有个class类直接放在文件夹就好;

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;
            }

welcome、、

var renderOverlay : DisplayTextureFullScreen;

function Start() {

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

function Update () {

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

 else     {
        Application.LoadLevel("first");//我想说,我好聪明,这样实现了场景的切换;;;哇哦
    }

}

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;
        }
    }
}

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

时间: 2024-10-07 22:29:10

玲珑杯Unity开发心得——欢迎界面淡出并且转场景的相关文章

玲珑杯Unity开发心得——进度条界面(异步加载游戏场景)

/////////////2015/08/04////////////// ////////////by xbw//////////////////// ///////////环境 unity 4.6////////// 先上效果图 还可以吧,先贴一下代码, using UnityEngine; using System.Collections; public class Loading4 : MonoBehaviour { public Texture2D load_write; //进度条底

玲珑杯Unity开发心得——开始菜单GUI制作

///////////////2015/08/04////////////// //////////////by xbw///////////////////// /////////////环境  unity 4.6////////// 先看一下效果图 不错吧,,, 来代码 using UnityEngine; using System.Collections; [RequireComponent(typeof(AudioSource))] public class MainMenuGUI :

玲珑杯Unity开发心得——游戏中暂停及积分显示GUI

//////////////////2015/08/04////////////// /////////////////by xbw//////////////////// ////////////////环境  unity 4.6///////// 先看一下效果图, 来两段代码 using UnityEngine; using System.Collections; public class jifencontrol: MonoBehaviour { //This script handles

Unity 开发心得(1)

C#与JS用于unity开发的区别: C#中定义函数必须声明函数类型(void等),但是JS中可以未知函数类型直接定义(function) 注意 C#脚本在Rect前有个new JS脚本没有. 例:在unity中创建GUI控件 在unity中使用脚本都需要绑定游戏对象.例如GUI需要绑定在camera对象中才能在Game界面中显示出来.具体的操作是,选中游戏对象(例如camera),点击右边Inspector中的"Add Component"并选择需要绑定的脚本. C#脚本: void

玲珑杯Uinty开发心得——安卓平台发布

///////////2015/08/04/////////// ///////////by xbw///////////////// ///////////环境 unity4.6/////// 有些日子没写了,想的是把这个玲珑杯的工程昨晚再整理呢,今天终于结束了,先想到哪写哪吧:: 先说说最终的安卓版环境配置,这个关于配置网上有很多介绍了,我在这里说一下细节吧, 配置好了在switch platform时总会出现一些错误,可能是js脚本的问题,等等,总会有一些报错,但是查找资料后发现了一个好东

Unity开发实战探讨-资源的加载释放最佳策略简要心得

Unity开发实战探讨-资源的加载释放最佳策略简要心得 看过我另外一篇关于Unity资源释放随笔<Unity开发实战探讨-资源的加载释放最佳策略>如果觉得略微复杂,那么下面是一些比较简要的心得体会: 概括 常用资源加载的方法有三种:静态,Resources内部资源,AssetBundle外部资源 资源释放的方式 有二种:立刻释放和统一释放. 静态 静态就是资源直接放场景,静态资源无法立刻释放,但场景关闭由引擎统一释放,开发者无法干预,所以最为无脑. 但静态过于死板,除了整个场景生命周期中必须使

unity 开发入门

---恢复内容开始--- 使用Unity开发一个打飞机的初级入门小游戏. 实现功能: 一.界面UI:3个界面:1开始界面,2游戏界面,3解释界面. 1.开始界面: 主要代码: using UnityEngine;using System.Collections; public class projectile : MonoBehaviour { private Transform m_projectile; private Rigidbody goprojectile; void Start (

AEAI Portlet开发心得

1 背景概述 Portlet是AEAI Portal组件API,是基于Java的Web组件,由Portlet容器管理,并由容器处理请求,生产动态内容.AEAI Portal中已经预置了许多Portlet组件,可以直接配置使用.由于不同业务需求也可以将Portlet进行定制开发.本文是本人在中建投项目中由于业务需要动态显示风险统计信息,即对某一风险进行评估时引用不同的风险点对其的影响(可能性与影响程度的乘积)进行分析,并在页面以个数的形式显示不同区间所包含风险点的影响.故而对Portlet的定制开

安卓版App开发心得

从2016年4月到6月主要做的工作是网站的开发,而6月到现在2016年8月初,主要做的工作是Android和IOS两种App的开发,又以Android为主. 将这段时间的Android开发心得记录如下. 1.开发环境和参考资料 由于学会FQ的时间比较短(2016年7月才学会),现在在用的mac版AndroidStudio是在国内某站上下载的.今年将开发环境由windows转为mac了,好在各种IDE都是跨平台的,迁过来后麻烦不多,Android Studio也贴心地支持Eclipse风格快捷键,