Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Serializable]
- [EditorCreatedObject]
- public class EditorEntity_GroupSetup : SceneEntity
- {
- private bool _SetupMode = false;
- [EditorProperty(true, Description = "GroupSetupMode", ToolTipText = "This is to allow turning on or off grouping setup. False, the group moves based on setup distance. True, no children moves will be actioned.")]
- public bool PlayerForce
- {
- get { return _SetupMode; }
- set { _SetupMode = value; PassThrough.GroupSetupMode = value; }
- }
- public override void SetObjectData(SerializationInfo info, StreamingContext c)
- {
- base.SetObjectData(info, c);
- SerializationHelper.DeserializeField(ref _SetupMode, info, "GroupSetupMode", true);
- PassThrough.GroupSetupMode = _SetupMode;
- }
- public override void GetObjectData(SerializationInfo info, StreamingContext c)
- {
- base.GetObjectData(info, c);
- info.AddValue("GroupSetupMode", _SetupMode);
- }
- }
- [Serializable]
- public static class PassThrough
- {
- // This static variable is used to marshal the values between the Custom Editor SceneEntity and the Component
- // It also holds the default value, so if the component is added without the Custom Editor SceneEntity it will still do something.
- public static float PlayerForce = 0.5f;
- public static float PointsSmall = 1f;
- public static float PointsMedium = 10f;
- public static float PointsLarge = 50f;
- public static float PointsXLarge = 100f;
- public static float PointsBonus = 20f;
- public static float LevelPoints = 0;
- public static bool GroupSetupMode_Primed = false;
- public static bool GroupSetupMode = false;
- public static Matrix ParentMatrix = new Matrix();
- public static Vector3 ParentTranslation = new Vector3();
- }
- [Serializable]
- public class Component_Parent : BaseComponentAutoSerialization<ISceneEntity>
- {
- public override void OnUpdate(GameTime gameTime)
- {
- PassThrough.ParentMatrix = ParentObject.World;
- PassThrough.ParentTranslation = ParentObject.World.Translation;
- }
- }
- [Serializable]
- public class Component_Child : BaseComponentAutoSerialization<ISceneEntity>
- {
- Vector3 _parentOffset;
- Quaternion _parentQuaternionOffset;
- public override void OnUpdate(GameTime gameTime)
- {
- // Get a sceneobject from the ParentObject
- SceneObject sceneobject = (SceneObject)ParentObject;
- // This relies on the position never being at 0,0,0 for setup, so please don't do that
- // or change it with more look ups so that you don't need to rely on a Zero Vector3 :-)
- if (PassThrough.GroupSetupMode || _parentOffset == Vector3.Zero)
- {
- if (PassThrough.ParentTranslation != Vector3.Zero)
- {
- // Get the distance between the child and the parent which we keep as the offset
- _parentOffset = sceneobject.World.Translation - PassThrough.ParentTranslation;
- }
- }
- else
- {
- if (_parentOffset != Vector3.Zero)
- {
- // Decompose World Matrix (Child)
- Quaternion rotationQ = new Quaternion();
- Vector3 childLocation = new Vector3();
- Vector3 childScale = new Vector3();
- sceneobject.World.Decompose(out childScale, out rotationQ, out childLocation);
- // Decompose World Matrix (Parent)
- Quaternion parentQ = new Quaternion();
- Vector3 parentLocation = new Vector3();
- Vector3 parentScale = new Vector3();
- PassThrough.ParentMatrix.Decompose(out parentScale, out parentQ, out parentLocation);
- Matrix pLocation = Matrix.CreateTranslation(parentLocation);
- Matrix pRotation = Matrix.CreateFromQuaternion(parentQ);
- Matrix rotation2 = Matrix.CreateFromQuaternion(_parentQuaternionOffset);
- Matrix newWorld = pRotation * pLocation;
- Vector3 testTranslation = newWorld.Translation + ((newWorld.Left * _parentOffset.X) + (newWorld.Up * _parentOffset.Y) + (newWorld.Forward * _parentOffset.Z));
- Matrix cScale = Matrix.CreateScale(childScale);
- sceneobject.World = cScale * (pRotation * (Matrix.CreateTranslation(testTranslation)));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement