Beispiel #1
0
 /*
  * 判断给出的楼梯是可以使用的
  */
 /*
  * 判断给出的楼梯是可以使用的
  */
 public bool lift_available(LiftController c)
 {
     // at first is null.
     if (used_list == null)
     {
         return(true);
     }
     return(!used_list.Contains(c));
 }
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);
                }
            }
        }