public Vector3 ReturnVector3Component(Enums.ComponentType componentType, int entityId) { Vector3 vc; if (componentType == Enums.ComponentType.Position) { if (positions.TryGetValue(entityId, out vc)) { return(vc); } } else if (componentType == Enums.ComponentType.Scale) { if (scales.TryGetValue(entityId, out vc)) { return(vc); } } else if (componentType == Enums.ComponentType.Direction) { if (directions.TryGetValue(entityId, out vc)) { return(vc); } } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } Debug.LogWarning(string.Format("Entity doesn't have component in the wanted component list, entity id : {0} component type: {1}", entityId, componentType)); return(Vector3.zero); }
public void SetComponent(Enums.ComponentType componentType, Quaternion component, int entityId) { if (componentType == Enums.ComponentType.Rotation) { rotations[entityId] = component; } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } }
public void SetComponent(Enums.ComponentType componentType, bool component, int entityId) { if (componentType == Enums.ComponentType.IsVisible) { isVisibles[entityId] = component; } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } }
public void SetComponent(Enums.ComponentType componentType, float component, int entityId) { if (componentType == Enums.ComponentType.MaxSpeed) { maxSpeeds[entityId] = component; } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } }
public void AddComponent(Enums.ComponentType componentType, bool component, int entityId) { if (componentType == Enums.ComponentType.IsVisible) { isVisibles.Add(entityId, component); } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } entityManager.entities[entityId].components.Add(componentType); }
public void AddComponent(Enums.ComponentType componentType, Components.MovementInput component, int entityId) { if (componentType == Enums.ComponentType.InputToMovement) { inputToMovement.Add(entityId, component); } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } entityManager.entities[entityId].components.Add(componentType); }
public void AddComponent(Enums.ComponentType componentType, Quaternion component, int entityId) { if (componentType == Enums.ComponentType.Rotation) { rotations.Add(entityId, component); } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } entityManager.entities[entityId].components.Add(componentType); }
public void AddComponent(Enums.ComponentType componentType, float component, int entityId) { if (componentType == Enums.ComponentType.MaxSpeed) { maxSpeeds.Add(entityId, component); } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } entityManager.entities[entityId].components.Add(componentType); }
public int ReturnIntComponent(Enums.ComponentType componentType, int entityId) { int integer; if (false) { } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } Debug.LogWarning(string.Format("Entity doesn't have component in the wanted component list, entity id : {0} component type: {1}", entityId, componentType)); return(0); }
protected void SetComponent(int type) { _currentComponent = (Enums.ComponentType)type; if (_currentComponent == ComponentType.All) { _isActive = (int)ComponentType.All; } else if (_currentComponent == ComponentType.Countries) { _isActive = (int)ComponentType.Countries; } else if (_currentComponent == ComponentType.States) { _isActive = (int)ComponentType.States; } StateHasChanged(); }
public bool ReturnBooleanComponent(Enums.ComponentType componentType, int entityId) { bool bl; if (componentType == Enums.ComponentType.IsVisible) { if (isVisibles.TryGetValue(entityId, out bl)) { return(bl); } } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } Debug.LogWarning(string.Format("Entity doesn't have component in the wanted component list, entity id : {0} component type: {1}", entityId, componentType)); return(false); }
public float ReturnFloatComponent(Enums.ComponentType componentType, int entityId) { float fl; if (componentType == Enums.ComponentType.MaxSpeed) { if (maxSpeeds.TryGetValue(entityId, out fl)) { return(fl); } } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } Debug.LogWarning(string.Format("Entity doesn't have component in the wanted component list, entity id : {0} component type: {1}", entityId, componentType)); return(0); }
public Quaternion ReturnQuaternionComponent(Enums.ComponentType componentType, int entityId) { Quaternion qt; if (componentType == Enums.ComponentType.Rotation) { if (rotations.TryGetValue(entityId, out qt)) { return(qt); } } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } Debug.LogWarning(string.Format("Entity doesn't have component in the wanted component list, entity id : {0} component type: {1}", entityId, componentType)); return(Quaternion.identity); }
public void SetComponent(Enums.ComponentType componentType, Vector3 component, int entityId) { if (componentType == Enums.ComponentType.Position) { positions[entityId] = component; } else if (componentType == Enums.ComponentType.Direction) { directions[entityId] = component; } else if (componentType == Enums.ComponentType.Scale) { scales[entityId] = component; } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } }
public void AddComponent(Enums.ComponentType componentType, Vector3 component, int entityId) { if (componentType == Enums.ComponentType.Position) { positions.Add(entityId, component); } else if (componentType == Enums.ComponentType.Direction) { directions.Add(entityId, component); } else if (componentType == Enums.ComponentType.Scale) { scales.Add(entityId, component); } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } entityManager.entities[entityId].components.Add(componentType); }
public void RemoveComponent(Enums.ComponentType componentType, int entityId) { switch (componentType) { default: throw new ArgumentException("No component lists were found with the given type", "componentType"); case Enums.ComponentType.Position: positions.Remove(entityId); break; case Enums.ComponentType.Scale: scales.Remove(entityId); break; case Enums.ComponentType.Rotation: rotations.Remove(entityId); break; case Enums.ComponentType.Direction: directions.Remove(entityId); break; case Enums.ComponentType.MaxSpeed: maxSpeeds.Remove(entityId); break; case Enums.ComponentType.Movement: movementComponents.Remove(entityId); break; case Enums.ComponentType.InputToMovement: inputToMovement.Remove(entityId); break; } entityManager.entities[entityId].components.Remove(componentType); }
public Components.Movement ReturnMovementComponent(Enums.ComponentType componentType, int entityId) { Components.Movement mc; if (componentType == Enums.ComponentType.Movement) { if (movementComponents.TryGetValue(entityId, out mc)) { return(mc); } } else if (componentType == Enums.ComponentType.PreviousFrameMovement) { if (previousFrameMovementComponents.TryGetValue(entityId, out mc)) { return(mc); } } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } Debug.LogWarning(string.Format("Entity doesn't have component in the wanted component list, entity id : {0} component type: {1}", entityId, componentType)); return(null); }
public override void OnInspectorGUI() { if (target == null) { return; } Entity e = (Entity)target; if (EntityManager.Instance == null || ComponentManager.Instance == null) { return; } PlayerManager playerManager = PlayerManager.Instance; EntityManager entityManager = EntityManager.Instance; ComponentManager componentManager = ComponentManager.Instance; if (e.id == 0 || entityManager.entities.ContainsKey(e.id) == false) { if (GUILayout.Button("Create Entity")) { e.id = entityManager.GenerateEntityID(); e.components = new List <ComponentType>(); entityManager.entities.Add(e.id, e); componentManager.entityGameObjects.Add(e.id, e.gameObject); componentManager.entityTransforms.Add(e.id, e.transform); componentManager.rigidbodies.Add(e.id, e.GetComponent <Rigidbody>()); } return; } else { if (GUILayout.Button("Delete Entity")) { entityManager.DeleteEntity(e.id); return; } } EditorGUILayout.IntField("EntityID", e.id); EditorGUILayout.BeginHorizontal(); componentTypeToSet = (Fudo.Enums.ComponentType)EditorGUILayout.EnumPopup("Component to create:", componentTypeToSet); if (GUILayout.Button("Create")) { if (e.components.Contains(componentTypeToSet) == false) { switch (componentTypeToSet) { case Enums.ComponentType.Position: componentManager.AddComponent(Enums.ComponentType.Position, Vector3.zero, e.id); break; case Enums.ComponentType.Scale: componentManager.AddComponent(Enums.ComponentType.Scale, Vector3.one, e.id); break; case Enums.ComponentType.Rotation: componentManager.AddComponent(Enums.ComponentType.Rotation, Quaternion.identity, e.id); break; case Enums.ComponentType.Direction: componentManager.AddComponent(Enums.ComponentType.Direction, Vector3.forward, e.id); break; case Enums.ComponentType.MaxSpeed: componentManager.AddComponent(Enums.ComponentType.MaxSpeed, 5.0f, e.id); break; case Enums.ComponentType.Movement: componentManager.AddComponent(Enums.ComponentType.Movement, new Components.Movement(), e.id); break; case Enums.ComponentType.InputToMovement: componentManager.AddComponent(Enums.ComponentType.InputToMovement, new Components.MovementInput(), e.id); break; } } } if (GUILayout.Button("Remove")) { if (e.components.Contains(componentTypeToSet)) { componentManager.RemoveComponent(componentTypeToSet, e.id); } } EditorGUILayout.EndHorizontal(); foreach (Enums.ComponentType componentType in e.components) { EditorGUILayout.Space(); Rect rect = EditorGUILayout.BeginVertical(); EditorGUI.DrawRect(rect, Color.gray); switch (componentType) { default: Debug.LogWarning("Component draw not implemented for: " + componentType); break; case Enums.ComponentType.MaxSpeed: float f = componentManager.ReturnFloatComponent(componentType, e.id); f = EditorGUILayout.FloatField(componentType.ToString(), f); componentManager.SetComponent(componentType, f, e.id); break; case Enums.ComponentType.IsVisible: bool b = componentManager.ReturnBooleanComponent(componentType, e.id); b = EditorGUILayout.Toggle(componentType.ToString(), b); componentManager.SetComponent(componentType, b, e.id); break; case Enums.ComponentType.Position: case Enums.ComponentType.Direction: case Enums.ComponentType.Scale: Vector3 v = componentManager.ReturnVector3Component(componentType, e.id); v = EditorGUILayout.Vector3Field(componentType.ToString(), v); componentManager.SetComponent(componentType, v, e.id); break; case Enums.ComponentType.Rotation: Quaternion qt = componentManager.ReturnQuaternionComponent(componentType, e.id); qt = Quaternion.Euler(EditorGUILayout.Vector3Field(componentType.ToString(), qt.eulerAngles)); componentManager.SetComponent(componentType, qt, e.id); break; case Enums.ComponentType.Movement: case Enums.ComponentType.PreviousFrameMovement: EditorGUILayout.LabelField(componentType.ToString()); Components.Movement mv = componentManager.ReturnMovementComponent(componentType, e.id); mv.velocity = EditorGUILayout.Vector3Field("Velocity", mv.velocity); break; case Enums.ComponentType.Controllable: Components.Controllable controllable; if (componentManager.controllableComponents.TryGetValue(e.id, out controllable)) { EditorGUILayout.LabelField(componentType.ToString()); } break; } EditorGUILayout.EndVertical(); } }
protected override void OnInitialized() { _currentComponent = Enums.ComponentType.All; _isActive = (int)_currentComponent; }