public static AxesInputDelayControl getInstance()
    {
        if( Instance == null )
            Instance = new AxesInputDelayControl();

        return Instance;
    }
    // Use this for initialization
    void Start()
    {
        // Start Start.

        if( Instance == null )
        {
            Instance = this;
            Initialize();
            DontDestroyOnLoad(transform.gameObject);
            DontDestroyOnLoad( Instance );
        }
    }
Esempio n. 3
0
    void Initialize()
    {
        // Getting Game system refrecnces:
        if( _gameData == null )
            _gameData = GameData.getInstance();
        if( axesInputDelayControl == null )
            axesInputDelayControl = AxesInputDelayControl.getInstance();

        // Preseting data here since UNITY seems to ignore anything global:
        MapWidth = (int)MazeGlobals.SMALL_MAP_SIZE.x;
        MapHeight = (int)MazeGlobals.SMALL_MAP_SIZE.y;

        // XML/Saving data:
        isSavable = true; //Globals.defaultIsSavable;
        xmlElementName = MazeGlobals.mazeXMLlElementNameDefault;
        xmlNamespace = MazeGlobals.mazeXMLNamespaceDefault;

        savePathAndName = MazeGlobals.mazeSavePathAndNameDefault;

        // Initalizing the list to hold the maps:
        if( _mapList == null )
            _mapList = new GenericManager<int, Map>( isSavable, xmlElementName, xmlNamespace, savePathAndName );

        // Loading a floor if needed:
        if( FloorObj == null )
        {
            FloorObj = GameObject.CreatePrimitive( PrimitiveType.Cube );
            FloorObj.name = GameGlobals.FLOOR_BLOCK_NAME;
            FloorObj.tag = GameGlobals.FLOOR_BLOCK_TAG;
            FloorObj.renderer.material = Resources.Load( GameGlobals.FLOOR_BLOCK_MAT, typeof(Material)) as Material;;
            FloorObj.renderer.material.shader = Shader.Find( GameGlobals.floorShaderList[ (int) SettingsData.getInstance().GameDifficulty ] );
            FloorObj.transform.localScale = GameGlobals.floorSize;

        }

        // Loading a wall if needed:
        if( WallObj == null )
        {
            WallObj = GameObject.CreatePrimitive( PrimitiveType.Cube );
            WallObj.name = GameGlobals.WALL_BLOCK_NAME;
            WallObj.tag = GameGlobals.WALL_BLOCK_TAG;
            WallObj.renderer.material = Resources.Load( ( GameGlobals.WALL_BLOCK_RANDOM_MAT + Random.Range( 2, 13).ToString() ), typeof(Material)) as Material;;
            //WallObj.renderer.material.shader = Shader.Find( GameGlobals.wallShaderList[ (int) _gameData.settings.GameDifficulty ] );
            WallObj.transform.localScale = GameGlobals.wallSize;
        }

        // If the wal or floor are null then exit:
        if( FloorObj == null || WallObj == null )
        {
            Debug.Log("Error wall and/or floor are not initalized");
            return;
        }

        #region Creating the light

        // Creating the light:
        if( AreaLight == null )
        {
            //AreaLight = new GameObject("The Light");
            //AreaLight.AddComponent<Light>();
            //AreaLight.light.color = AreaLightColor;
            //AreaLight.light.type = LightType.Directional;
            //AreaLight.light.intensity = 0.5f;
            //AreaLight.transform.localRotation = new Quaternion( 90, 0, 0, 0 );
            //AreaLight.transform.position = new Vector3( ( MapWidth * FloorSize.x ) / GameGlobals.HALF, ( FloorSize.y + WallSize.y ) * 10,  ( MapHeight * FloorSize.z ) / GameGlobals.HALF );
        }
        #endregion

        #region Map Loading/Gernerating

        Generator = new MazeGenerator();

        // Attempting to laod an XML file and make the first maze,
        // If this does not work then we load the default maze:
        if( !_mapList.loadObjectList( false, Path.Combine( Application.dataPath, savePathAndName ), xmlElementName, xmlNamespace ) )
        {
            // Creating the default raw map data:
            MainMap = new Map();
            MainMap.initalizeDefaultMap(false);

            // Transforming the default raw map data into Unity objects:
            Generator.genrate( ref MainMap, ref MapWidth, ref MapHeight, ref FloorObj, ref WallObj );
            _mapList.addObject( _mapList.Listcount, MainMap );

            // Adding aditional raw map data as needed:
            AddingMazeHelper.mazeListToAdd( ref _mapList ); // Use this to add lots of maps.

            // Saving the raw map data to xml:
            _mapList.saveObjectList( Path.Combine( Application.dataPath, savePathAndName ), xmlElementName, xmlNamespace );
        }
        else
        {
            MainMap = _mapList.getObject(0);
            MainMap.initalizeLoadedMap( false );
            Generator.genrate( ref MainMap, ref MapWidth, ref MapHeight, ref FloorObj, ref WallObj );
        }

        #endregion

        #region Creating Start and End Positions
        // Creating the Start Position Marker:
        if( StartPoint == null )
        {
            StartVector = MainMap.playerStartPoint;
            StartVector.x = (StartVector.x) * FloorObj.transform.localScale.x;
            StartVector.z = (StartVector.z) * FloorObj.transform.localScale.z;
            StartPoint = GameObject.CreatePrimitive( PrimitiveType.Cube );
            StartPoint.name = GameGlobals.START_POSITION_NAME;
            StartPoint.tag = GameGlobals.START_POSITION_TAG;
            StartPoint.transform.localScale = GameGlobals.startAndEndMarkerSize;
            StartPoint.transform.position = new Vector3( StartVector.x, StartPoint.transform.localScale.y, StartVector.z);
            StartMat = Resources.Load( GameGlobals.START_BLOCK_MAT, typeof(Material)) as Material;
            StartPoint.renderer.material = StartMat;

        }

        // Creating the End Position Marker:
        if( EndPoint == null )
        {
            EndVector = MainMap.playerEndPoint;
            EndVector.x = EndVector.x * FloorObj.transform.localScale.x;
            EndVector.z = EndVector.z * FloorObj.transform.localScale.z;
            EndPoint = GameObject.CreatePrimitive( PrimitiveType.Sphere );
            EndPoint.name = GameGlobals.END_POSITION_NAME;
            EndPoint.tag = GameGlobals.END_POSITION_TAG;
            EndPoint.transform.localScale = GameGlobals.startAndEndMarkerSize;
            EndPoint.transform.position = new Vector3( EndVector.x, EndPoint.transform.localScale.y, EndVector.z );  ;
            EndMat = Resources.Load( GameGlobals.END_BLOCK_MAT, typeof(Material)) as Material;
            EndPoint.renderer.material = EndMat;
            EndPoint.collider.isTrigger = true;
            EndPoint.AddComponent<EndPointScript>();
        }

        #endregion

        #region Creating the Player
        // Creating the Player and puting it in the game:
        //Player = Instantiate( Resources.Load( "Player" , typeof(GameObject)) ) as GameObject;
        Player = Instantiate( Resources.Load( "Prefabs/FPSPlayer" , typeof(GameObject)) ) as GameObject;
        Player.name = "FPSPlayer";
        Player.transform.position = new Vector3
            (  StartVector.x, 2, StartVector.z );
        playerScript = Player.GetComponent<vp_FPSPlayer>();
        #endregion

        // Setting up gameplay variables:
        gameState = GameGlobals.GameState.running;

        // Interface Variables
        _playTime = 0.0f;
        _playTimePosition = new Rect( Screen.width - 50,  20, 50, 50 );

        #region Pause Button

        // Seting up the pause Button:
        //_pauseTextureList = new Texture[ GUIGlobals.numberOfButtonStates ];
        //_pauseButtonPosition = new Rect( 0,  Screen.height - 50, 100, 50 );

        //listCount = _pauseTextureList.Length;
        //for( i = 0; i < listCount; i++ )
            //_pauseTextureList[i] = (Texture2D)Resources.Load( GUIGlobals.pauseButtonPathList[i], typeof(Texture2D));

        #endregion

        #region Pause Menu

        // Creating the Pause Menu:
        pauseMenu = new GameObject();
        pauseMenu.name = PauseMenuGlobals.PAUSE_MENU_NAME;
        pauseMenu.tag = PauseMenuGlobals.PAUSE_MENU_TAG;
        pauseMenu.AddComponent<MenuBase>();
        pauseMenu.GetComponent<MenuBase>().initialize( GUIGlobals.menuTypeDefs.PAUSE, PauseMenuGlobals.PAUSE_MENU_BACKGROUND_PATH, PauseMenuGlobals.PAUSE_MENU_BUTTON_TEXTURES, PauseMenuGlobals.PAUSE_MENU_TOOL_TIPS, PauseMenuGlobals.PAUSE_MENU_BUTTON_POSITIONS );
        pauseMenu.SetActive( false );

        #endregion

        // Cleaning up the origanal wall and floor objects:
        Destroy(WallObj);
        Destroy(FloorObj);
    }
Esempio n. 4
0
    // Use this for initialization
    public void initialize( GUIGlobals.menuTypeDefs menuType, string backgroundPath, string[] buttonPathList, string[] toolTipList, Rect[] buttonPositionList )
    {
        // Start Constructor.

        // Misc:
        _nothingActive = GUIGlobals.NOTHING;

        // Setting the menuType and name:
        _menuType = menuType;
        _menuName = GUIGlobals.menuNameList[ (int)menuType ];

        // Tool Tip Settings:
        _toolTipList = toolTipList;
        _toolTipTimmer = 0.0f;
        ToolTipDelay = GUIGlobals.toolTipDelay;

        // Setting the active button to null just in case:
        _currentActiveButtonTexture = null;
        _currentActiveButtonIndex = _nothingActive;

        // Axis input related variables:
        if( axesInputDelayControl == null )
            axesInputDelayControl = AxesInputDelayControl.getInstance();
        _mouseInputSecondary = false;

        // Keyboard Input Variables:
        menuHardCodedOkButton = KeyCode.Return;

        // Loading the background:
        _backgroundTexture = (Texture2D)Resources.Load( backgroundPath, typeof(Texture2D));

        // Loading the button Graphics and calculating the number of buttons seprate of states:
        listCount = buttonPathList.Length;
        _buttonTextureList = new List<Texture2D>();
        for( i = 0; i < listCount; i++ )
        {
            if( buttonPathList[i] != null )
                _buttonTextureList.Add( (Texture2D)Resources.Load( buttonPathList[i], typeof(Texture2D)) );
        }
        _numberOfButtons = ( _buttonTextureList.Count / GUIGlobals.numberOfButtonStates );

        // Setting the button positions:
        listCount = _numberOfButtons;
        _buttonRectList = new List<Rect>();
        for( i = 0; i < listCount; i++ )
        {
            // No need for null checking since we alerady know how many buttons there are.
            _buttonRectList.Add( buttonPositionList[i] );
        }

        // Grabing Game Object Refernces:
        //if( gameData == null )
            //gameData = GameObject.FindGameObjectWithTag("GameData").GetComponent<GameData>();

        if( menuGenerator == null && menuType != GUIGlobals.menuTypeDefs.PAUSE )
            menuGenerator = MenuGenerator.getInstance();

        // Setting Menu draw size and order:
        if( menuType == GUIGlobals.menuTypeDefs.PAUSE || menuType == GUIGlobals.menuTypeDefs.TROPHIES_WARNING || menuType == GUIGlobals.menuTypeDefs.SCORE_WARNING  )
        {
            MenuRectangle = new Rect( ( 1280 - _backgroundTexture.width ) / 2, ( 720 - _backgroundTexture.height ) / 2, _backgroundTexture.width, _backgroundTexture.height );
            guiDepth = 0;
        }
        else
        {
            MenuRectangle = new Rect( 0, 0, 1280, 720 );
            guiDepth = 1;
        }

        // Misc variables:
        bool overlay;

        // Calling the Initalize on the inheriting class:
        OnInitialize();
    }