示例#1
0
文件: Resource.cs 项目: RTS-Game/RTS
        void Start()
        {
            ResourcePlane.gameObject.SetActive(false);

            CollectOneUnitTime = 1 / CollectAmountPerSecond;

            SelectionMgr = GameManager.Instance.SelectionMgr;
            ResourceMgr  = GameManager.Instance.ResourceMgr;

            //Get the worker manager:
            WorkerMgr = gameObject.GetComponent <WorkerManager>();

            //Set the resource ID:
            ResourceID = ResourceMgr.GetResourceID(Name);

            //Set the selection object if we're using a different collider for player selection:
            if (PlayerSelection != null)
            {
                //set the player selection object for this building/resource:
                PlayerSelection.MainObj = this.gameObject;
            }
            else
            {
                Debug.LogError("Player selection collider is missing!");
            }

            ResourceMgr.RegisterResource(this);
        }
示例#2
0
        }                                            //this component manages resource collectors

        public override void Init(GameManager gameMgr)
        {
            base.Init(gameMgr);

            //get the resource components
            TreasureComp = GetComponent <Treasure>();
            WorkerMgr    = GetComponent <WorkerManager>();

            //initialize the components
            WorkerMgr.Init();

            FactionID = -1;                                                    //set faction ID to -1 by default.

            plane.gameObject.SetActive(false);                                 //hide the resource's plane initially

            ID    = gameMgr.ResourceMgr.GetResourceID(resourceType.GetName()); //get the resource ID from the resource manager
            color = resourceType.GetMinimapIconColor();                        //assign the resource's color

            if (secondaryModel != null)                                        //if there's a secondary model, enable it and disable the initial one
            {
                secondaryModel.SetActive(false);

                if (secondarySelection != null)                     //if there's secondary selection
                {
                    secondarySelection.gameObject.SetActive(false); //and hide it
                    secondarySelection.Init(this.gameMgr, this);    //assign the same source for the secondary selection component
                }
            }

            collectOneUnitDuration /= gameMgr.GetSpeedModifier(); //set collection time regarding speed modifier

            ToggleModel(true);                                    //show the initial model
            gameMgr.MinimapIconMgr?.Assign(selection);            //assign the minimap icon

            gameMgr.ResourceMgr.AddResource(this);                //register the resource in the resource manager

            CustomEvents.OnResourceAdded(this);                   //trigger the resource added custom event
        }