示例#1
0
        /// <summary>
        /// Refreshes the controller. Call this method after adding and/or removing <see cref="CubismFadeParameter"/>s.
        /// </summary>
        public void Refresh()
        {
            _animator = GetComponent <Animator>();

            // Fail silently...
            if (_animator == null)
            {
                return;
            }

            DestinationParameters = this.FindCubismModel().Parameters;
            DestinationParts      = this.FindCubismModel().Parts;
            _motionController     = GetComponent <CubismMotionController>();
            _parameterStore       = GetComponent <CubismParameterStore>();

            // Get cubism update controller.
            HasUpdateController = (GetComponent <CubismUpdateController>() != null);

            _fadeStates = (ICubismFadeState[])_animator.GetBehaviours <CubismFadeStateObserver>();

            if ((_fadeStates == null || _fadeStates.Length == 0) && _motionController != null)
            {
                _fadeStates = _motionController.GetFadeStates();
            }

            if (_fadeStates == null)
            {
                return;
            }
            _isFading = new bool[_fadeStates.Length];
        }
示例#2
0
        public void Awake(ModelType type, string name)
        {
            try
            {
                Type = type;
                Name = name;
                URL  = Live2dPathHelper.GetModelConfigPath(type, name);
                TextAsset config = ResourcesHelper.GetAsset <TextAsset>(URL);
                ModelConfig           = JsonMapper.ToObject <Live2dModelConfig>(config.text);
                ModelConfig.AssetPath = Live2dPathHelper.GetAssetPath(type, name);
                string modelPath  = ModelConfig.GetModelPath();
                var    model3Json = CubismModel3Json.LoadAtPath(modelPath, BuiltinLoadAssetAtPath);
                Model = model3Json.ToModel();
                EntityRef.GameObject       = Model.gameObject;
                EntityRef.Transform        = Model.gameObject.transform;
                EntityRef.GameObject.layer = LayerHelper.LayerNameToLayer("Unit");
                GameObjectHelper.Traversal(EntityRef.Transform, (arg) =>
                {
                    arg.gameObject.layer = LayerHelper.LayerNameToLayer("Unit");
                }, true);

                Animations     = new Dictionary <string, AnimationClip>();
                fadeController = EntityRef.GameObject.AddComponent <CubismFadeController>();
                fadeController.CubismFadeMotionList = ScriptableObject.CreateInstance <CubismFadeMotionList>();
                fadeController.CubismFadeMotionList.MotionInstanceIds       = new int[ModelConfig.Motions.Length];
                fadeController.CubismFadeMotionList.CubismFadeMotionObjects = new CubismFadeMotionData[ModelConfig.Motions.Length];

                for (int i = 0; i < ModelConfig.Motions.Length; ++i)
                {
                    string motion      = ModelConfig.Motions[i];
                    string motionPath  = ModelConfig.GetMotionPath(motion);
                    var    motion3Json = CubismMotion3Json.LoadFrom(ResourcesHelper.GetAsset <TextAsset>(motionPath));
                    var    clip        = ResourcesHelper.GetAsset <AnimationClip>(ModelConfig.GetAnimationClipPath(motion));
                    clip.name = motion;

                    int instanceId = clip.GetInstanceID();
                    var events     = clip.events;
                    for (var j = 0; j < events.Length; ++j)
                    {
                        if (events[j].functionName != "InstanceId")
                        {
                            continue;
                        }

                        instanceId = events[j].intParameter;
                    }

                    fadeController.CubismFadeMotionList.MotionInstanceIds[i]       = instanceId;
                    fadeController.CubismFadeMotionList.CubismFadeMotionObjects[i] = CubismFadeMotionData.CreateInstance(motion3Json, clip.name, clip.length);

                    Animations.Add(motion, clip);
                }

                motionController = EntityRef.GameObject.AddComponent <CubismMotionController>();
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
示例#3
0
        /// <summary>
        /// 设置Live2D对象
        /// </summary>
        /// <param name="live2DData"></param>
        public void SetLive2DData(Live2DData live2DData)
        {
            if (this.live2DData != null)
            {
                Clear();
            }

            this.live2DData = live2DData;
            gameObject      = live2DData.GetGameObject();
            transform       = gameObject.transform;

            animator = gameObject.GetComponent <Animator>();

            fadeController = gameObject.GetComponent <CubismFadeController>();
            if (fadeController == null)
            {
                fadeController = gameObject.AddComponent <CubismFadeController>();
            }
            fadeController.CubismFadeMotionList = live2DData.fadeMotionList;

            motionController = gameObject.GetComponent <CubismMotionController>();
            if (motionController == null)
            {
                motionController = gameObject.AddComponent <CubismMotionController>();
            }
        }
示例#4
0
 /// <summary>
 /// 清理
 /// </summary>
 public void Clear()
 {
     transform = null;
     animator  = null;
     fadeController.CubismFadeMotionList = null;
     fadeController   = null;
     motionController = null;
     live2DData.ReleaseGameObject(gameObject);
     live2DData = null;
 }
        /// <summary>
        /// Get motion controller.
        /// </summary>
        private void Start()
        {
            var model = this.FindCubismModel();

            _motionController = model.GetComponent <CubismMotionController>();

            if (Animation == null)
            {
                return;
            }

            _motionController.PlayAnimation(Animation, priority: CubismMotionPriority.PriorityIdle, isLoop: false);
        }
        /// <summary>
        /// Get motion controller.
        /// </summary>
        private void Start()
        {
            var model = this.FindCubismModel();

            _motionController = model.GetComponent <CubismMotionController>();

            _motionController.AnimationEndHandler += PlayIdleAnimation;

            if (Animation == null)
            {
                return;
            }

            PlayIdleAnimation();
        }
        /// <summary>
        /// Load model.
        /// </summary>
        private void Start()
        {
            var model = this.FindCubismModel();

            // Get components.
            _motionController     = model.GetComponent <CubismMotionController>();
            _expressionController = model.GetComponent <CubismExpressionController>();
            _raycaster            = model.GetComponent <CubismRaycaster>();


            // Set behavior at the end of animation.
            _motionController.AnimationEndHandler = AnimationEnded;


            // Get up to 4 results of collision detection.
            _raycastResults = new CubismRaycastHit[4];


            // Cache the drawable in which the component is set.
            {
                _hasHitDrawables = new List <HitDrawableInfomation>();

                var hitAreas  = Enum.GetValues(typeof(HitArea));
                var drawables = model.Drawables;


                for (var i = 0; i < hitAreas.Length; i++)
                {
                    for (var j = 0; j < drawables.Length; j++)
                    {
                        var cubismHitDrawable = drawables[j].GetComponent <CubismHitDrawable>();

                        if (cubismHitDrawable)
                        {
                            if (cubismHitDrawable.Name == hitAreas.GetValue(i).ToString())
                            {
                                var hitDrawable = new HitDrawableInfomation();
                                hitDrawable.drawable = drawables[j];
                                hitDrawable.hitArea  = (HitArea)i;

                                _hasHitDrawables.Add(hitDrawable);
                                break;
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Get motion controller.
        /// </summary>
        private void Start()
        {
            var model = this.FindCubismModel();

            _motionController = model.GetComponent <CubismMotionController>();
        }