示例#1
0
        static public void MaskSprite(LightTile tile, LayerSetting layerSetting, Material material, LightTilemapCollider2D tilemap, float lightSizeSquared)
        {
            virtualSpriteRenderer.sprite = tile.GetOriginalSprite();

            if (virtualSpriteRenderer.sprite == null)
            {
                return;
            }

            LightTilemapCollider.Base tilemapBase = tilemap.GetCurrentTilemap();

            Vector2 tilePosition = tile.GetWorldPosition(tilemapBase) - ShadowEngine.light.transform2D.position;

            material.color = LayerSettingColor.Get(tilePosition, layerSetting, MaskEffect.Lit, 1);             // 1?

            material.mainTexture = virtualSpriteRenderer.sprite.texture;

            Vector2 scale = tile.worldScale * tile.scale;

            GLExtended.SetColor(Color.white);

            tilePosition += ShadowEngine.drawOffset;

            Universal.Sprite.FullRect.Simple.Draw(tile.spriteMeshObject, material, virtualSpriteRenderer, tilePosition, scale, tile.worldRotation);

            material.mainTexture = null;
        }
        //**************************** CSVのロード用 ****************************//

        /// <summary>
        /// CSVファイルからロードして初期化
        /// </summary>
        /// <param name="parent">コルーチンをまわすためのMonoBehaviour</param>
        /// <param name="url">ファイルパス</param>
        /// <param name="version">シナリオバージョン(-1以下で必ずサーバーからデータを読み直す)</param>
        /// <returns></returns>
        public IEnumerator LoadCsvAsync(MonoBehaviour parent, string url, int version)
        {
            //起動ファイルの読み込み
            {
                AssetFile file = AssetFileManager.GetFileCreateIfMissing(url);
                if (version < 0)
                {
                    file.Version = file.CacheVersion + 1;
                }
                AssetFileManager.Load(file, this);
                while (!file.IsLoadEnd)
                {
                    yield return(0);
                }
                SettingData.InitFromCsv(file.Csv, url);
                file.Unuse(this);
            }

            parent.StartCoroutine(ScenarioSetting.LoadCsvAsync(SettingData.ScenarioSettingUrlList));
            parent.StartCoroutine(CharacterSetting.LoadCsvAsync(SettingData.CharacterSettingUrlList));
            parent.StartCoroutine(TextureSetting.LoadCsvAsync(SettingData.TextureSettingUrlList));
            parent.StartCoroutine(SoundSetting.LoadCsvAsync(SettingData.SoundSettingUrlList));
            parent.StartCoroutine(DefaultParam.LoadCsvAsync(SettingData.ParamSettingUrlList));
            parent.StartCoroutine(LayerSetting.LoadCsvAsync(SettingData.LayerSettingUrlList));
            parent.StartCoroutine(SceneGallerySetting.LoadCsvAsync(SettingData.SceneGallerySettingUrlList));


            while (!IsLoadEndCsv())
            {
                yield return(0);
            }
        }
示例#3
0
        public static void Mask(Light2D light, LightCollider2D id, LayerSetting layerSetting)
        {
            if (id.InLight(light) == false)
            {
                return;
            }

            int shapeCount = id.shapes.Count;

            for (int i = 0; i < shapeCount; i++)
            {
                LightColliderShape shape = id.shapes[i];

                List <MeshObject> meshObjects = shape.GetMeshes();

                if (meshObjects == null)
                {
                    return;
                }

                Vector2 position = shape.transform2D.position - light.transform2D.position;

                Vector2 pivotPosition = shape.GetPivotPoint() - light.transform2D.position;
                GL.Color(LayerSettingColor.Get(pivotPosition, layerSetting, id.maskEffect, id.maskTranslucency));

                GLExtended.DrawMeshPass(meshObjects, position, shape.transform.lossyScale, shape.transform2D.rotation);
            }
        }
        //**************************** CSVのロード用 ****************************//

        /// <summary>
        /// CSVファイルからロードして初期化
        /// </summary>
        /// <param name="parent">コルーチンをまわすためのMonoBehaviour</param>
        /// <param name="url">ファイルパス</param>
        /// <param name="version">シナリオバージョン(-1以下で必ずサーバーからデータを読み直す)</param>
        /// <returns></returns>
        public IEnumerator LoadCsvAsync(MonoBehaviour parent, string url, int version)
        {
            //起動ファイルの読み込み
            {
                AssetFile file = AssetFileManager.Load(url, version, this);
                Debug.Log("Boot Scenario Version:" + file.Version);
                while (!file.IsLoadEnd)
                {
                    yield return(0);
                }
                SettingData.InitFromCsv(file.Csv, url);
                file.Unuse(this);
            }

            importVersion = Version;

            parent.StartCoroutine(ScenarioSetting.LoadCsvAsync(SettingData.ScenarioSettingUrlList));
            parent.StartCoroutine(CharacterSetting.LoadCsvAsync(SettingData.CharacterSettingUrlList));
            parent.StartCoroutine(TextureSetting.LoadCsvAsync(SettingData.TextureSettingUrlList));
            parent.StartCoroutine(SoundSetting.LoadCsvAsync(SettingData.SoundSettingUrlList));
            parent.StartCoroutine(DefaultParam.LoadCsvAsync(SettingData.ParamSettingUrlList));
            parent.StartCoroutine(LayerSetting.LoadCsvAsync(SettingData.LayerSettingUrlList));
            parent.StartCoroutine(SceneGallerySetting.LoadCsvAsync(SettingData.SceneGallerySettingUrlList));


            while (!IsLoadEndCsv())
            {
                yield return(0);
            }
        }
示例#5
0
        private void SaveLayerSetting(LayerSetting setting)
        {
            // Not exporting, don't save layer settings
            if (!setting.doExport)
            {
                return;
            }

            // Get the asset
            var    layer       = Psd.Layers[setting.layerIndex];
            string layerPath   = GetLayerPath(layer.Name);
            var    layerSprite = AssetDatabase.LoadAssetAtPath(layerPath, typeof(Sprite));

            if (layerSprite == null)
            {
                return;
            }

            // Write out the labels for the layer settings
            // layer settings is just import size
            string[] labels = new string[1];

            if (setting.scaleBy == PSDExporter.ScaleDown.Default)
            {
                labels[0] = TagImport1;
            }
            if (setting.scaleBy == PSDExporter.ScaleDown.Half)
            {
                labels[0] = TagImport2;
            }
            if (setting.scaleBy == PSDExporter.ScaleDown.Quarter)
            {
                labels[0] = TagImport4;
            }

            // Write the label for the texture
            AssetDatabase.SetLabels(layerSprite, labels);

            // Set the alignment for the texture

            // Get the texture importer for the asset
            TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(layerPath);
            // Read out the texture import settings so import pivot point can be changed
            TextureImporterSettings importSetting = new TextureImporterSettings();

            textureImporter.ReadTextureSettings(importSetting);

            // Set the alignment
            importSetting.spriteAlignment = (int)setting.pivot;

            // And write settings into the importer
            textureImporter.SetTextureSettings(importSetting);

            EditorUtility.SetDirty(layerSprite);
            AssetDatabase.WriteImportSettingsIfDirty(layerPath);
            AssetDatabase.ImportAsset(layerPath, ImportAssetOptions.ForceUpdate);
        }
 /// <summary>
 /// 起動時の初期化
 /// </summary>
 /// <param name="rootDirResource">ルートディレクトリのリソース</param>
 public void BootInit(string rootDirResource)
 {
     SettingData.BootInit(rootDirResource);
     LayerSetting.BootInit(SettingData);
     ScenarioSetting.BootInit(SettingData);
     CharacterSetting.BootInit(SettingData);
     TextureSetting.BootInit(SettingData);
     SoundSetting.BootInit(SettingData);
     SceneGallerySetting.BootInit(SettingData);
 }
示例#7
0
        /// <summary>
        /// 设置父子关系
        /// </summary>
        /// <param name="parentObj"></param>
        /// <param name="childObj"></param>
        public static void SetParent(Transform parentObj, Transform childObj)
        {
            var layerName = LayerSetting.Default;

            if (null != parentObj)
            {
                childObj.SetParent(parentObj);
                layerName = LayerMask.LayerToName(parentObj.gameObject.layer);
            }
            LayerSetting.ChangeLayer(childObj, layerName);
        }
示例#8
0
        static public void MaskShape(Light2D light, LightTilemapCollider2D id, LayerSetting layerSetting)
        {
            Vector2 lightPosition = -light.transform.position;

            LightTilemapCollider.Base tilemap = id.GetCurrentTilemap();

            bool isGrid = !tilemap.IsPhysicsShape();

            Vector2 scale = tilemap.TileWorldScale();

            float rotation = id.transform.eulerAngles.z;

            MeshObject tileMesh = null;

            if (isGrid)
            {
                tileMesh = LightTile.GetStaticMesh(tilemap);
            }

            int count = tilemap.chunkManager.GetTiles(light.GetWorldRect());

            for (int i = 0; i < count; i++)
            {
                LightTile tile = tilemap.chunkManager.display[i];

                Vector2 tilePosition = tilemap.TileWorldPosition(tile);

                tilePosition += lightPosition;

                if (tile.NotInRange(tilePosition, light.size))
                {
                    continue;
                }

                if (isGrid == false)
                {
                    tileMesh = null;
                    tileMesh = tile.GetDynamicMesh();
                }

                if (tileMesh == null)
                {
                    continue;
                }

                Color color = LayerSettingColor.Get(tilePosition, layerSetting, MaskEffect.Lit, 1); // 1?

                GL.Color(color);

                GLExtended.DrawMeshPass(tileMesh, tilePosition, scale, rotation + tile.rotation);
            }

            GL.Color(Color.white);
        }
 /// <summary>
 /// データをクリア
 /// </summary>
 public void Clear()
 {
     settingData = new AdvBootSetting();
     LayerSetting.Clear();
     CharacterSetting.Clear();
     TextureSetting.Clear();
     SoundSetting.Clear();
     ScenarioSetting.Clear();
     DefaultParam.Clear();
     SceneGallerySetting.Clear();
 }
示例#10
0
        public LayerSetting[] Get()
        {
            for (int i = 0; i < list.Length; i++)
            {
                if (list[i] == null)
                {
                    list[i] = new LayerSetting();
                }
            }

            return(list);
        }
示例#11
0
    void Start()
    {
        SetMaterial();

        for (int i = 0; i < layerCount; i++)
        {
            if (layerSetting[i] == null)
            {
                layerSetting[i]         = new LayerSetting();
                layerSetting[i].layerID = LightingLayer.Layer1;
            }
        }
    }
示例#12
0
    void Start()
    {
        SetMaterial();

        for (int i = 0; i < layerCount; i++)
        {
            if (layerSetting[i] == null)
            {
                layerSetting[i]                = new LayerSetting();
                layerSetting[i].layerID        = LightingLayer.Layer1;
                layerSetting[i].type           = LightingLayerType.Default;
                layerSetting[i].renderingOrder = LightRenderingOrder.Default;
            }
        }
    }
示例#13
0
        public static void SetPass(Light2D lightObject, LayerSetting layer)
        {
            light       = lightObject;
            lightSize   = Mathf.Sqrt(light.size * light.size + light.size * light.size);
            lightOffset = -light.transform2D.position;

            effectLayer = layer.shadowEffectLayer;

            objectOffset = Vector2.zero;

            effectPolygons.Clear();

            softShadowObjects = layer.shadowEffect == LightLayerShadowEffect.SoftObjects;

            softShadow = softShadowObjects || layer.shadowEffect == LightLayerShadowEffect.SoftVertex;

            if (lightObject.IsPixelPerfect())
            {
                Camera camera = Camera.main;

                Vector2 pos = LightingPosition.GetPosition2D(-camera.transform.position);

                drawOffset = light.transform2D.position + pos;
            }
            else
            {
                drawOffset = Vector2.zero;
            }

            if (layer.shadowEffect == LightLayerShadowEffect.Projected)
            {
                drawMode = 2;

                GenerateEffectLayers();
            }
            else if (softShadow)
            {
                drawMode = 1;
            }
            else if (layer.shadowEffect == LightLayerShadowEffect.SpriteProjection)
            {
                drawMode = 3;
            }
            else
            {
                drawMode = 0;
            }
        }
示例#14
0
        public static void Draw(Light2D light)
        {
            ShadowEngine.Prepare(light);

            LayerSetting[] layerSettings = light.GetLayerSettings();

            if (layerSettings == null)
            {
                return;
            }

            if (layerSettings.Length < 1)
            {
                return;
            }

            for (int layerID = 0; layerID < layerSettings.Length; layerID++)
            {
                LayerSetting layerSetting = layerSettings[layerID];

                if (layerSetting == null)
                {
                    continue;
                }

                if (pass.Setup(light, layerSetting) == false)
                {
                    continue;
                }

                ShadowEngine.SetPass(light, layerSetting);

                if (layerSetting.sorting == LightLayerSorting.None)
                {
                    NoSort.Draw(pass);
                }
                else
                {
                    pass.sortPass.SortObjects();

                    Sorted.Draw(pass);
                }
            }

            LightSource.Main.Draw(light);
        }
示例#15
0
        private void LoadLayerSetting(string layerName, int layerIndex, bool visible)
        {
            LayerSetting setting = new LayerSetting
            {
                doExport   = visible,
                layerIndex = layerIndex,
                pivot      = Pivot,
                scaleBy    = PSDExporter.ScaleDown.Default
            };

            string layerPath   = GetLayerPath(layerName);
            Sprite layerSprite = (Sprite)AssetDatabase.LoadAssetAtPath(layerPath, typeof(Sprite));

            if (layerSprite != null)
            {
                // Layer import size is stored via tags
                string[] labels = AssetDatabase.GetLabels(layerSprite);
                foreach (var label in labels)
                {
                    if (label.Equals(TagImport1))
                    {
                        setting.scaleBy = PSDExporter.ScaleDown.Default;
                    }
                    if (label.Equals(TagImport2))
                    {
                        setting.scaleBy = PSDExporter.ScaleDown.Half;
                    }
                    if (label.Equals(TagImport4))
                    {
                        setting.scaleBy = PSDExporter.ScaleDown.Quarter;
                    }
                }                 // End label loop

                // Anchor is determined by import settings

                // Get the texture importer for the asset
                TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(layerPath);
                // Read out the texture import settings so import pivot point can be changed
                TextureImporterSettings importSetting = new TextureImporterSettings();
                textureImporter.ReadTextureSettings(importSetting);

                setting.pivot = (SpriteAlignment)importSetting.spriteAlignment;
            }             // End layer settings loading

            layerSettings.Add(layerIndex, setting);
        }
        /// <summary>
        /// 起動時の初期化
        /// </summary>
        /// <param name="rootDirResource">ルートディレクトリのリソース</param>
        public void BootInit(string rootDirResource)
        {
            if (importVersion < Version)
            {
                Debug.LogError("Version Error! Please Import Scenario Data");
            }

            SettingData.BootInit(rootDirResource);
            LayerSetting.BootInit(SettingData);
            CharacterSetting.BootInit(SettingData);
            TextureSetting.BootInit(SettingData);
            SoundSetting.BootInit(SettingData);
            DefaultParam.BootInit();
            SceneGallerySetting.BootInit(SettingData);
            ScenarioSetting.BootInit(SettingData);
            PageContoroller.Clear();
        }
示例#17
0
    static int ChangeLayer(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1 && TypeChecker.CheckTypes <UnityEngine.GameObject>(L, 1))
            {
                UnityEngine.GameObject arg0 = (UnityEngine.GameObject)ToLua.ToObject(L, 1);
                LayerSetting.ChangeLayer(arg0);
                return(0);
            }
            else if (count == 1 && TypeChecker.CheckTypes <UnityEngine.Component>(L, 1))
            {
                UnityEngine.Component arg0 = (UnityEngine.Component)ToLua.ToObject(L, 1);
                LayerSetting.ChangeLayer(arg0);
                return(0);
            }
            else if (count == 2 && TypeChecker.CheckTypes <UnityEngine.GameObject, string>(L, 1))
            {
                UnityEngine.GameObject arg0 = (UnityEngine.GameObject)ToLua.ToObject(L, 1);
                string arg1 = ToLua.ToString(L, 2);
                LayerSetting.ChangeLayer(arg0, arg1);
                return(0);
            }
            else if (count == 2 && TypeChecker.CheckTypes <UnityEngine.Component, string>(L, 1))
            {
                UnityEngine.Component arg0 = (UnityEngine.Component)ToLua.ToObject(L, 1);
                string arg1 = ToLua.ToString(L, 2);
                LayerSetting.ChangeLayer(arg0, arg1);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: LayerSetting.ChangeLayer"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
        /// <summary>
        /// 設定データのエクセルシートを読み込む
        /// </summary>
        /// <param name="sheetName">シート名</param>
        /// <param name="grid">シートのStringGridデータ</param>
        public void ParseFromExcel(string sheetName, StringGrid grid)
        {
            importVersion = Version;
            switch (sheetName)
            {
            case SheetNameBoot:
                SettingData.InitFromStringGrid(grid);
                break;

            case SheetNameScenario:
                ScenarioSetting.InitFromStringGrid(grid);
                break;

            case SheetNameCharacter:
                CharacterSetting.InitFromStringGrid(grid);
                break;

            case SheetNameTexture:
                TextureSetting.InitFromStringGrid(grid);
                break;

            case SheetNameSound:
                SoundSetting.InitFromStringGrid(grid);
                break;

            case SheetNameLayer:
                LayerSetting.InitFromStringGrid(grid);
                break;

            case SheetNameParam:
                DefaultParam.InitFromStringGrid(grid);
                break;

            case SheetNameSceneGallery:
                SceneGallerySetting.InitFromStringGrid(grid);
                break;

            default:
                Debug.LogError(LanguageAdvErrorMsg.LocalizeTextFormat(AdvErrorMsg.NotSettingSheet, sheetName));
                break;
            }
        }
示例#19
0
    static public void DrawShadowsAndMask(LightingBuffer2D buffer, int layer)
    {
        buffer.CalculateCoords();

        offset.x = -buffer.lightSource.transform.position.x;
        offset.y = -buffer.lightSource.transform.position.y;

        manager = LightingManager2D.Get();

        layerSettings = buffer.lightSource.layerSetting[layer];

        z = buffer.transform.position.z;
        lightSizeSquared = Mathf.Sqrt(buffer.lightSource.lightSize * buffer.lightSource.lightSize + buffer.lightSource.lightSize * buffer.lightSource.lightSize);

        SortObjects(buffer, layer);

        drawMask = false;
        if (buffer.lightSource.layerSetting[layer].type != LightingLayerType.ShadowOnly)
        {
            drawMask = true;
        }

        drawShadows = false;
        if (buffer.lightSource.layerSetting[layer].type != LightingLayerType.MaskOnly)
        {
            drawShadows = true;
        }

        GL.PushMatrix();

        if (manager.lightingSpriteAtlas && SpriteAtlasManager.Get().atlasTexture != null)
        {
            DrawWithAtlas(buffer, layer);
        }
        else
        {
            DrawWithoutAtlas(buffer, layer);
        }

        GL.PopMatrix();
    }
示例#20
0
    public static Color Get(Vector2 position, LayerSetting layerSetting, MaskEffect maskEffect, float maskTranslucency)
    {
        if (maskEffect == MaskEffect.Unlit)
        {
            return(Color.black);
        }

        //	return(Color.white);
        if (layerSetting.maskEffect == LightLayerMaskEffect.AboveLit)
        {
            return(LayerSettingsColorEffects.GetColor(position.y, layerSetting));
        }
        else if (layerSetting.maskEffect == LightLayerMaskEffect.NeverLit)
        {
            return(Color.black);
        }
        else
        {
            return(new Color(1, 1, 1, maskTranslucency));
        }
    }
示例#21
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        // target 은 값을 가져오는 용도로만 사용 가능.
        LayerSetting ls = target as LayerSetting;

        ls.AddLayerMatchingComponent();

        ShowList(layerMaskProp);

        // target 은 값을 가져오는 용도로만 사용 가능.
//        LayerSetting ls = target as LayerSetting;

        serializedObject.ApplyModifiedProperties();

        //Rect r = GUILayoutUtility.GetRect(0f, 16f);
        //bool showNext = EditorGUI.PropertyField(r, layerProp, true);
        //bool hasName = layerProp.NextVisible(showNext);

        //        if (layerListFold = EditorGUILayout.Foldout(layerListFold, "Layers"))
    }
示例#22
0
        private void listSubLayerNum_SelectedIndexChanged(object sender, EventArgs e)
        {
            int sublayerNum = Convert.ToInt32(listSubLayerNum.Text);

            int LayoutIdx = m_listBoxLayout.SelectedIndex;
            int layerIdx  = cbxListLayer.SelectedIndex;

            if (LayoutIdx < 0 || layerIdx < 0)
            {
                return;
            }

            LayerSetting curLayerSetting = m_LayoutSettingList.Items[LayoutIdx].Layout.layerSetting[layerIdx];

            subLayerPanel.Controls.Clear();
            for (int i = 0; i < sublayerNum; i++)
            {
                Panel panel = BuileSubLayerPanel();
                subLayerPanel.Controls.Add(panel);

                if (i >= curLayerSetting.subLayerNum)
                {
                    continue;
                }

                //bool enableLine = ((curLayerSetting.nEnableLine >> i) & 1) == 1 ? true : false;
                bool enableLine = true;
                int  source     = ((curLayerSetting.nlayersource >> (i * 2)) & 0x3);
                int  dataType   = 0;
                if (curLayerSetting.ndatasource != null && curLayerSetting.ndatasource.Length > i)
                {
                    dataType = (int)curLayerSetting.ndatasource[i];
                }

                SetSubLayerPanel(panel, enableLine, curLayerSetting.printColor[i], source, dataType);
            }

            subLayerPanel.Refresh();
        }
示例#23
0
    static int _CreateLayerSetting(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 0)
            {
                LayerSetting obj = new LayerSetting();
                ToLua.PushObject(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: LayerSetting.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
示例#24
0
    public static Color GetColor(float positionDistance, LayerSetting layerSetting)
    {
        float distance = 0.001f;         //layerSetting.maskEffectDistance;

        float pos, c;

        if (distance > 0)
        {
            pos = (positionDistance - distance / 2) / distance;

            c = (pos + 1);
        }
        else
        {
            pos = positionDistance;

            if (pos < 0)
            {
                c = 0;
            }
            else
            {
                c = 1;
            }
        }

        if (c < 0)
        {
            c = 0;
        }

        if (c > 1)
        {
            c = 1;
        }

        return(new Color(c, c, c, 1));
    }
示例#25
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        var coll = indexLayerName.Keys;

        layerProp.arraySize = coll.Count;

        // target 은 값을 가져오는 용도로만 사용할 것
        LayerSetting ls = target as LayerSetting;

        ls.UpdateLayerMask();

        EditorGUILayout.PropertyField(layerMaskProp);
        ShowList(layerProp);

        serializedObject.ApplyModifiedProperties();

        //Rect r = GUILayoutUtility.GetRect(0f, 16f);
        //bool showNext = EditorGUI.PropertyField(r, layerProp, true);
        //bool hasName = layerProp.NextVisible(showNext);

        //        if (layerListFold = EditorGUILayout.Foldout(layerListFold, "Layers"))
    }
示例#26
0
        public static void DrawCollisions(Light2D light)
        {
            ShadowEngine.Prepare(light);

            LayerSetting[] layerSettings = light.GetLayerSettings();

            if (layerSettings == null)
            {
                return;
            }

            if (layerSettings.Length < 1)
            {
                return;
            }

            for (int layerID = 0; layerID < layerSettings.Length; layerID++)
            {
                LayerSetting layerSetting = layerSettings[layerID];

                if (layerSetting == null)
                {
                    continue;
                }

                if (pass.Setup(light, layerSetting) == false)
                {
                    continue;
                }

                ShadowEngine.SetPass(light, layerSetting);

                NoSort.Shadows.Draw(pass);
            }

            // LightSource.Main.Draw(light);
        }
示例#27
0
    public static Color Get(LightColliderShape lightShape, Vector2 position, LayerSetting layerSetting, MaskEffect maskEffect, float maskTranslucency)
    {
        if (maskEffect == MaskEffect.Unlit)
        {
            return(Color.black);
        }

        if (maskEffect == MaskEffect.Isometric)
        {
            Rect rect = lightShape.GetIsoWorldRect();
            if (rect.width < rect.height)
            {
                float x = position.y + position.x / 2;
                return(LayerSettingsColorEffects.GetColor(x, layerSetting));
            }
            else
            {
                float y = position.y - position.x / 2;
                return(LayerSettingsColorEffects.GetColor(y, layerSetting));
            }
        }

        //	return(Color.white);
        if (layerSetting.maskEffect == LightLayerMaskEffect.AboveLit)
        {
            return(LayerSettingsColorEffects.GetColor(position.y, layerSetting));
        }
        else if (layerSetting.maskEffect == LightLayerMaskEffect.NeverLit)
        {
            return(Color.black);
        }
        else
        {
            return(new Color(1, 1, 1, maskTranslucency));
        }
    }
示例#28
0
        static public void Sprite(Light2D light, LightTilemapCollider2D id, Material material, LayerSetting layerSetting)
        {
            Vector2 lightPosition = -light.transform.position;

            LightTilemapCollider.Base tilemap = id.GetCurrentTilemap();
            Vector2 scale    = tilemap.TileWorldScale();
            float   rotation = id.transform.eulerAngles.z;

            int count = tilemap.chunkManager.GetTiles(light.GetWorldRect());

            Texture2D currentTexture = null;
            Color     currentColor   = Color.black;

            GL.Begin(GL.QUADS);

            for (int i = 0; i < count; i++)
            {
                LightTile tile = tilemap.chunkManager.display[i];

                if (tile.GetOriginalSprite() == null)
                {
                    return;
                }

                Vector2 tilePosition = tile.GetWorldPosition(tilemap);

                tilePosition += lightPosition;

                if (tile.NotInRange(tilePosition, light.size))
                {
                    continue;
                }

                virtualSpriteRenderer.sprite = tile.GetOriginalSprite();

                if (virtualSpriteRenderer.sprite.texture == null)
                {
                    continue;
                }

                Color color = LayerSettingColor.Get(tilePosition, layerSetting, MaskEffect.Lit, 1); // 1?

                if (currentTexture != virtualSpriteRenderer.sprite.texture || currentColor != color)
                {
                    currentTexture = virtualSpriteRenderer.sprite.texture;
                    currentColor   = color;

                    material.mainTexture = currentTexture;
                    material.color       = currentColor;

                    material.SetPass(0);
                }

                Universal.Sprite.FullRect.Simple.Draw(tile.spriteMeshObject, material, virtualSpriteRenderer, tilePosition, scale * tile.scale, rotation + tile.rotation);
            }

            GL.End();

            material.mainTexture = null;
        }
示例#29
0
        static public void BumpedSprite(Light2D light, LightTilemapCollider2D id, Material material, LayerSetting layerSetting)
        {
            Texture bumpTexture = id.bumpMapMode.GetBumpTexture();

            if (bumpTexture == null)
            {
                return;
            }

            material.SetTexture("_Bump", bumpTexture);

            Vector2 lightPosition = -light.transform.position;

            LightTilemapCollider.Base tilemap = id.GetCurrentTilemap();
            Vector2 scale = tilemap.TileWorldScale();

            Texture2D currentTexture = null;

            GL.Begin(GL.QUADS);

            foreach (LightTile tile in tilemap.mapTiles)
            {
                if (tile.GetOriginalSprite() == null)
                {
                    return;
                }

                Vector2 tilePosition = tilemap.TileWorldPosition(tile);

                tilePosition += lightPosition;

                if (tile.NotInRange(tilePosition, light.size))
                {
                    continue;
                }

                virtualSpriteRenderer.sprite = tile.GetOriginalSprite();

                if (virtualSpriteRenderer.sprite.texture == null)
                {
                    continue;
                }

                if (currentTexture != virtualSpriteRenderer.sprite.texture)
                {
                    currentTexture       = virtualSpriteRenderer.sprite.texture;
                    material.mainTexture = currentTexture;

                    material.SetPass(0);
                }

                Color color = LayerSettingColor.Get(tilePosition, layerSetting, MaskEffect.Lit, 1); // 1

                GLExtended.SetColor(color);

                Universal.Sprite.FullRect.Simple.DrawPass(tile.spriteMeshObject, virtualSpriteRenderer, tilePosition, scale, tile.worldRotation);
            }

            GL.End();

            material.mainTexture = null;
        }
		private void LoadLayerSetting(string layerName, int layerIndex, bool visible)
		{
			LayerSetting setting = new LayerSetting
			{
				doExport = visible,
				layerIndex = layerIndex,
				pivot = Pivot,
				scaleBy = PSDExporter.ScaleDown.Default
			};

			string layerPath = GetLayerPath(layerName);
			Sprite layerSprite = (Sprite)AssetDatabase.LoadAssetAtPath(layerPath, typeof(Sprite));
			if (layerSprite != null)
			{
				// Layer import size is stored via tags
				string[] labels = AssetDatabase.GetLabels(layerSprite);
				foreach (var label in labels)
				{
					if (label.Equals(TagImport1))
						setting.scaleBy = PSDExporter.ScaleDown.Default;
					if (label.Equals(TagImport2))
						setting.scaleBy = PSDExporter.ScaleDown.Half;
					if (label.Equals(TagImport4))
						setting.scaleBy = PSDExporter.ScaleDown.Quarter;
				} // End label loop

				// Anchor is determined by import settings

				// Get the texture importer for the asset
				TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(layerPath);
				// Read out the texture import settings so import pivot point can be changed
				TextureImporterSettings importSetting = new TextureImporterSettings();
				textureImporter.ReadTextureSettings(importSetting);

				setting.pivot = (SpriteAlignment) importSetting.spriteAlignment;
			} // End layer settings loading

			layerSettings.Add(layerIndex, setting);
		}
		private void SaveLayerSetting(LayerSetting setting)
		{
			// Not exporting, don't save layer settings
			if (!setting.doExport)
				return;

			// Get the asset
			var layer = Psd.Layers[setting.layerIndex];
			string layerPath = GetLayerPath(layer.Name);
			var layerSprite = AssetDatabase.LoadAssetAtPath(layerPath, typeof(Sprite));

			if (layerSprite == null)
				return;

			// Write out the labels for the layer settings
			// layer settings is just import size
			string[] labels = new string[1];

			if (setting.scaleBy == PSDExporter.ScaleDown.Default)
				labels[0] = TagImport1;
			if (setting.scaleBy == PSDExporter.ScaleDown.Half)
				labels[0] = TagImport2;
			if (setting.scaleBy == PSDExporter.ScaleDown.Quarter)
				labels[0] = TagImport4;

			// Write the label for the texture
			AssetDatabase.SetLabels(layerSprite, labels);

			// Set the alignment for the texture

			// Get the texture importer for the asset
			TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(layerPath);
			// Read out the texture import settings so import pivot point can be changed
			TextureImporterSettings importSetting = new TextureImporterSettings();
			textureImporter.ReadTextureSettings(importSetting);

			// Set the alignment
			importSetting.spriteAlignment = (int) setting.pivot;

			// And write settings into the importer
			textureImporter.SetTextureSettings(importSetting);

			EditorUtility.SetDirty(layerSprite);
			AssetDatabase.WriteImportSettingsIfDirty(layerPath);
			AssetDatabase.ImportAsset(layerPath, ImportAssetOptions.ForceUpdate);
		}
示例#32
0
        public static void Mask(Light2D light, LightCollider2D id, Material material, LayerSetting layerSetting)
        {
            if (id.InLight(light) == false)
            {
                return;
            }

            foreach (LightColliderShape shape in id.shapes)
            {
                SkinnedMeshRenderer skinnedMeshRenderer = shape.skinnedMeshShape.GetSkinnedMeshRenderer();

                if (skinnedMeshRenderer == null)
                {
                    return;
                }

                List <MeshObject> meshObject = shape.GetMeshes();

                if (meshObject == null)
                {
                    return;
                }

                if (skinnedMeshRenderer.sharedMaterial != null)
                {
                    material.mainTexture = skinnedMeshRenderer.sharedMaterial.mainTexture;
                }
                else
                {
                    material.mainTexture = null;
                }

                Vector2 position = shape.transform2D.position - light.transform2D.position;

                Vector2 pivotPosition = shape.GetPivotPoint() - light.transform2D.position;
                material.color = LayerSettingColor.Get(pivotPosition, layerSetting, id.maskEffect, id.maskTranslucency);

                material.SetPass(0);

                GLExtended.DrawMesh(meshObject, position, id.mainShape.transform2D.scale, shape.transform2D.rotation);

                material.mainTexture = null;
            }
        }