private bool SetPositionProperty(Vector3Int position, String name, GridInformationType dataType, System.Object positionProperty) { Grid grid = GetComponentInParent<Grid>(); if (grid != null && positionProperty != null) { GridInformationKey positionKey; positionKey.position = position; positionKey.name = name; GridInformationValue positionValue; positionValue.type = dataType; positionValue.data = positionProperty; m_PositionProperties.Add(positionKey, positionValue); return true; } return false; }
private bool SetPositionProperty(Vector3Int position, string name, GridInformationType dataType, object positionProperty) { Grid grid = GetComponentInParent <Grid>(); if (grid != null && positionProperty != null) { GridInformationKey positionKey; positionKey.position = position; positionKey.name = name; GridInformationValue positionValue; positionValue.type = dataType; positionValue.data = positionProperty; m_PositionProperties[positionKey] = positionValue; return(true); } return(false); }
internal T GetPositionProperty <T>(Vector3Int position, String name, T defaultValue, GridInformationType gridInformationType) { GridInformationKey positionKey; positionKey.position = position; positionKey.name = name; GridInformationValue positionValue; if (m_PositionProperties.TryGetValue(positionKey, out positionValue)) { if (positionValue.type != gridInformationType) { throw new InvalidCastException("Value stored in GridInformation is not of the right type"); } return((T)System.Convert.ChangeType(positionValue.data, typeof(T))); } return((T)System.Convert.ChangeType(defaultValue, typeof(T))); }