Slate Forums › Support › Props? › Reply To: Props?
Hello,
Thanks a lot for getting Slate and for your feedback!
Considering I have understood correctly, I created a new action clip for easily attaching objects (props) to a child transform of the actor.
Bellow is the code of that new action clip which will also be included in the next version 🙂
I’ve also tested this along with an animation playing and it works as expected here.
Please let me know if that is what you were indeed after.
Thanks!
AttachObject.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
using UnityEngine; using System.Collections.Generic; namespace Slate.ActionClips{ [Category("Transform")] [Description("Attach an object to a child transform of the actor (or the actor itself) either permantentely or temporary if length is greater than zero.")] public class AttachObject : ActorActionClip { [SerializeField] [HideInInspector] private float _length; public Transform targetObject; public string childTransformName; public Vector3 localPosition; public Vector3 localRotation; public Vector3 localScale = Vector3.one; private TransformSnapshot snapshot; private bool temporary; public override bool isValid{ get {return targetObject != null;} } public override float length{ get {return _length;} set {_length = value;} } protected override void OnEnter(){ temporary = length > 0; Do(); } protected override void OnReverseEnter(){ if (temporary){ Do(); } } protected override void OnExit(){ if (temporary){ UnDo(); } } protected override void OnReverse(){ UnDo(); } void Do(){ snapshot = new TransformSnapshot(targetObject.gameObject); var actorTransform = ResolveTransform(childTransformName); if (actorTransform == null){ Debug.LogError(string.Format("Child Transform with name '{0}', can't be found on actor '{1}' hierarchy", childTransformName, actor.name), actor.gameObject); return; } targetObject.SetParent(actorTransform); targetObject.localPosition = localPosition; targetObject.localEulerAngles = localRotation; targetObject.localScale = localScale; } void UnDo(){ snapshot.Restore(); } Transform ResolveTransform(string name){ if (string.IsNullOrEmpty(name)){ return actor.transform; } foreach (var t in actor.GetComponentsInChildren<Transform>()){ if (t.name == childTransformName){ return t; } } return null; } } } |
Join us on Discord: https://discord.gg/97q2Rjh