Beispiel #1
0
    BattleUnit SpawnOneUnit(int playerIdx, int carResID, string resPath, Transform hangNode, Vector2 pos, Vector2 speed, int unitType)
    {
        int        objID = 0;
        GameObject obj   = ResMgr.instance.CreateObject(resPath, out objID);

        if (obj == null)
        {
            Debug.LogError("ObjMgr SpawnOneUnit obj == null resPath:" + resPath);
        }
        BattleUnit unitObj = new BattleUnit(playerIdx, objID, resPath, obj, hangNode, pos, speed, unitType);
        // attr com
        AttrCom attrCom = unitObj.GetRenderObjTr().GetComponent <AttrCom>();

        if (attrCom == null)
        {
            attrCom = unitObj.GetRenderObjTr().gameObject.AddComponent <AttrCom>();
        }
        unitObj.AddCom(attrCom);
        attrCom.InitAttr(carResID, unitType);

        // move com
        MoveCom move = unitObj.GetRenderObjTr().GetComponent <MoveCom>();

        if (move == null)
        {
            move = unitObj.GetRenderObjTr().gameObject.AddComponent <MoveCom>();
        }
        unitObj.AddCom(move);
        move.Init(speed);

        // collider com
        ColliderCom collider = unitObj.GetRenderObjTr().GetComponent <ColliderCom>();

        if (collider == null)
        {
            collider = unitObj.GetRenderObjTr().gameObject.AddComponent <ColliderCom>();
        }
        unitObj.AddCom(collider);

        // Scale com
        ScaleCom scaleCom = unitObj.GetRenderObjTr().GetComponent <ScaleCom>();

        if (scaleCom == null)
        {
            scaleCom = unitObj.GetRenderObjTr().gameObject.AddComponent <ScaleCom>();
        }
        unitObj.AddCom(scaleCom);

        // NitrogenCom
        NitrogenCom nitrogenCom = unitObj.GetRenderObjTr().GetComponent <NitrogenCom>();

        if (nitrogenCom == null)
        {
            nitrogenCom = unitObj.GetRenderObjTr().gameObject.AddComponent <NitrogenCom>();
        }
        unitObj.AddCom(nitrogenCom);


        SkillCom skillCom = unitObj.GetRenderObjTr().GetComponent <SkillCom>();

        if (skillCom == null)
        {
            skillCom = unitObj.GetRenderObjTr().gameObject.AddComponent <SkillCom>();
        }
        unitObj.AddCom(skillCom);


        StatusCom statusCom = unitObj.GetRenderObjTr().GetComponent <StatusCom>();

        if (statusCom == null)
        {
            statusCom = unitObj.GetRenderObjTr().gameObject.AddComponent <StatusCom>();
        }
        unitObj.AddCom(statusCom);

        return(unitObj);
    }