Ejemplo n.º 1
0
    public static void SetObjPos(GameObject obj, Vector3 pos)
    {
        InGameBaseObj ingameobj = obj.GetComponent <InGameBaseObj>();

        if (ingameobj == null)
        {
            return;
        }
        if (ingameobj.GetObjType() != InGameBaseObj.enObjType.map)
        {
            return;
        }
        Vector2 mappos = GameCommon.GetMapPos(pos);

        obj.transform.position = GameCommon.GetWorldPos(mappos);

        MapObjConf conf = ConfigManager.GetEditorMapObjConfManager().map[ingameobj.confid];

        if (conf == null)
        {
            return;
        }
        GameCommon.SetObjZIndex(obj, conf.depth);
        return;
        //MapEditor me = GameObject.Find("levelOption").transform.GetComponent<MapEditor>();

        //if (me == null)
        //{
        //    EditorUtility.DisplayDialog("ERROR", "Cant't find the 'levelOption' !!", "ENTRY");
        //    return;
        //}
    }
Ejemplo n.º 2
0
    public InGameBaseEquip OutEquip(GameObject go, int level, float fm)
    {
        EquipConf equipConf = ConfigManager.equipConfManager.GetRandomEquip();

        GameObject equipobj = (GameObject)Resources.Load(equipConf.prefabpath + equipConf.prefabname);

        equipobj = MonoBehaviour.Instantiate(equipobj);
        equipobj.transform.position = GameCommon.GetWorldPos(GameCommon.GetMapPos(go.transform.position));
        GameCommon.SetObjZIndex(equipobj, 3.1f);

        InGameBaseEquip equip = equipobj.GetComponent <InGameBaseEquip>();

        equip.Init(-1, equipConf.id, enMSCamp.en_camp_item);
        equip.level   = level;
        equip.quality = ConfigManager.equipQualityManager.GetEquipQuality(fm);

        EquipOutAction equipOutAction = equipobj.AddComponent <EquipOutAction>();

        equipOutAction.Init(equipobj.transform.position);
        return(equip);
    }
Ejemplo n.º 3
0
    public override bool ObjUpdate()
    {
        if (source == null)
        {
            SetDie(true);
            return(false);
        }
        //Debug.Log("move vec : " + moveVector);
        transform.position = transform.position + moveVector * Time.deltaTime * 10;

        GameCommon.SetObjZIndex(gameObject, 3);

        if (Vector2.Distance(startPos, transform.position) > 20)
        {
            SetDie(true);
            return(false);
        }
        Vector3 collisionpos = transform.position - additionPos;
        //游戏物体碰撞
        List <InGameBaseObj> list = InGameManager.GetInstance().inGameObjManager.GetObjListByDistance(collisionpos, 0.5f);

        for (int i = 0; i < list.Count; i++)
        {
            if (HitGameObj(list[i]))
            {
                return(false);
            }
        }

        //地图碰撞
        Vector2 mapos = GameCommon.GetMapPos(collisionpos);

        if (InGameManager.GetInstance().inGameLevelManager.gameMap.GetPointType((int)mapos.x, (int)mapos.y) == MazeCreate.PointType.wall)
        {
            SetDie(true);
            return(false);
        }

        return(base.ObjUpdate());
    }
Ejemplo n.º 4
0
    static void OnSceneGUI(SceneView sceneView)
    {
        if (Event.current.type == EventType.MouseDown)
        {
            mouseStartDownpos = Event.current.mousePosition;
            return;
        }
        if (Event.current.type == EventType.MouseUp)
        {
            if (Vector3.Distance(mouseStartDownpos, Event.current.mousePosition) > 0.3f)
            {
                return;
            }
            //Event.current.Use();
            if (Selection.gameObjects.Length <= 0)
            {
                return;
            }
            GameObject obj = Selection.gameObjects[0];
            //Debug.Log(obj.name);

            InGameBaseMapObj mapObj = obj.GetComponent <InGameBaseMapObj>();
            if (mapObj == null)
            {
                return;
            }
            MapObjConf conf    = ConfigManager.GetEditorMapObjConfManager().map[mapObj.confid];
            GameObject tempObj = Resources.Load(conf.path) as GameObject;
            tempObj = (GameObject)Instantiate(tempObj);

            tempObj.transform.position = GetWorldPosition(sceneView);
            tempObj.transform.parent   = obj.transform.parent;
            GameCommon.SetObjZIndex(tempObj, conf.depth);

            //聚焦到当前物体
            Selection.activeGameObject = tempObj;
            copyObj = tempObj;
            //Event.current.Use();
        }
    }
Ejemplo n.º 5
0
    public void ReloadScene(DataStream datastream)
    {
        Debug.Log("ReloadScene");

        LevelOption me = null;

        List <GameObject> delarr = new List <GameObject>();

        foreach (GameObject sceneObject in Object.FindObjectsOfType(typeof(GameObject)))
        {
            if (sceneObject.name == "MapEditor")
            {
                me = sceneObject.GetComponent <LevelOption>();
                me.deserialize(datastream);
                GameCommon.GAME_DATA_VERSION = me.version;
                continue;
            }
            else if (sceneObject.name != "Main Camera" && sceneObject.name != "Directional Light")
            {
                delarr.Add(sceneObject);
            }
        }

        //创建关卡配置物体
        if (me == null)
        {
            GameObject tGO = new GameObject("MapEditor");
            me = tGO.AddComponent <LevelOption>();
            me.deserialize(datastream);

            MapEditor me1 = tGO.AddComponent <MapEditor>();
            me1.lo = me;
        }

        Debug.Log(me.levelName + " / " + me.version);

        foreach (GameObject obj in delarr)
        {
            DestroyImmediate(obj);
        }
        int objcount = datastream.ReadSInt32();

        Debug.Log("objcount : " + objcount);
        Dictionary <int, InGameBaseObj> dic = new Dictionary <int, InGameBaseObj>();
        MapObjConfManager mapObjConfManager = ConfigManager.GetEditorMapObjConfManager();

        for (int i = 0; i < objcount; i++)
        {
            //MSBaseObject.CreateObj(datastream);
            //从字节流中获取id

            int   confid = 0;
            float x = 0, y = 0, sx = 1, sy = 1;

            MapObjConf    conf = null;
            GameObject    go = null, tempObj;
            InGameBaseObj baseObj = null;
            int           dataid  = datastream.ReadByte();
            while (dataid != 0)
            {
                switch (dataid)
                {
                case 1:
                    confid  = datastream.ReadSInt32();
                    conf    = mapObjConfManager.map[confid];
                    tempObj = Resources.Load(conf.path) as GameObject;
                    if (tempObj == null)
                    {
                        Debug.Log(confid + " is null!");
                    }
                    go      = (GameObject)Instantiate(tempObj);
                    baseObj = go.GetComponent <InGameBaseObj>();
                    break;

                case 2: x = datastream.ReadSInt32() / 1000f; break;

                case 3: y = datastream.ReadSInt32() / 1000f; break;

                case 4:
                    int parentid = datastream.ReadSInt32();
                    if (dic.ContainsKey(parentid))
                    {
                        go.transform.parent = dic[parentid].transform;
                    }
                    else
                    {
                        go.transform.parent = me.transform;
                    }
                    break;

                case 5:
                    int instanceid = datastream.ReadSInt32();
                    dic.Add(instanceid, baseObj);
                    break;

                case 7: go.name = datastream.ReadString16(); break;

                case 8: sx = datastream.ReadSInt32() / 1000f; break;

                case 9: sy = datastream.ReadSInt32() / 1000f; break;

                case 6: baseObj.Deserialize(datastream); break;
                }
                dataid = datastream.ReadByte();
            }

            go.transform.position   = new Vector3(x, y);
            go.transform.localScale = new Vector3(sx, sy, 1);
            GameCommon.SetObjZIndex(go, conf.depth);
        }
    }
Ejemplo n.º 6
0
    protected void InsertGroup(Vector2 pos, int groupid)
    {
        Debug.Log(groupid);
        int          x = (int)pos.x, y = (int)pos.y;
        MapGroupConf conf = ConfigManager.mapGroupConfManager.dataMap[groupid];

        if (conf == null)
        {
            return;
        }
        TextAsset text = Resources.Load(conf.path) as TextAsset;

        byte[]     data       = GameCommon.UnGZip(text.bytes);
        DataStream datastream = new DataStream(data, true);

        //配置LevelOption
        GameObject logo = new GameObject(conf.path);

        //logo.transform.parent = this.mapObj.transform;
        logo.transform.position = GameCommon.GetWorldPos(pos);
        LevelOption me = logo.AddComponent <LevelOption>();

        me.deserialize(datastream);

        //生成物体
        int objcount = datastream.ReadSInt32();

        for (int i = 0; i < objcount; i++)
        {
            //MSBaseObject.CreateObj(datastream);
            //从字节流中获取id
            //int confid = datastream.ReadSInt32();
            //float objx = datastream.ReadSInt32() / 1000f;
            //float objy = datastream.ReadSInt32() / 1000f;
            int        confid = 0;
            float      objx = 0, objy = 0, objsx = 0, objsy = 0;
            MapObjConf objconf = null;
            GameObject column  = null;
            int        dataid  = datastream.ReadByte();
            string     goname  = "";
            while (dataid != 0)
            {
                switch (dataid)
                {
                case 1:
                    confid  = datastream.ReadSInt32();
                    objconf = ConfigManager.mapObjConfManager.map[confid];
                    break;

                case 2: objx = datastream.ReadSInt32() / 1000f; break;

                case 3: objy = datastream.ReadSInt32() / 1000f; break;

                case 4:
                    int parentid = datastream.ReadSInt32();
                    break;

                case 5:
                    int instanceid = datastream.ReadSInt32();
                    break;

                case 7: goname = datastream.ReadString16(); break;

                case 8:
                    objsx = datastream.ReadSInt32() / 1000f;
                    break;

                case 9:
                    objsy = datastream.ReadSInt32() / 1000f;
                    break;

                case 6:
                    if (objconf.isstatic == 1)
                    {
                        column = (GameObject)Resources.Load(objconf.path);
                        column = MonoBehaviour.Instantiate(column);
                        column.transform.parent   = mapObj.transform;
                        column.transform.position = GameCommon.GetWorldPos(pos) + new Vector2(objx, objy);
                        InGameBaseObj point = column.GetComponent <InGameBaseObj>();
                        point.Deserialize(datastream);
                        GameCommon.SetObjZIndex(column, objconf.depth);
                    }

                    break;
                }
                dataid = datastream.ReadByte();
            }

            if (confid == 4000002)
            {
                startPointList.Add(pos + GameCommon.GetMapPos(new Vector2(objx, objy)));
                continue;
            }
            if (objconf.isstatic == 1)
            {
                SetWayProperty(pos + GameCommon.GetMapPos(new Vector2(objx, objy)), objconf);
                column.transform.localScale = new Vector3(objsx, objsy, 1);
                continue;
            }

            SetGroupPoint(pos + GameCommon.GetMapPos(new Vector2(objx, objy)), objconf, new Vector3(objsx, objsy, 1));
        }
    }
Ejemplo n.º 7
0
    //动态生成地面
    public override void Update()
    {
        smallMap.Update();

        Vector2 startPos = InGameManager.GetInstance().inGameCameraManager.GetCameraPos();

        Vector2 startMapPos = GameCommon.GetMapPos(startPos);

        int startX = (int)startMapPos.x - UPDATE_MAP_SIZE / 2;
        int startY = (int)startMapPos.y - UPDATE_MAP_SIZE / 2;

        for (int i = 0; i < lastScreenObj.Count; i++)
        {
            Vector2 pos = lastScreenObj[i].pos;
            if (pos.x >= startX && pos.x < startX + UPDATE_MAP_SIZE &&
                pos.y >= startY && pos.y < startY + UPDATE_MAP_SIZE)
            {
                continue;
            }

            List <MapPointObj> _list = lastScreenObj[i].objList;
            for (int j = 0; j < _list.Count; j++)
            {
                if (_list[j].obj == null)
                {
                    continue;
                }
                AddPoolObj(_list[j].conf.id, _list[j].obj);
                _list[j].obj = null;
            }
        }

        lastScreenObj.Clear();

        for (int x = 0; x < UPDATE_MAP_SIZE; x++)
        {
            for (int y = 0; y < UPDATE_MAP_SIZE; y++)
            {
                int sx = startX + x;
                int sy = startY + y;

                int _x = UPDATE_MAP_SIZE / 2 - x;
                int _y = UPDATE_MAP_SIZE / 2 - y;

                if (sx < 0 || sx >= map.GetLength(0))
                {
                    break;
                }
                if (sy < 0 || sy >= map.GetLength(1))
                {
                    continue;
                }

                bool isopen = false;
                //小地图中的点是否打开,如果已经打开 则不用计算距离
                if (!smallMap.IsOpenPoint(sx, sy))
                {
                    if (Mathf.Sqrt(_x * _x + _y * _y) <= UPDATE_MAP_SIZE / 2)
                    {
                        isopen = true;
                    }
                }

                InGameMapPointData data = map[sx, sy];
                if (data == null)
                {
                    if (isopen)
                    {
                        smallMap.OpenUnit(sx, sy, MazeCreate.PointType.nullpoint);
                    }
                    continue;
                }

                if (isopen)
                {
                    smallMap.OpenUnit(sx, sy, data.type);
                }

                for (int i = 0; i < data.objList.Count; i++)
                {
                    if (data.objList[i].obj == null)
                    {
                        MapPointObj      mapPointObj = data.objList[i];
                        InGameBaseMapObj obj         = GetPoolObj(mapPointObj.conf);
                        obj.transform.position = GameCommon.GetWorldPos(mapPointObj.pos) + new Vector2(0, Random.Range(0, 0.1f));

                        obj.transform.localScale = mapPointObj.scale;

                        GameCommon.SetObjZIndex(obj.gameObject, mapPointObj.conf.depth);
                        mapPointObj.obj = obj;

                        obj.Show();
                        mapObjActionList.Add(obj);
                    }
                }
                lastScreenObj.Add(data);
            }
        }


        //处理mapobj 动画

        for (int i = mapObjActionList.Count - 1; i >= 0; i--)
        {
            InGameBaseMapObj obj = mapObjActionList[i];
            obj.ActionUpdate();
            if (!obj.isAction)
            {
                mapObjActionList.RemoveAt(i);
            }
        }
    }
Ejemplo n.º 8
0
 public void SetZPos()
 {
     GameCommon.SetObjZIndex(gameObject, 3);
 }