예제 #1
0
        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);
            }
        }
예제 #2
0
        private static void TryLoadScene()
        {
            // start by deleting current objects
            TimeManager.SelectedObject?.Deselected();
            foreach (var obj in FindObjectsOfType <Animatable>())
            {
                GestureManager.ProcessObjectDeletion(obj);
                Destroy(obj.gameObject);
            }

            // let's try loading the scene now
            try
            {
                string data  = System.IO.File.ReadAllText(sceneFileName);
                var    scene = JsonConvert.DeserializeObject <SerializableScene>(data);

                TimeManager.SetFrameCount(scene.NumFrame);

                var shelfObjects = FindObjectsOfType <ShelfObject>();
                Dictionary <string, ShelfObject> shelfObjMap = new Dictionary <string, ShelfObject>(shelfObjects.Length);

                foreach (var obj in shelfObjects)
                {
                    shelfObjMap.Add(obj.name, obj);
                }

                foreach (var obj in scene.Objects)
                {
                    InstantiateFromSaved(obj, shelfObjMap);
                }

                TimeManager.PlayAnimationInScript();
            }
            catch (Exception e)
            {
                Debug.LogWarning(e.Message);
                Debug.Log(e.StackTrace);
            }
        }
예제 #3
0
        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]);
                }
            }
        }
예제 #4
0
 private void OnDestroy()
 {
     TimeManager.DeregisterObject(this);
     PoseManager.DeleteReferencesToObject(this);
 }