// Use this for initialization
    void Start()
    {
        _fSC = FindObjectOfType <InstalledObjectSpriteController>();
        _jobGameObjectMap = new Dictionary <Job, GameObject>();

        WorldController.Instance.World.JobQueue.RegisterJobCreationCallback(OnJobCreated);
    }
    void Start()
    {
        // Setting the instance equal to this current one (with check)
        if (Instance != null)
        {
            Debug.LogError("There shouldn't be two world controllers.");
        }
        else
        {
            Instance = this;
        }

        // Instatiate dictionary that binds a GameObject with data
        installedObjectGameObjectMap = new Dictionary <InstalledObject, GameObject>();
        installedObjectSpritesMap    = new Dictionary <string, Sprite>();

        // Load all sprites on start
        LoadSprites();

        // Register function
        World.RegisterInstalledObjectCreated(OnInstalledObjectCreated);

        // Loop through any PRE-EXISTING installedObjects (installedObject that were loaded in OnEnable) and call the OnCreatedCallback manually
        foreach (InstalledObject installedObject in World.installedObjects)
        {
            OnInstalledObjectCreated(installedObject);
        }
    }
Exemple #3
0
    void Start()
    {
        _world = WorldController.Instance.World;

        _dragPreviewGameObjects = new List <GameObject>();
        _buildModeController    = FindObjectOfType <BuildModeController>();

        _iOSC            = FindObjectOfType <InstalledObjectSpriteController>();
        _mouseController = FindObjectOfType <MouseController>();
    }
    void Start()
    {
        JobGameObjectMap = new Dictionary <Job, GameObject>();
        iosc             = GameObject.FindObjectOfType <InstalledObjectSpriteController>(); // Initialise the reference to the Sprite Controller for the installed objects

        // This sprite controller on start tells the JobQueue that the OnJobCreation is what needs to be called whenever there is a new objetc added to the queue
        // This will happen every time the BUildModeController() Class tells it to
        // They are kept seperate to segregate data for organisation
        WorldController.Instance.world.jobQueue.RegisterJobCreationCallback(OnJobCreated);     // Registers the callback in the JobQueue to thw OnJobCreate() function in this class
    }
Exemple #5
0
    // Start is called before the first frame update
    void Start()
    {
        iosc = FindObjectOfType <InstalledObjectSpriteController>();

        WorldController.instance.world.jobQueue.RegisterJobCreatedCallback(OnJobCreated);
    }
Exemple #6
0
    /// <summary>
    /// Stuff to do after creating a new job:
    /// - Get the correct sprite
    /// - Register callback actions
    /// </summary>
    /// <param name="job">The newly created job.</param>
    void OnJobCreated(Job job)
    {
        // This job doesn't have a sprite => no need to render anything
        if (job.JobObjectType == null)
        {
            return;
        }

        // Grab reference first time creating a job
        if (installedObjectSpriteController == null)
        {
            installedObjectSpriteController = InstalledObjectSpriteController.Instance;
        }

        // FIXME: This
        // Temp check to see if job isn't already in the queue
        if (jobGameObjectMap.ContainsKey(job))
        {
            Debug.LogError("OnJobCreated for a job_GameObject that already exists -- likely a job being re-enqueued instead of actually getting created.");
            return;
        }

        // Creating new gameObject
        GameObject job_GameObject = new GameObject();

        // Add job and gameobject to dictionary (job is the key)
        jobGameObjectMap.Add(job, job_GameObject);

        // Adding a name and position to each installedObject_GameObject
        job_GameObject.name = "JOB_" + job.JobObjectType + "_" + job.tile.X + "_" + job.tile.Y;
        job_GameObject.transform.position = new Vector2(job.tile.X, job.tile.Y);

        // Setting the new tile as a child, maintaining a clean hierarchy
        job_GameObject.transform.SetParent(this.transform, true);

        // Create spriterenderer, set its sprite and sortinglayer
        SpriteRenderer spriteRenderer = job_GameObject.AddComponent <SpriteRenderer>();

        spriteRenderer.sprite           = installedObjectSpriteController.GetSpriteForInstalledObject(job.JobObjectType);
        spriteRenderer.sortingLayerName = "Jobs";
        spriteRenderer.color            = new Color(0.5f, 1f, 0.5f, 0.25f);

        if (job.JobObjectType == "Door")
        {
            /// By default the door sprite is for walls to the east & west
            /// Check to see if this door is meant for walls to the north & south
            /// If so, rotate this gameobject by 90 degrees

            Tile northTile = job.tile.World.GetTileAt(job.tile.X, job.tile.Y + 1);
            Tile southTile = job.tile.World.GetTileAt(job.tile.X, job.tile.Y - 1);

            // If true, there are wall to the north and south => rotate the GO 90 degress
            if (northTile != null &&
                southTile != null &&
                northTile.InstalledObject != null &&
                southTile.InstalledObject != null &&
                northTile.InstalledObject.ObjectType == "Wall" &&
                southTile.InstalledObject.ObjectType == "Wall")
            {
                job_GameObject.transform.rotation = Quaternion.Euler(0, 0, 90);
            }
        }

        // Registering callback actions for new job
        job.RegisterJobCompleteCallback(OnJobEnded);
        job.RegisterJobCancelCallback(OnJobEnded);
    }