Ejemplo n.º 1
0
 public void ResetGame()
 {
     enemyBehaviours.Clear();
     attackedTiles.Clear();
     playerBehaviour   = null;
     handledEnemyIndex = 0;
 }
 /// <summary>
 /// Удалить компонент обновления
 /// </summary>
 /// <param name="mono">компонент</param>
 public void Delete(CustomMonoBehaviour mono)
 {
     if (itemsToUpdate.Contains(mono))
     {
         itemsToUpdate.Remove(mono);
     }
 }
Ejemplo n.º 3
0
    static void RemoveComponent(MenuCommand command)
    {
        CustomMonoBehaviour target = (CustomMonoBehaviour)command.context;

        if (PrefabUtility.IsPartOfPrefabAsset(target))
        {
            var prefabPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(target);
            var root       = PrefabUtility.LoadPrefabContents(prefabPath);

            target.onPrefabAssetRemoveComponent?.Invoke(root);

            // note that in the prefab asset inspector, you can only inspect the root gameObject, so the
            // removed component must be a part of it; automatically picks the right CustomMonoBehaviour
            DestroyImmediate(root.GetComponent <CustomMonoBehaviour>());

            PrefabUtility.SaveAsPrefabAsset(root, prefabPath);
            PrefabUtility.UnloadPrefabContents(root);

            Undo.ClearAll(); // not the best fix for unexpected Undo behaviour
        }
        else
        {
            Undo.DestroyObjectImmediate(target);
        }
    }
 /// <summary>
 /// Зарегистрировать объект обновления
 /// </summary>
 /// <param name="mono">компонент</param>
 public void Register(CustomMonoBehaviour mono)
 {
     if (!itemsToUpdate.Contains(mono))
     {
         itemsToUpdate.Add(mono);
     }
 }
Ejemplo n.º 5
0
    private void DoEnemyMove()
    {
        CustomMonoBehaviour enemy = enemyBehaviours[handledEnemyIndex];

        if (enemy.enabled)
        {
            enemy.OnEnemyMove();
            return;
        }

        // If not enabled we just end the turn
        OnEnemyTurnEnd();
    }
Ejemplo n.º 6
0
    public static void ObjectPoolReturn(this IList <GameObject> list, GameObject prefab)
    {
        if (GameManager.instance)
        {
            customMonoBehaviour = GameManager.instance.GetComponent <CustomMonoBehaviour>();
        }
        else
        {
            return;
        }

        customMonoBehaviour.StartCoroutine(customMonoBehaviour.WaitForSecondsCoroutine(0.1f, action: () =>
        {
            prefab.transform.SetParent(GameManager.instance.objectPoolManager.objectPoolContainer);
            list.Add(prefab);
        }));
    }
Ejemplo n.º 7
0
 public void RemoveEnemy(CustomMonoBehaviour enemy)
 {
     enemyBehaviours.Remove(enemy);
 }
Ejemplo n.º 8
0
 public void RegisterEnemy(CustomMonoBehaviour enemy)
 {
     enemyBehaviours.Add(enemy);
 }
Ejemplo n.º 9
0
    public override void OnInspectorGUI()
    {
        CustomMonoBehaviour customBehaviour = target as CustomMonoBehaviour;

        customBehaviour.ShowInspectorGUI(this);
    }
Ejemplo n.º 10
0
    public override void OnPreviewGUI(Rect r, GUIStyle background)
    {
        CustomMonoBehaviour customBehaviour = target as CustomMonoBehaviour;

        customBehaviour.ShowPreviewGUI(r, background);
    }
Ejemplo n.º 11
0
    public override bool HasPreviewGUI()
    {
        CustomMonoBehaviour customBehaviour = target as CustomMonoBehaviour;

        return(customBehaviour.HasPreviewGUI());
    }
Ejemplo n.º 12
0
    public virtual void OnSceneGUI()
    {
        CustomMonoBehaviour customBehaviour = target as CustomMonoBehaviour;

        customBehaviour.ShowSceneGUI();
    }
Ejemplo n.º 13
0
    protected Vector3 DoPathfinding(Vector3 oldPosition)
    {
        player = GameManager.Instance.playerBehaviour;

        Debug.Log("Finding path between " + transform.position + " and " + player.transform.position);
        Vector3 playerPosition = player.transform.position;

        List <Vector3> trialPositions = new List <Vector3>();

        trialPositions.Add(playerPosition + new Vector3(1, 0, 0));
        trialPositions.Add(playerPosition + new Vector3(0, 1, 0));
        trialPositions.Add(playerPosition + new Vector3(-1, 0, 0));
        trialPositions.Add(playerPosition + new Vector3(0, -1, 0));

        trialPositions.Sort(delegate(Vector3 a, Vector3 b)
        {
            return(Vector3.Distance(a, transform.position)
                   .CompareTo(
                       Vector3.Distance(b, transform.position)));
        });

        List <Vector3> advancedPositions = new List <Vector3>();

        advancedPositions.Add(playerPosition + new Vector3(1, 1, 0));
        advancedPositions.Add(playerPosition + new Vector3(-1, 1, 0));
        advancedPositions.Add(playerPosition + new Vector3(-1, 1, 0));
        advancedPositions.Add(playerPosition + new Vector3(-1, -1, 0));

        for (int i = 0; i < 4; i++)
        {
            if (IsOccupied(trialPositions[i]))
            {
                continue;
            }

            List <Vector3> path = AStar.FindPath(pathfindingTilemap, transform.position, trialPositions[i]);

            if (path == null)
            {
                // No path returned, stay
                return(transform.position);
            }

            return(GetFirstTile(path));
        }

        for (int i = 0; i < 4; i++)
        {
            if (IsOccupied(advancedPositions[i]))
            {
                continue;
            }

            List <Vector3> path = AStar.FindPath(pathfindingTilemap, transform.position, advancedPositions[i]);
            if (path == null)
            {
                // No path returned, stay
                return(transform.position);
            }

            return(GetFirstTile(path));
        }

        return(oldPosition);
    }