Beispiel #1
0
 // if find "human" with tag
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.CompareTag("Human"))
     {
         if (this.gameObject.layer != other.gameObject.layer)
         {
             return;
         }
         HumanController hc = other.GetComponent <HumanController> ();
         //
         if (!ConfigConstexpr.get_instance().has_disaster&& hc.take_subway)
         {
             // 无灾难,坐地铁,跑路
             return;
         }
         if (CameraScript.Instance.watched_player == other.transform)
         {
             CameraScript.Instance.deBind();
         }
         other.gameObject.SetActive(false);
         Debug.Log("Human pass! in Layer" + other.gameObject.layer);
     }
 }
Beispiel #2
0
        protected virtual void OnTriggerEnter2D(Collider2D other)
        {
            if (other.gameObject.CompareTag("Human"))
            {
                GameObject      game_obj = other.gameObject;
                HumanController script   = game_obj.GetComponent <HumanController> ();
                if (!script.lift_available(this))
                {
                    Debug.Log("Lift not availabe");
                    return;
                }
                string parent_name = script.get_parent_script().name;

                if (in_cross_channel && !ConfigConstexpr.get_instance().has_disaster)
                {
                    if (parent_name.Contains("First"))
                    {
                        if (script.in_disaster)
                        {
                            return;
                        }
                        if (!script.take_subway)
                        {
                            // 一楼,乘地铁
                            return;
                        }
                        // 判断是向上的扶梯还是向下的扶梯
                        if (IsElescator && elescator_up)
                        {
                            // 向上扶梯
                            return;
                        }
                    }
                    else if (parent_name.Contains("Second"))
                    {
                        if (script.take_subway && !script.in_disaster)
                        {
                            Debug.Log("二楼,乘地铁");
                            return;
                        }
                        if (IsElescator && !elescator_up)
                        {
                            return;
                        }
                    }
                }

                if (script == null)
                {
                    Debug.Log("Bad Human! Human here don't have script!");
                    return;
                }

                // 变换主从关系


                /*
                 * 更换父对象的代码
                 * 考虑父对象使用自己的生成算法
                 */
                // 更改game_obj的父对象
                var rotate     = other.transform.localRotation;
                var localscale = other.transform.localScale;

                {
                    ++pass_by_cnt;
                    bkg_ctrl.childObjects.humans.Remove(game_obj);
                    // 获得Link对象的父脚本to_script
                    var to_s = to.GetComponent <LiftController>();
                    BackgroundController to_script = to_s.get_parent_script();
                    //				BackgroundController to_script = to.transform.parent.GetComponent<BackgroundController> ();

                    if (to_script == null)
                    {
                        var lifts = GameObject.FindGameObjectsWithTag("Lift");
                        foreach (GameObject lift_go in lifts)
                        {
                            LiftController lc = lift_go.GetComponent <LiftController> ();
                            if (lc.to == this)
                            {
                                to_script = lc.get_parent_script();
                            }
                        }
                        if (to_script == null)
                        {
                            Debug.LogError("Empty1");
                        }
                    }

                    // 更新 used_lift
                    LiftController to_controller = to.GetComponent <LiftController> ();
                    if (to_controller != null)
                    {
                        script.used_list = un_allowed_lifts;
                    }

                    Rigidbody2D rb = GetComponent <Rigidbody2D> ();

                    game_obj.transform.parent = to.transform.parent;

                    to_script.add_person(game_obj);

                    // 改变位置
                    other.transform.position = to.transform.position;

                    // 更换目标
                    script.change_new_father_container(to_script);
                    script.change_destine();

                    game_obj.layer = to_script.gameObject.layer;

                    /*
                     *  need to change layer.
                     */
                    script.transform.rotation = rotate;
                    PersonAdder.LayerChange(script, to_script);
                }
            }
        }
Beispiel #3
0
        private float[,] get_apf()
        {
//			// DEBUG: temporary mark this
            if (fixed_apf)
            {
                if (fixed_already_apf != null)
                {
                    Debug.Log("Fixed apf!");

                    return(fixed_already_apf);
                }
                else
                {
                    Debug.LogError("你这还有问题...");
                }
            }
            // 背景脚本
            BackgroundController bkg_script = get_parent_script();

            float[,] needed_apf;
            var pos = bkg_script.pos2mapv(transform.position);

            // 获得现在的x y坐标
            int    cur_x = (int)pos.x, cur_y = (int)pos.y;
            bool   if_print = false;
            string debug_str;
            int    pos_in_list = 0;

            if (bkg_script.gameObject.name.Contains("Second"))
            {
                if_print = true;
            }

            if (!bkg_script.on_stair_or_not())
            {
                // 在楼层上
                // 楼梯扶梯可用
                if (has_app)
                {
                    // 有app
                    if (take_subway)
                    {
                        // 要乘车
                        if (in_disaster)
                        {
                            needed_apf = bkg_script.APF01;

                            debug_str = ("Choose APF01");
                        }
                        else
                        {
                            needed_apf = bkg_script.APF11;
                            debug_str  = ("Choose APF11");
                        }
                    }
                    else
                    {
                        if (in_disaster)
                        {
                            needed_apf = bkg_script.APF02;
                            debug_str  = ("Choose APF02");
                        }
                        else
                        {
                            needed_apf = bkg_script.APF12;
                            debug_str  = ("Choose APF12");
                        }
                    }
                }
                else
                {
                    List <float[, ]> search_list;

                    // 根据有无app选择对应的list
                    if (take_subway)
                    {
                        if (in_disaster)
                        {
                            search_list = bkg_script.APF05;
                            debug_str   = ("Choose APF05");
                        }
                        else
                        {
                            search_list = bkg_script.APF15;
                            debug_str   = ("Choose APF15");
                        }
                    }
                    else
                    {
                        if (in_disaster)
                        {
                            search_list = bkg_script.APF06;
                            debug_str   = ("Choose APF06");
                        }
                        else
                        {
                            search_list = bkg_script.APF16;
                            debug_str   = ("Choose APF16");
                        }
                    }

                    const float MIN_V = 30.0f;
                    // 找到最小的数组
                    float[,] min_arr = find_min_apf(search_list, cur_y, cur_x, ref pos_in_list);
                    needed_apf       = min_arr;
                    // 先直接找最近的出口吧,这个逻辑恨坑的
                    init_destine();
                }
                if (if_print)
                {
                    Debug.Log(debug_str + " and pos " + pos_in_list);
                }
            }
            else
            {
                // 如果在楼梯/扶梯上
                if (ConfigConstexpr.get_instance().es_is_running)
                {
                    // 楼梯扶梯可用
                    if (has_app)
                    {
                        // 有app

                        if (take_subway)
                        {
                            needed_apf = bkg_script.APF01;
                        }
                        else
                        {
                            needed_apf = bkg_script.APF02;
                        }
                    }
                    else
                    {
                        if (take_subway)
                        {
                            needed_apf = bkg_script.APF03;
                        }
                        else
                        {
                            needed_apf = bkg_script.APF04;
                        }
                    }
                }
                else
                {
                    // 扶梯不能运行
                    if (has_app)
                    {
                        // 有app
                        if (take_subway)
                        {
                            needed_apf = bkg_script.APF11;
                        }
                        else
                        {
                            needed_apf = bkg_script.APF12;
                        }
                    }
                    else
                    {
                        if (take_subway)
                        {
                            needed_apf = bkg_script.APF13;
                        }
                        else
                        {
                            needed_apf = bkg_script.APF14;
                        }
                    }
                }
            }

            return(needed_apf);
        }