Ejemplo n.º 1
0
    //public void OnHandle(WorldUpdateEvent message)
    //{
    //  //if (message.Reset)
    //  //{
    //  //  //  a new world has been set up
    //  //  //
    //  //  foreach (var character in _characterGraphics.Values)
    //  //  {
    //  //    Destroy(character.main);
    //  //  }

    //  //  _characterGraphics = new Dictionary<Character, CharacterInfo>();
    //  //}
    //}

    public void OnHandle(CharacterCreatedEvent message)
    {
        Debug.Log("CharacterController.CharacterCreatedEvent");

        var characterInfo = new CharacterInfo();

        _characterGraphics.Add(message.Character, characterInfo);

        characterInfo.main = new GameObject();

        characterInfo.main.name = "astro" + _characterGraphics.Count;
        characterInfo.main.transform.position = new Vector3(message.Character.CurrentTile.Position.x, message.Character.CurrentTile.Position.y);
        characterInfo.main.transform.SetParent(this.transform, true);

        var renderer = characterInfo.main.AddComponent <SpriteRenderer>();

        renderer.sprite           = _resourceCollection.GetSprite("Astronaut_B_South");
        renderer.sortingLayerName = "Character";

        //  create hand object
        characterInfo.hand      = new GameObject();
        characterInfo.hand.name = "hand" + characterInfo.main.name;

        //  hands need to be in unitspace
        characterInfo.hand.transform.position = new Vector3(characterInfo.main.transform.position.x - 0.3f, characterInfo.main.transform.position.y, -1);
        characterInfo.hand.transform.SetParent(characterInfo.main.transform, true);

        renderer                  = characterInfo.hand.AddComponent <SpriteRenderer>();
        renderer.sprite           = _resourceCollection.GetSprite("Hands_B");
        renderer.sortingLayerName = "Character";
    }
Ejemplo n.º 2
0
    public void OnHandle(BuildingResourceUpdatedEvent message)
    {
        Log($"SpriteController.OnHandle_BuildingResourceUpdatedEvent = {message.Resource.Id} => {message.Resource.Amount}");

        if (!_resourceGraphics.ContainsKey(message.Resource))
        {
            var graphic = new GameObject();

            graphic.name = $"{message.Resource.Type}_{message.Resource.Tile.Position}";
            graphic.transform.position = message.Resource.Tile.Position.GetVector();
            graphic.transform.SetParent(this.transform, true);

            _resourceGraphics.Add(message.Resource, graphic);
            var renderer = graphic.AddComponent <SpriteRenderer>();
            renderer.sprite           = _resourceCollection.GetSprite($"{message.Resource.Type}_Resource");
            renderer.sortingLayerName = "FixedObjects";
        }
        else
        {
            // is depleted
            if (message.Resource.Amount == 0)
            {
                Log($"SpriteController.OnHandle_BuildingResourceUpdatedEvent => destroy");
                Destroy(_resourceGraphics[message.Resource]);
            }
        }
    }
Ejemplo n.º 3
0
    //public void AddJob(Job job)
    //{
    //  CreateGraphics(job);

    //  IoC.Get<WorldController>().AddJob(job);



    //  job.Tile.JobScheduled = true;
    //}

    private void CreateGraphics(Job job)
    {
        var graphic = new GameObject();

        //graphic.name = $"{job.Item.Type}_{job.Tile.Position}";
        graphic.name = $"{job.Item}_{job.Tile.Position}";
        graphic.transform.position = job.Tile.Position.GetVector();
        graphic.transform.SetParent(this.transform, true);

        _jobGraphics.Add(job, graphic);
        var renderer = graphic.AddComponent <SpriteRenderer>();

        renderer.sprite           = _resourceCollection.GetSprite(GetSpriteName(job));
        renderer.sortingLayerName = "FixedObjects";

        //var audio = new GameObject();
        //audio.transform.position = job.Tile.Position.GetVector();
        //audio.transform.SetParent(this.transform, true);

        //  TODO SOUND
        //  doesn't seem to be working correct
        //job.AudioSource = graphic.AddComponent<AudioSource>();

        //// get sound
        //var factory = IoC.Get<ObjectFactory>().GetFactory(job.Item);
        //job.AudioSource.clip = Resources.Load<AudioClip>($"Sounds/{factory.BuildSound}"); ;

        ////job.AudioSource.loop = true;
        //job.AudioSource.volume = 0.1f;
        //job.AudioSource.spatialBlend = 1.0f;
        //job.AudioSource.rolloffMode = AudioRolloffMode.Linear;
        //job.AudioSource.minDistance = 5;
        //job.AudioSource.maxDistance = 11.5f;
    }
Ejemplo n.º 4
0
    private void CreatePrefabs()
    {
        _defaultBuildCursor       = new GameObject();
        _defaultBuildCursor.name  = $"build cursor";
        _defaultBuildCursor.layer = 5; // "UI"

        _defaultBuildCursor.transform.position = new Vector3();
        _defaultBuildCursor.transform.SetParent(this.transform, true);
        var renderer = _defaultBuildCursor.AddComponent <SpriteRenderer>();

        renderer.sprite           = _resouceCollection.GetSprite("build");
        renderer.sortingLayerName = "BuildPreview";


        _previewGameObject       = new GameObject();
        _previewGameObject.name  = "build preview";
        _previewGameObject.layer = 5; // "UI"

        _previewGameObject.transform.position = new Vector3();
        _previewGameObject.transform.SetParent(this.transform, true);
        renderer = _previewGameObject.AddComponent <SpriteRenderer>();
        renderer.sortingLayerName = "BuildPreview";
    }