Beispiel #1
0
 public Node(GridBehavior grid, Vector3 position, Vector2 coord, float weight)
 {
     _position = position;
     _coord = coord;
     _weight = weight;
     Grid = grid;
 }
Beispiel #2
0
    /// <summary>
    /// Performs the logic behind the depth-first search.
    /// </summary>
    /// <param name="maxDepth">Maximum depth to perform checking to.</param>
    /// <param name="currentDepth">Current depth within the search.</param>
    /// <param name="grid">Grid the graph is being built on.</param>
    /// <param name="path">List of move points representing the constructed path.</param>
    /// <param name="skipIgnoreList">Whether or not the ignore list check should be skipped.</param>
    public void BuildGraph(int maxDepth, int currentDepth, GridBehavior grid, ref List <MovePointBehavior> path, bool skipIgnoreList)
    {
        if (currentDepth >= maxDepth || neighborList.Length == 0)
        {
            return;
        }

        if (!path.Contains(this))
        {
            path.Add(this);
        }

        currentDepth++;

        foreach (MovePointBehavior neighbor in neighborList)
        {
            if (neighbor == null)
            {
                continue;
            }

            if (!skipIgnoreList && grid.ignoreList != null && grid.ignoreList.Contains(neighbor))
            {
                continue;
            }

            //neighbor.renderer.enabled = true;
            if (!path.Contains(neighbor))
            {
                path.Add(neighbor);
            }

            neighbor.BuildGraph(maxDepth, currentDepth, grid, ref path, skipIgnoreList);
        }
    }
    /// <summary>
    /// Initializes the combat system.
    /// </summary>
    /// <param name="offensiveSquad">GameObject for the squad performing the attack.</param>
    /// <param name="defensiveSquad">GameObject for the squad on defense.</param>
    /// <param name="grid">Grid behavior on which the combat is taking place.</param>
    public void BeginCombat(CombatSquadBehavior offensiveSquad, CombatSquadBehavior defensiveSquad, GridBehavior grid)
    {
        if (offensiveSquad.Squad == null || defensiveSquad.Squad == null)
        {
            Debug.LogError("Combat was started with either the offensive or defense squad being null!");
            return;
        }

        combatRange = (int)Mathf.Ceil(Vector3.Distance(offensiveSquad.transform.position, defensiveSquad.transform.position));

        this.grid = grid;

        GridBehavior.inCombat  = true;
        AudioBehavior.inCombat = true;

        this.offensiveSquad = offensiveSquad;
        this.defensiveSquad = defensiveSquad;

        int unitCount = offensiveSquad.Squad.Units.Count + defensiveSquad.Squad.Units.Count;

        unitPrefabs = new List <NodeSkeletonBehavior>(unitCount);

        createUnits(offensiveSquad.Squad.Units, true, 0.0f);
        createUnits(defensiveSquad.Squad.Units, false, 1.0f);

        currentAttacker = CurrentAttacker.OffensiveFront;
    }
Beispiel #4
0
        /// <summary>
        /// Met à jour la visibilité des colonnes en fonction de la vue.
        /// </summary>
        /// <param name="view">La vue.</param>
        private void UdpateColumnsVisibility(GanttGridView view)
        {
            switch (view)
            {
            case GanttGridView.WBS:
                GridBehavior.TryShow(ColumnVideo, view);
                GridBehavior.TryShow(ColumnTask, view);
                GridBehavior.TryShow(ColumnDuration, view);
                GridBehavior.TryShow(ColumnCategory, view);
                GridBehavior.TryShow(ColumnWBS, view);
                GridBehavior.TryShow(ColumnResource, view);
                GridBehavior.TryShow(ColumnPredecessors, view);
                break;

            default:
                GridBehavior.TryShow(ColumnVideo, view);
                GridBehavior.TryShow(ColumnTask, view);
                GridBehavior.TryShow(ColumnDuration, view);
                GridBehavior.TryShow(ColumnCategory, view);
                GridBehavior.TryHide(ColumnWBS, view);
                GridBehavior.TryHide(ColumnResource, view);
                GridBehavior.TryHide(ColumnPredecessors, view);
                break;
            }

            SetupUnlinkMarkersMode();
        }
Beispiel #5
0
    private void Awake()
    {
        _gridBehaviour   = FindObjectOfType <GridBehavior>();
        player           = GameObject.FindGameObjectWithTag("Player");
        chancesGenerator = FindObjectOfType <ChancesGenerator>();

        oresPrefabsFromResources = Resources.LoadAll <GameObject>("OresPrefabs").ToList();
    }
Beispiel #6
0
    private OreDurability block; // block to mine

    private void Awake()
    {
        csGlobal           = FindObjectOfType <CsGlobal>();
        _gridBehavior      = FindObjectOfType <GridBehavior>();
        animatorController = FindObjectOfType <CharacterAnimatorController>();

        SetInfoActive(false);
    }
Beispiel #7
0
    // Start is called before the first frame update
    void Start()
    {
        Debug.Assert(transform.parent != null);
        GameObject parent = transform.parent.gameObject;

        grid = parent.GetComponent <GridBehavior>();
        Debug.Assert(grid != null);
    }
 public Node(GridBehavior grid, Vector3 position, Vector2 coord, float weight, float zIndex = 0)
 {
     _position = position;
     _coord = coord;
     _weight = weight;
     Grid = grid;
     ZIndex = zIndex;
 }
 public override void ActivateBehaviour()
 {
     grid = GridBehavior.Instance;
     GetNewTarget();
     var pos = transform.position;
     pos.z = grid.getNodeAtPos(pos).ZIndex;
     transform.position = pos;
 }
Beispiel #10
0
    // Use this for initialization
    void Start()
    {
        grid = GameObject.FindGameObjectsWithTag("Grid")[0].GetComponent <GridBehavior>();

        terrain = FindObjectsOfType <Terrain>()[0];
        heights = terrain.terrainData.GetHeights(0, 0, terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapWidth);

        filter = gameObject.AddComponent <MeshFilter>();
    }
Beispiel #11
0
 private void MineStart()
 {
     playerGO                 = GameObject.FindGameObjectWithTag("Player");
     generateLevel            = FindObjectOfType <GenerateLevel>();
     _gridBehavior            = FindObjectOfType <GridBehavior>();
     oreGenerator             = FindObjectOfType <OreGenerator>();
     _nextLevelLoadController = FindObjectOfType <NextLevelLoadController>();
     progressBar              = FindObjectOfType <ProgressBar>();
     _chancesGenerator        = FindObjectOfType <ChancesGenerator>();
 }
	/// <summary>
	/// Captures an instance of the game controller behavior from the game object.
	/// </summary>
	/// <remarks>
	/// Because GameControllerBehavior is a required component (see class attributes),
	/// this will never be null.
	/// </remarks>
	public void Start()
	{
		gameController = GetComponent<GameControllerBehaviour>();
		grid = GetComponent<GridBehavior>();

		// Locate a CameraBehavior if one is set.
		GameObject cameraObject = GameObject.FindGameObjectWithTag(CAMERA_TAG);
		if(cameraObject)
			camera = cameraObject.GetComponent<CameraBehavior>();
	}
Beispiel #13
0
    void Start()
    {
        gc = GameObject.FindGameObjectWithTag("GameController");
        gm = gc.GetComponent <GameManager>();
        gridBehaviorCode = gc.GetComponent <GridBehavior>();

        inAttackRange = false;
        stepLimit     = 0;

        this.GetComponent <Renderer>().material.SetFloat("_SecondOutlineWidth", 0.0f);
    }
Beispiel #14
0
    // Use this for initialization
    void Start()
    {
        GameObject grid = GameObject.FindWithTag("grid");

        //Get the grid components
        if (grid != null)
        {
            gridBehavior = grid.GetComponent <GridBehavior>();
        }

        transform.position = StartPos;
    }
Beispiel #15
0
    void CheckTSpin()
    {
        int moveRequirement = 0;

        if (tetromino == "T")
        {
            if (LastMovementIsRotate == true)
            {
                //Check LEFT
                transform.position += new Vector3(-1, 0, 0);
                if (IsValidGridPos())
                {
                    transform.position += new Vector3(1, 0, 0);
                }
                else
                {
                    transform.position += new Vector3(1, 0, 0);
                    ++moveRequirement;
                }

                //Check RIGHT
                transform.position += new Vector3(1, 0, 0);
                if (IsValidGridPos())
                {
                    transform.position += new Vector3(-1, 0, 0);
                }
                else
                {
                    transform.position += new Vector3(-1, 0, 0);
                    ++moveRequirement;
                }


                //Check UP
                transform.position += new Vector3(0, 1, 0);
                if (IsValidGridPos())
                {
                    transform.position += new Vector3(0, -1, 0);
                }
                else
                {
                    transform.position += new Vector3(0, -1, 0);
                    ++moveRequirement;
                }

                if (moveRequirement == 3)
                {
                    GridBehavior.TSpinOccured();
                }
            }
        }
    }
Beispiel #16
0
    /// <summary>
    /// Captures an instance of the game controller behavior from the game object.
    /// </summary>
    /// <remarks>
    /// Because GameControllerBehavior is a required component (see class attributes),
    /// this will never be null.
    /// </remarks>
    public void Start()
    {
        gameController = GetComponent <GameControllerBehaviour>();
        grid           = GetComponent <GridBehavior>();

        // Locate a CameraBehavior if one is set.
        GameObject cameraObject = GameObject.FindGameObjectWithTag(CAMERA_TAG);

        if (cameraObject)
        {
            camera = cameraObject.GetComponent <CameraBehavior>();
        }
    }
Beispiel #17
0
        public static void FixCamera()
        {
            GameObject mainCamera = GameObject.FindGameObjectWithTag("MainCamera");

            CameraBehavior cameraBehavior = mainCamera.GetComponent <CameraBehavior>();
            float          cameraSpeed    = cameraBehavior.MovementRate;

            // Destroy the camera in preparation for adding the new one.
            GameObject.DestroyImmediate(mainCamera);

            // Retrieve the MainCamera prefab from the asset database.
            GameObject newCamera = (GameObject)GameObject.Instantiate(AssetDatabase.LoadAssetAtPath(
                                                                          "Assets/Prefabs/Main Camera.prefab", typeof(GameObject)));

            newCamera.transform.name = "Main Camera";

            cameraBehavior = newCamera.GetComponent <CameraBehavior>();
            cameraBehavior.MovementRate = cameraSpeed;

            // Update the main camera property of the combat camera.
            CombatSystemBehavior combatSystem = (CombatSystemBehavior)GameObject.Find("Combat Camera").GetComponent <CombatSystemBehavior>();

            combatSystem.mainCamera = newCamera.camera;

            EditorUtility.SetDirty(combatSystem);

            // Disable all text renderers on the camera.
            MeshRenderer[] renderers = newCamera.GetComponentsInChildren <MeshRenderer>();
            foreach (MeshRenderer renderer in renderers)
            {
                if (renderer.gameObject.name == "MiniMapBG")
                {
                    continue;
                }

                renderer.enabled = false;
            }

            // Update the grid for the minimap.
            GridBehavior         grid        = GameObject.FindGameObjectWithTag("Grid").GetComponent <GridBehavior>();
            MiniMapGridBehaviour minimapGrid = newCamera.GetComponentInChildren <MiniMapGridBehaviour>();

            minimapGrid.theGrid        = grid;
            minimapGrid.gameController = grid.GetComponent <GameControllerBehaviour>();

            EditorUtility.SetDirty(newCamera);

            Selection.activeGameObject = newCamera;

            Debug.Log("Camera fixed.");
        }
Beispiel #18
0
    public void SoftDrop()
    {
        // Modify position
        transform.position += new Vector3(0, -1, 0);

        // See if valid
        if (IsValidGridPos())
        {
            // It's valid. Update grid.
            score.GetComponent <ScoreBehaviour>().AddToScore(1);
            updateGrid();
            canMoveDown = false;
            Invoke("DelayMoveDown", mainSpeed * 0.078f);
            CheckLastStep();
            keepBeforeHardDrop = false;
        }
        else if (keepBeforeHardDrop == false)
        {
            keepBeforeHardDrop = true;
            canMoveDown        = false;
            Invoke("DelayMoveDownBeforeHardDrop", 0.75f);
            // It's not valid. revert.
            transform.position += new Vector3(0, 1, 0);
        }
        else
        {
            keepBeforeHardDrop       = false;
            lockDelay                = mainSpeed;
            transform.gameObject.tag = "DeadGroup";
            // It's not valid. revert.
            transform.position += new Vector3(0, 1, 0);
            CheckTSpin();
            if (GridBehavior.CheckIfFullRows() > 0)
            {
                Invoke("OnDropDown", 0.0f);
            }
            else
            {
                Invoke("OnDropDown", 0.0f);
            }

            // Disable script
            isDown = true;
            if (particles != null)
            {
                Instantiate(particles, transform.position, particles.transform.rotation);
            }
            audios[2].Play();
        }
        lastFall = Time.time;
    }
Beispiel #19
0
 void OnDropDown()
 {
     score.GetComponent <ScoreBehaviour>().AddToTetromiones(1);
     // Clear filled horizontal lines
     GridBehavior.DeleteFullRows();
     // Spawn next Group
     foreach (Transform child in transform)
     {
         child.transform.gameObject.layer = LayerMask.NameToLayer("LockedBlock");
     }
     Destroy(GameObject.FindGameObjectWithTag("CurrentShadow"));
     FindObjectOfType <Spawner>().SpawnNext();
     FindObjectOfType <Spawner>().lockHold = false;
 }
Beispiel #20
0
    /// <summary>
    /// Captures a reference to the Grid and Game Controller components on the object.
    /// </summary>
    public void Start()
    {
        controller = GetComponent <GameControllerBehaviour>();
        if (controller == null)
        {
            Debug.LogError("GridControlBehavior is applied to an object that does not have the GameControllerBehavior!");
        }

        grid = GetComponent <GridBehavior>();
        if (grid == null)
        {
            Debug.LogError("GridBehavior is applied to an object that does not have the GridBehavior!");
        }
    }
Beispiel #21
0
    private void Awake()
    {
        if (onDescending == null)
        {
            new UnityEvent();
        }

        _player         = GameObject.FindGameObjectWithTag("Player");
        _gridBehavior   = FindObjectOfType <GridBehavior>();
        _csGlobal       = FindObjectOfType <CsGlobal>();
        oreGenerator    = FindObjectOfType <OreGenerator>();
        generateLevel   = FindObjectOfType <GenerateLevel>();
        progressBar     = FindObjectOfType <ProgressBar>();
        _canvas         = FindObjectOfType <Canvas>();
        _dataController = FindObjectOfType <DataController>();
    }
Beispiel #22
0
 // Use this for initialization
 public bool CustomStart()
 {
     for (int j = 0; j < groups.Length; j++)
     {
         groups[j] = Resources.Load <GameObject>("Prefabs/Blocks/Group" + order[j].ToString() + PlayerPrefs.GetInt("TetrominoesStyle").ToString("D2"));
     }
     for (int j = 0; j < nexts.Length; j++)
     {
         nexts[j] = Resources.Load <GameObject>("Prefabs/Blocks/Next" + order[j].ToString() + PlayerPrefs.GetInt("TetrominoesStyle").ToString("D2"));
     }
     GarbageGroup = Resources.Load <GameObject>("Prefabs/Blocks/GarbageGroup" + PlayerPrefs.GetInt("TetrominoesStyle").ToString("D2"));
     if (PlayerPrefs.GetInt("GameType") == 3 && PlayerPrefs.GetInt("SaveGame") == 0)
     {
         StartCoroutine(GridBehavior.SetCleaningArea(GarbageGroup));
     }
     audios           = GetComponents <AudioSource>();
     audios[0].volume = audios[0].volume * ((float)PlayerPrefs.GetInt("EffectsVolume") / 10);
     if (PlayerPrefs.GetInt("SaveGame") == 1)
     {
         LoadSaveGameGroups();
     }
     else
     {
         i = NewRandomNumber();
         while (order [i] == 'S' || order [i] == 'Z')
         {
             i = NewRandomNumber();
         }
         GameObject Next01 = Instantiate(nexts[i], transform.Find("Next01").position, Quaternion.identity) as GameObject;
         Next01.transform.parent     = transform.Find("Next01");
         Next01.transform.localScale = new Vector3(1, 1, 1);
         i = NewRandomNumber();
         GameObject Next02 = Instantiate(nexts[i], transform.Find("Next02").position, Quaternion.identity) as GameObject;
         Next02.transform.parent = transform.Find("Next02");
         i = NewRandomNumber();
         GameObject Next03 = Instantiate(nexts[i], transform.Find("Next03").position, Quaternion.identity) as GameObject;
         Next03.transform.parent = transform.Find("Next03");
         i = NewRandomNumber();
         GameObject Next04 = Instantiate(nexts[i], transform.Find("Next04").position, Quaternion.identity) as GameObject;
         Next04.transform.parent = transform.Find("Next04");
         i = NewRandomNumber();
         GameObject Next05 = Instantiate(nexts[i], transform.Find("Next05").position, Quaternion.identity) as GameObject;
         Next05.transform.parent = transform.Find("Next05");
         SpawnNext();
     }
     return(true);
 }
Beispiel #23
0
    // Use this for initialization
    void Start()
    {
        this.resource = GameObject.FindGameObjectWithTag("ResourceManager").GetComponent <ResourceBehavior>().resource;
        grid          = GameObject.FindGameObjectsWithTag("Grid")[0].GetComponent <GridBehavior>();
        filter        = gameObject.GetComponent <MeshFilter>();

        GameObject[] gms = GameObject.FindGameObjectsWithTag("Connector");
        foreach (GameObject gm in gms)
        {
            if (gm.GetComponent <ConnectorBehavior>() != null)
            {
                gm.GetComponent <ConnectorBehavior>().UpdateModel();
            }
        }

        UpdateActivity();
    }
    // Use this for initialization
    void Start()
    {
        grid = FindObjectOfType<GridBehavior>();

        lights = FindObjectsOfType<LightController>();
        foreach (LightController light in lights)
        {
            if (light.CurrentStatus == LightController.Status.On)
            {
                ActiveLights++;
            }
        }

        guardHUD = FindObjectOfType<GuardHUD>();
        guardHUD.SetMaxLightLevel(MaxActiveLights);
        guardHUD.SetLightLevel(ActiveLights);
    }
Beispiel #25
0
    private void Awake()
    {
        _gridBehavior      = FindObjectOfType <GridBehavior>();
        csGlobal           = FindObjectOfType <CsGlobal>();
        rigidBody          = gameObject.GetComponent <Rigidbody2D>();
        animatorController = FindObjectOfType <CharacterAnimatorController>();

        if (atStop == null)
        {
            new UnityEvent();
        }

        if (whenMovementResumes == null)
        {
            new UnityEvent();
        }
    }
Beispiel #26
0
 void OnMouseDown()
 {
     if (pw.OverRect.Contains(Input.mousePosition) && gameGUI.canZoom)
     {
         gameGUI.zoomedIn = true;
         foreach (GameObject gridPart in GameObject.FindGameObjectsWithTag("Grid"))
         {
             GridBehavior g = gridPart.GetComponent <GridBehavior>();
             if (g != null)
             {
                 g.growIndex = gridIndex;
                 g.setGridsActive(true);
                 g.squish();
             }
         }
     }
 }
Beispiel #27
0
    public void HardDrop()
    {
        bool end = false;

        keepBeforeHardDrop = false;
        ghostLine.HardDrop();
        while (end == false)
        {
            // Modify position
            transform.position += new Vector3(0, -1, 0);

            // See if valid
            if (IsValidGridPos())
            {
                // It's valid. Update grid.
                score.GetComponent <ScoreBehaviour>().AddToScore(2);
                updateGrid();
            }
            else
            {
                lockDelay = mainSpeed;
                // It's not valid. revert.
                transform.position += new Vector3(0, 1, 0);
                CheckTSpin();
                if (GridBehavior.CheckIfFullRows() > 0)
                {
                    Invoke("OnDropDown", 0.0f);
                }
                else
                {
                    Invoke("OnDropDown", 0.0f);
                }

                // Disable script
                isDown = true;
                transform.gameObject.tag = "DeadGroup";
                end = true;
                if (particles != null)
                {
                    Instantiate(particles, transform.position, particles.transform.rotation);
                }
                audios[2].Play();
                score.GetComponent <ScoreBehaviour>().AddToScore(2);
            }
        }
    }
Beispiel #28
0
    public GridData(GridBehavior gridBehavior)
    {
        gridArray = new bool[GridBehavior.WIDTH, GridBehavior.HEIGHT];

        for (int x = 0; x < GridBehavior.WIDTH; x++)
        {
            for (int y = 0; y < GridBehavior.HEIGHT; y++)
            {
                if (gridBehavior.gridArray[x, y])
                {
                    gridArray[x, y] = true;
                }
            }
        }

        descentPos[0] = gridBehavior.descentPos.x;
        descentPos[1] = gridBehavior.descentPos.y;
    }
Beispiel #29
0
    void MakeGrid(int x, int y, Vector2 gridCounter, Vector2 gridIndex)
    {
        GameObject g = Instantiate(Grid, new Vector3(x, y, 0), Quaternion.identity) as GameObject;

        foreach (GameObject c in GameObject.FindGameObjectsWithTag("Cell"))
        {
            if (Mathf.Abs(c.transform.position.x - g.transform.position.x) < 3 && Mathf.Abs(c.transform.position.y - g.transform.position.y) < 3)
            {
                c.transform.parent = g.transform;
            }
        }

        GridBehavior gridBehavior = g.GetComponent <GridBehavior>();

        gridBehavior.gridCounter = gridCounter;
        gridBehavior.gridIndex   = gridIndex;
        gridBehavior.setGridsActive(true);
    }
Beispiel #30
0
 bool IsValidGridPos()
 {
     foreach (Transform child in transform)
     {
         Vector2 v = GridBehavior.RoundVec2(child.position);
         //not inside border ?
         if (!GridBehavior.InsideBorder(v))
         {
             return(false);
         }
         //Block in grid cell (and not part of the same group) ?
         if (GridBehavior.grid[(int)v.x, (int)v.y] != null &&
             GridBehavior.grid[(int)v.x, (int)v.y].parent != transform)
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #31
0
    // Start is called before the first frame update
    void Start()
    {
        gm               = GameObject.FindGameObjectWithTag("GameController");
        gmCode           = gm.GetComponent <GameManager>();
        gridBehaviorCode = gm.GetComponent <GridBehavior>();
        enemyStats       = this.GetComponent <CharacterStats>();


        SetOutline("_FirstOutlineWidth", 0.0f);

        SetOutline("_SecondOutlineWidth", 0.55f);

        detectableRange = gmCode.GetComponent <WeaponStats>().GiveFarestRange(this.enemyStats.weaponNumber) + this.enemyStats.moveSpeed.GetValue();


        triggerEnemyToFunction = false;
        triggerForLerp         = false;
        mouseOver = false;
        triggerSelectOnePositionToMove = false;
        triggerShowMoveableBlocks      = false;
        attackNext = false;
    }
Beispiel #32
0
    /// <summary>
    /// Enables the renderer on any nodes the unit can move to.
    /// </summary>
    /// <param name="actor">Actor associated with this movement attempt.</param>
    /// <param name="grid">Grid associated with the movement.</param>
    /// <param name="range">Maximum distance (in grid squares) to highlight.</param>
    public void HighlightValidNodes(ActorBehavior actor, GridBehavior grid, int range = -1)
    {
        int depth = 0;

        if (actor.currentMovePoint == null)
        {
            Debug.LogError("Current move point is null!");
            return;
        }

        //int maxDistance = 0;
        CombatSquadBehavior csb = actor.GetComponent <CombatSquadBehavior>();

        if (csb == null)
        {
            Debug.LogWarning("Attempting to move a unit that does not have a squad associated!");
        }

        bool skipIgnoreList = false;

        if (range == -1)
        {
            range = (csb == null ? 1 : csb.Squad.Speed);
        }
        else
        {
            skipIgnoreList = true;
        }

        List <MovePointBehavior> moveGraph = new List <MovePointBehavior>();

        actor.currentMovePoint.BuildGraph(range, depth, grid, ref moveGraph, skipIgnoreList);
        moveGraph.RemoveAt(0);

        foreach (MovePointBehavior node in moveGraph)
        {
            node.renderer.enabled = true;
        }
    }
    void Start()
    {
        if (GameObject.Find("PlayerInventory") != null)
        {
            playerDataObject = GameObject.Find("PlayerInventory");

            inventory = playerDataObject.GetComponent <PlayerData>().inventory;
        }
        else
        {
            print("Missing Inventory object");
        }


        gm = GameObject.FindGameObjectWithTag("GameController");
        gridBehaviorCode = gm.GetComponent <GridBehavior>();
        gmCode           = gm.GetComponent <GameManager>();
        playerStats      = this.GetComponent <CharacterStats>();

        triggerMoving     = false;
        checkHealing      = false;
        playerIsActive    = false;
        playerIsPlayable  = true;
        mouseOver         = false;
        speedOfBallMoving = 1;
        moveOrAttack      = 0;

        SetOutline("_FirstOutlineWidth", 0.0f);
        thisActionPoint = playerStats.actionPoint;

        if (GameObject.FindGameObjectsWithTag("Audio") != null)
        {
            audio = GameObject.FindGameObjectWithTag("Audio");
        }
        else
        {
            print("audio manager missing");
        }
    }
Beispiel #34
0
    void updateGrid()
    {
        // Remove old children from grid
        for (int y = 0; y < GridBehavior.h; ++y)
        {
            for (int x = 0; x < GridBehavior.w; ++x)
            {
                if (GridBehavior.grid[x, y] != null)
                {
                    if (GridBehavior.grid[x, y].parent == transform)
                    {
                        GridBehavior.grid[x, y] = null;
                    }
                }
            }
        }

        // Add new children to grid
        foreach (Transform child in transform)
        {
            Vector2 v = GridBehavior.RoundVec2(child.position);
            GridBehavior.grid[(int)v.x, (int)v.y] = child;
        }
    }
Beispiel #35
0
    private void Awake()
    {
        boosterTypes = Enum.GetValues(typeof(BoostersController.BoosterTypes))
                       .Cast <BoostersController.BoosterTypes>();

        _gridBehavior        = FindObjectOfType <GridBehavior>();
        _oreGenerator        = FindObjectOfType <OreGenerator>();
        progressBar          = FindObjectOfType <ProgressBar>();
        extractedOresCounter = FindObjectOfType <SingleExtractedOresCounter>();
        animatorController   = FindObjectOfType <CharacterAnimatorController>();

        maxDurability     = oreStats.durability;
        currentDurability = maxDurability;
        armour            = oreStats.armor - AwakeningUpgradeSingleton.armourPiercing;
        if (armour < 0)
        {
            armour = 0;
        }
        index                  = oreStats.index;
        _sprites               = Resources.LoadAll <Sprite>("OresSprites/" + (index + 1));
        _sprite                = _sprites[Random.Range(0, _sprites.Length)];
        _spriteRenderer        = gameObject.GetComponent <SpriteRenderer>();
        _spriteRenderer.sprite = _sprite;
    }
	/// <summary>
	/// Attempts to find a path to the target node.
	/// </summary>
	/// <param name="targetNode">Final node the unit should move to.</param>
	/// <param name="maxDistance">Maximum distnance the unit can move.</param>
	/// <param name="grid">Grid that the pathfinding is occurring on.</param>
	/// <param name="skipIgnoreList">Skips the ignore list when building the initial graph.</param>
	/// <returns></returns>
	public List<MovePointBehavior> FindPath(MovePointBehavior targetNode, int maxDistance, GridBehavior grid, bool skipIgnoreList = false)
	{
		// Build the Dijkstra's Graph
		List<MovePointBehavior> graph = new List<MovePointBehavior>();
		List<MovePointBehavior> tGraph = new List<MovePointBehavior>();
		
		BuildGraph(maxDistance, 0, grid, ref graph, skipIgnoreList);

		if (!graph.Contains(targetNode))
			return null;

		Dictionary<MovePointBehavior, int> distance = new Dictionary<MovePointBehavior, int>();
		Dictionary<MovePointBehavior, MovePointBehavior> previous = new Dictionary<MovePointBehavior, MovePointBehavior>();

		foreach (MovePointBehavior node in graph)
		{
			distance.Add(node, int.MaxValue);
			previous.Add(node, null);

			tGraph.Add(node);
		}

		distance[this] = 0;
		previous[this] = null;

		while (tGraph.Count > 0)
		{
			// Find the item with the smallest distance.
			MovePointBehavior node = tGraph[0];
			for (int _i = 0; _i < tGraph.Count; _i++)
			{
				MovePointBehavior _node = tGraph[_i];

				if (grid.ignoreList.Contains(_node) && !skipIgnoreList)
					continue;

				if (distance[_node] < distance[node])
				{
					node = _node;
					MovePointBehavior tNode = tGraph[0];
					tGraph[0] = _node;
					tGraph[_i] = tNode;
				}
			}

			tGraph.RemoveAt(0);

			if (distance[node] == int.MaxValue)
				break;

			foreach (MovePointBehavior neighbor in node.neighborList)
			{
				if (neighbor == null || (!skipIgnoreList && grid.ignoreList.Contains(neighbor)) || !graph.Contains(neighbor))
					continue;

				int alt = distance[node] + 1;

				if(alt < distance[neighbor])
				{
					distance[neighbor] = alt;
					previous[neighbor] = node;
				}
			}
		}

		List<MovePointBehavior> path = new List<MovePointBehavior>();
		MovePointBehavior u = targetNode;

		while (previous[u] != null)
		{
			path.Add(u);
			u = previous[u];
		}

		path.Reverse();

		return path;
	}
	/// <summary>
	/// Enables the renderer on any nodes the unit can move to.
	/// </summary>
	/// <param name="actor">Actor associated with this movement attempt.</param>
	/// <param name="grid">Grid associated with the movement.</param>
	/// <param name="range">Maximum distance (in grid squares) to highlight.</param>
    public void HighlightValidNodes(ActorBehavior actor, GridBehavior grid, int range = -1)
    {
		int depth = 0;

		if(actor.currentMovePoint == null)
		{
			Debug.LogError("Current move point is null!");
			return;
		}

		//int maxDistance = 0;
		CombatSquadBehavior csb = actor.GetComponent<CombatSquadBehavior>();
		if (csb == null)
			Debug.LogWarning("Attempting to move a unit that does not have a squad associated!");

		bool skipIgnoreList = false;

		if(range == -1)
			range = (csb == null ? 1 : csb.Squad.Speed);
		else
			skipIgnoreList = true;

		List<MovePointBehavior> moveGraph = new List<MovePointBehavior>();

		actor.currentMovePoint.BuildGraph(range, depth, grid, ref moveGraph, skipIgnoreList);
		moveGraph.RemoveAt(0);

		foreach (MovePointBehavior node in moveGraph)
			node.renderer.enabled = true;
    }
 void Awake()
 {
     grid = FindObjectOfType<GridBehavior>();
     follower = GetComponent<TargetFollower>();
 }
	/// <summary>
	/// Initializes the combat system.
	/// </summary>
	/// <param name="offensiveSquad">GameObject for the squad performing the attack.</param>
	/// <param name="defensiveSquad">GameObject for the squad on defense.</param>
	/// <param name="grid">Grid behavior on which the combat is taking place.</param>
	public void BeginCombat(CombatSquadBehavior offensiveSquad, CombatSquadBehavior defensiveSquad, GridBehavior grid)
	{
		if (offensiveSquad.Squad == null || defensiveSquad.Squad == null)
		{
			Debug.LogError("Combat was started with either the offensive or defense squad being null!");
			return;
		}

		combatRange = (int)Mathf.Ceil(Vector3.Distance(offensiveSquad.transform.position, defensiveSquad.transform.position));

		this.grid = grid;

		GridBehavior.inCombat = true;
        AudioBehavior.inCombat = true;

		this.offensiveSquad = offensiveSquad;
		this.defensiveSquad = defensiveSquad;

		int unitCount = offensiveSquad.Squad.Units.Count + defensiveSquad.Squad.Units.Count;
		unitPrefabs = new List<NodeSkeletonBehavior>(unitCount);

		createUnits (offensiveSquad.Squad.Units, true, 0.0f);
		createUnits (defensiveSquad.Squad.Units, false, 1.0f);

		currentAttacker = CurrentAttacker.OffensiveFront;
	}
	/// <summary>
	/// Performs the logic behind the depth-first search.
	/// </summary>
	/// <param name="maxDepth">Maximum depth to perform checking to.</param>
	/// <param name="currentDepth">Current depth within the search.</param>
	/// <param name="grid">Grid the graph is being built on.</param>
	/// <param name="path">List of move points representing the constructed path.</param>
	public void BuildGraph(int maxDepth, int currentDepth, GridBehavior grid, ref List<MovePointBehavior> path)
	{
		BuildGraph(maxDepth, currentDepth, grid, ref path, false);
	}
    // Use this for initialization
    void Start()
    {
        theGrid = GameObject.FindGameObjectWithTag("Grid").GetComponent<GridBehavior>();
        GameObject[] navNodeObjects = GameObject.FindGameObjectsWithTag("Waypoint");

        bool needToFillAllNodeList = false;

        if(allNodeList.Count == 0)
        {
            needToFillAllNodeList = true;
        }

        if(navNodeObjects.Length > 0)
        {
            foreach(GameObject navNode in navNodeObjects)
            {
                NavigationNodeBehavior navNodeComponent = navNode.GetComponent<NavigationNodeBehavior>();
                if(needToFillAllNodeList && navNodeComponent != null)
                {
                    allNodeList.Add(navNodeComponent);
                }

                //check for ordinal locations.
                //foreach(MovePoint mp in theGrid)
                {
                    //check to see if north,east than add to neighbor list.
                    //neighbor is full after grid runs.

                    neighborList.Add(navNodeComponent);

                }
            }
        }
    }
 // Use this for initialization
 void Start()
 {
     grid = FindObjectOfType<GridBehavior>();
     lights = FindObjectsOfType<LightController>();
     lastPos = transform.position;
 }
	/// <summary>
	/// Captures a reference to the Grid and Game Controller components on the object.
	/// </summary>
	public void Start()
	{
		controller = GetComponent<GameControllerBehaviour>();
		if(controller == null)
			Debug.LogError ("GridControlBehavior is applied to an object that does not have the GameControllerBehavior!");

		grid = GetComponent<GridBehavior>();
		if(grid == null)
			Debug.LogError ("GridBehavior is applied to an object that does not have the GridBehavior!");
	}
	/// <summary>
	/// Performs the logic behind the depth-first search.
	/// </summary>
	/// <param name="maxDepth">Maximum depth to perform checking to.</param>
	/// <param name="currentDepth">Current depth within the search.</param>
	/// <param name="grid">Grid the graph is being built on.</param>
	/// <param name="path">List of move points representing the constructed path.</param>
	/// <param name="skipIgnoreList">Whether or not the ignore list check should be skipped.</param>
	public void BuildGraph(int maxDepth, int currentDepth, GridBehavior grid, ref List<MovePointBehavior> path, bool skipIgnoreList)
	{
		if (currentDepth >= maxDepth || neighborList.Length == 0)
			return;

		if (!path.Contains(this))
			path.Add(this);

		currentDepth++;

		foreach (MovePointBehavior neighbor in neighborList)
		{
			if (neighbor == null)
				continue;

			if (!skipIgnoreList && grid.ignoreList != null && grid.ignoreList.Contains(neighbor))
				continue;

			//neighbor.renderer.enabled = true;
			if (!path.Contains(neighbor))
				path.Add(neighbor);

			neighbor.BuildGraph(maxDepth, currentDepth, grid, ref path, skipIgnoreList);
		}
	}
 void Awake()
 {
     grid = FindObjectOfType<GridBehavior>();
 }