void UpdateTileMapInfo()
        {
            this.tileWidthCount  = 0;
            this.tileHeightCount = 0;

            if (curTileMap == null)
            {
                this.curTileMap = GameObject.FindObjectOfType <TileMapRoot>();
            }

            if (curTileMap)
            {
                this.tileWidthCount  = curTileMap.TileWidthCount;
                this.tileHeightCount = curTileMap.TileHeightCount;
                this.screen2D        = curTileMap.GetMapInfo().screen2D;

                curTileMap.InitTileMapEngine();
                EditorUtility.SetDirty(TileMapEngine.Instance);
            }

            GUI.FocusControl("");
        }
Пример #2
0
        void OnDrawGizmosSelected()
        {
            if (!Application.isPlaying)
            {
                if (tileMap == null)
                {
                    SetTileMap();
                }

                bool screen2D = false;
                if (tileMap)
                {
                    screen2D = tileMap.GetMapInfo().screen2D;
                }

                Gizmos.color = Color.blue;

                Vector3 size;
                if (screen2D)
                {
                    size = new Vector3(squareSize.x * 0.9f, squareSize.y * 0.9f, 0.0f);
                }
                else
                {
                    size = new Vector3(squareSize.x * 0.9f, 0.0f, squareSize.y * 0.9f);
                }

                Gizmos.DrawWireCube(WorldPosition, size);

                foreach (ITileMapNode connectedNode in connections)
                {
                    Gizmos.color = Color.green;
                    Gizmos.DrawWireCube(
                        WorldPosition + (connectedNode.WorldPosition - WorldPosition) * 0.5f,
                        size * 0.5f
                        );
                }
            }
        }
        void OnGUI()
        {
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

            selectMode = (SelectMode)EditorGUILayout.EnumPopup("Select Mode: ", selectMode);

            // about create tile
            {
                TileMapRoot beforeTileMap = curTileMap;
                curTileMap = EditorGUILayout.ObjectField("curTileMap", curTileMap, typeof(TileMapRoot), true) as TileMapRoot;
                if (beforeTileMap != curTileMap)
                {
                    UpdateTileMapInfo();
                }

                if (curTileMap)
                {
                    if (GUILayout.Button("select", GUILayout.Width(100.0f)))
                    {
                        Selection.activeObject = curTileMap.gameObject;
                    }
                }

                tilePrefab = EditorGUILayout.ObjectField("Tile Prefab", tilePrefab, typeof(SquareTileMapNode), false) as SquareTileMapNode;
                screen2D   = EditorGUILayout.Toggle("screen2D", screen2D);

                tileWidthCount = EditorGUILayout.IntField("Tile Width Count: ", tileWidthCount);
                if (tileWidthCount < 0)
                {
                    tileWidthCount = 0;
                }
                if (tileWidthCount > maxTileWidthCount)
                {
                    tileWidthCount = maxTileWidthCount;
                }

                tileHeightCount = EditorGUILayout.IntField("Tile Height Count: ", tileHeightCount);
                if (tileHeightCount < 0)
                {
                    tileHeightCount = 0;
                }
                if (tileHeightCount > maxTileHeightCount)
                {
                    tileHeightCount = maxTileHeightCount;
                }

                if (tilePrefab && tileWidthCount > 0 && tileHeightCount > 0)
                {
                    GUILayout.BeginHorizontal();

                    if (GUILayout.Button("Make New TileMap"))
                    {
                        MakeTileMap();
                    }

                    if (curTileMap)
                    {
                        if (GUILayout.Button("Remake TileMap"))
                        {
                            RemakeTileMap();
                        }

                        if (curTileMap.GetMapInfo().tileWidthCount <= tileWidthCount &&
                            curTileMap.GetMapInfo().tileHeightCount <= tileHeightCount)
                        {
                            if (GUILayout.Button("Extend TileMap"))
                            {
                                ExtendTileMap();
                            }
                        }
                    }

                    GUILayout.EndHorizontal();
                }
            }

            GUIDrawLine();

            // about tile selection
            {
                // collect selected tileMapNodes
                selectedTileMapNodes.Clear();
                GameObject[] selectedObjects = Selection.gameObjects;
                foreach (GameObject selectedGameObj in selectedObjects)
                {
                    SquareTileMapNode tileMapNode = selectedGameObj.GetComponent <SquareTileMapNode>();
                    if (tileMapNode && selectedGameObj.activeInHierarchy)
                    {
                        selectedTileMapNodes.Add(tileMapNode);
                    }
                }

                // show selected tileMapNodes count
                GUILayout.Label(string.Format("selectedTileMapNodes count: {0}", selectedTileMapNodes.Count));

                // about tile remake
                tilePrefabForChange = EditorGUILayout.ObjectField("Tile Prefab for change", tilePrefabForChange, typeof(SquareTileMapNode), true) as SquareTileMapNode;
                if (tilePrefabForChange && selectedTileMapNodes.Count > 0)
                {
                    if (GUILayout.Button("Change selected tiles"))
                    {
                        foreach (SquareTileMapNode selectedMapTile in selectedTileMapNodes)
                        {
                            GameObject        tileMapNodeGroup  = selectedMapTile.transform.parent.gameObject;
                            SquareTileMapNode squareTileMapNode = MakeTileMapOneTile(
                                selectedMapTile.NodeID,
                                selectedMapTile.TilePosX,
                                selectedMapTile.TilePosY,
                                tilePrefabForChange,
                                tileMapNodeGroup);
                        }

                        foreach (SquareTileMapNode selectedMapTile in selectedTileMapNodes)
                        {
                            DestroyImmediate(selectedMapTile.gameObject);
                        }

                        MakeConnectionEachOtherNodes();
                    }
                }

                GUIDrawLine();

                // about tile map object creation
                {
                    curTileMapObjectGroup = EditorGUILayout.ObjectField("TileMapObjectGroup ", curTileMapObjectGroup, typeof(TileMapObjectGroup), true) as TileMapObjectGroup;
                    if (curTileMapObjectGroup)
                    {
                        if (IsPrefabTarget(curTileMapObjectGroup.gameObject))
                        {
                            if (selectedTileMapNodes.Count > 0 && curTileMap != null)
                            {
                                if (GUILayout.Button("Create TileMapObjectGroup"))
                                {
                                    if (positionedObjGroupGameObj == null)
                                    {
                                        const string positionGroupOfTileMapObjectGroup = "_PositionedObjectGroups";
                                        positionedObjGroupGameObj = GameObject.Find(positionGroupOfTileMapObjectGroup);
                                        if (positionedObjGroupGameObj == null)
                                        {
                                            positionedObjGroupGameObj = new GameObject(positionGroupOfTileMapObjectGroup);
                                        }
                                    }

                                    foreach (SquareTileMapNode tileMapNode in selectedTileMapNodes)
                                    {
                                        GameObject newTileMapObjGroup = PrefabUtility.InstantiatePrefab(curTileMapObjectGroup.gameObject) as GameObject;
                                        newTileMapObjGroup.transform.parent = positionedObjGroupGameObj.transform;

                                        TileMapObjectGroup newTileMapObjGroupCompo = newTileMapObjGroup.GetComponent <TileMapObjectGroup>();
                                        newTileMapObjGroupCompo.SetTilePos(tileMapNode);
                                    }
                                }
                            }
                        }
                        else
                        {
                            groundTileForChangeAtSelectedObjectBlockPos =
                                EditorGUILayout.ObjectField("GroundTileForChangeAtObjectBlockPositions",
                                                            groundTileForChangeAtSelectedObjectBlockPos,
                                                            typeof(SquareTileMapNode),
                                                            true) as SquareTileMapNode;

                            if (groundTileForChangeAtSelectedObjectBlockPos && curTileMap)
                            {
                                if (GUILayout.Button("Change groundTile at object block pos"))
                                {
                                    MakeConnectionEachOtherNodes();

                                    List <SquareTileMapNode> forChangeGroundTileList = new List <SquareTileMapNode>();
                                    int[,] blockTileData = curTileMapObjectGroup.GetBlockTileData();

                                    for (int x = 0; x < curTileMapObjectGroup.TileMapSize.width; ++x)
                                    {
                                        for (int y = 0; y < curTileMapObjectGroup.TileMapSize.height; ++y)
                                        {
                                            int blockFlag = blockTileData[x, y];

                                            if (blockFlag == 1)
                                            {
                                                TilePos           tilePos = curTileMapObjectGroup.TilePos + new TilePos(x, y);
                                                SquareTileMapNode node    = TileMapEngine.Instance.GetTileNode(tilePos);
                                                if (node == null)
                                                {
                                                    Debug.LogError(string.Format("null node : {0}_{1}", tilePos.x, tilePos.y));
                                                    continue;
                                                }

                                                forChangeGroundTileList.Add(node);
                                            }
                                        }
                                    }

                                    foreach (SquareTileMapNode node in forChangeGroundTileList)
                                    {
                                        GameObject tileMapNodeGroup = node.transform.parent.gameObject;

                                        SquareTileMapNode squareTileMapNode = MakeTileMapOneTile(
                                            node.NodeID,
                                            node.TilePosX,
                                            node.TilePosY,
                                            groundTileForChangeAtSelectedObjectBlockPos,
                                            tileMapNodeGroup);
                                    }

                                    foreach (SquareTileMapNode node in forChangeGroundTileList)
                                    {
                                        DestroyImmediate(node.gameObject);
                                    }
                                }
                            }
                        }
                    }

                    tileMapObjPrefabForCreation = EditorGUILayout.ObjectField("TileMapObj Prefab for Creation", tileMapObjPrefabForCreation, typeof(TileMapObject), true) as TileMapObject;
                    if (tileMapObjPrefabForCreation && selectedTileMapNodes.Count > 0 && curTileMap != null)
                    {
                        if (GUILayout.Button("Create TileMapObjs to selected nodes pos"))
                        {
                            GameObject objectGroupGameObj;
                            if (curTileMapObjectGroup != null)
                            {
                                objectGroupGameObj = curTileMapObjectGroup.gameObject;
                            }

                            // get objectGroup gameobject
                            {
                                const string objectGroupGameObjectName = "_ObjectGroup";

                                objectGroupGameObj = GameObject.Find(objectGroupGameObjectName);
                                if (objectGroupGameObj == null)
                                {
                                    objectGroupGameObj = new GameObject(objectGroupGameObjectName);
                                }

                                objectGroupGameObj.transform.position = Vector3.zero;

                                //BattleObject bo = objectGroupGameObj.GetComponent<BattleObject>();
                                //if (bo == null) {
                                //bo = objectGroupGameObj.AddComponent<BattleObject>();
                                //}

                                TileMapObjectGroup objectGroup = objectGroupGameObj.GetComponent <TileMapObjectGroup>();
                                if (objectGroup == null)
                                {
                                    objectGroup = objectGroupGameObj.AddComponent <TileMapObjectGroup>();
                                }
                                objectGroup.Init(new TileMapSize(curTileMap.TileWidthCount, curTileMap.TileHeightCount), new TilePos(0, 0));

                                curTileMapObjectGroup = objectGroup;
                            }

                            foreach (SquareTileMapNode tileMapNode in selectedTileMapNodes)
                            {
                                // create tile-map-object
                                GameObject newTileMapObj = PrefabUtility.InstantiatePrefab(tileMapObjPrefabForCreation.gameObject) as GameObject;
                                newTileMapObj.transform.position = tileMapNode.transform.position;

                                TileMapObject tileMapObjCompo = newTileMapObj.GetComponent <TileMapObject>();
                                tileMapObjCompo.Init(Kino.TileMap.Direction.Bottom, new TilePos(tileMapNode.TilePosX, tileMapNode.TilePosY));

                                newTileMapObj.transform.parent = objectGroupGameObj.transform;
                            }
                        }
                    }
                }
            }

            GUIDrawLine();

            // about tile map data export
            {
                if (curTileMap)
                {
                    GUILayout.Label(string.Format("tileMapID: {0}, tileMapName: {1}, width: {2}, height: {3}",
                                                  curTileMap.MapID, curTileMap.MapName, curTileMap.TileWidthCount, curTileMap.TileHeightCount));

                    if (GUILayout.Button("select", GUILayout.Width(100.0f)))
                    {
                        Selection.activeObject = curTileMap.gameObject;
                    }

                    if (GUILayout.Button("Export TileMapData"))
                    {
                        ExportCurrentTileMapData();
                    }

                    if (GUILayout.Button("Export TileMapData for client"))
                    {
                        ExportCurrentTileMapDataForClient();
                    }
                }
            }

            // about tile map object data export
            {
                if (curTileMapObjectGroup)
                {
                    //BattleObject bo = curTileMapObjectGroup.GetComponent<BattleObject>();

                    //if (bo) {
                    //GUILayout.Label(string.Format("objectID: {0}, objectName: {1}, width: {2}, height: {3}, hp: {4}, respawnTime: {5}",
                    //bo.ObjectID,
                    //bo.ObjectName,
                    //curTileMapObjectGroup.TileMapSize.width,
                    //curTileMapObjectGroup.TileMapSize.height,
                    //bo.HP,
                    //bo.RespawnTimeBySec));
                    //}

                    if (GUILayout.Button("select", GUILayout.Width(100.0f)))
                    {
                        Selection.activeObject = curTileMapObjectGroup.gameObject;
                    }

                    if (GUILayout.Button("Export TileMapObjectGroupData"))
                    {
                        ExportCurrentTileMapObjectGroupData();
                    }
                }
            }

            // about tile map object groups pos data export
            {
                positionedObjGroupGameObj = EditorGUILayout.ObjectField("positionedObjGroupGameObj for export", positionedObjGroupGameObj, typeof(GameObject), true) as GameObject;

                if (curTileMap && positionedObjGroupGameObj)
                {
                    if (GUILayout.Button("Export PositionInfos about positionedObjectGroups"))
                    {
                        ExportPositionInfosAboutPositionedObjectGroupsDatas();
                    }
                }
            }

            GUIDrawLine();

            // PathFinder Test
            {
                GUILayout.Label("PathFind Test");

                if (GUILayout.Button("Init for Test"))
                {
                    MakeConnectionEachOtherNodes();
                    ClearAboutPathTest();
                }

                if (GUILayout.Button("clear"))
                {
                    ClearAboutPathTest();
                }

                if (selectedTileMapNodes.Count > 0)
                {
                    SquareTileMapNode targetNode = selectedTileMapNodes[0];

                    GUILayout.Label(string.Format("target nodeID:{0}", targetNode.nodeID));

                    if (GUILayout.Button("Set StartNode"))
                    {
                        if (!targetNode.Invalid)
                        {
                            if (pathFindTestStartNode)
                            {
                                DestroyImmediate(pathFindTestStartNode.gameObject.GetComponent <StartNodeMarker>());
                                DestroyImmediate(pathFindTestStartNode.gameObject.GetComponent <GoalNodeMarker>());
                            }

                            pathFindTestStartNode = targetNode;
                            pathFindTestStartNode.gameObject.AddComponent <StartNodeMarker>();
                        }
                    }

                    if (GUILayout.Button("Set GoalNode"))
                    {
                        if (!targetNode.Invalid)
                        {
                            if (pathFindTestGoalNode)
                            {
                                DestroyImmediate(pathFindTestGoalNode.gameObject.GetComponent <StartNodeMarker>());
                                DestroyImmediate(pathFindTestGoalNode.gameObject.GetComponent <GoalNodeMarker>());
                            }

                            pathFindTestGoalNode = targetNode;
                            pathFindTestGoalNode.gameObject.AddComponent <GoalNodeMarker>();
                        }
                    }
                }

                if (pathFindTestStartNode != null && pathFindTestGoalNode != null)
                {
                    if (GUILayout.Button("Find Path"))
                    {
                        List <SquareTileMapNode> findedPath = TileMapEngine.Instance.Calculate(pathFindTestStartNode, pathFindTestGoalNode);

                        GameObject nodePathGameObj = GameObject.Find(NodePathMarker.GameObjName);
                        if (nodePathGameObj)
                        {
                            DestroyImmediate(nodePathGameObj);
                        }

                        if (findedPath == null || findedPath.Count == 0)
                        {
                            ShowNotification(new GUIContent("cannot find path"));
                        }
                        else
                        {
                            nodePathGameObj = new GameObject(NodePathMarker.GameObjName);

                            NodePathMarker nodePathMarker = nodePathGameObj.AddComponent <NodePathMarker>();
                            nodePathMarker.findedPath = findedPath;
                        }
                    }
                }
            }

            GUIDrawLine();

            GUILayout.Label("tood:");

            EditorGUILayout.EndScrollView();

            if (Event.current.type == EventType.MouseMove)
            {
                Repaint();
            }
        }