GUISkin

Форум для самых маленьких, а так же тех, кому недосуг читать справку самостоятельно.

GUISkin

Сообщение dronik911 17 окт 2012, 14:27

Добрый вечер, использую готовый проект, в гуискин стоит картинка "Window" и актив и прочие, но никак не отображается на экране, в чем может быть проблема?
dronik911
UNIт
 
Сообщения: 81
Зарегистрирован: 19 фев 2012, 11:48

Re: GUISkin

Сообщение trololoid 17 окт 2012, 16:18

С чего начнём?
С показа кода, которым ты выводишь окно.
Аватара пользователя
trololoid
Старожил
 
Сообщения: 712
Зарегистрирован: 15 сен 2011, 19:18
Откуда: Туапсе, Краснодарский край, Россия

Re: GUISkin

Сообщение dronik911 17 окт 2012, 17:51

Синтаксис:
Используется javascript
#pragma strict

@script AddComponentMenu("Shooter Engine/GUI/Pause Menu")

enum Page {
        None,
        Main,
        LoadLevels,
        Options,
        Credits
}

var isMainMenu : boolean = false;

private var currentPage : Page;
private var gameStatus : GameStatus;
private var player : Player;
private var pauseEffect : MonoBehaviour;
private var savedTimeScale : float;
private var toolbarInt : int = 0;
private var toolbarStrings : String[] = ["Audio", "Graphics", "Game", "System"];
private var scrollPosition : Vector2;
private var hideScripts : HideGuiWhenPaused[];
private var ingameMenu : boolean = false;
private var wasLocked : boolean = false;
private var levelName : boolean = false;

function Start () {
        Time.timeScale = 1.0;
       
        if (Screen.fullScreen)
                GameStatus.fullscreenMode = true;
        GameStatus.savedRes.width = Screen.width;
        GameStatus.savedRes.height = Screen.height;
        gameStatus = FindObjectOfType(GameStatus);
        player = FindObjectOfType(Player);
        scrollPosition = Vector2(gameStatus.mainMenu.menuWidth, gameStatus.mainMenu.menuHeight * 0.5);
       
        if (isMainMenu)
                PauseGame();
        else
                Screen.lockCursor = true;
               
        ShowLevelName();
}

function LateUpdate () {
        if (Input.GetKeyDown("escape")) {
                switch (currentPage) {
                        case Page.None:
                                PauseGame();
                                break;
                               
                        case Page.Main:
                                if (!isMainMenu)
                                        UnPauseGame();
                                break;
                               
                        default:
                                currentPage = Page.Main;
                }
        }
       
        if (Input.GetMouseButton (0) && !IsGamePaused())
                Screen.lockCursor = true;
               
        if (!Screen.lockCursor && wasLocked) {
                if (!IsGamePaused())
                        PauseGame();
                wasLocked = false;
        } else if (Screen.lockCursor && !wasLocked) {
                if (IsGamePaused())
                        UnPauseGame();
                wasLocked = true;
        }
}

function OnGUI () {
        if (gameStatus.mainMenu.guiSkin != null)
                GUI.skin = gameStatus.mainMenu.guiSkin;
        GUI.color = gameStatus.mainMenu.guiColor;
       
        if (isMainMenu) {
                GUI.Label (Rect(0, Screen.height * 0.05, Screen.width, Screen.height * 0.1), gameStatus.mainMenu.gameTitle, gameStatus.mainMenu.titlesGuiStyle);
        } else if (IsGamePaused()) {
                if (pauseEffect == null && gameStatus.mainMenu.alternateBackground != null) {
                        var backgroundStyle : GUIStyle = new GUIStyle();
                        backgroundStyle.normal.background = gameStatus.mainMenu.alternateBackground;
                        GUI.Label (Rect(0, 0, Screen.width, Screen.height), "", backgroundStyle);
                }
               
                GUI.Label (Rect(0, Screen.height * 0.05, Screen.width, Screen.height * 0.1), "Paused", gameStatus.mainMenu.titlesGuiStyle);
        } else {
                if (ingameMenu)
                        ShowInGameMenu();
                       
                if (levelName)
                        GUI.Label (Rect(0, Screen.height - Screen.height * 0.1, Screen.width, Screen.height * 0.1), GameStatus.currentLevelName, gameStatus.mainMenu.textGuiStyle);
        }
       
        if (IsGamePaused() && !GameStatus.isLoading) {
                switch (currentPage) {
                        case Page.Main:
                                PauseMenu();
                                break;
                               
                        case Page.LoadLevels:
                                ShowLevels();
                                break;
                               
                        case Page.Options:
                                ShowToolbar();
                                break;
                               
                        case Page.Credits:
                                ShowCredits();
                                break;
                }
        }
       
        ShowLegal();
}

function PauseMenu () {
        BeginPage(gameStatus.mainMenu.menuWidth * 0.75, gameStatus.mainMenu.menuHeight);
       
        GUILayout.BeginVertical ();
        GUILayout.FlexibleSpace();
       
        if (GUILayout.Button (isMainMenu ? "New Game" : "Continue")) {
                UnPauseGame();
                if (isMainMenu)
                        gameStatus.LoadLevelWithProgress(gameStatus.levels[0].level, gameStatus.levels[0].loadFadeTexture);
        }
       
        if (/*IsBrowser() && */!isMainMenu && GUILayout.Button ("Restart Level")) {
                UnPauseGame();
//              Application.OpenURL(restartUrl);
//              Application.LoadLevel(Application.loadedLevel);
                if (gameStatus.currTexture != null)
                        LevelLoadFade.FadeAndLoadLevel(Application.loadedLevelName, gameStatus.currTexture, gameStatus.mainMenu.fadeTime);
                else
                        LevelLoadFade.FadeAndLoadLevel(Application.loadedLevelName, gameStatus.mainMenu.fadeColor, gameStatus.mainMenu.fadeTime);
        }
       
        if (gameStatus.levels.Length > 1 && gameStatus.levels[0].levelDone && GUILayout.Button ("Load Game")) {
                currentPage = Page.LoadLevels;
        }
       
        if (!isMainMenu && GUILayout.Button ("Main Menu")) {
                UnPauseGame();
                gameStatus.ResetGame();
//              Application.LoadLevel(gameStatus.mainMenuLevel);
                if (gameStatus.mainMenu.fadeTexture != null)
                        LevelLoadFade.FadeAndLoadLevel(gameStatus.mainMenuLevel, gameStatus.mainMenu.fadeTexture, gameStatus.mainMenu.fadeTime);
                else
                        LevelLoadFade.FadeAndLoadLevel(gameStatus.mainMenuLevel, gameStatus.mainMenu.fadeColor, gameStatus.mainMenu.fadeTime);
        }
       
        if (GUILayout.Button ("Options")) {
                currentPage = Page.Options;
        }
       
        if (GUILayout.Button ("Credits")) {
                currentPage = Page.Credits;
        }
       
        if (!IsBrowser() && GUILayout.Button ("Quit")) {
                Application.Quit();
        }
       
        GUILayout.FlexibleSpace();
        GUILayout.EndVertical();
       
        EndPage();
}

function InGameMenu () {
        ingameMenu = (player != null && player.gameObject.active) ? !ingameMenu : false;
}

function ShowInGameMenu () {
        if (player == null || !player.gameObject.active)
                return;
               
        GUILayout.BeginArea(Rect((Screen.width - gameStatus.ingameMenu.ingameWidth) * 0.5, Screen.height * 0.05, gameStatus.ingameMenu.ingameWidth, gameStatus.ingameMenu.ingameHeight), "", gameStatus.ingameMenu.backGuiStyle);
       
        GUILayout.BeginVertical ();
        GUILayout.FlexibleSpace();
       
        GUILayout.BeginHorizontal();
       
        GUILayout.BeginVertical ();
        GUILayout.Label ("Player controls:");
        GUILayout.BeginHorizontal();
       
        if (player.tpsCam != null) {
                if (player.tpsCam.startThirdPerson && GUILayout.Button (GUIContent(gameStatus.ingameMenu.fpsView), gameStatus.ingameMenu.buttonsGuiStyle))
                        player.tpsCam.startThirdPerson = false;
                else if (!player.tpsCam.startThirdPerson && GUILayout.Button(GUIContent(gameStatus.ingameMenu.tpsView), gameStatus.ingameMenu.buttonsGuiStyle))
                        player.tpsCam.startThirdPerson = true;
        }
       
        if ((player.tpsCam != null ? !player.tpsCam.downSight : !player.fpsCam.downSight) && GUILayout.Button (GUIContent(gameStatus.ingameMenu.inSight), gameStatus.ingameMenu.buttonsGuiStyle)) {
                if (player.tpsCam != null)
                        player.tpsCam.downSight = true;
                else
                        player.fpsCam.downsight = true;
        } else if ((player.tpsCam != null ? player.tpsCam.downSight : player.fpsCam.downSight) && GUILayout.Button(GUIContent(gameStatus.ingameMenu.outOfSight), gameStatus.ingameMenu.buttonsGuiStyle)) {
                if (player.tpsCam != null)
                        player.tpsCam.downSight = false;
                else
                        player.fpsCam.downsight = false;
        }
       
        if ((player.tpsAnim != null ? !player.tpsAnim.crouch : !player.fpsAnim.crouch) && GUILayout.Button (GUIContent(gameStatus.ingameMenu.crouched), gameStatus.ingameMenu.buttonsGuiStyle)) {
                if (player.tpsAnim != null)
                        player.tpsAnim.Crouch();
                else
                        player.fpsAnim.Crouch();
        } else if ((player.tpsAnim != null ? player.tpsAnim.crouch : player.fpsAnim.crouch) && GUILayout.Button(GUIContent(gameStatus.ingameMenu.standing), gameStatus.ingameMenu.buttonsGuiStyle)) {
                if (player.tpsAnim != null)
                        player.tpsAnim.Crouch();
                else
                        player.fpsAnim.Crouch();
        }
       
        GUILayout.EndHorizontal();
        GUILayout.EndVertical();
       
        GUILayout.FlexibleSpace();
       
        if (player.weapons[0].hasWeapon || player.currentWeapon != 0) {
       
                GUILayout.BeginVertical ();
                GUILayout.Label ("Weapon controls:");
                GUILayout.BeginHorizontal();
               
                if (player.weapons[player.currentWeapon].weapon.switchModes) {
                        if (player.weapons[player.currentWeapon].weapon.burstMode == BurstMode.Auto && GUILayout.Button (GUIContent(gameStatus.ingameMenu.singleFireMode), gameStatus.ingameMenu.buttonsGuiStyle))
                                player.weapons[player.currentWeapon].weapon.burstMode = BurstMode.Single;
                        else if (player.weapons[player.currentWeapon].weapon.burstMode == BurstMode.Single && GUILayout.Button(GUIContent(gameStatus.ingameMenu.burstFireMode), gameStatus.ingameMenu.buttonsGuiStyle))
                                player.weapons[player.currentWeapon].weapon.burstMode = BurstMode.Burst;
                        else if (player.weapons[player.currentWeapon].weapon.burstMode == BurstMode.Burst && GUILayout.Button(GUIContent(gameStatus.ingameMenu.autoFireMode), gameStatus.ingameMenu.buttonsGuiStyle))
                                player.weapons[player.currentWeapon].weapon.burstMode = BurstMode.Auto;
                }
               
                if (!player.primary && GUILayout.Button (GUIContent(gameStatus.ingameMenu.privaryMode), gameStatus.ingameMenu.buttonsGuiStyle)) {
                        for (var switchWeapon : SwitchWeapons in player.switchWeapons) {
                                if (switchWeapon.primaryIndex == player.currentWeapon || switchWeapon.secondaryIndex == player.currentWeapon)
                                        switchWeapon.SwitchWeapon();
                        }
                } else if (player.primary && GUILayout.Button(GUIContent(gameStatus.ingameMenu.secondaryMode), gameStatus.ingameMenu.buttonsGuiStyle)) {
                        for (var switchWeapon : SwitchWeapons in player.switchWeapons) {
                                if (switchWeapon.primaryIndex == player.currentWeapon || switchWeapon.secondaryIndex == player.currentWeapon)
                                        switchWeapon.SwitchWeapon();
                        }
                }
               
                if (GUILayout.Button(GUIContent(gameStatus.ingameMenu.previousWeapon), gameStatus.ingameMenu.buttonsGuiStyle))
                        PlayerWeapons.PreviousWeapon();
                if (GUILayout.Button (GUIContent(gameStatus.ingameMenu.nextWeapon), gameStatus.ingameMenu.buttonsGuiStyle))
                        PlayerWeapons.NextWeapon();
                       
                if (GUILayout.Button(GUIContent(gameStatus.ingameMenu.dropWeapon), gameStatus.ingameMenu.buttonsGuiStyle))
                        player.Drop(player.currentWeapon, true);
                       
                GUILayout.EndHorizontal();
                GUILayout.EndVertical();
        }
       
        GUILayout.EndHorizontal();
       
        GUILayout.BeginHorizontal();
       
        GUILayout.Label ("Go to pause menu:");
        GUILayout.FlexibleSpace();
        if (GUILayout.Button(GUIContent(gameStatus.ingameMenu.pauseMenu), gameStatus.ingameMenu.buttonsGuiStyle)) {
                ingameMenu = false;
                PauseGame();
        }
       
        GUILayout.EndHorizontal();
       
        GUILayout.FlexibleSpace();
        GUILayout.EndVertical();
       
        GUILayout.EndArea();
}

function PauseGame () {
        savedTimeScale = Time.timeScale;
        Screen.lockCursor = false;
        currentPage = Page.Main;
        if (!isMainMenu) {
                Time.timeScale = 0.0;
                AudioListener.pause = true;
                pauseEffect = Camera.main.GetComponent(GameStatus.pauseEffect) as MonoBehaviour;
                if (pauseEffect != null)
                        pauseEffect.enabled = true;
                hideScripts = FindObjectsOfType(HideGuiWhenPaused) as HideGuiWhenPaused[];
                for (var hideScript : HideGuiWhenPaused in hideScripts)
                        hideScript.DidPause(true);
        }
}

function UnPauseGame () {
        if (GameStatus.fullscreenMode)
                Screen.SetResolution(GameStatus.savedRes.width, GameStatus.savedRes.height, true);
        currentPage = Page.None;
       
        if (!isMainMenu) {
//              Time.timeScale = savedTimeScale;
                Time.timeScale = 1.0;
                Screen.lockCursor = true;
                AudioListener.pause = false;
                pauseEffect = Camera.main.GetComponent(GameStatus.pauseEffect) as MonoBehaviour;
                if (pauseEffect != null)
                        pauseEffect.enabled = false;
                hideScripts = FindObjectsOfType(HideGuiWhenPaused) as HideGuiWhenPaused[];
                for (var hideScript : HideGuiWhenPaused in hideScripts)
                        hideScript.DidPause(false);
                       
                PlayerPrefs.SetFloat("mouseSensitivityX", GameStatus.mouseSensitivityX);
                PlayerPrefs.SetFloat("mouseSensitivityY", GameStatus.mouseSensitivityY);
        }
}

function BeginPage (width : float, height : float) {
        GUILayout.BeginArea(Rect((Screen.width - width) * 0.01, (Screen.height - height) * 0.01, width, height), "", gameStatus.mainMenu.backGuiStyle);
}

function ShowBackButton () {
        if (GUILayout.Button ("Back")) {
                currentPage = Page.Main;
        }
}

function EndPage () {
        if (currentPage != Page.Main) {
                ShowBackButton();
        }
       
        GUILayout.EndArea();
}

function ShowLevels () {
        BeginPage(gameStatus.mainMenu.menuWidth, gameStatus.mainMenu.menuHeight);
       
        GUILayout.Box ("Select level to load:");
       
        var i : int;
        var currLevel : int = 0;
        for (i=0; i<gameStatus.levels.Length-1; i++) {
                if (gameStatus.levels[i].levelDone)
                        currLevel = i+1;
        }
       
        if (currLevel >1 && !gameStatus.levels[currLevel].levelDone)
                ShowHorizontal(currLevel, "Load current", 120);
               
        scrollPosition = GUILayout.BeginScrollView (scrollPosition);
       
        for (i=0; i<gameStatus.levels.Length-1; i++) {
                if (gameStatus.levels[i].levelDone)
                        ShowHorizontal(i+1, "Load", 60);
        }
       
        GUILayout.EndScrollView ();
       
        EndPage();
}

function ShowHorizontal (index : int, text : String, buttonWidth : int) {
        GUILayout.BeginHorizontal("box");
        if (gameStatus.levels[index].levelThumbnail != null)
                GUILayout.Label (gameStatus.levels[index].levelThumbnail);
        if (gameStatus.levels[index].levelDescription != "")
                GUILayout.Label (gameStatus.levels[index].levelDescription);
        else
                GUILayout.Label (gameStatus.levels[index].level);
        if (GUILayout.Button(text, GUILayout.Width(buttonWidth))) {
                UnPauseGame();
                gameStatus.LoadLevelWithProgress(gameStatus.levels[index].level, gameStatus.levels[index].loadFadeTexture);
        }
        GUILayout.EndHorizontal();
}

function ShowToolbar () {
        BeginPage(gameStatus.mainMenu.menuWidth, gameStatus.mainMenu.menuHeight);
        toolbarInt = GUILayout.Toolbar (toolbarInt, toolbarStrings);
       
        switch (toolbarInt) {
                case 0:
                        VolumeControl();
                        break;
                       
                case 1:
                        Qualities();
                        QualityControl();
                        break;
                       
                case 2:
                        GameSettings();
                        break;
                       
                case 3:
                        ShowDevice();
                        break;
        }
       
        EndPage();
}

function VolumeControl () {
        GUILayout.Label ("Volume: "+AudioListener.volume.ToString("f1"));
        AudioListener.volume = GUILayout.HorizontalSlider (AudioListener.volume, 0.0, 1.0);
}

function Qualities () {
        var resolutions : Resolution[] = Screen.resolutions;
        if (resolutions.length > 1 || Application.isEditor) {
                if (!Screen.fullScreen)
                        GUILayout.Label ("Select fullscreen resolution:");
                else
                        GUILayout.Label ("Select resolution:");
                       
                scrollPosition = GUILayout.BeginScrollView (scrollPosition);
               
                for (var res in resolutions) {
                        if (GUILayout.Button (res.width+"x"+res.height)) {
                                if (Screen.fullScreen || IsBrowser()) {
                                        Screen.SetResolution (res.width, res.height, true);
                                        GameStatus.fullscreenMode = true;
                                } else {
                                        Screen.SetResolution (res.width, res.height, false);
                                        GameStatus.fullscreenMode = false;
                                }
                                GameStatus.savedRes = res;
                        }
                }
               
                GUILayout.EndScrollView ();
               
                if (Screen.fullScreen || GameStatus.fullscreenMode) {
                        GUILayout.Label ("Fullscreen mode: "+GameStatus.savedRes.width+"x"+GameStatus.savedRes.height);
                        if (GUILayout.Button ("Exit fullscreen mode")) {
                                GameStatus.fullscreenMode = false;
                                if (Screen.fullScreen)
                                        Screen.fullScreen = false;
                        }
                } else {
                        GUILayout.Label("Window mode: "+Screen.width+"x"+Screen.height);
                        if (!IsBrowser() && GUILayout.Button("Switch to fullscreen mode")) {
                                GameStatus.fullscreenMode = true;
                                Screen.SetResolution (GameStatus.savedRes.width, GameStatus.savedRes.height, true);
                        }
                }
        }
       
        switch (QualitySettings.currentLevel) {
                case QualityLevel.Fastest:
                        GUILayout.Label("Quality: Fastest");
                        break;
                       
                case QualityLevel.Fast:
                        GUILayout.Label("Quality: Fast");
                        break;
                       
                case QualityLevel.Simple:
                        GUILayout.Label("Quality: Simple");
                        break;
                       
                case QualityLevel.Good:
                        GUILayout.Label("Quality: Good");
                        break;
                       
                case QualityLevel.Beautiful:
                        GUILayout.Label("Quality: Beautiful");
                        break;
                       
                case QualityLevel.Fantastic:
                        GUILayout.Label("Quality: Fantastic");
                        break;
        }
}

function QualityControl () {
        GUILayout.BeginHorizontal();
       
        if (GUILayout.Button("Decrease")) {
                QualitySettings.DecreaseLevel();
        }
       
        if (GUILayout.Button("Increase")) {
                QualitySettings.IncreaseLevel();
        }
       
        GUILayout.EndHorizontal();
}

function GameSettings () {
        if (GameStatus.gameType == GameType.ThirdPerson) {
                GameStatus.combinedControls = GUILayout.Toggle(GameStatus.combinedControls, "Use combined controls for Player");
                #if !UNITY_IPHONE && !UNITY_ANDROID
                        GameStatus.scrollSelectsWeapons = GUILayout.Toggle(GameStatus.scrollSelectsWeapons, "Select weapons with mouse scroll");
                #endif
        }
        if (gameStatus.showRadarMenu) {
                GameStatus.showRadar = GUILayout.Toggle(GameStatus.showRadar, "Show Radar");
                GUILayout.Label ("Radar Map Scale: "+Radar.radarScale.ToString("f2"));
                Radar.radarScale = GUILayout.HorizontalSlider(Radar.radarScale, 0.25, 4.0);
        }
        GUILayout.Label ("Mouse Sensitivity X: "+gameStatus.mouseSensitivityX.ToString("f1"));
        gameStatus.mouseSensitivityX = GUILayout.HorizontalSlider(gameStatus.mouseSensitivityX, 1.0, 20.0);
        GUILayout.Label ("Mouse Sensitivity Y: "+gameStatus.mouseSensitivityY.ToString("f1"));
        gameStatus.mouseSensitivityY = GUILayout.HorizontalSlider(gameStatus.mouseSensitivityY, 0.5, 10.0);
        #if !UNITY_IPHONE && !UNITY_ANDROID
                GUILayout.Label ("Max number of blood projectors: "+gameStatus.maxProjectors);
                gameStatus.maxProjectors = GUILayout.HorizontalSlider (gameStatus.maxProjectors, 0, 20);
        #endif
}

function ShowDevice () {
        GUILayout.Label ("Unity player version: "+Application.unityVersion);
        GUILayout.Label ("Graphics: "+SystemInfo.graphicsDeviceName+" "+
        SystemInfo.graphicsMemorySize+"MB\n"+
        SystemInfo.graphicsDeviceVersion+"\n"+
        SystemInfo.graphicsDeviceVendor);
        GUILayout.Label ("Shadows: "+SystemInfo.supportsShadows);
        GUILayout.Label ("Image Effects: "+SystemInfo.supportsImageEffects);
        GUILayout.Label ("Render Textures: "+SystemInfo.supportsRenderTextures);
}

function ShowCredits () {
        BeginPage(gameStatus.mainMenu.menuWidth, gameStatus.mainMenu.menuHeight);
       
        GUILayout.Box ("Credits:");
        for (var credit : String in gameStatus.mainMenu.credits) {
                GUILayout.Label (credit);
        }
        GUILayout.BeginHorizontal();
        for (var credit : Texture in gameStatus.mainMenu.creditIcons) {
                GUILayout.Label (credit);
        }
        GUILayout.EndHorizontal();
       
        EndPage();
}

function ShowLegal () {
        if (!IsLegal()) {
                GUI.Label (Rect(Screen.width - 130, Screen.height - 30, 130, 30), "the3daction.com");
        }
}

function ShowLevelName () {
        yield Time.timeSinceLevelLoad > 0.0;
        while (LevelStatus.introDuration > 0.0) {
                yield;
        }
        yield WaitForSeconds(1.0);
        levelName = true;
        yield WaitForSeconds(5.0);
        levelName = false;
}

function IsGamePaused () {
        if (!isMainMenu)
                return Time.timeScale == 0.0;
               
        return true;
}

function IsLegal () {
        return !IsBrowser() ||  Application.absoluteURL.StartsWith("http://the3daction.com/");
}

static function IsDashboard () {
        return Application.platform == RuntimePlatform.OSXDashboardPlayer;
}

static function IsBrowser () {
        return (Application.platform == RuntimePlatform.WindowsWebPlayer ||
                Application.platform == RuntimePlatform.OSXWebPlayer);
}

function OnMouseDown () {
        if (!IsGamePaused())
                Screen.lockCursor = true;
}

function OnApplicationPause (pause : boolean) {
        if (IsGamePaused()) {
                AudioListener.pause = pause;
        }
}
 


Синтаксис:
Используется javascript
#pragma strict

@script AddComponentMenu("Shooter Engine/Level/Game Status")

// GameStatus: Master game state machine script.

enum GameType {
        Undefined = 0,
        FirstPerson = 1,
        ThirdPerson = 2
}

static var gameType = GameType.Undefined;
static var currentLevelName : String;
static var currLevel : String;
static var currTexture : Texture2D;
static var nextLevel : String;
static var nextTexture : Texture2D;
static var enemiesOnLevel : int = 0;
static var enemiesKilled : int = 0;
static var enemiesLeftAlive : int = 0;
static var bossesOnLevel : int = 0;
static var bossesKilled : int = 0;
static var itemsOnLevel : int = 0;
static var itemsFound : int = 0;
static var playerDeaths : int = 0;
static var timeOnLevelStart : float = 0.0;
static var levelTime : float = 0.0;
static var levelScore : int = 0;

static var totalEnemies : int = 0;
static var totalEnemiesKilled : int = 0;
static var totalEnemiesLeftAlive : int = 0;
static var totalBossesKilled : int = 0;
static var totalItems : int = 0;
static var totalItemsFound : int = 0;
static var totalPlayerDeaths : int = 0;
static var totalGameTime : float = 0.0;
static var totalScore : int = 0;

static var fullscreenMode : boolean = false;
static var savedRes : Resolution;

static var combinedControls : boolean = true;
static var scrollSelectsWeapons : boolean = true;
static var showRadar : boolean = true;
static var mouseSensitivityX : float = 4.0;
static var mouseSensitivityY : float = 1.6;
static var pauseEffect : String;
static var projectors : int = 0;
static var projectorsAllowed : boolean = true;
static var autoselectWeapon : boolean = false;
static var levelToLoad : String;
static var loadTexture : Texture2D;
static var isLoading : boolean = false;
static var fade : boolean = false;

var mainMenuLevel : String = "StartMenu";
var scoreLevel : String = "Score";
var gameOverLevel : String = "GameOver";

class Levels {
        var level : String = "Level01";
        var levelDone : boolean = false;
        var levelDescription : String = "Tiberius Station";
        var levelThumbnail : Texture;
        var loadFadeTexture : Texture2D;
}

var levels : Levels[] = new Levels[1];

class MainMenu {
        var guiSkin : GUISkin;
        var guiColor : Color = Color.white;
        var fadeColor : Color = Color.black;
        var fadeTexture : Texture2D;
        var fadeTime : float = 1.0;
        var menuWidth : float = 300.0;
        var menuHeight : float = 300.0;
        var gameTitle : String = "Unity Shooter Engine 2.2";
        var titlesGuiStyle : String = "mainMenuTitle";
        var textGuiStyle : String = "menuText";
        var backGuiStyle : String = "background";
        var loadingTextGuiStyle : String = "loadingText";
        var progressBarPrefab : GameObject;
        var pauseFilterEffect : String = "PauseMenuEffect";
        var alternateBackground : Texture2D;
        var credits : String[] = [
                "Unity Shooter Engine 2.2",
                "",
                "Controls:",
                "WASD, Arrows - move; LMB - Fire/Aim;",
                "RMB - View down iron sight/optical scope;",
                "MMB - Zoom; Space - Jump; E - Action;",
                "1 - 3 - Select weapons/Switch primary/secondary;",
                "F - Switch primary/secondary; T - Burst Mode;",
                "R - Reloading; V - Stop aiming; X - Sit/Stand;",
                "Num+ - Num- - Time control; 0 - Show FPS"];
        var creditIcons : Texture[];
       
        @System.NonSerialized var progressBar : GameObject;
        @System.NonSerialized var progressBarGUI : GUITexture;
        @System.NonSerialized var originalPixelRect : Rect;
}

var mainMenu : MainMenu = MainMenu();

class IngameMenu {
        var ingameWidth : float = 360.0;
        var ingameHeight : float = 120.0;
        var buttonsGuiStyle : String = "ingameMenu";
        var backGuiStyle : String = "background";
        var fpsView : Texture;
        var tpsView : Texture;
        var inSight : Texture;
        var outOfSight : Texture;
        var crouched : Texture;
        var standing : Texture;
        var singleFireMode : Texture;
        var burstFireMode : Texture;
        var autoFireMode : Texture;
        var privaryMode : Texture;
        var secondaryMode : Texture;
        var previousWeapon : Texture;
        var nextWeapon : Texture;
        var dropWeapon : Texture;
        var pauseMenu : Texture;
}

var ingameMenu : IngameMenu = IngameMenu();

var autoselectWeapons : boolean = false;
var showRadarMenu : boolean = false;
var maxProjectors : int = 5;

private var hitPoints : float = 0.0;
private var lives : int = 0;
private var thirdPerson : boolean = false;
private var currentWeapon : int = 0;
private var numberOfWeapons : int = 0;
private var hasWeapon : boolean[];
private var clips : int[];
private var bulletsLeft : int[];

function Awake () {
        DontDestroyOnLoad(this);
       
        if (Application.loadedLevelName == mainMenuLevel)
                ResetTotalScore();
               
        for (var i : int=0; i<levels.Length; i++) {
                if (!levels[i].levelDone)
                        levels[i].levelDone = PlayerPrefs.GetInt(levels[i].level) != 0;
        }
       
        if (mainMenu.progressBarPrefab != null) {
                mainMenu.progressBar = Instantiate(mainMenu.progressBarPrefab, Vector3(0.5, 0.5, 0), Quaternion.identity);
                mainMenu.progressBarGUI = mainMenu.progressBar.GetComponent.<GUITexture>();
                mainMenu.originalPixelRect = mainMenu.progressBarGUI.pixelInset;
                mainMenu.progressBarGUI.enabled = false;
                DontDestroyOnLoad(mainMenu.progressBar);
        }
       
        pauseEffect = mainMenu.pauseFilterEffect;
        autoselectWeapon = autoselectWeapons;
}

function Update () {
        projectorsAllowed = (projectors >= maxProjectors) ? false : true;
}

function OnGUI () {
        if (isLoading) {
                if (mainMenu.guiSkin != null)
                        GUI.skin = mainMenu.guiSkin;
                GUI.color = mainMenu.guiColor;
               
                var progressBarFraction : float = Application.GetStreamProgressForLevel(levelToLoad);
               
                if (mainMenu.progressBar != null) {
                        mainMenu.progressBarGUI.enabled = true;
                        mainMenu.progressBarGUI.pixelInset.xMax = mainMenu.originalPixelRect.xMin + progressBarFraction * mainMenu.originalPixelRect.width;
                }
                var percents : int = Mathf.RoundToInt(progressBarFraction * 100);
                GUI.Label (Rect(0, Screen.height * 0.5, Screen.width, 20), "Loaded "+percents.ToString()+"%", mainMenu.loadingTextGuiStyle);
               
                if (progressBarFraction == 1 && Application.CanStreamedLevelBeLoaded(levelToLoad)) {
                        if (mainMenu.progressBar != null)
                                mainMenu.progressBarGUI.enabled = false;
                               
//                      Application.LoadLevel(levelToLoad);
                        if (loadTexture != null)
                                LevelLoadFade.FadeAndLoadLevel(levelToLoad, loadTexture, mainMenu.fadeTime);
                        else if (mainMenu.fadeTexture != null)
                                LevelLoadFade.FadeAndLoadLevel(levelToLoad, mainMenu.fadeTexture, mainMenu.fadeTime);
                        else
                                LevelLoadFade.FadeAndLoadLevel(levelToLoad, mainMenu.fadeColor, mainMenu.fadeTime);
                               
                        isLoading = false;
                }
        }
}

@ContextMenu ("Delete All Saved Games")
function DeleteSaved () {
        var player : Player = FindObjectOfType(Player);
       
        if (PlayerPrefs.HasKey("numberOfWeapons")) PlayerPrefs.DeleteKey("numberOfWeapons");
       
        for (var i : int=0; i<levels.Length; i++) {
                if (PlayerPrefs.HasKey(levels[i].level)) PlayerPrefs.DeleteKey(levels[i].level);
                if (PlayerPrefs.HasKey(i+"totalEnemies")) PlayerPrefs.DeleteKey(i+"totalEnemies");
                if (PlayerPrefs.HasKey(i+"totalEnemiesKilled")) PlayerPrefs.DeleteKey(i+"totalEnemiesKilled");
                if (PlayerPrefs.HasKey(i+"totalEnemiesLeftAlive")) PlayerPrefs.DeleteKey(i+"totalEnemiesLeftAlive");
                if (PlayerPrefs.HasKey(i+"totalBossesKilled")) PlayerPrefs.DeleteKey(i+"totalBossesKilled");
                if (PlayerPrefs.HasKey(i+"totalItems")) PlayerPrefs.DeleteKey(i+"totalItems");
                if (PlayerPrefs.HasKey(i+"totalItemsFound")) PlayerPrefs.DeleteKey(i+"totalItemsFound");
                if (PlayerPrefs.HasKey(i+"totalPlayerDeaths")) PlayerPrefs.DeleteKey(i+"totalPlayerDeaths");
                if (PlayerPrefs.HasKey(i+"totalGameTime")) PlayerPrefs.DeleteKey(i+"totalGameTime");
                if (PlayerPrefs.HasKey(i+"totalScore")) PlayerPrefs.DeleteKey(i+"totalScore");
                if (PlayerPrefs.HasKey(i+"hitPoints")) PlayerPrefs.DeleteKey(i+"hitPoints");
                if (PlayerPrefs.HasKey(i+"lives")) PlayerPrefs.DeleteKey(i+"lives");
                if (PlayerPrefs.HasKey(i+"thirdPerson")) PlayerPrefs.DeleteKey(i+"thirdPerson");
                if (PlayerPrefs.HasKey(i+"currentWeapon")) PlayerPrefs.DeleteKey(i+"currentWeapon");
                for (var w : int=0; w<(player != null ? player.weapons.Length : 11); w++) {
                        if (PlayerPrefs.HasKey(i+"hasWeapon"+w)) PlayerPrefs.DeleteKey(i+"hasWeapon"+w);
                        if (PlayerPrefs.HasKey(i+"clips"+w)) PlayerPrefs.DeleteKey(i+"clips"+w);
                        if (PlayerPrefs.HasKey(i+"bulletsLeft"+w)) PlayerPrefs.DeleteKey(i+"bulletsLeft"+w);
                }
        }
}

function ResetScore (player : Player) {
        enemiesKilled = 0;
        enemiesLeftAlive = 0;
        bossesKilled = 0;
        itemsFound = 0;
        playerDeaths = 0;
        timeOnLevelStart = Time.time;
        levelTime = 0.0;
        levelScore = 0;
        projectors = 0;
       
        currLevel = Application.loadedLevelName;
        numberOfWeapons = (player != null) ? player.weapons.Length : PlayerPrefs.GetInt("numberOfWeapons");
       
        for (var i : int=0; i<levels.Length; i++) {
                if (levels[i].level == currLevel) {
                        currTexture = (levels[i].loadFadeTexture != null) ? levels[i].loadFadeTexture : mainMenu.fadeTexture;
                        nextLevel = (i < levels.Length-1) ? levels[i+1].level : gameOverLevel;
                        nextTexture = (i < levels.Length-1) ? levels[i+1].loadFadeTexture : mainMenu.fadeTexture;
                        Debug.Log("Current level - "+currLevel+", next level - "+nextLevel);
                        if (i != 0) {
                                totalEnemies = PlayerPrefs.GetInt(i+"totalEnemies");
                                totalEnemiesKilled = PlayerPrefs.GetInt(i+"totalEnemiesKilled");
                                totalEnemiesLeftAlive = PlayerPrefs.GetInt(i+"totalEnemiesLeftAlive");
                                totalBossesKilled = PlayerPrefs.GetInt(i+"totalBossesKilled");
                                totalItems = PlayerPrefs.GetInt(i+"totalItems");
                                totalItemsFound = PlayerPrefs.GetInt(i+"totalItemsFound");
                                totalPlayerDeaths = PlayerPrefs.GetInt(i+"totalPlayerDeaths");
                                totalGameTime = PlayerPrefs.GetFloat(i+"totalGameTime");
                                totalScore = PlayerPrefs.GetInt(i+"totalScore");
                                if (player != null && PlayerPrefs.GetFloat(i+"hitPoints") != 0) {
                                        player.playerHealth.hitPoints = PlayerPrefs.GetFloat(i+"hitPoints");
                                        player.playerHealth.lives = PlayerPrefs.GetInt(i+"lives");
                                        if (player.tpsCam != null) player.tpsCam.startThirdPerson = PlayerPrefs.GetInt(i+"thirdPerson") != 0;
                                        player.currentWeapon = PlayerPrefs.GetInt(i+"currentWeapon");
                                        if (player.weapons.Length != 0) {
                                                for (var w : int=0; w<player.weapons.Length; w++) {
                                                        player.weapons[w].hasWeapon = PlayerPrefs.GetInt(i+"hasWeapon"+w) != 0;
                                                        if (player.weapons[w].weapon != null) {
                                                                player.weapons[w].weapon.clips = PlayerPrefs.GetInt(i+"clips"+w);
                                                                player.weapons[w].weapon.bulletsLeft = PlayerPrefs.GetInt(i+"bulletsLeft"+w);
                                                        }
                                                }
                                        }
                                } else if (PlayerPrefs.GetFloat(i+"hitPoints") != 0) {
                                        hitPoints = PlayerPrefs.GetFloat(i+"hitPoints");
                                        lives = PlayerPrefs.GetInt(i+"lives");
                                        thirdPerson = PlayerPrefs.GetInt(i+"thirdPerson") != 0;
                                        currentWeapon = PlayerPrefs.GetInt(i+"currentWeapon");
                                        hasWeapon = new boolean[numberOfWeapons];
                                        clips = new int[numberOfWeapons];
                                        bulletsLeft = new int[numberOfWeapons];
                                        if (numberOfWeapons != 0) {
                                                for (var n : int=0; n<numberOfWeapons; n++) {
                                                        hasWeapon[n] = PlayerPrefs.GetInt(i+"hasWeapon"+n) != 0;
                                                        clips[n] = PlayerPrefs.GetInt(i+"clips"+n);
                                                        bulletsLeft[n] = PlayerPrefs.GetInt(i+"bulletsLeft"+n);
                                                }
                                        }
                                }
                        }
                }
        }
       
        if (player != null && currLevel != levels[0].level)
                player.BroadcastMessage("SelectCurrentWeapon", player.currentWeapon, SendMessageOptions.DontRequireReceiver);
}

function GetScore (player : Player) {
        if (player != null) {
                enemiesLeftAlive = enemiesOnLevel - enemiesKilled;
                levelTime = Time.time - timeOnLevelStart;
                levelScore += Mathf.RoundToInt(100000*(100*enemiesKilled-50*enemiesLeftAlive/1+playerDeaths)/levelTime);
                totalEnemies = totalEnemies + enemiesOnLevel;
                totalEnemiesKilled = totalEnemiesKilled + enemiesKilled;
                totalEnemiesLeftAlive = totalEnemiesLeftAlive + enemiesLeftAlive;
                totalBossesKilled = totalBossesKilled + bossesKilled;
                totalItems = totalItems + itemsOnLevel;
                totalItemsFound = totalItemsFound + itemsFound;
                totalPlayerDeaths = totalPlayerDeaths + playerDeaths;
                totalGameTime = totalGameTime + levelTime;
                totalScore = totalScore + levelScore;
               
                PlayerPrefs.SetInt("numberOfWeapons", numberOfWeapons);
        }
       
        for (var i : int=0; i<levels.Length; i++) {
                if (levels[i].level == currLevel) {
                        for (var l : int=i+1; l<levels.Length; l++) {
                                if (levels[l].levelDone) {
                                        levels[l].levelDone = false;
                                        PlayerPrefs.SetInt(levels[l].level, 0);
                                }
                        }
                        levels[i].levelDone = true;
                        PlayerPrefs.SetInt(levels[i].level, PlayerPrefs.GetInt(levels[i].level) + 1);
                } else if (levels[i].level == nextLevel) {
                        PlayerPrefs.SetInt(i+"totalEnemies", totalEnemies);
                        PlayerPrefs.SetInt(i+"totalEnemiesKilled", totalEnemiesKilled);
                        PlayerPrefs.SetInt(i+"totalEnemiesLeftAlive", totalEnemiesLeftAlive);
                        PlayerPrefs.SetInt(i+"totalBossesKilled", totalBossesKilled);
                        PlayerPrefs.SetInt(i+"totalItems", totalItems);
                        PlayerPrefs.SetInt(i+"totalItemsFound", totalItemsFound);
                        PlayerPrefs.SetInt(i+"totalPlayerDeaths", totalPlayerDeaths);
                        PlayerPrefs.SetFloat(i+"totalGameTime", totalGameTime);
                        PlayerPrefs.SetInt(i+"totalScore", totalScore);
                        if (player != null) {
                                PlayerPrefs.SetFloat(i+"hitPoints", player.playerHealth.hitPoints);
                                PlayerPrefs.SetInt(i+"lives", player.playerHealth.lives);
                                if (player.tpsCam != null) PlayerPrefs.SetInt(i+"thirdPerson", player.tpsCam.startThirdPerson ? 1 : 0);
                                PlayerPrefs.SetInt(i+"currentWeapon", player.currentWeapon);
                                if (player.weapons.Length != 0) {
                                        for (var w : int=0; w<player.weapons.Length; w++) {
                                                PlayerPrefs.SetInt(i+"hasWeapon"+w, player.weapons[w].hasWeapon ? 1 : 0);
                                                if (player.weapons[w].weapon != null) {
                                                        PlayerPrefs.SetInt(i+"clips"+w, player.weapons[w].weapon.clips);
                                                        PlayerPrefs.SetInt(i+"bulletsLeft"+w, player.weapons[w].weapon.GetBulletsLeft());
                                                }
                                        }
                                }
                        } else if (hitPoints != 0) {
                                PlayerPrefs.SetFloat(i+"hitPoints", hitPoints);
                                PlayerPrefs.SetInt(i+"lives", lives);
                                PlayerPrefs.SetInt(i+"thirdPerson", thirdPerson ? 1 : 0);
                                PlayerPrefs.SetInt(i+"currentWeapon", currentWeapon);
                                if (numberOfWeapons != 0) {
                                        for (var n : int=0; n<numberOfWeapons; n++) {
                                                PlayerPrefs.SetInt(i+"hasWeapon"+n, hasWeapon[n] ? 1 : 0);
                                                PlayerPrefs.SetInt(i+"clips"+n, clips[n]);
                                                PlayerPrefs.SetInt(i+"bulletsLeft"+n, bulletsLeft[n]);
                                        }
                                }
                        }
                }
        }
}

function ResetTotalScore () {
        totalEnemies = 0;
        totalEnemiesKilled = 0;
        totalBossesKilled = 0;
        totalItems = 0;
        totalItemsFound = 0;
        totalEnemiesLeftAlive = 0;
        totalPlayerDeaths = 0;
        totalGameTime = 0.0;
        totalScore = 0;
}

static function LoadLevelWithProgress (level : String, textureToFade : Texture2D) {
        levelToLoad = level;
        loadTexture = textureToFade;
        isLoading = true;
}

function ResetGame () {
        Destroy(mainMenu.progressBar);
        Destroy(gameObject);
}
 
dronik911
UNIт
 
Сообщения: 81
Зарегистрирован: 19 фев 2012, 11:48

Re: GUISkin

Сообщение dronik911 18 окт 2012, 10:12

нужна помощь...
dronik911
UNIт
 
Сообщения: 81
Зарегистрирован: 19 фев 2012, 11:48

Re: GUISkin

Сообщение gate1 18 окт 2012, 20:03

как-то маловато кода ...
Аватара пользователя
gate1
UNITрон
 
Сообщения: 198
Зарегистрирован: 27 дек 2011, 22:19
Откуда: Минск

Re: GUISkin

Сообщение dronik911 19 окт 2012, 10:05

это 2 скрипта, больше скриптов нет на сцене
dronik911
UNIт
 
Сообщения: 81
Зарегистрирован: 19 фев 2012, 11:48

Re: GUISkin

Сообщение shadow454 20 окт 2012, 18:39

даа а кода правдо мало \:D/

а ты не думал что у 99,9% форумчан просто не захотят разгребать эту кашу :ymparty:
shadow454
 


Вернуться в Почемучка

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 26