public GameObject() { /// Properties for use in the map editor // Object Name var nameProperty = new GameObjectProperty("Name", PropertyType.STRING); Properties.Add("Name", nameProperty); }
public GameObjectAnimated() { /// Properties for use in the map editor // Object Name var animProperty = new GameObjectProperty("Animation", PropertyType.STRING); Properties.Add("Animation", animProperty); }
private GameObjectProperty FillGameObjectProperty(DataRow Fields) { GameObjectProperty gop = new GameObjectProperty(); int gameobjid = (int)Fields[GameObjectPropertyNames.GameObjectId]; int propid = (int)Fields[GameObjectPropertyNames.PropertyId]; gop.Id = (int)Fields[GameObjectPropertyNames.Id]; gop.GameObject = BuildGameObjectDictionary()[gameobjid]; gop.Property = BuildPropertyDictionary()[propid]; return(gop); }
public GameObject() { // Event init MouseClickedEvent += MouseClicked; MouseMovedEvent += MouseMoved; /// Properties for use in the map editor // Object Name var nameProperty = new GameObjectProperty("Name", PropertyType.STRING); Properties.Add("Name", nameProperty); }
public override void Draw(GraphicsDevice device, SpriteBatch spriteBatch, GameInfo info) { base.Draw(device, spriteBatch, info); foreach (HelperRectangle rectangle in HelperRectangles) { GameObjectProperty posX = null; GameObjectProperty posY = null; GameObjectProperty width = null; GameObjectProperty height = null; if (info.objectManager.SelectionObject.Selection.Contains(this) && Properties.TryGetValue(rectangle.PosXProperty, out posX) && Properties.TryGetValue(rectangle.PosYProperty, out posY) && Properties.TryGetValue(rectangle.WidthProperty, out width) && Properties.TryGetValue(rectangle.HeightProperty, out height)) { ObjectManager.DrawRectangle(spriteBatch, device, new Rectangle((int)posX.GetAsInt32() + (int)GetPosition().X, (int)posY.GetAsInt32() + (int)GetPosition().Y, (int)width.GetAsInt32(), (int)height.GetAsInt32()), 1, new Color(242, 228, 121, 120)); } } foreach (ComponentInfo component in Components) { component.Draw(device, info.gameTime, spriteBatch, info, this); } }
public void CreatePropertyBox(GameObjectProperty boundProperty, Panel ParentControl) { GameObjectProperty property = boundProperty; int propertyStripHeight = 20; int newPos = (ParentControl.Children.Count) * propertyStripHeight; PropertyViewer.Height += 20; PropertyViewer.Width = MainScrollViewer.ActualWidth; switch (property.propertyType) { case PropertyType.BOOL: // Create property strip, set text name to property name and make events the property strip can hook to. PropertyStripCheckbox propertyStripBool = new PropertyStripCheckbox(); propertyStripBool.PropertyHeader.Text = property.RealName; propertyStripBool.PropertyCheckBox.IsChecked = property.GetAsBool(); propertyStripBool.Width = ParentControl.Width; ParentControl.Children.Add(propertyStripBool); Canvas.SetTop(propertyStripBool, newPos); // Event to set property when the checkbox is checked or unchecked. propertyStripBool.PropertyCheckBox.Click += (sender, e) => { property.SetValue((bool)propertyStripBool.PropertyCheckBox.IsChecked); }; break; case PropertyType.DOUBLE: // Create property strip, set text name to property name and make events the property strip can hook to. PropertyStripText propertyStripDouble = new PropertyStripText(); propertyStripDouble.PropertyHeader.Text = property.RealName; propertyStripDouble.PropertyTextBox.Text = property.GetAsDouble().ToString(); propertyStripDouble.Width = MainScrollViewer.ActualWidth; ParentControl.Children.Add(propertyStripDouble); Canvas.SetTop(propertyStripDouble, newPos); // Event to set property when the textbox is changed if the textbox is a valid double. propertyStripDouble.PropertyTextBox.TextChanged += (sender, e) => { double dummyOut; if (double.TryParse(propertyStripDouble.PropertyTextBox.Text, out dummyOut)) { propertyStripDouble.PropertyTextBox.Foreground = new SolidColorBrush(Color.FromRgb(189, 195, 199)); property.SetValue(dummyOut); } else { propertyStripDouble.PropertyTextBox.Foreground = new SolidColorBrush(Color.FromRgb(181, 74, 47)); } }; break; case PropertyType.FLOAT: // Create property strip, set text name to property name and make events the property strip can hook to. PropertyStripText propertyStripFloat = new PropertyStripText(); propertyStripFloat.PropertyHeader.Text = property.RealName; propertyStripFloat.PropertyTextBox.Text = property.GetAsFloat().ToString(); propertyStripFloat.Width = MainScrollViewer.ActualWidth; ParentControl.Children.Add(propertyStripFloat); Canvas.SetTop(propertyStripFloat, newPos); // Event to set property when the textbox is changed if the textbox is a valid float. propertyStripFloat.PropertyTextBox.TextChanged += (sender, e) => { float dummyOut; if (float.TryParse(propertyStripFloat.PropertyTextBox.Text, out dummyOut)) { propertyStripFloat.PropertyTextBox.Foreground = new SolidColorBrush(Color.FromRgb(189, 195, 199)); property.SetValue(dummyOut); } else { propertyStripFloat.PropertyTextBox.Foreground = new SolidColorBrush(Color.FromRgb(181, 74, 47)); } }; break; case PropertyType.INT: // Create property strip, set text name to property name and make events the property strip can hook to. PropertyStripText propertyStripInt = new PropertyStripText(); propertyStripInt.PropertyHeader.Text = property.RealName; propertyStripInt.PropertyTextBox.Text = property.GetAsInt32().ToString(); propertyStripInt.Width = MainScrollViewer.ActualWidth; ParentControl.Children.Add(propertyStripInt); Canvas.SetTop(propertyStripInt, newPos); // Event to set property when the textbox is changed if the textbox is a valid int. propertyStripInt.PropertyTextBox.TextChanged += (sender, e) => { int dummyOut; if (int.TryParse(propertyStripInt.PropertyTextBox.Text, out dummyOut)) { propertyStripInt.PropertyTextBox.Foreground = new SolidColorBrush(Color.FromRgb(189, 195, 199)); property.SetValue(dummyOut); } else { propertyStripInt.PropertyTextBox.Foreground = new SolidColorBrush(Color.FromRgb(181, 74, 47)); } }; break; case PropertyType.STRING: // Create property strip, set text name to property name and make events the property strip can hook to. PropertyStripText propertyStripString = new PropertyStripText(); propertyStripString.PropertyHeader.Text = property.RealName; propertyStripString.PropertyTextBox.Text = property.GetAsString(); propertyStripString.Width = MainScrollViewer.ActualWidth; ParentControl.Children.Add(propertyStripString); Canvas.SetTop(propertyStripString, newPos); // Event to set property when the textbox is changed if the textbox is a valid int. propertyStripString.PropertyTextBox.TextChanged += (sender, e) => { property.SetValue(propertyStripString.PropertyTextBox.Text); }; break; } }
/// <summary> /// This function is used to help set basic properties on a game object /// in a generic way. /// </summary> /// <param name="gameObject">The game object whose properties are to be set.</param> /// <param name="targetProperty">The target property to set.</param> /// <param name="propertyValue">The value to set the target property to.</param> public static void SetGameObjectProperty(GameObject gameObject, GameObjectProperty targetProperty, float propertyValue) { //check if the game object is null if (gameObject == null) { return; } //set the property switch (targetProperty) { case GameObjectProperty.XPosition: if (gameObject.transform != null) { gameObject.transform.position = new Vector3(propertyValue, gameObject.transform.position.y, gameObject.transform.position.z); } break; case GameObjectProperty.YPosition: if (gameObject.transform != null) { gameObject.transform.position = new Vector3(gameObject.transform.position.x, propertyValue, gameObject.transform.position.z); } break; case GameObjectProperty.ZPosition: if (gameObject.transform != null) { gameObject.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, propertyValue); } break; case GameObjectProperty.XRotation: if (gameObject.transform != null) { gameObject.transform.rotation = Quaternion.Euler(new Vector3(propertyValue, gameObject.transform.rotation.eulerAngles.y, gameObject.transform.rotation.eulerAngles.z)); } break; case GameObjectProperty.YRotation: if (gameObject.transform != null) { gameObject.transform.rotation = Quaternion.Euler(new Vector3(gameObject.transform.rotation.eulerAngles.x, propertyValue, gameObject.transform.rotation.eulerAngles.z)); } break; case GameObjectProperty.ZRotation: if (gameObject.transform != null) { gameObject.transform.rotation = Quaternion.Euler(new Vector3(gameObject.transform.rotation.eulerAngles.x, gameObject.transform.rotation.eulerAngles.y, propertyValue)); } break; case GameObjectProperty.XVelocity: if (gameObject.rigidbody != null) { gameObject.rigidbody.velocity = new Vector3(propertyValue, gameObject.rigidbody.velocity.y, gameObject.rigidbody.velocity.z); } else if (gameObject.transform != null) { gameObject.transform.Translate(propertyValue * Time.deltaTime, 0.0f, 0.0f); } break; case GameObjectProperty.YVelocity: if (gameObject.rigidbody != null) { gameObject.rigidbody.velocity = new Vector3(gameObject.rigidbody.velocity.x, propertyValue, gameObject.rigidbody.velocity.z); } else if (gameObject.transform != null) { gameObject.transform.Translate(0.0f, propertyValue * Time.deltaTime, 0.0f); } break; case GameObjectProperty.ZVelocity: if (gameObject.rigidbody != null) { gameObject.rigidbody.velocity = new Vector3(gameObject.rigidbody.velocity.x, gameObject.rigidbody.velocity.y, propertyValue); } else if (gameObject.transform != null) { gameObject.transform.Translate(0.0f, 0.0f, propertyValue * Time.deltaTime); } break; case GameObjectProperty.XAngularVelocity: if (gameObject.rigidbody != null) { gameObject.rigidbody.angularVelocity = new Vector3(propertyValue, gameObject.rigidbody.angularVelocity.y, gameObject.rigidbody.angularVelocity.z); } else if (gameObject.transform != null) { gameObject.transform.Rotate(propertyValue * Time.deltaTime, 0.0f, 0.0f); } break; case GameObjectProperty.YAngularVelocity: if (gameObject.rigidbody != null) { gameObject.rigidbody.angularVelocity = new Vector3(gameObject.rigidbody.angularVelocity.x, propertyValue, gameObject.rigidbody.angularVelocity.z); } else if (gameObject.transform != null) { gameObject.transform.Rotate(0.0f, propertyValue * Time.deltaTime, 0.0f); } break; case GameObjectProperty.ZAngularVelocity: if (gameObject.rigidbody != null) { gameObject.rigidbody.angularVelocity = new Vector3(gameObject.rigidbody.angularVelocity.x, gameObject.rigidbody.angularVelocity.y, propertyValue); } else if (gameObject.transform != null) { gameObject.transform.Rotate(0.0f, 0.0f, propertyValue * Time.deltaTime); } break; case GameObjectProperty.UniformScale: if (gameObject.transform) { gameObject.transform.localScale = new Vector3(propertyValue, propertyValue, propertyValue); } break; case GameObjectProperty.XScale: if (gameObject.transform) { gameObject.transform.localScale = new Vector3(propertyValue, gameObject.transform.localScale.y, gameObject.transform.localScale.z); } break; case GameObjectProperty.YScale: if (gameObject.transform) { gameObject.transform.localScale = new Vector3(gameObject.transform.localScale.x, propertyValue, gameObject.transform.localScale.z); } break; case GameObjectProperty.ZScale: if (gameObject.transform) { gameObject.transform.localScale = new Vector3(gameObject.transform.localScale.x, gameObject.transform.localScale.y, propertyValue); } break; default: break; } }
set => SetValue(GameObjectProperty, value);
/// <summary> /// This function is used to help set basic properties on a game object /// in a generic way. /// </summary> /// <param name="gameObject">The game object whose properties are to be set.</param> /// <param name="targetProperty">The target property to set.</param> /// <param name="propertyValue">The value to set the target property to.</param> public static void SetGameObjectProperty(GameObject gameObject, GameObjectProperty targetProperty, float propertyValue) { //check if the game object is null if (gameObject == null) { return; } //set the property switch (targetProperty) { case GameObjectProperty.XPosition: if (gameObject.transform != null) gameObject.transform.position = new Vector3(propertyValue, gameObject.transform.position.y, gameObject.transform.position.z); break; case GameObjectProperty.YPosition: if (gameObject.transform != null) gameObject.transform.position = new Vector3(gameObject.transform.position.x, propertyValue, gameObject.transform.position.z); break; case GameObjectProperty.ZPosition: if (gameObject.transform != null) gameObject.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, propertyValue); break; case GameObjectProperty.XRotation: if (gameObject.transform != null) gameObject.transform.rotation = Quaternion.Euler(new Vector3(propertyValue, gameObject.transform.rotation.eulerAngles.y, gameObject.transform.rotation.eulerAngles.z)); break; case GameObjectProperty.YRotation: if (gameObject.transform != null) gameObject.transform.rotation = Quaternion.Euler(new Vector3(gameObject.transform.rotation.eulerAngles.x, propertyValue, gameObject.transform.rotation.eulerAngles.z)); break; case GameObjectProperty.ZRotation: if (gameObject.transform != null) gameObject.transform.rotation = Quaternion.Euler(new Vector3(gameObject.transform.rotation.eulerAngles.x, gameObject.transform.rotation.eulerAngles.y, propertyValue)); break; case GameObjectProperty.XVelocity: if (gameObject.GetComponent<Rigidbody>() != null) gameObject.GetComponent<Rigidbody>().velocity = new Vector3(propertyValue, gameObject.GetComponent<Rigidbody>().velocity.y, gameObject.GetComponent<Rigidbody>().velocity.z); else if (gameObject.transform != null) gameObject.transform.Translate(propertyValue * Time.deltaTime, 0.0f, 0.0f); break; case GameObjectProperty.YVelocity: if (gameObject.GetComponent<Rigidbody>() != null) gameObject.GetComponent<Rigidbody>().velocity = new Vector3(gameObject.GetComponent<Rigidbody>().velocity.x, propertyValue, gameObject.GetComponent<Rigidbody>().velocity.z); else if (gameObject.transform != null) gameObject.transform.Translate(0.0f, propertyValue * Time.deltaTime, 0.0f); break; case GameObjectProperty.ZVelocity: if (gameObject.GetComponent<Rigidbody>() != null) gameObject.GetComponent<Rigidbody>().velocity = new Vector3(gameObject.GetComponent<Rigidbody>().velocity.x, gameObject.GetComponent<Rigidbody>().velocity.y, propertyValue); else if (gameObject.transform != null) gameObject.transform.Translate(0.0f, 0.0f, propertyValue * Time.deltaTime); break; case GameObjectProperty.XAngularVelocity: if (gameObject.GetComponent<Rigidbody>() != null) gameObject.GetComponent<Rigidbody>().angularVelocity = new Vector3(propertyValue, gameObject.GetComponent<Rigidbody>().angularVelocity.y, gameObject.GetComponent<Rigidbody>().angularVelocity.z); else if (gameObject.transform != null) gameObject.transform.Rotate(propertyValue * Time.deltaTime, 0.0f, 0.0f); break; case GameObjectProperty.YAngularVelocity: if (gameObject.GetComponent<Rigidbody>() != null) gameObject.GetComponent<Rigidbody>().angularVelocity = new Vector3(gameObject.GetComponent<Rigidbody>().angularVelocity.x, propertyValue, gameObject.GetComponent<Rigidbody>().angularVelocity.z); else if (gameObject.transform != null) gameObject.transform.Rotate(0.0f, propertyValue * Time.deltaTime, 0.0f); break; case GameObjectProperty.ZAngularVelocity: if (gameObject.GetComponent<Rigidbody>() != null) gameObject.GetComponent<Rigidbody>().angularVelocity = new Vector3(gameObject.GetComponent<Rigidbody>().angularVelocity.x, gameObject.GetComponent<Rigidbody>().angularVelocity.y, propertyValue); else if (gameObject.transform != null) gameObject.transform.Rotate(0.0f, 0.0f, propertyValue * Time.deltaTime); break; case GameObjectProperty.UniformScale: if (gameObject.transform) gameObject.transform.localScale = new Vector3(propertyValue, propertyValue, propertyValue); break; case GameObjectProperty.XScale: if (gameObject.transform) gameObject.transform.localScale = new Vector3(propertyValue, gameObject.transform.localScale.y, gameObject.transform.localScale.z); break; case GameObjectProperty.YScale: if (gameObject.transform) gameObject.transform.localScale = new Vector3(gameObject.transform.localScale.x, propertyValue, gameObject.transform.localScale.z); break; case GameObjectProperty.ZScale: if (gameObject.transform) gameObject.transform.localScale = new Vector3(gameObject.transform.localScale.x, gameObject.transform.localScale.y, propertyValue); break; default: break; } }
/// <summary> /// This is callled when this commponent is reset. /// </summary> public override void Reset() { base.Reset(); targetProperty = Defaults.targetProperty; }
/// <summary> /// This function is used to help set basic properties on a game object /// in a generic way. /// </summary> /// <param name="gameObject">The game object whose properties are to be set.</param> /// <param name="targetProperty">The target property to set.</param> /// <param name="propertyValue">The value to set the target property to.</param> /// public static void SetGameObjectProperty(GameObject gameObject, GameObjectProperty targetProperty, float propertyValue) { GameObject player = GameObject.Find("Player"); ExponentialMovingAverage trailAvg = new ExponentialMovingAverage(0.06f); //check if the game object is null if (gameObject == null) { return; } //set the property switch (targetProperty) { case GameObjectProperty.XPosition: if (gameObject.transform != null) { gameObject.transform.position = new Vector3(propertyValue, gameObject.transform.position.y, gameObject.transform.position.z); } break; case GameObjectProperty.YPosition: if (gameObject.transform != null) { gameObject.transform.position = new Vector3(gameObject.transform.position.x, propertyValue, gameObject.transform.position.z); } break; case GameObjectProperty.ZPosition: if (gameObject.transform != null) { gameObject.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, propertyValue); } break; case GameObjectProperty.XRotation: if (gameObject.transform != null) { gameObject.transform.rotation = Quaternion.Euler(new Vector3(propertyValue, gameObject.transform.rotation.eulerAngles.y, gameObject.transform.rotation.eulerAngles.z)); } break; case GameObjectProperty.YRotation: if (gameObject.transform != null) { gameObject.transform.rotation = Quaternion.Euler(new Vector3(gameObject.transform.rotation.eulerAngles.x, propertyValue, gameObject.transform.rotation.eulerAngles.z)); } break; case GameObjectProperty.ZRotation: if (gameObject.transform != null) { gameObject.transform.rotation = Quaternion.Euler(new Vector3(gameObject.transform.rotation.eulerAngles.x, gameObject.transform.rotation.eulerAngles.y, propertyValue)); } break; case GameObjectProperty.XVelocity: if (gameObject.GetComponent <Rigidbody>() != null) { gameObject.GetComponent <Rigidbody>().velocity = new Vector3(propertyValue, gameObject.GetComponent <Rigidbody>().velocity.y, gameObject.GetComponent <Rigidbody>().velocity.z); } else if (gameObject.transform != null) { gameObject.transform.Translate(propertyValue * Time.deltaTime, 0.0f, 0.0f); } break; case GameObjectProperty.YVelocity: if (gameObject.GetComponent <Rigidbody>() != null) { gameObject.GetComponent <Rigidbody>().velocity = new Vector3(gameObject.GetComponent <Rigidbody>().velocity.x, propertyValue, gameObject.GetComponent <Rigidbody>().velocity.z); } else if (gameObject.transform != null) { gameObject.transform.Translate(0.0f, propertyValue * Time.deltaTime, 0.0f); } break; case GameObjectProperty.ZVelocity: if (gameObject.GetComponent <Rigidbody>() != null) { gameObject.GetComponent <Rigidbody>().velocity = new Vector3(gameObject.GetComponent <Rigidbody>().velocity.x, gameObject.GetComponent <Rigidbody>().velocity.y, propertyValue); } else if (gameObject.transform != null) { gameObject.transform.Translate(0.0f, 0.0f, propertyValue * Time.deltaTime); } break; case GameObjectProperty.XAngularVelocity: if (gameObject.GetComponent <Rigidbody>() != null) { gameObject.GetComponent <Rigidbody>().angularVelocity = new Vector3(propertyValue, gameObject.GetComponent <Rigidbody>().angularVelocity.y, gameObject.GetComponent <Rigidbody>().angularVelocity.z); } else if (gameObject.transform != null) { gameObject.transform.Rotate(propertyValue * Time.deltaTime, 0.0f, 0.0f); } break; case GameObjectProperty.YAngularVelocity: if (gameObject.GetComponent <Rigidbody>() != null) { gameObject.GetComponent <Rigidbody>().angularVelocity = new Vector3(gameObject.GetComponent <Rigidbody>().angularVelocity.x, propertyValue, gameObject.GetComponent <Rigidbody>().angularVelocity.z); } else if (gameObject.transform != null) { gameObject.transform.Rotate(0.0f, propertyValue * Time.deltaTime, 0.0f); } break; case GameObjectProperty.ZAngularVelocity: if (gameObject.GetComponent <Rigidbody>() != null) { gameObject.GetComponent <Rigidbody>().angularVelocity = new Vector3(gameObject.GetComponent <Rigidbody>().angularVelocity.x, gameObject.GetComponent <Rigidbody>().angularVelocity.y, propertyValue); } else if (gameObject.transform != null) { gameObject.transform.Rotate(0.0f, 0.0f, propertyValue * Time.deltaTime); } break; case GameObjectProperty.UniformScale: if (gameObject.transform) { gameObject.transform.localScale = new Vector3(propertyValue, propertyValue, propertyValue); } break; case GameObjectProperty.XScale: if (gameObject.transform) { gameObject.transform.localScale = new Vector3(propertyValue, gameObject.transform.localScale.y, gameObject.transform.localScale.z); } break; case GameObjectProperty.YScale: if (gameObject.transform) { gameObject.transform.localScale = new Vector3(gameObject.transform.localScale.x, propertyValue, gameObject.transform.localScale.z); } break; case GameObjectProperty.ZScale: if (gameObject.transform) { gameObject.transform.localScale = new Vector3(gameObject.transform.localScale.x, gameObject.transform.localScale.y, propertyValue); } break; case GameObjectProperty.YParentOffset1: if (gameObject.transform) { float smoothpVal; smoothpVal = trailAvg.average(propertyValue); gameObject.transform.position = new Vector3(player.transform.position.x, player.transform.position.y + smoothpVal, 0f); } break; case GameObjectProperty.YParentOffset2: if (gameObject.transform) { float smoothpVal; smoothpVal = trailAvg.average(propertyValue); gameObject.transform.position = new Vector3(player.transform.position.x, player.transform.position.y - smoothpVal, 0f); } break; case GameObjectProperty.TrailWidth: if (gameObject.transform) { gameObject.transform.GetComponent <TrailRenderer>().startWidth = Mathf.Pow(propertyValue, 2); } break; default: break; } }