void CreateOrReinitLivingEntityData(BaseLivingEntityConfig entetyConfig, ref LivingEntityData entityData) { Vector3 getPosition(Vector2 normalizedPosition) { var sb = sceneBounds(); var center = sb.center; var size = sb.size; size = new Vector3(normalizedPosition.x * size.x, normalizedPosition.y * size.y); return(center + size); } if (entityData == null) { entityData = new LivingEntityData(); } var initData = entetyConfig.GetData(); entityData.position = getPosition(initData.position); entityData.rotation = initData.rotation; entityData.scale = initData.scale; entityData.speed = initData.speed; entityData.baseColor = initData.color; entityData.layer = initData.layer; entityData.radius = initData.radius; entityData.alpha = 0f; }
void UpdateLivingEntityData() { if (_lastLivingEntityData != _LivingEntityData) { OnLivingEntityDataChanged?.Invoke(); _lastLivingEntityData = _LivingEntityData; } }
public void Populate(int numberOfEntities, BaseLivingEntityConfig entetyConfig) { while (_enteties.Count < numberOfEntities) { LivingEntityData entityData = null; CreateOrReinitLivingEntityData(entetyConfig, ref entityData); _enteties.Add(entityData); } }
public void Update(BaseLivingEntityConfig entityConfig) { var tSceneBounds = sceneBounds(); var deltaTime = Time.deltaTime; var refenceScale = entetiesReferenceScale(); var referenceAlpha = entetiesReferenceAlpha(); var referenceSpeed = entetiesReferenceSpeed(); bool updateEntity(LivingEntityData data) { var deltaPosition = (Vector2)(data.Rotation * Vector3.up * data.speed * referenceSpeed * deltaTime); data.position += deltaPosition; data.scaleFactor = refenceScale; data.alphaFactor = referenceAlpha; if (data.alpha < 1) { data.alpha = Mathf.Clamp(data.alpha + deltaTime * AlphaFadeOutSpeed, 0, 1); } var boundRadius = data.scaleFactor * data.radius; return(Physics2DUtils.CircleWithin(tSceneBounds, data.position, boundRadius)); } for (int i = 0; i < _enteties.Count; i++) { var entityData = _enteties[i]; if (!updateEntity(entityData)) { CreateOrReinitLivingEntityData(entityConfig, ref entityData); } } if (useSort()) { _enteties.Sort(_sEntetiesComparer); } }
private void Awake() { _lastLivingEntityData = _LivingEntityData; _fpsDisplay = FindObjectOfType <FPSDisplay>(); }
void OnGUI() { const float spawnerBoxWidth = 550f; if (_spawnerComboBox == null) { var width = spawnerBoxWidth * UICoeff; var height = UIMediumMargin + UISmallMargin * 2; var x = Screen.width - width - UIMediumMargin; var y = Screen.height - height - UIMediumMargin; var rect = new Rect(x, y, width, height); var comboBoxList = new GUIContent[] { new GUIContent("GameObject"), // Basic new GUIContent("Draw Mesh"), new GUIContent("One Mesh"), new GUIContent("Particle System") }; var buttonStyle = new GUIStyle("button"); buttonStyle.fontSize = (int)(60f * UICoeff); var boxStyle = new GUIStyle("box"); var listStyle = new GUIStyle(); listStyle.fontSize = (int)(60f * UICoeff); listStyle.normal.textColor = Color.white; listStyle.onHover.background = listStyle.hover.background = new Texture2D(2, 2); listStyle.padding.left = listStyle.padding.right = listStyle.padding.top = listStyle.padding.bottom = 4; _spawnerComboBox = new ComboBox( rect, comboBoxList, buttonStyle, boxStyle, listStyle ); _spawnerComboBox.OnItemSelected += (i, userHasPressed) => { if (!userHasPressed) { return; } _SelectedType = (SpawnerType)i; UpdateType(); }; _spawnerComboBox.Direction = ComboBox.PopupDirection.FromBottomToTop; _spawnerComboBox.SelectedItemIndex = _type.HasValue? (int)_type.Value : 0; } else { var width = spawnerBoxWidth * UICoeff; var height = UIMediumMargin + UISmallMargin * 2; var x = Screen.width - width - UIMediumMargin; var y = Screen.height - height - UIMediumMargin; var rect = new Rect(x, y, width, height); _spawnerComboBox.rect = rect; } if (_configComboBox == null) { var width = 550 * UICoeff; var height = UIMediumMargin + UISmallMargin * 2; var x = Screen.width - UIMediumMargin - spawnerBoxWidth * UICoeff - UISmallMargin - width; var y = Screen.height - height - UIMediumMargin; var rect = new Rect(x, y, width, height); var comboBoxList = new GUIContent[_LivingEntityDatas.Length]; for (int i = 0; i < comboBoxList.Length; i++) { comboBoxList[i] = new GUIContent(_LivingEntityDatas[i].Name); } var buttonStyle = new GUIStyle("button"); buttonStyle.fontSize = (int)(60f * UICoeff); var boxStyle = new GUIStyle("box"); var listStyle = new GUIStyle(); listStyle.fontSize = (int)(60f * UICoeff); listStyle.normal.textColor = Color.white; listStyle.onHover.background = listStyle.hover.background = new Texture2D(2, 2); listStyle.padding.left = listStyle.padding.right = listStyle.padding.top = listStyle.padding.bottom = 4; _configComboBox = new ComboBox( rect, comboBoxList, buttonStyle, boxStyle, listStyle ); _configComboBox.OnItemSelected += (i, userHasPressed) => { if (!userHasPressed) { return; } _LivingEntityData = _LivingEntityDatas[i]; UpdateLivingEntityData(); }; _configComboBox.Direction = ComboBox.PopupDirection.FromBottomToTop; _configComboBox.SelectedItemIndex = System.Array.FindIndex(_LivingEntityDatas, (d) => d.Equals(_LivingEntityData)); } else { var width = 550 * UICoeff; var height = UIMediumMargin + UISmallMargin * 2; var x = Screen.width - UIMediumMargin - spawnerBoxWidth * UICoeff - UISmallMargin - width; var y = Screen.height - height - UIMediumMargin; var rect = new Rect(x, y, width, height); _configComboBox.rect = rect; } if (GUIVisibility) { _spawnerComboBox.Show(); _configComboBox.Show(); } }