コード例 #1
0
    /// <summary>
    /// Bootstrap the game state and data.
    /// </summary>
    protected void Awake()
    {
        InitLogging();
        GameLogger.Info("Game started.");

        lock (_singletonLock)
        {
            if (_singleton != null)
            {
                GameLogger.FatalError("It appears there are multiple root Game objects.");
            }

            _singleton = this;
        }

        GameLogger.Info("Creating game objects.");
        InitGameObjects();
    }
コード例 #2
0
        /// <summary>
        /// Handle a click event on the terrain.
        /// </summary>
        /// <param name="sender">Not used.</param>
        /// <param name="args">The terrain click arguments.</param>
        private void Clicked(object sender, TerrainClickedArgs args)
        {
            if (args.Button == MouseButton.Left)
            {
                if (IsValidTerrain())
                {
                    Transition(GameState.PlacingPath, args);
                }
            }

            // DEBUGGING:
            if (args.Button == MouseButton.Right)
            {
                GameLogger.Info("IsValidTerrain: {0}; IsSmoothAndFree: {1}; IsPath: {2}",
                                IsValidTerrain(),
                                _terrain.Editor.CheckSmoothAndFree(_cursor.Position.x, _cursor.Position.y, _cursor.Position.x, _cursor.Position.y)[0],
                                Game.Campus.Paths.IsPath(_cursor.Position.x, _cursor.Position.y));
            }
        }
コード例 #3
0
        /// <summary>
        /// Handle a click event on the terrain.
        /// </summary>
        /// <param name="sender">Not used.</param>
        /// <param name="args">The terrain click arguments.</param>
        private void Clicked(object sender, TerrainClickedArgs args)
        {
            if (args.Button == MouseButton.Left)
            {
                Transition(GameState.EditingTerrain, args);
            }

            if (Application.isEditor)
            {
                GameLogger.Info("Selected ({0}); Point Heights ({1}, {2}, {3}, {4})",
                                args.ClickLocation,
                                _terrain.GetVertexHeight(args.ClickLocation.x, args.ClickLocation.z),
                                _terrain.GetVertexHeight(args.ClickLocation.x + 1, args.ClickLocation.z),
                                _terrain.GetVertexHeight(args.ClickLocation.x, args.ClickLocation.z + 1),
                                _terrain.GetVertexHeight(args.ClickLocation.x + 1, args.ClickLocation.z + 1));

                if (Input.GetKey(KeyCode.LeftControl))
                {
                    int submaterial = _terrain.GetSubmaterial(args.ClickLocation.x, args.ClickLocation.z);
                    _terrain.SetSubmaterial(args.ClickLocation.x, args.ClickLocation.z, (submaterial + 1) % _terrain.SubmaterialCount, Rotation.deg270);
                }
            }
        }
コード例 #4
0
ファイル: GridMesh.cs プロジェクト: GoodSky/game-nuggets
        /// <summary>
        /// Instantiates an instance of the GridMesh.
        /// </summary>
        /// <param name="mesh">The Unity Mesh behavior.</param>
        /// <param name="collider">The Unity MeshCollider behavior.</param>
        /// <param name="renderer">The Unity MeshRenderer behavior.</param>
        /// <param name="args">The arguments used to create the GridMesh.</param>
        public GridMesh(Mesh mesh, MeshCollider collider, MeshRenderer renderer, GridMeshArgs args)
        {
            if (mesh == null)
            {
                throw new ArgumentNullException("mesh");
            }

            if (collider == null)
            {
                throw new ArgumentNullException("collider");
            }

            if (renderer == null)
            {
                throw new ArgumentNullException("renderer");
            }

            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            GameLogger.Info("Generating GridMesh. {0}x{1} squares @ {2:0.00f}; Starting height {3} of {4} @ {5:0.00f}; Material '{6}';",
                            args.CountX,
                            args.CountZ,
                            args.GridSquareSize,
                            args.StartingHeight,
                            args.CountY,
                            args.GridStepSize,
                            args.GridMaterial == null ? "NULL" : args.GridMaterial.name);

            _mesh      = mesh;
            _collider  = collider;
            _renderer  = renderer;
            GameObject = renderer.gameObject;

            GridSquareSize  = args.GridSquareSize;
            GridStepSize    = args.GridStepSize;
            CountX          = args.CountX;
            CountZ          = args.CountZ;
            CountY          = args.CountY;
            SubmaterialSize = args.SubmaterialSize;

            if (args.GridMaterial.mainTexture.width % SubmaterialSize != 0 ||
                args.GridMaterial.mainTexture.height % SubmaterialSize != 0)
            {
                throw new InvalidOperationException(string.Format("GridMesh material '{0}' is not a {1}x{1} grid sheet. [{2}x{3}]",
                                                                  args.GridMaterial.name,
                                                                  SubmaterialSize,
                                                                  args.GridMaterial.mainTexture.width,
                                                                  args.GridMaterial.mainTexture.height));
            }

            _submaterialCountX = (args.GridMaterial.mainTexture.width / SubmaterialSize);
            _submaterialCountZ = (args.GridMaterial.mainTexture.height / SubmaterialSize);
            SubmaterialCount   = _submaterialCountX * _submaterialCountZ;

            _material     = args.GridMaterial;
            _gridData     = new GridData[CountX, CountZ];
            _vertexHeight = new int[CountX + 1, CountZ + 1];

            Convert = new GridConverter(
                gridSize: GridSquareSize,
                gridStepSize: GridStepSize,
                minTerrainX: GameObject.transform.position.x,
                minTerrainZ: GameObject.transform.position.z,
                minTerrainY: args.StartingHeight * -GridStepSize);

            Editor = new SafeTerrainEditor(this);

            if (args.SkirtPrefab != null)
            {
                var skirtObject = UnityEngine.Object.Instantiate(args.SkirtPrefab);
                skirtObject.transform.parent = GameObject.transform;

                // the skirt prefab is rotated 90 degrees, so scale y-axis instead of z
                skirtObject.transform.localScale = new Vector3(CountX * GridSquareSize, CountZ * GridSquareSize, 1.0f);
            }

            GenerateMesh();
            Flatten(args.StartingHeight);
        }
コード例 #5
0
 /// <summary>
 /// Cleanup game state and data.
 /// </summary>
 protected void OnDestroy()
 {
     GameLogger.Info("Game exiting.");
     GameLogger.Close();
 }
コード例 #6
0
        protected override void Start()
        {
            base.Start();

            OnSelect = () => { GameLogger.Info("Building '{0}' selected!", _building.Name); };
        }