예제 #1
0
    void Awake()
    {
        crowdMgr = GetComponent <CrowdManager>();
        crowdMgr.SetNumInstances(Count);

        weaponMgr = GetComponent <WeaponManager>();
        weaponMgr.SetInstanceNum(Count);

        grid        = gameObject.AddComponent <SceneGrid>();
        grid.center = new Vector2(spawnRadius, spawnRadius);

        GridID     = new int[Count];
        Velocities = new Vector3[Count];
        Rotations  = new Quaternion[Count];
        Positions  = new Vector3[Count];
        Weapons    = new int[Count];

        // State machine definitions
        stateDefinition    = new AnimationState[3];
        stateDefinition[0] = new AnimationState(spd => spd < 0.1 ? 0 : 1);
        stateDefinition[1] = new AnimationState(spd => spd < 0.1 ? 0 : (spd >= 9 ? 2 : 1), spd => spd / 9 + 0.3f);
        stateDefinition[2] = new AnimationState(spd => spd < 9 ? 1 : 2);

        // Agent moving toggle
        GameObject AgentMovingToggleComponent = GameObject.Find("AgentMovingToggle");
        Toggle     AgentMovingToggle          = AgentMovingToggleComponent.GetComponent <Toggle>();

        AgentMovingToggle.onValueChanged.AddListener(delegate {
            isAgentMoving = AgentMovingToggle.isOn;
        });
        isAgentMoving = AgentMovingToggle.isOn;
    }
예제 #2
0
    public static void AddScene(string sceneName, Dictionary <Vector3, WorldTile>[] tiles)
    {
        CheckOrInitSceneList();
        SceneGrid thisGrid = new SceneGrid(sceneName, tiles);

        sceneList.Add(thisGrid);
    }
예제 #3
0
        private async Task <bool> DeleteSelectedScene(Scene scene)
        {
            if (
                MessageBox.Show($"Are you sure you want to delete the '{scene.Name}' scene?",
                                "Are you sure?", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
            {
                return(false);
            }
            if (scene.IsRunning)
            {
                ShowSceneEditWarning(scene.Name);
            }
            else
            {
                _context.Scenes.Local.Remove(scene);
            }

            var result = await _context.TrySaveChangesAsync(_app.Cts.Token);

            if (result.HasError)
            {
                await Log.ReportErrorFormatAsync(_app.Cts.Token, "Error deleting scene. {0}", result.Message);
            }

            SceneGrid.Focus();
            return(true);
        }
예제 #4
0
        private async void SortDown_Click_1(object sender, RoutedEventArgs e)
        {
            var scene = SceneGrid.SelectedItem as Scene;

            if (scene == null)
            {
                return;
            }
            var sceneWeAreReplacing = _sceneCollection.FirstOrDefault(s => s.SortOrder == scene.SortOrder + 1);

            if (sceneWeAreReplacing != null)
            {
                sceneWeAreReplacing.SortOrder--;
            }

            scene.SortOrder++;

            SortSceneGridBySortOrder();
            await NormalizeSortOrderAsync();

            SortSceneGridBySortOrder();

            SceneGrid.SelectedItem = scene;
            SceneGrid.Focus();
        }
예제 #5
0
        private void UserControl_Loaded_1(object sender, RoutedEventArgs e)
        {
            if (SceneGrid.Items.Count > 0)
            {
                SceneGrid.SelectedIndex = 0;
            }

            SceneGrid.Focus();
        }
    public override void OnInspectorGUI()
    {
        SceneGrid sg = (SceneGrid)target;

        sg.save_images = EditorGUILayout.Toggle("Save Images", sg.save_images);

        if (sg.save_images)
        {
            sg.folderpath = EditorGUILayout.TextField("Folderpath", sg.folderpath);
        }

        EditorGUILayout.Space();

        sg.triangle_limit = EditorGUILayout.IntField("Triangle Limit", sg.triangle_limit);

        EditorGUILayout.Space();

        sg.size   = EditorGUILayout.IntField("Size", sg.size);
        sg.spread = EditorGUILayout.IntField("Spread", sg.size);

        EditorGUILayout.Space();

        sg.y_height = EditorGUILayout.FloatField("Y Height", sg.y_height);

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("Images", EditorStyles.boldLabel);

        sg.width  = EditorGUILayout.IntField("Texture Width", sg.width);
        sg.height = EditorGUILayout.IntField("Texture Height", sg.height);

        EditorGUILayout.Space();

        if (GUILayout.Button("Simp"))
        {
            sg.simplify();
        }

        if (GUILayout.Button("Init"))
        {
            sg.init();
        }

        if (GUILayout.Button("Remove Cameras"))
        {
            sg.remove_cameras();
        }
    }
예제 #7
0
        private void SKCanvasView_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            SKImageInfo info = e.Info;
            // we get the current surface from the event args
            var surface = e.Surface;
            // then we get the canvas that we can draw on
            var canvas = surface.Canvas;

            // clear the canvas / view
            canvas.Clear(SKColors.White);
            if (grid == null)
            {
                grid = new SceneGrid(info.GetCanvasCenter(), info.GetCanvasSize(), 3f);
            }
            grid.Draw(canvas);
        }
    private void OnSceneGUI()
    {
        SceneGrid sg = (SceneGrid)target;

        if (sg.transform.childCount == 0)
        {
            return;
        }

        if (!sg.is_initialized)
        {
            return;
        }

        Handles.color = Color.magenta;

        if (sg.grid == null)
        {
            sg.find_nodes();
        }

        for (int x = 0; x <= sg.size; ++x)
        {
            for (int z = 0; z <= sg.size; ++z)
            {
                if (sg.grid[x, z].has_frustum(Direction.NORTH))
                {
                    Handles.DrawLine(sg.grid[x, z].transform.position, sg.grid[x, z].transform.position + new Vector3(0.0f, 0.0f, 1.5f));
                }

                if (sg.grid[x, z].has_frustum(Direction.EAST))
                {
                    Handles.DrawLine(sg.grid[x, z].transform.position, sg.grid[x, z].transform.position + new Vector3(1.5f, 0.0f, 0.0f));
                }

                if (sg.grid[x, z].has_frustum(Direction.SOUTH))
                {
                    Handles.DrawLine(sg.grid[x, z].transform.position, sg.grid[x, z].transform.position + new Vector3(0.0f, 0.0f, -1.5f));
                }

                if (sg.grid[x, z].has_frustum(Direction.WEST))
                {
                    Handles.DrawLine(sg.grid[x, z].transform.position, sg.grid[x, z].transform.position + new Vector3(-1.5f, 0.0f, 0.0f));
                }
            }
        }
    }
예제 #9
0
        private void SortSceneGridBySortOrder()
        {
            SceneGrid.CancelEdit();

            var dataView = CollectionViewSource.GetDefaultView(SceneGrid.ItemsSource);

            if (dataView == null)
            {
                return;
            }
            //clear the existing sort order
            dataView.SortDescriptions.Clear();
            //create a new sort order for the sorting that is done lastly
            dataView.SortDescriptions.Add(new SortDescription("SortOrder", ListSortDirection.Ascending));
            //refresh the view which in turn refresh the grid
            dataView.Refresh();
        }
예제 #10
0
        private async void ButtonDuplicate_OnClick(object sender, RoutedEventArgs e)
        {
            var scene = SceneGrid.SelectedItem as Scene;

            if (scene == null)
            {
                return;
            }

            if (MessageBox.Show("Are you sure you want to duplicate this scene?",
                                "Are you sure?", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
            {
                return;
            }

            var newScene = new Scene {
                Name = "Copy of " + scene.Name, SortOrder = SceneGrid.Items.Count + 1
            };

            foreach (var sc in scene.Commands)
            {
                newScene.Commands.Add(new SceneStoredCommand
                {
                    Argument         = sc.Argument,
                    Argument2        = sc.Argument2,
                    CommandId        = sc.CommandId,
                    Description      = sc.Description,
                    TargetObjectName = sc.TargetObjectName,
                    SortOrder        = sc.SortOrder
                });
                SceneGrid.Focus();
            }
            _context.Scenes.Local.Add(newScene);
            var result = await _context.TrySaveChangesAsync(_app.Cts.Token);

            if (result.HasError)
            {
                await Log.ReportErrorFormatAsync(_app.Cts.Token, "Error duplicating scene. {0}", result.Message);
            }
        }
예제 #11
0
    /// <summary>
    ///     创建地图场景
    /// </summary>
    /// <param name="cfgSceneId"></param>
    /// <returns></returns>
    public SceneGrid[,] CreateTiledScene(int cfgSceneId)
    {
        //  TODO: 初始化关卡地图信息
        var grids = new SceneGrid[10, 10];

        for (var i = 0; i < 10; i++)
        {
            for (var j = 0; j < 10; j++)
            {
                grids[i, j] = new SceneGrid
                {
                    Type = TiledType.Normal
                }
            }
        }
        ;

        // TODO: 初始化怪物

        //  TODO: 玩家移动到出生点

        return(grids);
    }