예제 #1
0
        public void SelectToolboxSpawner(ToolBoxSpawnerTemplate selectedSpawner)
        {
            HideProperties();
            EditorTileManager.Instance.HideEditorHighlight();
            HighlightSelectedSpawnerTemplate(selectedSpawner.assetCode);
            tileTemplate = selectedSpawner;

            if (string.IsNullOrEmpty(selectedSpawner.assetCode))
            {
                EditorTileManager.Instance.DisableSpawnerSpawnDetection();
            }
            else
            {
                EditorTileManager.Instance.EnableSpawnerSpawnDetection();
            }
        }
        public void OnPointerClick(PointerEventData eventData)
        {
            if (ToolboxManager.Instance.selectedTileType == ToolBoxTileType.Spawner)
            {
                Vector3 pressPosition = eventData.pointerPressRaycast.worldPosition;

                ToolBoxSpawnerTemplate template = (ToolBoxSpawnerTemplate)ToolboxManager.Instance.tileTemplate;
                Object     prefab = AssetManager.Instance.GetPrefabByKeyword(template.assetCode);
                GameObject go     = Instantiate(prefab) as GameObject;
                go.transform.SetParent(EditorTileManager.Instance.spawnerParent);

                MapEditorSpawnerController spawnControl = go.AddComponent <MapEditorSpawnerController>();
                EditorSpawnerData          spawnData    = new EditorSpawnerData();
                spawnData.assetCode     = template.assetCode;
                spawnData.spawnerMethod = (int)template.spawnMethod;
                spawnData.spawnerType   = (int)template.spawnerType;
                spawnData.spawnInterval = 1;
                spawnData.spawnRate     = 1;
                spawnData.maxSpawn      = 10;
                spawnData.radius        = 0.5f;

                if (template.spawnMethod == SpawnerMethodEditor.Point)
                {
                    spawnData.spawnStartPos = spawnData.spawnEndPos = new Vector2(pressPosition.x, pressPosition.y);
                }
                else if (template.spawnMethod == SpawnerMethodEditor.Line)
                {
                    spawnData.spawnStartPos = new Vector2(pressPosition.x - 0.5f, pressPosition.y);
                    spawnData.spawnEndPos   = new Vector2(pressPosition.x + 0.5f, pressPosition.y);
                }

                spawnControl.Init(spawnData);

                Debug.Log("Spawner Spawn " + spawnData.assetCode);
            }
        }