private void Awake()
    {
        Instance = this;
        //_photonView = PhotonView.Get(this);
        //_currentSpaceshipIndex = 0;
        _mySpaceships        = new List <GameObject>();
        _myAttackSpaceships  = new List <GameObject>();
        _myDefenceSpaceships = new List <GameObject>();
        _myMiningSpaceships  = new List <GameObject>();

        _selectSpaceshipManager = GetComponent <SelectSpaceshipManager>();
        _pathfinder             = GameObject.Find("Pathfinder2D").GetComponent <FlowPathfinding.Pathfinder>();

        _audioSource = GetComponent <AudioSource>();
    }
Exemple #2
0
 public SearchPathJob(Tile _destinationNode, List <Seeker> _units, Pathfinder _pathfinder)
 {
     destinationNode = _destinationNode;
     units           = _units;
     pathfinder      = _pathfinder;
 }
Exemple #3
0
 public SearchPathJob(Tile destinationNode, List <Seeker> units, Pathfinder pathfinder)
 {
     _destinationNode = destinationNode;
     _units           = units;
     _pathfinder      = pathfinder;
 }
Exemple #4
0
 public WorldData(Pathfinder pathfinder)
 {
     Pathfinder = pathfinder;
 }
Exemple #5
0
 public MapAdjustedJob(Pathfinder _pathfinder)
 {
     pathfinder = _pathfinder;
 }
Exemple #6
0
        void OnSceneGUI()
        {
            Pathfinder myTarget = (Pathfinder)target;

            if (myTarget.worldData.WorldAreas.Count != 0) // no values/ nothing generated
            {
                if (myTarget.worldData.drawCost)
                {
                    if (_brush == null)
                    {
                        _brush = myTarget.transform.GetChild(1).gameObject.transform;
                        _brush.gameObject.SetActive(true);
                    }

                    _brush.localScale = new Vector3(myTarget.brushSize * myTarget.tileSize, 1, myTarget.brushSize * myTarget.tileSize);

                    Event current   = Event.current;
                    int   controlId = GUIUtility.GetControlID(GetHashCode(), FocusType.Passive);
                    int   layer     = (1 << myTarget.groundLayer);

                    switch (current.type)
                    {
                    case EventType.MouseMove:
                    {
                        Ray ray = HandleUtility.GUIPointToWorldRay(current.mousePosition);

                        if (Physics.Raycast(ray, out var hit, 100f, layer))
                        {
                            WorldArea area    = myTarget.worldData.TileManager.GetWorldAreaAtPosition(hit.point);
                            Tile      tileHit = myTarget.worldData.TileManager.GetTileInWorldArea(area, hit.point);

                            if (tileHit != null)
                            {
                                _brush.position = myTarget.worldData.TileManager.GetTileWorldPosition(tileHit, area);
                            }
                        }

                        break;
                    }


                    case EventType.MouseDrag:
                    {
                        if (current.button == 0)
                        {
                            //Ray ray = Camera.current.ScreenPointToRay(e.mousePosition);
                            Ray ray = HandleUtility.GUIPointToWorldRay(current.mousePosition);

                            if (Physics.Raycast(ray, out var hit, 100f, layer))
                            {
                                WorldArea area    = myTarget.worldData.TileManager.GetWorldAreaAtPosition(hit.point);
                                Tile      tileHit = myTarget.worldData.TileManager.GetTileInWorldArea(area, hit.point);

                                if (tileHit != null)
                                {
                                    tileHit.Cost += myTarget.brushStrength;
                                    if (tileHit.Cost > myTarget.maxCostValue)
                                    {
                                        tileHit.Cost = myTarget.maxCostValue;
                                    }

                                    _tilesCostChanged.Clear();
                                    _tilesCostChanged.Add(tileHit);
                                    _brush.position = myTarget.worldData.TileManager.GetTileWorldPosition(tileHit, area);



                                    if (myTarget.brushSize != 1)
                                    {
                                        int brushMaxDif = (int)(myTarget.brushSize * 0.5f);

                                        for (int x = -brushMaxDif; x <= brushMaxDif; x++)
                                        {
                                            for (int y = -brushMaxDif; y <= brushMaxDif; y++)
                                            {
                                                if (x != 0 || y != 0)
                                                {
                                                    if (Physics.Raycast(_brush.position + new Vector3(x * myTarget.tileSize, 0.1f, y * myTarget.tileSize) + (Vector3.up * myTarget.generationClimbHeight), Vector3.down, out hit, myTarget.generationClimbHeight + 0.2f, layer))
                                                    {
                                                        area    = myTarget.worldData.TileManager.GetWorldAreaAtPosition(hit.point);
                                                        tileHit = myTarget.worldData.TileManager.GetTileInWorldArea(area, hit.point);

                                                        if (tileHit != null)
                                                        {
                                                            int fallOff = Mathf.Max(Mathf.Abs(x), Mathf.Abs(y)) * myTarget.brushFallOff;
                                                            if (fallOff < myTarget.brushStrength)
                                                            {
                                                                tileHit.Cost += myTarget.brushStrength - fallOff;
                                                                if (tileHit.Cost > myTarget.maxCostValue)
                                                                {
                                                                    tileHit.Cost = myTarget.maxCostValue;
                                                                }

                                                                _tilesCostChanged.Add(tileHit);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }


                                    myTarget.costManager.EditCostFieldAlpha(_tilesCostChanged);
                                }
                            }
                        }
                        current.Use();
                        break;
                    }


                    case EventType.Layout:
                        HandleUtility.AddDefaultControl(controlId);
                        break;
                    }

                    if (GUI.changed)
                    {
                        EditorUtility.SetDirty(target);
                    }
                }
                else
                {
                    if (_brush != null)
                    {
                        _brush.gameObject.SetActive(false);
                    }

                    _brush = null;
                }
            }
        }
Exemple #7
0
        public override void OnInspectorGUI()
        {
            Pathfinder myTarget = (Pathfinder)target;

            Undo.RecordObject(myTarget, "modify settings on Pathfinder");

            EditorGUILayout.Space();
            Settings(myTarget);

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            VisualDebugging(myTarget);


            EditorGUILayout.Space();
            EditorGUILayout.Space();

            CostDrawing(myTarget);



            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();



            GUI.backgroundColor = Color.yellow;
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            _content.text    = "Generate Map";
            _content.tooltip = "Gives you a preview of what the map will look like, and allows you to draw cost in the editor.";
            if (GUILayout.Button(_content))
            {
                myTarget.GenerateWorld(false, false);
                EditorUtility.SetDirty(target);
            }


            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            _content.text    = "Remove Existing CostField";
            _content.tooltip = "Save an empty cost field over the existing one.";
            if (GUILayout.Button(_content))
            {
                myTarget.worldData.CostFields = new List <int[][]>();
                myTarget.GetComponent <SaveLoad>().SaveLevel();
            }



            //SECURITY!! only change if you understand what this changes, read documentation
            if (GUI.changed)
            {
                if (myTarget.generationClimbHeight > myTarget.characterHeight * 0.98f)
                {
                    myTarget.generationClimbHeight = myTarget.characterHeight * 0.98f;
                }

                //myTarget.characterClimbHeight = myTarget.generationClimbHeight;
                // if (myTarget.characterClimbHeight > myTarget.generationClimbHeight * 0.98f)
                //    myTarget.characterClimbHeight = myTarget.generationClimbHeight * 0.98f;



                //myTarget.tileSize = EditorGUILayout.FloatField("Tile Size ", myTarget.tileSize);
                // Undo.RegisterUndo(myTarget, "Tile Size");
                //Undo.RecordObject(myTarget, "Set Tile Size");
                EditorUtility.SetDirty(target);
            }
        }