Esempio n. 1
0
        // Construct from JSON.
        public MapFeatureData(JSONNode json)
        {
            this.x = json["x"].AsFloat;
            this.y = json["y"].AsFloat;

            JSONNode spriteJSON = json["sprite"];

            // Loading the 2D texture from the path provided in the JSON
            // so we can specify the size using the width and height parameters.
            // We no longer need to give a size in the filename and parse it
            // via JSON.
            texture = Resources.Load <Texture2D>(spriteJSON["path"]);

            this.spritePath = spriteJSON["path"];

            // Calling the width and height parameters in the Texture2D object.
            this.spriteWidth  = texture.width;
            this.spriteHeight = texture.height;

            this.lightData = new LightData(Vector3.zero);
            this.hasLight  = false;

            if (spriteJSON["lights"] != null)
            {
                this.lightData = new LightData(spriteJSON["lights"]);
                this.hasLight  = true;
            }
        }
Esempio n. 2
0
        public void Draw(GameObject mapFeature, LightData lightData)
        {
            Vector3 position  = mapFeature.transform.position;
            string  lightName = "light-" + mapFeature.name;

            GameObject lightGameObject = new GameObject(lightName);

            lightGameObject.transform.parent = mapFeature.transform;

            Light lightComp = lightGameObject.AddComponent <Light> ();

            lightComp.color = Color.white;

            lightGameObject.transform.position = new Vector3(
                position.x + lightData.x,
                position.y + lightData.y,
                position.z);

            lightComp.intensity = lightData.intensity;
            lightComp.range     = lightData.range;
        }
Esempio n. 3
0
        // Attach Light
        public void AttachLight(GameObject mapFeature, LightData lightData)
        {
            LightManager lightManager = mapFeature.AddComponent <LightManager>();

            lightManager.Draw(mapFeature, lightData);
        }