Example #1
0
    /*
     * 某人下车
     */
    private void add_person()
    {
        if (!ConfigConstexpr.human_addable())
        {
            return;
        }
        ++add_person_cnt;
//		Debug.Log ("My daddy: " + get_parent_script().transform);
        var pos = generate_pos();

        Debug.Log("Add Pos = " + pos + " with father " + this.gameObject.name);
//		PersonAdder.LayerChange ();

        var gameobj = HumanController.add_human(pos, parentTransform.gameObject);

        gameobj.transform.parent = p_script.transform;          // reset father.

        gameobj.gameObject.layer = p_script.gameObject.layer;
        HumanController p_c = gameobj.GetComponent <HumanController> ();

        p_c.transform.parent = parentTransform;
        PersonAdder.LayerChange(p_c, p_script);
        p_c.take_subway = false;
        p_c.Start();
    }
Example #2
0
        // 添加人
        void dest_add_person()
        {
            // 如果是不可以加人的状态,那么什么都不会发生
            ++add_person_cnt;
            Debug.Log("召唤准备!");
            for (int i = 0; i < person_per_wave; ++i)
            {
                if (!ConfigConstexpr.human_addable())
                {
                    // 什么都不召唤
                    break;
                }
                var newman = HumanController.add_human(transform.position, get_parent_script().gameObject);
                if (newman == null)
                {
                    Debug.LogError("召唤失败");
                }
                newman.layer = gameObject.layer;
                HumanController new_script = newman.GetComponent <HumanController> ();
                PersonAdder.LayerChange(new_script, get_parent_script());
                new_script.take_subway = true;
            }

            Invoke("dest_add_person", add_time);
        }
Example #3
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);
                }
            }
        }