I’ve encountered a problem with Unity 3.5. So far I could write script that worked in editor and manipulated the values of its members (this is List actually). And after launching play mode the List data remained. But since I’ve installed Unity 3.5 that trick is over. Each time list is filled by script in editor mode and I start play mode the list data is erased and the count of list members goes to 0. But if I manually fill the list by references in Inspector then it runs OK. Here is the script when the list _neighbors is filled in editor when I build the scene and set to empty each time I trigger play mode.
using UnityEngine;
using System.Collections.Generic;
[ExecuteInEditMode]
public class Positioning : MonoBehaviour
{
public List<Cell> _neighbors = new List<Cell>();
private Transform _transform;
private Vector3 _lastPos;
private CellManager _cellManager;
public List<Cell> Neighbors
{
get
{
return _neighbors;
}
set
{
_neighbors = value;
}
}
void Awake()
{
_transform = transform;
_cellManager = GameObject.Find("CellManager").GetComponent<CellManager>();
}
void Start()
{
_cellManager.AddCell(GetComponent<Cell>());
_lastPos = _transform.position;
}
void Update()
{
if (_cellManager.Cells.Count > 1 &&
Vector3.Distance(_transform.position, _lastPos) > 0.01f)
{
Cell nearestCell = _cellManager.NearestCell(_transform.position, gameObject.GetComponent<Cell>());
if (Vector3.Distance(nearestCell.transform.position, _transform.position) < 1.0f)
{
if (_neighbors.Count > 0)
{
foreach (Cell neighborCell in _neighbors)
{
if (neighborCell != gameObject.GetComponent<Cell>())
{
neighborCell.gameObject.GetComponent<Positioning>().Neighbors.Remove(GetComponent<Cell>());
}
}
_neighbors.Clear();
}
Vector3 pos =
nearestCell.GetFreeNeighborPlace(_transform.position);
_transform.position = pos;
_transform.rotation = nearestCell.transform.rotation;
List<Cell> neighbors = _cellManager.NearestCells(_transform.position, gameObject.GetComponent<Cell>());
foreach (Cell neighbor in neighbors)
{
neighbor.gameObject.GetComponent<Positioning>().Neighbors.Add(GetComponent<Cell>());
_neighbors.Add(neighbor);
}
}
}
_lastPos = _transform.position;
}
}
I know that all the public members in scripts derived by MonoBehaviour are serialized and it worked before. I have no idea what is happened. Maybe I’m doing something wrong and I should go another way. Hope someone could help me with this. Thanks.