public void Init(ShelfObject parent) { Creator = parent; OnInit?.Invoke(); TimeManager.RegisterObject(this); foreach (var mf in GetComponentsInChildren <MeshFilter>()) { mf.mesh = mf.sharedMesh; } foreach (var child in GetComponentsInChildren <Animatable>()) { if (child.GetInstanceID() == GetInstanceID()) { continue; } child.Init(null); } }
private static void SetPropertiesFromJsonObject(Animatable sceneObject, SerializableAnimatable obj) { TimeManager.RegisterObject(sceneObject, false); sceneObject.StartFrame = obj.StartFrame; foreach (var pair in obj.TranslationKeys) { sceneObject.AddTranslationKey(pair.Item2, pair.Item1 + obj.StartFrame); } foreach (var pair in obj.RotationKeys) { sceneObject.AddRotationKey(pair.Item2, pair.Item1 + obj.StartFrame); } foreach (var pair in obj.ScaleKeys) { sceneObject.AddScaleKey(pair.Item2, pair.Item1 + obj.StartFrame); } sceneObject.EvaluateTransform(0); // recurse for top-level folks if (obj.IsTopLevel) { var sceneChildren = sceneObject.GetComponentsInChildren <Animatable>(); Debug.Assert(sceneChildren.Length - 1 == obj.Children.Count, "#children in saved file differs from loaded object! " + sceneChildren.Length + " != " + obj.Children.Count); // Since GetComponentsInChildren<T> uses depth-first search, the first // component must be `obj` itself, which we skip for (int i = 1; i < sceneChildren.Length; ++i) { SetPropertiesFromJsonObject(sceneChildren[i], obj.Children[i - 1]); } } }