コード例 #1
0
        private void SyncRigidbody()
        {
            if (!animationEditContext.CanEdit())
            {
                _atomJSON.valNoCallback      = _target.parentAtomId ?? "None";
                _rigidbodyJSON.valNoCallback = _target.parentRigidbodyId ?? "None";
                return;
            }

            var parentAtomId      = string.IsNullOrEmpty(_atomJSON.val) || _atomJSON.val == "None" ? null : _atomJSON.val;
            var parentRigidbodyId = string.IsNullOrEmpty(_rigidbodyJSON.val) || _rigidbodyJSON.val == "None" ? null : _rigidbodyJSON.val;

            if (_target.parentRigidbodyId == null && parentRigidbodyId == null)
            {
                return;
            }
            if (_target.parentAtomId == parentAtomId && _target.parentRigidbodyId == parentRigidbodyId)
            {
                return;
            }

            animationEditContext.clipTime = 0f;

            var targetControllerTransform = _target.controller.transform;
            var previousPosition          = targetControllerTransform.position;
            var previousRotation          = targetControllerTransform.rotation;

            var snapshot = operations.Offset().Start(0f, new[] { _target });

            _target.SetParent(parentAtomId, parentRigidbodyId);
            if (!_target.EnsureParentAvailable())
            {
                SuperController.LogError($"Timeline: Cannot automatically adjust from {_target.parentAtomId ?? "None"}/{_target.parentRigidbodyId ?? "None"} to {parentAtomId ?? "None"}/{parentRigidbodyId ?? "None"} because the current parent is not available.");
                return;
            }

            targetControllerTransform.position = previousPosition;
            targetControllerTransform.rotation = previousRotation;
            animationEditContext.SetKeyframeToCurrentTransform(_target, 0f);

            operations.Offset().Apply(snapshot, 0f, current.animationLength, OffsetOperations.ChangePivotMode);
        }
コード例 #2
0
        private void DeserializeClip(AtomAnimationClip clip, JSONClass clipJSON)
        {
            var animationPatternUID = clipJSON["AnimationPattern"]?.Value;

            if (!string.IsNullOrEmpty(animationPatternUID))
            {
                var animationPattern = SuperController.singleton.GetAtomByUid(animationPatternUID)?.GetComponentInChildren <AnimationPattern>();
                if (animationPattern == null)
                {
                    SuperController.LogError($"Animation Pattern '{animationPatternUID}' linked to animation '{clip.animationName}' of atom '{_atom.uid}' was not found in scene");
                }
                else
                {
                    clip.animationPattern = animationPattern;
                }
            }

            var controllersJSON = clipJSON["Controllers"].AsArray;

            if (controllersJSON != null)
            {
                foreach (JSONClass controllerJSON in controllersJSON)
                {
                    var controllerName = controllerJSON["Controller"].Value;
                    var controller     = _atom.freeControllers.Single(fc => fc.name == controllerName);
                    if (controller == null)
                    {
                        SuperController.LogError($"Timeline: Atom '{_atom.uid}' does not have a controller '{controllerName}'");
                        continue;
                    }
                    var target = new FreeControllerAnimationTarget(controller)
                    {
                        controlPosition = DeserializeBool(controllerJSON["ControlPosition"], true),
                        controlRotation = DeserializeBool(controllerJSON["ControlRotation"], true),
                        weight          = DeserializeFloat(controllerJSON["Weight"], 1f)
                    };
                    if (controllerJSON.HasKey("Parent"))
                    {
                        var parentJSON = controllerJSON["Parent"].AsObject;
                        target.SetParent(parentJSON["Atom"], parentJSON["Rigidbody"]);
                    }
                    var dirty = false;
                    DeserializeCurve(target.x, controllerJSON["X"], ref dirty);
                    DeserializeCurve(target.y, controllerJSON["Y"], ref dirty);
                    DeserializeCurve(target.z, controllerJSON["Z"], ref dirty);
                    DeserializeCurve(target.rotX, controllerJSON["RotX"], ref dirty);
                    DeserializeCurve(target.rotY, controllerJSON["RotY"], ref dirty);
                    DeserializeCurve(target.rotZ, controllerJSON["RotZ"], ref dirty);
                    DeserializeCurve(target.rotW, controllerJSON["RotW"], ref dirty);
                    target.AddEdgeFramesIfMissing(clip.animationLength);
                    clip.Add(target);
                    if (dirty)
                    {
                        target.dirty = true;
                    }
                }
            }

            var floatParamsJSON = clipJSON["FloatParams"].AsArray;

            if (floatParamsJSON != null)
            {
                foreach (JSONClass paramJSON in floatParamsJSON)
                {
                    var storableId     = paramJSON["Storable"].Value;
                    var floatParamName = paramJSON["Name"].Value;
                    var target         = new FloatParamAnimationTarget(_atom, storableId, floatParamName);
                    var dirty          = false;
                    DeserializeCurve(target.value, paramJSON["Value"], ref dirty);
                    target.AddEdgeFramesIfMissing(clip.animationLength);
                    clip.Add(target);
                    if (dirty)
                    {
                        target.dirty = true;
                    }
                }
            }

            var triggersJSON = clipJSON["Triggers"].AsArray;

            if (triggersJSON != null)
            {
                foreach (JSONClass triggerJSON in triggersJSON)
                {
                    var target = new TriggersAnimationTarget
                    {
                        name = DeserializeString(triggerJSON["Name"], "Trigger")
                    };
                    foreach (JSONClass entryJSON in triggerJSON["Triggers"].AsArray)
                    {
                        var trigger = new AtomAnimationTrigger();
                        trigger.RestoreFromJSON(entryJSON);
                        target.SetKeyframe(trigger.startTime, trigger);
                    }
                    target.AddEdgeFramesIfMissing(clip.animationLength);
                    clip.Add(target);
                }
            }
        }