IEnumerator deleteProc()
    {
        // Iterate each object o array
        foreach (GameObject g in casters)
        {
            // if object is not null, destroy
            if (g != null)
            {
                // destroy and dont wait
                DestroyImmediate(g);
                if (dl)
                {
                    // if exist a light, then wait for end of frame for avoid rendering issues
                    yield return(new WaitForSeconds(.01f));

                    // call rebuild, and light will be updated
                    dl.Rebuild();
                }
                break;
            }
        }
        //restore key value after .1 sec
        yield return(new WaitForSeconds(.1f));

        key = false;
    }
    void OnSceneGUI()
    {
        if (light)
        {
            Transform lTransform = light.transform;
            Vector3   oldPoint   = lTransform.TransformPoint(new Vector3(light.LightRadius, 0, 0));
            float     size       = HandleUtility.GetHandleSize(oldPoint);


            Undo.RecordObject(light, "Move Light Radius Point");


            Vector3 newPoint = Handles.FreeMoveHandle(
                oldPoint, Quaternion.identity, size * 0.05f, pointSnap, Handles.DotCap);

            if (oldPoint != newPoint)
            {
                Undo.RecordObject(light, "resize radiusLight");
                light.LightRadius = (lTransform.InverseTransformPoint(newPoint).magnitude);
                light.Rebuild();
            }

            Vector3 oldPoint2 = lTransform.TransformPoint(new Vector3(-light.LightRadius, 0, 0));
            //oldPoint2.x *=-1;
            Vector3 newPoint2 = Handles.FreeMoveHandle(
                oldPoint2, Quaternion.identity, size * 0.05f, pointSnap, Handles.DotCap);

            if (oldPoint2 != newPoint2)
            {
                Undo.RecordObject(light, "resize radiusLight");
                light.LightRadius = (lTransform.InverseTransformPoint(newPoint2).magnitude);
                light.Rebuild();
            }



            Handles.color = Color.yellow;
            Handles.DrawWireDisc(lTransform.position, new Vector3(0, 0, -1), light.LightRadius);
            if (light.RangeAngle < 360)
            {
                Handles.DrawLine(lTransform.position, lTransform.TransformPoint(light.getMaxFromAllVerts()));
                Handles.DrawLine(lTransform.position, lTransform.TransformPoint(light.getMinFromAllVerts()));
            }

            dragAndDropEvents();
        }
    }
Esempio n. 3
0
        static void addSpotCar()
        {
            reloadAsset();

            //main spot

            Material   m          = AssetDatabase.LoadAssetAtPath(_path + "Prefabs/Lights/Materials/StandardSpotCarType1.mat", typeof(Material)) as Material;
            GameObject gameObject = new GameObject("2DSpotCar");

            gameObject.transform.position = getCameraPos();
            DynamicLight2D.DynamicLight s = gameObject.AddComponent <DynamicLight2D.DynamicLight>();
            s.Layer.value = AssetUtility.LoadPropertyAsInt("layerMask", tmpAsset);
            s.Version     = AssetUtility.LoadProperty("version", tmpAsset);
            s.setMainMaterial(m);
            s.Rebuild();
            s.Segments           = 5;
            s.RangeAngle         = 107;
            s.SolidColor         = true;
            s.LightColor         = new Color(229 / 255f, 1f, 171 / 255f);
            s.uv_Offset          = new Vector2(.5f, 0f);
            s.uv_Scale           = new Vector2(1.25f, 1f);
            s.debugLines         = false;
            s.recalculateNormals = false;
            s.SortOrderID        = -1;

            //Slave spot
            //m = AssetDatabase.LoadAssetAtPath(_path + "Prefabs/Lights/Materials/StandardSpotCarType1.mat", typeof(Material)) as Material;
            GameObject gameObject2 = new GameObject("2DSpotCarBright");

            gameObject2.transform.parent = gameObject.transform;
            s             = gameObject2.AddComponent <DynamicLight2D.DynamicLight>();
            s.Layer.value = AssetUtility.LoadPropertyAsInt("layerMask", tmpAsset);
            s.Version     = AssetUtility.LoadProperty("version", tmpAsset);
            s.setMainMaterial(m);
            s.Rebuild();
            s.Segments           = 5;
            s.RangeAngle         = 180;
            s.LightRadius        = 20;
            s.SolidColor         = true;
            s.LightColor         = new Color(229 / 255f, 1f, 171 / 255f);
            s.uv_Offset          = new Vector2(.5f, 0f);
            s.uv_Scale           = new Vector2(.54f, 2.9f);
            s.debugLines         = false;
            s.recalculateNormals = false;
            s.SortOrderID        = -1;
        }
Esempio n. 4
0
    static void addGradient()
    {
        reloadAsset();
        Material   m          = AssetDatabase.LoadAssetAtPath(_path + "Materials/StandardLightMaterialGradient.mat", typeof(Material)) as Material;
        GameObject gameObject = new GameObject("2DLight");

        DynamicLight2D.DynamicLight s = gameObject.AddComponent <DynamicLight2D.DynamicLight>();
        s.Layer.value = AssetUtility.LoadPropertyAsInt("layerMask", tmpAsset);
        s.Version     = AssetUtility.LoadProperty("version", tmpAsset);
        s.setMainMaterial(m);
        s.Rebuild();
    }
Esempio n. 5
0
    static void addTexturized()
    {
        reloadAsset();
        Material   m          = AssetDatabase.LoadAssetAtPath(_path + "Prefabs/Lights/Materials/StandardLightTexturizedMaterial.mat", typeof(Material)) as Material;
        GameObject gameObject = new GameObject("2DLight");

        DynamicLight2D.DynamicLight s = gameObject.AddComponent <DynamicLight2D.DynamicLight>();
        s.Layer.value = AssetUtility.LoadPropertyAsInt("layerMask", tmpAsset);
        s.SolidColor  = true;
        s.LightColor  = Color.red;
        s.setMainMaterial(m);
        s.Version = AssetUtility.LoadProperty("version", tmpAsset);
        s.Rebuild();
    }
Esempio n. 6
0
        static void addSpot()
        {
            reloadAsset();
            Material   m          = AssetDatabase.LoadAssetAtPath(_path + "Prefabs/Lights/Materials/StandardLightMaterialGradient.mat", typeof(Material)) as Material;
            GameObject gameObject = new GameObject("2DLight");

            gameObject.transform.position = getCameraPos();
            DynamicLight2D.DynamicLight s = gameObject.AddComponent <DynamicLight2D.DynamicLight>();
            s.Layer.value = AssetUtility.LoadPropertyAsInt("layerMask", tmpAsset);
            s.Version     = AssetUtility.LoadProperty("version", tmpAsset);
            s.setMainMaterial(m);
            s.Rebuild();
            s.Segments    = 9;
            s.RangeAngle  = 90;
            s.SortOrderID = -1;
        }
Esempio n. 7
0
        static void addTexturized2()
        {
            reloadAsset();
            Material   m          = AssetDatabase.LoadAssetAtPath(_path + "Prefabs/Lights/Materials/StandardLightTexturizedMaterialBlend.mat", typeof(Material)) as Material;
            GameObject gameObject = new GameObject("2DDLight");

            gameObject.transform.position = getCameraPos();
            DynamicLight2D.DynamicLight s = gameObject.AddComponent <DynamicLight2D.DynamicLight>();
            s.Layer.value = AssetUtility.LoadPropertyAsInt("layerMask", tmpAsset);
            s.SolidColor  = true;
            s.LightColor  = Color.red;
            s.uv_Scale    = new Vector3(.38f, .38f);
            s.SortOrderID = -1;
            s.setMainMaterial(m);
            s.Version = AssetUtility.LoadProperty("version", tmpAsset);
            s.Rebuild();
        }
Esempio n. 8
0
        static void addOccluder()
        {
            reloadAsset();
            Material   m          = AssetDatabase.LoadAssetAtPath(_path + "Prefabs/Lights/Materials/StandardOccluderMaterial.mat", typeof(Material)) as Material;
            GameObject gameObject = new GameObject("2DDLight");

            gameObject.transform.position = getCameraPos();
            DynamicLight2D.DynamicLight s = gameObject.AddComponent <DynamicLight2D.DynamicLight>();
            s.Layer.value = AssetUtility.LoadPropertyAsInt("layerMask", tmpAsset);
            s.SolidColor  = true;
            s.LightColor  = new Color(59 / 255f, 122 / 255f, 59 / 255f);
            s.uv_Scale    = new Vector3(.38f, .38f);
            s.SortOrderID = -1;
            s.setMainMaterial(m);
            //s.strokeRender = .35f;
            s.Segments = 30;
            //s.intelliderConvex = false;
            s.Version = AssetUtility.LoadProperty("version", tmpAsset);
            s.Rebuild();
        }
Esempio n. 9
0
        static void addSight()
        {
            //EditorUtility.DisplayDialog("NOTES","1. Events require 'Game' window and at least one 'Camera' to get working (runtime or/and editor). ", "OK");



            // adding sight object

            reloadAsset();
            Material   m          = AssetDatabase.LoadAssetAtPath(_path + "Prefabs/Lights/Materials/StandardLightMaterialGradient.mat", typeof(Material)) as Material;
            GameObject gameObject = new GameObject("2DSight");

            DynamicLight2D.DynamicLight s = gameObject.AddComponent <DynamicLight2D.DynamicLight>();
            s.Layer.value = AssetUtility.LoadPropertyAsInt("layerMask", tmpAsset);
            s.Version     = AssetUtility.LoadProperty("version", tmpAsset);
            s.setMainMaterial(m);
            s.Rebuild();
            s.Segments    = 5;
            s.RangeAngle  = 80;
            s.SortOrderID = -1;

            //Enable events
            s.useEvents          = true;
            s.objectsWithinSight = true;



            //adding listener
            Object     prefab = AssetDatabase.LoadAssetAtPath(_path + "Prefabs/Casters/box.prefab", typeof(GameObject));
            GameObject go     = Instantiate(prefab, new Vector3(0, 7f, 0), Quaternion.Euler(new Vector3(0, 0, 0.0001f))) as GameObject;

            go.name = "2DSight_Listener";
            go.AddComponent <SightListenerTemplate> ();
            go.layer = AssetUtility.LoadPropertyAsInt("layerCaster", tmpAsset);
            //SightListenerTemplate listener = go.GetComponent<SightListenerTemplate> ();

            s.addingPersistentUnityEvents(go);

            //EditorUtility.SetDirty (s);
        }
    void OnSceneGUI()
    {
        if (light)
        {
            Transform lTransform = light.transform;
            Vector3   oldPoint   = lTransform.TransformPoint(new Vector3(light.LightRadius, 0, 0));
            float     size       = HandleUtility.GetHandleSize(oldPoint);


            Undo.RecordObject(light, "Move Light Radius Point");


            Vector3 newPoint = Handles.FreeMoveHandle(
                oldPoint, Quaternion.identity, size * 0.05f, pointSnap, Handles.DotCap);

            if (oldPoint != newPoint)
            {
                Undo.RecordObject(light, "resize radiusLight");
                light.LightRadius = (lTransform.InverseTransformPoint(newPoint).magnitude);
                light.Rebuild();
            }

            Vector3 oldPoint2 = lTransform.TransformPoint(new Vector3(-light.LightRadius, 0, 0));
            //oldPoint2.x *=-1;
            Vector3 newPoint2 = Handles.FreeMoveHandle(
                oldPoint2, Quaternion.identity, size * 0.05f, pointSnap, Handles.DotCap);

            if (oldPoint2 != newPoint2)
            {
                Undo.RecordObject(light, "resize radiusLight");
                light.LightRadius = (lTransform.InverseTransformPoint(newPoint2).magnitude);
                light.Rebuild();
            }



            Handles.color = Color.yellow;
            Handles.DrawWireDisc(lTransform.position, new Vector3(0, 0, -1), light.LightRadius);
            if (light.RangeAngle < 360)
            {
                Handles.DrawLine(lTransform.position, lTransform.TransformPoint(light.getMaxFromAllVerts()));
                Handles.DrawLine(lTransform.position, lTransform.TransformPoint(light.getMinFromAllVerts()));
            }



            /* Angle Handler*/
            Handles.color = Color.grey;
            Vector3 oldAnglePoint = lTransform.TransformPoint(new Vector3(0, -((light.RangeAngle * light.LightRadius) / 360), 0));
            //float sizeAngle = HandleUtility.GetHandleSize(oldAnglePoint);
            Vector3 newAngPoint = Handles.FreeMoveHandle(
                oldAnglePoint, Quaternion.identity, size * 0.08f, pointAngleSnap, Handles.DotCap);


            Handles.DrawLine(lTransform.position, newAngPoint);

            if (oldAnglePoint != newAngPoint)
            {
                Undo.RecordObject(light, "resize range angle");
                newAngPoint   = lTransform.InverseTransformPoint(newAngPoint);
                oldAnglePoint = lTransform.InverseTransformPoint(oldAnglePoint);

                float _tmpAng = (newAngPoint - oldAnglePoint).y;
                light.RangeAngle -= _tmpAng;
                if (light.RangeAngle > 360f)
                {
                    light.RangeAngle = 360f;
                }
                if (light.RangeAngle < 1f)
                {
                    light.RangeAngle = 1f;
                }



                light.Rebuild();
            }
            /* end angle handler */


            dragAndDropEvents();
        }
    }