示例#1
0
        private void OnJobCreated(Job job)
        {
            if (job.JobObjectType == null)
            {
                // This job doesn't have a sprite associated with it.
                return;
            }

            if (_jobGameObjectMap.ContainsKey(job))
            {
                // Debug.LogError("OnJobCreated called for a JobGO that already exists.");
                return;
            }

            var jobGo = new GameObject();

            _jobGameObjectMap.Add(job, jobGo);

            jobGo.name = "JOB_" + job.JobObjectType + "_" + job.Tile.X + "_" + job.Tile.Y;

            var posOffset = new Vector3((float)(job.FurniturePrototype.Width - 1) / 2, (float)(job.FurniturePrototype.Height - 1) / 2, 0);

            jobGo.transform.position = new Vector3(job.Tile.X, job.Tile.Y, 0) + posOffset;
            jobGo.transform.SetParent(this.transform, true);

            var sr = jobGo.AddComponent <SpriteRenderer>();

            sr.sprite           = fsc.GetSpriteForFurniture(job.JobObjectType);
            sr.color            = new Color(0.5f, 1f, 0.5f, 0.25f);
            sr.sortingLayerName = "Jobs";

            job.RegisterOnJobCompletedCallback(OnJobEnded);
            job.RegisterOnJobStoppedCallback(OnJobEnded);
        }
示例#2
0
        private void ShowFurnitureSpriteAtTile(string furnType, Tile t)
        {
            var go = new GameObject();

            go.transform.SetParent(this.transform, true);
            _dragPreviewGameObjects.Add(go);

            var sr = go.AddComponent <SpriteRenderer>();

            sr.sprite = _fsc.GetSpriteForFurniture(furnType);

            if (WorldController.Instance.World.IsFurniturePlacementValid(furnType, t))
            {
                sr.color = new Color(0.5f, 1f, 0.5f, 0.25f);
            }
            else
            {
                sr.color = new Color(1f, 0.5f, 0.5f, 1f);
            }

            sr.sortingLayerName = "Jobs";

            var proto     = World.Instance.FurniturePrototypes[furnType];
            var posOffset = new Vector3((float)(proto.Width - 1) / 2, (float)(proto.Height - 1) / 2, 0);

            go.transform.position = new Vector3(t.X, t.Y, 0) + posOffset;
        }