File size: 1,477 Bytes
ac55997
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Quantum;

public unsafe class MovesIndicatorManager : QuantumCallbacks
{

  public GameObject HighlightPrefab;

  private List<GameObject> _prefabs = new List<GameObject>();

  public void UpdatePossibleMovements(int index)
  {
    var f = QuantumRunner.Default.Game.Frames.Verified;
    ResetPrefabs();
    for (int i = 0; i < f.Global->Board.Cells.Length; i++)
    {
      if (MoveValidatorHelper.IsValidMove(ref f.Global->Board, index, i, true))
      {
        var FPPosition = BoardHelper.GetCordinatesByIndex(i);
        Vector3 position = new Vector3((float)FPPosition.X + .5f, .5f, (float)FPPosition.Y + .5f);
        var prefab = GetPrefab();
        if (prefab == null)
        {
          var go = Instantiate(HighlightPrefab, position, Quaternion.identity, transform);
          go.SetActive(true);
          _prefabs.Add(go);
        }
        else
        {
          prefab.SetActive(true);
          prefab.transform.position = position;
        }
      }
    }
  }
  private GameObject GetPrefab()
  {
    for (int i = 0; i < _prefabs.Count; i++)
    {
      if (_prefabs[i] != null && _prefabs[i].activeSelf == false)
      {
        return _prefabs[i];
      }
    }
    return null;
  }

  public void ResetPrefabs()
  {
    for (int i = 0; i < _prefabs.Count; i++)
    {
      if (_prefabs[i] != null)
      {
        _prefabs[i].SetActive(false);
      }
    }
  }
}