示例#1
0
        public void OnInstalledItemCreated(InstalledItem inst)
        {
            //create a visible game object

            if (InstalledItems_GO_Map.ContainsKey(inst))
            {
                return;
            }
            GameObject go = CreateGameObject(inst.type + "_" + inst.tile.world_x + "_" + inst.tile.world_y, inst.tile.world_x, inst.tile.world_y);

            InstalledItems_GO_Map.Add(inst, go);
            SpriteRenderer spr = go.GetComponent <SpriteRenderer>();
            float          xt = 0, yt = 0;

            if (inst.width > 1)
            {
                xt = ((float)(inst.width) / 2.0f) - 0.5f;
            }

            if (inst.height > 1)
            {
                yt = ((float)(inst.height) / 2.0f) - 0.5f;
            }
            spr.transform.Translate(xt, yt, 0);

            SpriteHolder sh = spriteController.GetSprite(inst);

            if (inst.type == "installed::door")
            {
                spriteController.GetDoorSprite(inst, sh);
            }
            if (sh.r != 0)
            {
                spr.transform.Rotate(0, 0, sh.r);
            }
            //Debug.Log(sh.s + " @ r:" + sh.r);

            spr.sprite        = sh.s; // sprites[inst.spriteName];
            spr.sortingOrder += 1;
            go.transform.SetParent(this.transform, true);
            spr.sortingLayerName = "Objects";

            //world.RegisterInstalledItemCB(inst);
            inst.CBRegisterChanged(OnInstalledItemChanged);
            inst.CBRegisterDestroyed(OnInstalledItemDestroyed);
        }
        //public Sprite GetSprite(Character c) {
        //  return GetSprite(c.spriteName);
        //}

        public SpriteHolder GetDoorSprite(InstalledItem door, SpriteHolder sh)
        {
            float openness = door.itemParameters.GetFloat("openness");

            int index = (int)(openness / (1.0f / 7.0f));

            sh.s = GetSprite("installed_items::door_" + index);
            //if (openness > 0.75) {
            //  sh.s = GetSprite("installed_door_25");
            //} else if (openness > 0.5 && openness <= 0.75) {
            //  sh.s = GetSprite("installed_door_50");
            //} else if (openness > 0.1 && openness <= 0.5) {
            //  sh.s = GetSprite("installed_door_75");
            //} else {

            //}


            return(sh);
        }
示例#3
0
        void OnInstalledItemChanged(InstalledItem item)
        {
            //Debug.LogError("OnInstalledItemChanged " + item + " NOT IMPLEMENTED");

            if (InstalledItems_GO_Map.ContainsKey(item))
            {
                GameObject     go  = InstalledItems_GO_Map[item];
                SpriteRenderer spr = go.GetComponent <SpriteRenderer>();

                SpriteHolder sh = spriteController.GetSprite(item);
                if (item.type == "installed::door")
                {
                    spriteController.GetDoorSprite(item, sh);
                }

                spr.sprite             = sh.s;
                spr.transform.rotation = Quaternion.identity;
                spr.transform.Rotate(0, 0, sh.r);
            }
        }
        public SpriteHolder GetSprite(InstalledItem item)
        {
            SpriteHolder sp = new SpriteHolder();

            if (item.growthStage >= 0)
            {
                Growth g = item.growthStages[item.growthStage];
                sp.s = GetSprite(g.sprite);
            }
            else
            {
                sp.s = GetSprite(item.getRandomSpriteName());
            }



            if (item.randomRotation)
            {
                int r = Random.Range(0, 4);
                sp.r = 90 * r;
            }



            if (item.linksToNeighbour)
            {
                int  x = item.tile.world_x;
                int  y = item.tile.world_y;
                bool northMatches, eastMatches, southMatches, westMatches;
                int  countOfNeighbours = 0;
                //Dictionary<string, Tile> ngbrs = WorldController.Instance.world.GetNeighbours(item);
                Tile north             = item.tile.GetNeighbour(World.NORTH);
                Tile east              = item.tile.GetNeighbour(World.EAST);
                Tile south             = item.tile.GetNeighbour(World.SOUTH);
                Tile west              = item.tile.GetNeighbour(World.WEST);

                northMatches = hasMatchingNeighbour(north, item);
                if (northMatches)
                {
                    countOfNeighbours += 1;
                }
                eastMatches = hasMatchingNeighbour(east, item);
                if (eastMatches)
                {
                    countOfNeighbours += 1;
                }
                southMatches = hasMatchingNeighbour(south, item);
                if (southMatches)
                {
                    countOfNeighbours += 1;
                }
                westMatches = hasMatchingNeighbour(west, item);
                if (westMatches)
                {
                    countOfNeighbours += 1;
                }

                switch (countOfNeighbours)
                {
                case 0:

                    break;

                case 1:
                    sp.s = GetSprite(item.sprite_s);
                    if (northMatches)
                    {
                        sp.r = 180;
                    }
                    else if (eastMatches)
                    {
                        sp.r = 90;
                    }
                    else if (westMatches)
                    {
                        sp.r = -90;
                    }
                    break;

                case 2:
                    sp.s = GetSprite(item.sprite_ns);
                    if (eastMatches && westMatches)
                    {
                        sp.r = 90;
                    }
                    else if (northMatches && southMatches)
                    {
                        sp.r = 0;
                    }
                    else
                    {
                        sp.s = GetSprite(item.sprite_sw);
                        if (southMatches && westMatches)
                        {
                        }
                        else if (northMatches && eastMatches)
                        {
                            sp.r = -180;
                        }
                        else if (northMatches && westMatches)
                        {
                            sp.r = -90;
                        }
                        else if (eastMatches && southMatches)
                        {
                            sp.r = 90;
                        }
                    }
                    break;

                case 3:
                    sp.s = GetSprite(item.sprite_nsw);

                    if (northMatches && southMatches && westMatches)
                    {
                    }
                    else if (northMatches && eastMatches && westMatches)
                    {
                        sp.r = -90;
                    }
                    else if (eastMatches && southMatches && westMatches)
                    {
                        sp.r = 90;
                    }
                    else if (northMatches && eastMatches && southMatches)
                    {
                        sp.r = 180;
                    }

                    break;

                case 4:
                    sp.s = GetSprite(item.sprite_nesw);
                    break;
                }
            }
            else
            {
            }
            return(sp);
        }