353人加入学习
(6人评价)
Steam模拟经营游戏《冒险村的商人日记》从开发到上架全流程

开发 策划 美术 音乐 发行 全部教给你

价格 ¥ 890.00

有点乱,个人觉得更好的实现

using System;
using System.Collections.Generic;
using Game;
using UnityEngine;

namespace Architecture
{
    public class Farm : MonoBehaviour
    {
        public int productId = -1;
        public int productPeriod  = 7;
        public int count  = 5;
        public int cost  = 5;
        public int growPeriod = -1;


        public int stage2 = 2;
        public int stage3 = 3;

        private int _currentStage = 1;
        private int _showingStage = 1;
        private bool _isGrown;
        private bool _isNeedGrow;
        private int _passingDays;
        private readonly Dictionary<int, GameObject> _stages = new Dictionary<int, GameObject>();


        private void Awake()
        {
            WorldTimer.Instance.DoThisDay += NewDay;
            for (var i = 1; i <= 3; i++)
            {
                _stages[i] = transform.Find(i.ToString()).gameObject;
                if (i >= 2)
                {
                    _stages[i].SetActive(false);
                }
            }
            _isNeedGrow = growPeriod > 0;
        }
        
        private void Update()
        {
            if (_showingStage == _currentStage) return;
            _stages[_showingStage].SetActive(false);
            _stages[_currentStage].SetActive(true);
            _showingStage = _currentStage;
        }

        private void NewDay()
        {
            _passingDays += 1;

            if (growPeriod > 0 && !_isGrown)
            {
                if (_passingDays <= growPeriod) return;
                _isGrown = true;
                _passingDays = 0;
            }
            else
            {
                _currentStage = _passingDays < stage2 && !_isNeedGrow ? 1 : _passingDays < stage3 ? 2 : 3;
                if (_passingDays < productPeriod) return;
                _passingDays = 0;
                Knapsack.Instance.AddGoods(productId, count);
            }
        }

        private void OnDestroy()
        {
            WorldTimer.Instance.DoThisDay -= NewDay;
        }
    }
}

 

[展开全文]

授课教师

独立游戏制作人,业余程序

课程特色

视频(245)
下载资料(22)
图文(1)