public override void Operate0(int lightQuantity)
    {
        base.Operate0(lightQuantity);
        RayLight light = RayLight.GetLight(lightQuantity);

        deltaLightQuantity = luncher.ChangeEmitStatus(light);
    }
Exemplo n.º 2
0
    float lastTimeOfGettingLightElement = 0;        //为了放止在光球被销毁之前发生二次拾取

    public void OnLighting(RaycastHit2D hit, Vector3 direction, RayLight light)
    {
        if (isPausing || GameGlobal.GameData.isPausing)
        {
            return;
        }
        //判断人物是否能随光线移动
        bool flag = false;

        if (PlayerParticleController.lightQuantity > 0)
        {
            RayLight.LightColor playerColor = RayLight.GetLight(PlayerParticleController.lightQuantity).lightColor;
            RayLight.LightColor lightColor  = light.lightColor;
            if (playerColor == RayLight.LightColor.white)
            {
                flag = true;
            }
            else
            {
                if (playerColor == lightColor)
                {
                    flag = true;
                }
            }
        }
        //移动人物
        if (flag)
        {
            transform.Translate(-direction * Time.deltaTime * velocityOnLighting);
            if (verticalVelocity < 0)
            {
                verticalVelocity = 0;
            }
        }
    }
Exemplo n.º 3
0
    public static RayLight GetLight(int LightQuantity)
    {
        RayLight light = new RayLight();

        switch (LightQuantity % 5)
        {
        case 0:
            light.lightColor = LightColor.white;
            break;

        case 1:
            light.lightColor = LightColor.blue;
            break;

        case 2:
            light.lightColor = LightColor.green;
            break;

        case 3:
            light.lightColor = LightColor.yellow;
            break;

        case 4:
            light.lightColor = LightColor.red;
            break;
        }
        light.lightLevel = (LightQuantity - 1) / 5 + 1;
        if (LightQuantity == 0)
        {
            light.lightLevel = 0;
        }
        return(light);
    }
Exemplo n.º 4
0
 public override void OnLighting(RaycastHit2D hit, Vector3 direction, RayLight light)
 {
     hitIt       = hit;
     directionIt = direction;
     lightIt     = light;
     IsOnLight   = true;
 }
Exemplo n.º 5
0
 public void ResetRay(Vector2 rayDirection, Vector3 rayOrign, RayLight color)
 {
     ray.direction = rayDirection;
     ray.origin    = rayOrign + 0.01f * new Vector3(rayDirection.x, rayDirection.y, 0);
     rayColor      = color;
     EmitRay();
 }
Exemplo n.º 6
0
    public override void OnLighting(RaycastHit2D hit, Vector3 direction, RayLight light)
    {
        base.OnLighting(hit, direction, light);

        //将向量坐标归一化
        direction = direction.normalized;

        //计算反射光方向
        Ray ray = new Ray
        {
            origin    = hit.point,
            direction = Vector2.Reflect(-direction, hit.normal)
        };

        //生成一个lineRendererCarrier的实例
        GameObject lineInstance = Instantiate(linePrototype, this.transform);

        lineInstance.AddComponent <ReflectRay>();

        //整合反射光属性
        ReflectLight reflectLight = new ReflectLight
        {
            light = light,
            ray   = ray,
            line  = lineInstance
        };

        //将反射光添加进链表
        reflectLights.Add(reflectLight);
    }
Exemplo n.º 7
0
    public static RayLight GetLight(LightColor color, int level)
    {
        RayLight light = new RayLight();

        light.lightColor = color;
        light.lightLevel = level;
        return(light);
    }
Exemplo n.º 8
0
 //返回光的增量
 public int ChangeEmitStatus(RayLight light)
 {
     if (isEmitting == true || light.lightLevel == 0)
     {
         return(EndEmit());
     }
     else
     {
         return(BeginEmit(light));
     }
 }
Exemplo n.º 9
0
    public override void OnLighting(RaycastHit2D hit, Vector3 direction, RayLight light)
    {
        base.OnLighting(hit, direction, light);
        if (this.light == null)
        {
            this.light = light;
        }
        else
        {
            this.light = RayLight.GetLight(light.LightQuantity + this.light.LightQuantity);
        }

        isEmitting = true;
    }
Exemplo n.º 10
0
    bool haveFence(RaycastHit2D[] hits)
    {
        if (hits == null)
        {
            return(false);
        }
        else
        {
            bool flag = false;
            foreach (RaycastHit2D hit in hits)
            {
                if (!hit.collider.isTrigger)
                {
                    if (hit.collider.tag != "ColorfulPlatform")
                    {
                        flag = true;
                    }
                    //若目标平台是有颜色需求的
                    else
                    {
                        //获取目标平台脚本控件
                        ColorfulPlatform platInstance = hit.collider.transform.parent.parent.GetComponent <ColorfulPlatform>();

                        RayLight            playerLight   = RayLight.GetLight(PlayerParticleController.lightQuantity);
                        RayLight.LightColor platformColor = hit.collider.transform.parent.parent.GetComponent <ColorfulPlatform>().platformColor;
                        //若颜色一样
                        if (playerLight.lightColor == platformColor)
                        {
                            flag = true;
                        }
                        //反之
                        else
                        {
                            if (playerLight.lightColor == RayLight.LightColor.white &&
                                playerLight.LightQuantity != 0)
                            {
                                flag = true;
                            }
                            else
                            {
                                flag = false;
                                platInstance.OnScene();
                            }
                        }
                    }
                }
            }
            return(flag);
        }
    }
Exemplo n.º 11
0
 public override void OnLighting(RaycastHit2D hit, Vector3 direction, RayLight light)
 {
     base.OnLighting(hit, direction, light);
     if (isLightNeed == true)
     {
         if (lightNeed.lightColor != light.lightColor)
         {
             return;
         }
         if (lightNeed.lightLevel > light.lightLevel)
         {
             return;
         }
     }
 }
Exemplo n.º 12
0
    public void ActivateEvent()
    {
        //如果前置条件不满足,则退出
        foreach (TriggerEvent eve in preEvents)
        {
            if (eve.isUsed == false)
            {
                return;
            }
        }
        //如果光的颜色需求不符,则退出
        if (isLightColorNeeded)
        {
            RayLight playerLight = RayLight.GetLight(PlayerParticleController.lightQuantity);
            bool     flag        = false;
            //若颜色一样
            if (playerLight.lightColor == lightColorNeeded)
            {
                flag = true;
            }
            //反之
            else
            {
                if (playerLight.lightColor == RayLight.LightColor.white &&
                    playerLight.LightQuantity != 0)
                {
                    flag = true;
                }
                else
                {
                    flag = false;
                }
            }
            if (flag == false)
            {
                return;
            }
        }
        //如果已经激活过,则退出
        if (isUsed)
        {
            return;
        }
        isUsed = true;

        //广播事件
        eventList();
    }
Exemplo n.º 13
0
    public override void OnLighting(RaycastHit2D hit, Vector3 direction, RayLight light)
    {
        base.OnLighting(hit, direction, light);

        operatedAllowed = true;
        {
            var module = fogParticle.emission;
            module.rateOverTime = 0;
        }
        {
            var module = photosphereParticle.emission;
            module.rateOverTime = 50;
        }

        lightTimeVal = 0.1f;
    }
Exemplo n.º 14
0
    //绘制色散光线
    public void DrawLightDispertion(RaycastHit2D hitPoint, Vector3 lightDispertion, RayLight light)
    {
        GameObject   tempLight      = Instantiate(lightAfter, this.transform);
        TempLightRay tempLightRay   = tempLight.AddComponent <TempLightRay>();
        LineRenderer tempDispertion = tempLight.GetComponent <LineRenderer>();

        //tempDispertion.material = new Material(Shader.Find("LineLight"));
        tempDispertion.positionCount = 2;
        tempDispertion.startWidth    = 0.5f;
        tempDispertion.endWidth      = tempDispertion.startWidth;
        tempDispertion.startColor    = light.Color;
        tempDispertion.endColor      = light.Color;
        Vector3 startPos = new Vector3(hitPoint.point.x, hitPoint.point.y, 0);

        tempDispertion.SetPosition(0, startPos);
        tempDispertion.SetPosition(1, startPos + lightDispertion * 30);
        tempLightRay.ResetRay(lightDispertion, startPos, light);
    }
Exemplo n.º 15
0
    protected void EmitRay(RayLight light, Ray ray, LineRenderer lineRenderer)
    {
        bool flag = false;          //是否检测到挡光实体

        //设置LineRenderer
        lineRenderer.positionCount = 2;
        lineRenderer.startColor    = light.Color;
        lineRenderer.endColor      = new Color(light.Color.r, light.Color.g, light.Color.b, 0.0f);

        RaycastHit2D[] hitArray = Physics2D.RaycastAll(ray.origin, ray.direction);

        for (int i = 0; i < hitArray.Length; i++)
        {
            //如果检测目标为自身,则跳过
            if (hitArray[i].transform.parent.gameObject == colliderRoot)
            {
                continue;
            }
            //获得目标下的Entity脚本
            Entity other = hitArray[i].collider.transform.parent.parent.GetComponent <Entity>();

            if (other != null)
            {
                //激活目标的受光函数
                other.OnLighting(hitArray[i], -ray.direction, light);
                //如果目标挡光(具有漫反射属性),截断射线
                if (other.scatteringMode == ScatteringMode.diffuse)
                {
                    lineRenderer.SetPosition(0, ray.origin);
                    lineRenderer.SetPosition(1, hitArray[i].point);
                    flag = true;
                    break;
                }
            }
        }

        if (flag == false)
        {
            lineRenderer.SetPosition(0, ray.origin);
            lineRenderer.SetPosition(1, ray.origin + 20 * ray.direction);
        }
    }
Exemplo n.º 16
0
 public override void OnLighting(RaycastHit2D hit, Vector3 direction, RayLight light)
 {
     base.OnLighting(hit, direction, light);
     if (isLightNeed == true)
     {
         if (lightNeed.lightColor != light.lightColor)
         {
             return;
         }
         if (lightNeed.lightLevel > light.lightLevel)
         {
             return;
         }
     }
     displacement += 2 * Time.deltaTime * speed;
     if (displacement > upperLimit)
     {
         displacement = upperLimit;
     }
 }
Exemplo n.º 17
0
    void ResetHUD()
    {
        GameObject hud = GameObject.Find("UI/HUDCanvas");

        //检查场景是否搭载了HUD组件
        if (hud == null)
        {
            Debug.LogError("场景中缺少HUD组件");
            return;
        }

        //获取HUD组件
        Image lq_image   = hud.transform.Find("LightQuantity/Image").GetComponent <Image>();
        Text  lq_text    = hud.transform.Find("LightQuantity/Text").GetComponent <Text>();
        Text  pick_text  = hud.transform.Find("PickMode/Text").GetComponent <Text>();
        Text  pick_point = hud.transform.Find("PickMode/Point").GetComponent <Text>();

        //设置HUD光数
        Color currentColor = RayLight.GetLight(PlayerParticleController.lightQuantity).Color;

        lq_image.color = currentColor;
        lq_text.color  = currentColor;
        lq_text.text   = PlayerParticleController.lightQuantity.ToString();

        //设置拾取模式的显示
        if (isPickMode)
        {
            pick_point.color = Color.green;
            pick_text.text   = "  拾取模式";
        }
        else
        {
            pick_point.color = Color.red;
            pick_text.text   = "  锁定模式";
        }
    }
Exemplo n.º 18
0
 public override void OnLighting(RaycastHit2D hit, Vector3 direction, RayLight light)
 {
     base.OnLighting(hit, direction, light);
     playerController.OnLighting(hit, direction, light);
 }
Exemplo n.º 19
0
 /*由光线类调用,不是事件函数
  * point: 光的入射点,世界坐标下
  * dirction: 光源方向,指向光源
  */
 public virtual void OnLighting(RaycastHit2D hit, Vector3 direction, RayLight light)
 {
 }
Exemplo n.º 20
0
 private int BeginEmit(RayLight light)
 {
     this.light = light;
     isEmitting = true;
     return(-1);
 }
Exemplo n.º 21
0
    //色散和折射实现函数
    public void LightRefraction(RaycastHit2D hitPoint, RayLight colorOfLightIn, Vector3 directionOfLight)
    {
        Vector3[] lightDispertion = Refract(directionOfLight, hitPoint.normal, colorOfLightIn.Color);
        if (lightDispertion.Length == 4)            //色散发生
        {
            if (inGlass)
            {
                for (int j = 0; j < 4; j++)
                {
                    RayLight lightOfDis = new RayLight();
                    lightOfDis.lightLevel  = colorOfLightIn.lightLevel;
                    lightOfDis.lightColor  = RayLight.LightColor.blue;
                    lightOfDis.lightColor += j;
                    DrawLightDispertion(hitPoint, lightDispertion[j], lightOfDis);
                }
            }
            else
            {
                for (int j = 0; j < 4; j++)
                {
                    RayLight lightOfDis = new RayLight();
                    lightOfDis.lightLevel  = colorOfLightIn.lightLevel;
                    lightOfDis.lightColor  = RayLight.LightColor.blue;
                    lightOfDis.lightColor += j;

                    RaycastHit2D dispertionRayHit     = hitPoint;
                    int          numOftotalReflecting = 0;
                    do
                    {
                        dispertionRayHit   = Physics2D.Raycast(dispertionRayHit.point + new Vector2(lightDispertion[j].x, lightDispertion[j].y) * 0.01f, lightDispertion[j], 100f, 1 << 9);
                        lightDispertion[j] = Refract(lightDispertion[j], dispertionRayHit.normal, 1 / Mathf.Sqrt(2));
                        numOftotalReflecting++;
                    } while (totalReflecting && numOftotalReflecting < 5);

                    if (numOftotalReflecting < 5)
                    {
                        DrawLightDispertion(dispertionRayHit, lightDispertion[j], lightOfDis);
                    }
                }
            }
        }
        else
        {
            if (inGlass)
            {
                DrawLightDispertion(hitPoint, lightDispertion[0], colorOfLightIn);
            }
            else
            {
                RaycastHit2D dispertionRayHit     = hitPoint;
                int          numOftotalReflecting = 0;
                do
                {
                    dispertionRayHit   = Physics2D.Raycast(dispertionRayHit.point + new Vector2(lightDispertion[0].x, lightDispertion[0].y) * 0.01f, lightDispertion[0], 100f, 1 << 9);
                    lightDispertion[0] = Refract(lightDispertion[0], dispertionRayHit.normal, Mathf.Sqrt(2));
                    numOftotalReflecting++;
                } while (totalReflecting && numOftotalReflecting < 5);
                if (numOftotalReflecting <= 5)
                {
                    DrawLightDispertion(dispertionRayHit, lightDispertion[0], colorOfLightIn);
                }
            }
        }
    }
Exemplo n.º 22
0
 protected override void GameBehavierInit()
 {
     base.GameBehavierInit();
     lightNeed = RayLight.GetLight(lightColorNeed, lightLevelNeed);
 }