Пример #1
0
        private bool RouteBuild(MapAsset asset, bool isPost)
        {
            try
            {
                foreach (Builder builder in builders)
                {
                    bool success = false;

                    if (isPost)
                    {
                        success = builder.PostBuild();
                    }
                    else
                    {
                        success = builder.PreBuild(asset);
                    }

                    if (!success)
                    {
                        return(false);
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                LILogger.LogInfo(e.Message + "\n" + e.StackTrace);
                return(false);
            }
        }
Пример #2
0
        public void Apply(PolusShipStatus shipStatus)
        {
            if (!MapHandler.Load())
            {
                return;
            }

            MapData      map     = MapHandler.GetMap();
            PolusHandler polus   = new PolusHandler(shipStatus);
            AssetBuilder builder = new AssetBuilder(polus);

            polus.ClearTasks();
            polus.MoveToTemp();

            for (int i = 0; i < map.objs.Length; i++)
            {
                MapAsset asset   = map.objs[i];
                bool     success = builder.Build(asset);
                if (!success)
                {
                    LILogger.LogError("Failed to build " + asset.name);
                }
                else if (i % 1000 == 0)
                {
                    LILogger.LogMsg(i + " - Objects");
                }
            }

            polus.DeleteTemp();
            LILogger.LogInfo("Applied Map Data");
        }
Пример #3
0
        public bool PreBuild(MapAsset asset)
        {
            if (!asset.type.StartsWith("dec-"))
            {
                return(true);
            }
            DecData utilData = AssetDB.dec[asset.type];

            // Object
            GameObject obj = new GameObject(asset.type);

            // Sprite Renderer
            SpriteRenderer spriteRenderer = obj.AddComponent <SpriteRenderer>();

            spriteRenderer.sprite   = utilData.SpriteRenderer.sprite;
            spriteRenderer.material = utilData.SpriteRenderer.material;
            obj.layer = (int)Layer.ShortObjects;

            // Colliders
            AssetHelper.BuildColliders(asset, obj, utilData.Scale);

            polus.Add(obj, asset, utilData.Scale);

            return(true);
        }
Пример #4
0
        public bool PreBuild(MapAsset asset)
        {
            if (!asset.type.StartsWith("room-"))
            {
                return(true);
            }
            RoomData utilData = AssetDB.room[asset.type];

            // Object
            GameObject obj = new GameObject(asset.type);

            // Sprite Renderer
            SpriteRenderer spriteRenderer = obj.AddComponent <SpriteRenderer>();

            spriteRenderer.sprite   = utilData.SpriteRenderer.sprite;
            spriteRenderer.material = utilData.SpriteRenderer.material;
            obj.layer = (int)Layer.Ship;

            // Colliders
            AssetHelper.BuildColliders(asset, obj, utilData.Scale);

            // Add to Polus
            Vector3 bounds = spriteRenderer.sprite.bounds.center;

            polus.Add(obj, asset, utilData.Scale, bounds.x, bounds.y);

            return(true);
        }
Пример #5
0
    public void LoadAsset(MapAsset mapAsset)
    {
        GameObject isLoaded = IsThisALoadedAsset(mapAsset);

        if (isLoaded != null)
        {
            isLoaded.transform.position = mapAsset.Position;
            isLoaded.transform.rotation = Quaternion.Euler(0, mapAsset.Orientation, 0);
            return;
        }

        Vector3    position    = new Vector3(mapAsset.X, mapAsset.Y, mapAsset.Z);
        Quaternion orientation = Quaternion.Euler(0, mapAsset.Orientation, 0);

        Debug.Log(orientation.eulerAngles);
        Debug.Log("Asset loaded: " + mapAsset.Orientation);
        GameObject instantiatedAsset = Instantiate(GetPrefab(mapAsset.AssetId), position, orientation);

        instantiatedAsset.name = mapAsset.AssetId;
        sceneAssets.Add(instantiatedAsset);
        Debug.Log("Asset instantiated: " + instantiatedAsset.transform.rotation.eulerAngles);

        Animate(instantiatedAsset, "Success");

        if (!found)
        {
            found = true;
            Toast("You found the scene!", 2.0f);
            progressPanel.SetActive(false);
        }

        addButton.SetActive(true);
    }
Пример #6
0
    public static void CreateTilesPrefabAndData()
    {
        string tilesFilePath = "Assets" + MapDefine.TilesMapFilePath;

        // string directoryPath = tilesFilePath.Substring(0, tilesFilePath.LastIndexOf("/"));
        if (Directory.Exists(tilesFilePath))
        {
            Directory.Delete(tilesFilePath, true);
        }
        Directory.CreateDirectory(tilesFilePath);
        string[] bigMapIndexs = ("0_0").Split('_');
        int      bigMapX      = int.Parse(bigMapIndexs[0]);
        int      bigMapY      = int.Parse(bigMapIndexs[1]);
        //基于大地图偏移
        int      offsetX   = bigMapX * MapDefine.MAPITEMTOTALSIZE;
        int      offsetY   = bigMapY * MapDefine.MAPITEMTOTALSIZE;
        string   bigMapKey = bigMapX + "" + bigMapY;
        MapAsset mapAsset  = new MapAsset();

        tilesIndex = 0;
        EditorUtility.DisplayProgressBar("遍历瓦片数据", "地图瓦片遍历ing...", 0);
        CreateTilesMap(bigMapKey, offsetX, offsetY, mapAsset);
        // EditorUtility.DisplayProgressBar("遍历瓦片数据", "地图纹理瓦片遍历ing...", 0);
        // GameObject root = GameObject.Find("MapTilesRoot/MapTextureTiles");
        // CreateTileTexture(root.transform,bigMapKey, offsetX, offsetY, mapAsset);
        CreateTileDataFile(mapAsset, bigMapKey);
        EditorUtility.ClearProgressBar();
    }
Пример #7
0
 public void InitData(MapAsset mapData, Vector3 pos)
 {
     if (mapData == null)
     {
         Debug.LogError("MapAsset is null!!");
     }
     mapAsset = mapData;
     mapKey   = (int)pos.x / MapDefine.MAPITEMTOTALSIZE + "" + (int)pos.z / MapDefine.MAPITEMTOTALSIZE;
     if (mapAsset != null)
     {
         Dictionary <string, MapElement> tempElementDic = new Dictionary <string, MapElement>();
         for (int index = 0; index < mapAsset.elementList.Count; index++)
         {
             MapElement tempElement = mapAsset.elementList[index];
             tempElementDic[tempElement.elementKey] = tempElement;
         }
         AllMapElementDic[mapKey] = tempElementDic;
         Dictionary <string, MapElementGrid> tempElementGridDic = new Dictionary <string, MapElementGrid>();
         for (int index = 0; index < mapAsset.ElementGrids.Count; index++)
         {
             MapElementGrid tempElementGrid = mapAsset.ElementGrids[index];
             tempElementGridDic[tempElementGrid.gridKey] = tempElementGrid;
         }
         bigElementGridDic[mapKey] = tempElementGridDic;
     }
     else
     {
         Debug.LogError("MapAsset is null!!");
     }
 }
Пример #8
0
        public bool PreBuild(MapAsset asset)
        {
            if (!asset.type.StartsWith("util-spawn"))
            {
                return(true);
            }
            Vector2 pos = new Vector2(asset.x, -asset.y - 25.0f);

            if (asset.type == "util-spawn1")
            {
                polus.shipStatus.InitialSpawnCenter = pos;
            }
            else if (asset.type == "util-spawn2")
            {
                polus.shipStatus.MeetingSpawnCenter  = pos;
                polus.shipStatus.MeetingSpawnCenter2 = pos;
            }
            else
            {
                LILogger.LogError("Unknown Spawn Type '" + asset.type + "'");
                return(false);
            }

            return(true);
        }
Пример #9
0
        public bool Build(MapAsset asset)
        {
            GameObject obj = new GameObject("Custom Asset");

            // Base64
            string base64 = asset.type.Substring(asset.type.IndexOf(",") + 1);

            byte[] data;
            try
            {
                data = System.Convert.FromBase64String(base64);
            }
            catch
            {
                LILogger.LogError("Could not parse custom asset texture");
                return(false);
            }

            // Texture
            Texture2D tex = new Texture2D(1, 1);

            ImageConversion.LoadImage(tex, data);

            // Sprite Renderer
            SpriteRenderer spriteRenderer = obj.AddComponent <SpriteRenderer>();

            spriteRenderer.sprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f);

            // Polus
            polus.Add(obj, asset);
            return(true);
        }
Пример #10
0
 public void Add(GameObject obj, MapAsset asset)
 {
     obj.transform.position   = new Vector3(asset.x, -asset.y, asset.z);
     obj.transform.localScale = new Vector3(asset.xScale, asset.yScale, 1.0f);
     obj.transform.rotation   = Quaternion.Euler(new Vector3(0, 0, -asset.rotation));
     obj.transform.SetParent(gameObject.transform);
 }
Пример #11
0
 public void SetupDefaultMapData(MapAsset pMapAsset)
 {
     this.isDefaultMap = true;
     this.mapData      = pMapAsset.data;
     label.text        = mapData.map_name;
     this.name         = string.Format("Map_{0}", mapData.map_name);
     rawImage.texture  = pMapAsset.texture;
 }
 public static new void LoadMap(MapAsset map)
 {
     if (SocketConnection.GetIsServer())
     {
         SocketConnection.WriteToOpponent("LOADMAP|" + map.m_mapIndex); // Send the current map's ID
     }
     //SocketConnection.WriteToUI("SHOWMSG|Loading map " + map.m_mapIndex + " " + map.MapName); // Debug
     orig_LoadMap(map); // Call orig function
 }
Пример #13
0
        public bool Build(MapAsset asset)
        {
            SabData utilData = AssetDB.sabs[asset.type];

            // Object
            GameObject obj = new GameObject(asset.type);

            // Sprite Renderer
            SpriteRenderer spriteRenderer = obj.AddComponent <SpriteRenderer>();

            spriteRenderer.sprite   = utilData.SpriteRenderer.sprite;
            spriteRenderer.material = utilData.SpriteRenderer.material;

            // Console
            SystemConsole origConsole = utilData.GameObj.GetComponent <SystemConsole>();
            SystemConsole console     = obj.AddComponent <SystemConsole>();

            console.Image          = spriteRenderer;
            console.FreeplayOnly   = origConsole.FreeplayOnly;
            console.onlyFromBelow  = origConsole.onlyFromBelow;
            console.usableDistance = origConsole.usableDistance;
            console.MinigamePrefab = origConsole.MinigamePrefab;
            console.useIcon        = origConsole.useIcon;

            // Box Collider
            if (utilData.GameObj.GetComponent <CircleCollider2D>() != null)
            {
                CircleCollider2D origBox = utilData.GameObj.GetComponent <CircleCollider2D>();
                CircleCollider2D box     = obj.AddComponent <CircleCollider2D>();
                box.radius    = origBox.radius;
                box.offset    = origBox.offset;
                box.isTrigger = true;
            }
            else
            {
                BoxCollider2D origBox = utilData.GameObj.GetComponent <BoxCollider2D>();
                BoxCollider2D box     = obj.AddComponent <BoxCollider2D>();
                box.size      = origBox.size;
                box.offset    = origBox.offset;
                box.isTrigger = true;
            }

            // Button
            PassiveButton origBtn = utilData.GameObj.GetComponent <PassiveButton>();
            PassiveButton btn     = obj.AddComponent <PassiveButton>();

            btn.ClickMask   = origBtn.ClickMask;
            btn.OnMouseOver = new UnityEvent();
            btn.OnMouseOut  = new UnityEvent();
            Action action = console.Use;

            btn.OnClick.AddListener(action);

            polus.Add(obj, asset);

            return(true);
        }
Пример #14
0
        public bool Build(MapAsset asset)
        {
            GameObject dummy = new GameObject("Dummy");

            dummy.transform.SetParent(polus.gameObject.transform);
            dummy.transform.position = new Vector2(asset.x, asset.y);

            polus.shipStatus.DummyLocations = AssetBuilder.AddToArr(polus.shipStatus.DummyLocations, dummy.transform);
            return(true);
        }
Пример #15
0
        public bool PreBuild(MapAsset asset)
        {
            if (asset.type != "util-room")
            {
                return(true);
            }

            // Check Collider Count
            if (asset.colliders.Length <= 0)
            {
                LILogger.LogWarn(asset.name + " does not have any colliders!");
                return(false);
            }

            // Object
            GameObject obj = new GameObject(asset.name);

            // Collider
            PolygonCollider2D mainCollider = null;

            foreach (MapCollider collider in asset.colliders)
            {
                PolygonCollider2D polyCollider = obj.AddComponent <PolygonCollider2D>();
                polyCollider.isTrigger = true;
                polyCollider.SetPath(0, collider.GetPoints());
                mainCollider = polyCollider;
            }

            // Room
            PlainShipRoom room = obj.AddComponent <PlainShipRoom>();

            room.RoomId = (SystemTypes)roomId;
            if (asset.colliders.Length > 0)
            {
                room.roomArea = mainCollider;
            }

            // Room DB
            if (!db.ContainsKey(asset.id))
            {
                db.Add(asset.id, (SystemTypes)roomId);
            }

            // Text DB
            TextHandler.Add((SystemTypes)roomId, asset.name);

            // Polus
            polus.shipStatus.AllRooms = AssetHelper.AddToArr(polus.shipStatus.AllRooms, room);
            polus.shipStatus.FastRooms.Add((SystemTypes)roomId, room);
            MinimapGenerator.AddRoom(asset);
            polus.Add(obj, asset);

            roomId++;
            return(true);
        }
Пример #16
0
        public void PreBuild(PolusShipStatus shipStatus)
        {
            // Load Map and AssetDB
            if (!AssetDB.Import())
            {
                return;
            }
            if (!MapHandler.Load())
            {
                return;
            }

            // Vars
            map     = MapHandler.GetMap();
            polus   = new PolusHandler(shipStatus);
            builder = new AssetBuilder(polus);
            MinimapGenerator.Reset();

            // Rooms
            LILogger.LogInfo("...Building Rooms");
            for (int i = 0; i < map.objs.Length; i++)
            {
                if (map.objs[i].type != "util-room")
                {
                    continue;
                }
                MapAsset asset   = map.objs[i];
                bool     success = builder.PreBuild(asset);
                if (!success)
                {
                    LILogger.LogError("Failed to build " + asset.name);
                }
            }

            // Objects
            LILogger.LogInfo("...Building Objects");
            for (int i = 0; i < map.objs.Length; i++)
            {
                if (map.objs[i].type == "util-room")
                {
                    continue;
                }
                MapAsset asset   = map.objs[i];
                bool     success = builder.PreBuild(asset);
                if (!success)
                {
                    LILogger.LogError("Failed to build " + asset.name);
                }
                else if (i % 100 == 0 && i != 0)
                {
                    LILogger.LogInfo("..." + i + " Objects Built");
                }
            }
        }
Пример #17
0
 // Add Objs
 public void Add(GameObject obj, MapAsset asset, float scale = 1.0f, float xOffset = 0, float yOffset = 0)
 {
     obj.transform.position   = new Vector3(asset.x - xOffset, -asset.y - Y_OFFSET - yOffset, asset.z);
     obj.transform.localScale = new Vector3(
         asset.xScale * (asset.flipX ? -1 : 1) * scale,
         asset.yScale * (asset.flipY ? -1 : 1) * scale,
         1.0f
         );
     obj.transform.rotation = Quaternion.Euler(new Vector3(0, 0, -asset.rotation));
     obj.transform.SetParent(gameObject.transform);
 }
Пример #18
0
        protected override void Initialize()
        {
            // Orthogonal map.
            //MapAsset.LoadMap(@"Content\testmap.json");

            // Isometric map.
            MapAsset.LoadMap(@"Content\testmap-isometric.json");
            MapAsset.ActiveMap.ScaleFactor = 1;
            MapAsset.ActiveMap.CentreMap(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);

            base.Initialize();
        }
Пример #19
0
    //Saving assets using the MapSession
    public void SaveAssets()
    {
        List <MapAsset> mapAssets = new List <MapAsset>();

        foreach (GameObject asset in sceneAssets)
        {
            MapAsset mapAsset = new MapAsset(asset.name, asset.transform.rotation.eulerAngles.y, asset.transform.position);
            mapAssets.Add(mapAsset);
        }

        mapSession.StorePlacements(mapAssets);
    }
Пример #20
0
    private GameObject IsThisALoadedAsset(MapAsset asset)
    {
        foreach (var sceneAsset in sceneAssets)
        {
            if (asset.AssetId == sceneAsset.name)
            {
                return(sceneAsset);
            }
        }

        return(null);
    }
Пример #21
0
    //生成数据文件
    private static void CreateTileDataFile(MapAsset mapAsset, string bigMapKey)
    {
        string tempPth = string.Format(MapDefine.MapTilesAssetFolderPath, bigMapKey);

        if (!Directory.Exists(tempPth))
        {
            Directory.CreateDirectory(tempPth);
        }
        tempPth += string.Format(MapDefine.MapTilesAssetFileName, bigMapKey);
        AssetDatabase.CreateAsset(mapAsset, tempPth);
        AssetDatabase.Refresh();
    }
Пример #22
0
        public bool PreBuild(MapAsset asset)
        {
            if (asset.type != "util-player")
            {
                return(true);
            }
            GameObject dummy = new GameObject("Dummy");

            dummy.transform.SetParent(polus.gameObject.transform);
            dummy.transform.position = new Vector2(asset.x, -asset.y - PolusHandler.Y_OFFSET);

            polus.shipStatus.DummyLocations = AssetHelper.AddToArr(polus.shipStatus.DummyLocations, dummy.transform);
            return(true);
        }
Пример #23
0
    public void InitMapLittleElementView(MapAsset data)
    {
        MapBlockLoadData blockData = new MapBlockLoadData()
        {
            root          = elementRoot.transform,
            mapAsset      = data,
            disableMaxNum = 50,
            interval      = 8,
            cacheNum      = 50,
            pos           = Vector3.zero,
        };

        LittleElementBlockLoader = new MapBlockLoader(blockData);
    }
Пример #24
0
    //初始化
    public void InitMapElementView(MapAsset data)
    {
        elementRoot = new GameObject("MapElement");

        MapBlockLoadData blockData = new MapBlockLoadData()
        {
            root          = elementRoot.transform,
            mapAsset      = data,
            interval      = 16,
            disableMaxNum = 50,
            pos           = Vector3.zero,
        };

        elementBlockLoader = new MapBlockLoader(blockData);
    }
Пример #25
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="data">配置文件</param>
 /// <param interval="interval">九宫格大小</param>
 public MapBlockLoader(MapBlockLoadData data)
 {
     if (data != null)
     {
         elementRoot = data.root;
         mapAsset    = data.mapAsset;
         interval    = data.interval;
         buffNum     = data.disableMaxNum;
         cacheNum    = data.cacheNum;
         InitMapAsset(data.pos);
     }
     else
     {
         Debug.LogError("MapData is Error!!!");
     }
 }
Пример #26
0
    //Saving assets using the MapSession
    public void SaveAsset()
    {
        saveAssetButton.SetActive(false);

        List <MapAsset> mapAssetsToSave = new List <MapAsset> ();

        foreach (GameObject asset in assetsToSave)
        {
            MapAsset mapAsset = new MapAsset(asset.name, asset.transform.rotation.y, asset.transform.position);
            mapAssetsToSave.Add(mapAsset);
            Debug.Log("Asset stored at: " + asset.transform.position.ToString());
        }

        mapSession.StorePlacements(mapAssetsToSave);

        Toast("Please wait while your bear's garden is planted.", 10.0f);
    }
Пример #27
0
    //地形瓦片
    private static void CreateTilesMap(string bigMapKey, int offsetX, int offsetY, MapAsset mapAsset)
    {
        GameObject root = GameObject.Find("MapTilesRoot/MapTiles");

        if (root == null)
        {
            return;
        }


        //美术还没弄完先,目前只有一种类型,先特殊处理
        Renderer[] gos = root.transform.GetComponentsInChildren <Renderer>();


        for (int index = 0; index < gos.Length; index++)
        {
            Transform element = gos[index].transform;
            element.gameObject.name = gos[index].sharedMaterial.name;
            if (true)//element.gameObject.name.Contains(TilesMapKey))
            {
                string prefabPath = MapDefine.TilesMapFilePath + element.gameObject.name + ".prefab";
                if (!System.IO.File.Exists(Application.dataPath + prefabPath))
                {
                    PrefabUtility.CreatePrefab("Assets" + prefabPath, element.gameObject);
                }
                int    col            = (int)(element.position.x + offsetX) / MapDefine.MapElementSize;
                int    row            = (int)(element.position.z + offsetY) / MapDefine.MapElementSize;
                string elementGridKey = col + "" + row;
                string elementKey     = tilesIndex + "";
                tilesIndex++;
                string         gridKey     = col + "_" + row;
                MapElementInfo elementInfo = new MapElementInfo()
                {
                    Pos   = element.position,
                    Angle = element.eulerAngles,
                    Scale = element.localScale
                };
                MapElement mapElement = new MapElement();
                mapElement.elementKey  = elementKey;
                mapElement.elementType = element.name;
                mapElement.elementInfo = elementInfo;
                mapAsset.AddMapElement(mapElement);
                mapAsset.AddMapElementGridItem(gridKey, elementKey);
            }
        }
    }
Пример #28
0
        public bool Build(MapAsset asset)
        {
            RoomData utilData = AssetDB.room[asset.type];

            // Object
            GameObject obj = new GameObject(asset.type);

            // Sprite Renderer
            SpriteRenderer spriteRenderer = obj.AddComponent <SpriteRenderer>();

            spriteRenderer.sprite   = utilData.SpriteRenderer.sprite;
            spriteRenderer.material = utilData.SpriteRenderer.material;

            polus.Add(obj, asset);

            return(true);
        }
Пример #29
0
        public void Generate(MapAsset asset)
        {
            // Object
            GameObject sabRoomObj = new GameObject(asset.name);

            sabRoomObj.transform.localScale = new Vector3(0.8f, 0.8f, 1.0f);
            sabRoomObj.transform.SetParent(overlayObj.transform);
            sabRoomObj.transform.localPosition = new Vector3(0, 0, -25.0f);

            // MapRoom
            MapRoom sabMapRoom = sabRoomObj.AddComponent <MapRoom>();

            sabMapRoom.room   = ShipRoomBuilder.db[asset.id];
            sabMapRoom.Parent = overlay;
            overlay.rooms     = AssetHelper.AddToArr(overlay.rooms, sabMapRoom);

            sabDb.Add(sabMapRoom.room, sabMapRoom);
        }
Пример #30
0
        public static void BuildColliders(MapAsset asset, GameObject obj, float scale = 1.0f)
        {
            // Colliders
            GameObject shadowObj = new GameObject("Shadows");

            shadowObj.layer = (int)Layer.Shadow;
            shadowObj.transform.SetParent(obj.transform);
            foreach (MapCollider collider in asset.colliders)
            {
                EdgeCollider2D edgeCollider = obj.AddComponent <EdgeCollider2D>();
                edgeCollider.SetPoints(collider.GetPoints(scale, scale));

                if (collider.blocksLight)
                {
                    EdgeCollider2D lightCollider = shadowObj.AddComponent <EdgeCollider2D>();
                    lightCollider.SetPoints(collider.GetPoints(scale, scale));
                }
            }
        }