Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
Open-source release
Browse files Browse the repository at this point in the history
  • Loading branch information
SSS135 committed Jan 25, 2017
0 parents commit 72f03cb
Show file tree
Hide file tree
Showing 405 changed files with 92,401 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[Ll]ibrary/
[Tt]emp/
[Oo]bj/
[Bb]uild/
# Autogenerated VS/MD solution and project files
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
# Unity3D generated meta files
*.pidb.meta
# Unity3D Generated File On Crash Reports
sysinfo.txt
Assets/UnityVS/Editor/UnityVS.VersionSpecific.dll*
Assets/Data/FMOD/.cache/
/Assets/UnityVS/Editor/SyntaxTree.VisualStudio.Unity.Messaging.dll
/Assets/UnityVS/Editor/SyntaxTree.VisualStudio.Unity.Messaging.dll.meta
/Assets/UnityVS/Editor/SyntaxTree.VisualStudio.Unity.Bridge.dll
/Assets/UnityVS/Editor/SyntaxTree.VisualStudio.Unity.Bridge.dll.meta
/compilation log.txt
.hg/*
9 changes: 9 additions & 0 deletions Assets/Light2D.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Assets/Light2D/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 95 additions & 0 deletions Assets/Light2D/Editor/Light2DMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEditor;
using UnityEngine;

namespace Light2D
{
public static class Light2DMenu
{
[MenuItem("GameObject/Light2D/Lighting System", false, 6)]
public static void CreateLightingSystem()
{
LightingSystemCreationWindow.CreateWindow();
}

[MenuItem("GameObject/Light2D/Light Obstacle", false, 6)]
public static void CreateLightObstacle()
{
var baseObjects = Selection.gameObjects.Select(o => o.GetComponent<Renderer>()).Where(r => r != null).ToList();
if (baseObjects.Count == 0)
{
Debug.LogError("Can't create light obstacle from selected object. You need to select any object with renderer attached to it to create light obstacle.");
}

foreach (var gameObj in baseObjects)
{
var name = gameObj.name + " Light Obstacle";

var child = gameObj.transform.FindChild(name);
var obstacleObj = child == null ? new GameObject(name) : child.gameObject;

foreach (var obstacleSprite in obstacleObj.GetComponents<LightObstacleSprite>())
Util.Destroy(obstacleSprite);

obstacleObj.transform.parent = gameObj.transform;
obstacleObj.transform.localPosition = Vector3.zero;
obstacleObj.transform.localRotation = Quaternion.identity;
obstacleObj.transform.localScale = Vector3.one;

obstacleObj.AddComponent<LightObstacleSprite>();
}
}

[MenuItem("GameObject/Light2D/Light Source", false, 6)]
public static void CreateLightSource()
{
var obj = new GameObject("Light");
if (LightingSystem.Instance != null)
obj.layer = LightingSystem.Instance.LightSourcesLayer;
var light = obj.AddComponent<LightSprite>();
light.Material = AssetDatabase.LoadAssetAtPath<Material>("Assets/Light2D/Materials/Light60Points.mat");
light.Sprite = Resources.Load<Sprite>("DefaultLight");
light.Color = new Color(1, 1, 1, 0.5f);
Selection.activeObject = obj;
}

[MenuItem("GameObject/Light2D/Enable 2DTK Support", false, 6)]
public static void Enable2DToolkitSupport()
{
var targets = (BuildTargetGroup[]) Enum.GetValues(typeof (BuildTargetGroup));
foreach (var target in targets)
DefineSymbol("LIGHT2D_2DTK", target);
}

[MenuItem("GameObject/Light2D/Disable 2DTK Support", false, 6)]
public static void Disable2DToolkitSupport()
{
var targets = (BuildTargetGroup[])Enum.GetValues(typeof(BuildTargetGroup));
foreach (var target in targets)
UndefineSymbol("LIGHT2D_2DTK", target);
}

public static void DefineSymbol(string symbol, BuildTargetGroup target)
{
UndefineSymbol(symbol, target);

var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(target);
if (!defines.EndsWith(";"))
defines += ";";
defines += symbol;
PlayerSettings.SetScriptingDefineSymbolsForGroup(target, defines);
}

public static void UndefineSymbol(string symbol, BuildTargetGroup target)
{
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(target);
defines = defines.Replace(symbol + ";", "");
defines = defines.Replace(";" + symbol, "");
defines = defines.Replace(symbol, "");
PlayerSettings.SetScriptingDefineSymbolsForGroup(target, defines);
}
}
}
8 changes: 8 additions & 0 deletions Assets/Light2D/Editor/Light2DMenu.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions Assets/Light2D/Editor/LightingSystemCreationWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEditor;
using UnityEngine;

namespace Light2D
{
public class LightingSystemCreationWindow : EditorWindow
{
private int _lightObstaclesLayer;
private int _lightSourcesLayer;
private int _ambientLightLayer;

public static void CreateWindow()
{
var window = GetWindow<LightingSystemCreationWindow>("Lighting system creation window");
window.position = new Rect(200, 200, 500, 140);
}

void OnGUI()
{
if (FindObjectOfType<LightingSystem>())
{
GUILayout.Label("WARNING: existing lighting system is found.\nIt is recommended to remove it first, before adding new one.", EditorStyles.boldLabel);
}

GUILayout.Label("Select layers you wish to use. You could modify them later in created object.");
_lightObstaclesLayer = EditorGUILayout.LayerField("Light Obstacles", _lightObstaclesLayer);
_lightSourcesLayer = EditorGUILayout.LayerField("Light Sources", _lightSourcesLayer);
_ambientLightLayer = EditorGUILayout.LayerField("Ambient Light", _ambientLightLayer);

if (GUILayout.Button("Create"))
{
var mainCamera = Camera.main;
var lighingSystem = mainCamera.GetComponent<LightingSystem>() ?? mainCamera.gameObject.AddComponent<LightingSystem>();

var prefab = Resources.Load<GameObject>("Lighting Camera");
var lightingSystemObj = (GameObject)Instantiate(prefab);
lightingSystemObj.name = lightingSystemObj.name.Replace("(Clone)", "");
lightingSystemObj.transform.parent = mainCamera.transform;
lightingSystemObj.transform.localPosition = Vector3.zero;
lightingSystemObj.transform.localScale = Vector3.one;
lightingSystemObj.transform.localRotation = Quaternion.identity;

var config = lightingSystemObj.GetComponent<LightingSystemPrefabConfig>();

lighingSystem.LightCamera = lightingSystemObj.GetComponent<Camera>();
lighingSystem.AmbientLightComputeMaterial = config.AmbientLightComputeMaterial;
lighingSystem.LightOverlayMaterial = config.LightOverlayMaterial;
lighingSystem.AmbientLightBlurMaterial = lighingSystem.LightSourcesBlurMaterial = config.BlurMaterial;

DestroyImmediate(config);

lighingSystem.LightCamera.depth = mainCamera.depth - 1;

lighingSystem.LightCamera.cullingMask = 1 << _lightSourcesLayer;

lighingSystem.LightSourcesLayer = _lightSourcesLayer;
lighingSystem.AmbientLightLayer = _ambientLightLayer;
lighingSystem.LightObstaclesLayer = _lightObstaclesLayer;

mainCamera.cullingMask &=
~((1 << _lightSourcesLayer) | (1 << _ambientLightLayer) | (1 << _lightObstaclesLayer));

Close();
}
}
}
}
8 changes: 8 additions & 0 deletions Assets/Light2D/Editor/LightingSystemCreationWindow.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 72f03cb

Please sign in to comment.