예제 #1
0
        private static void AnimatorLoadOK(GameObject _hero, RuntimeAnimatorController _animatorController, bool _addHeroControl)
        {
            if (_hero != null)
            {
                _hero.GetComponent <Animator> ().runtimeAnimatorController = _animatorController;

                if (_addHeroControl)
                {
                    HeroControllerDispatcher heroControllerDispatcher = _hero.GetComponent <HeroControllerDispatcher>();

                    if (heroControllerDispatcher == null)
                    {
                        _hero.AddComponent <HeroControllerDispatcher>();
                    }
                }
            }
        }
예제 #2
0
        private static void AllLoadOK <T>(string _mainHandWeaponJoint, string _offHandWeaponJoint, float _weaponScale, float _horseScale, string[] _particleJoints, GameObject _hero, RuntimeAnimatorController _animatorController, GameObject _mainHandWeapon, GameObject _offHandWeapon, GameObject _horse, GameObject[] _particles, GameObject[] _mainHandWeaponParticles, GameObject[] _offHandWeaponParticles, GameObject _wing, Action <GameObject> _callBack, bool _addHeroControl, bool isDownHouse) where T : HeroController
        {
            Animator animator = _hero.GetComponent <Animator> ();

            if (animator.runtimeAnimatorController == null && _animatorController != null)
            {
                animator.runtimeAnimatorController = _animatorController;
            }

            if (_addHeroControl)
            {
                HeroController heroController = null;

                GameObject horseContainer = null;

                GameObject body = _hero.GetComponentInChildren <Renderer>().gameObject;

                HeroControllerDispatcher heroControllerDispatcher = _hero.GetComponent <HeroControllerDispatcher>();

                if (heroControllerDispatcher == null)
                {
                    _hero.AddComponent <HeroControllerDispatcher>();
                }

                if (_horse != null)
                {
                    horseContainer = new GameObject(_hero.name + "ma");

                    _horse.transform.SetParent(horseContainer.transform, false);

                    heroController = horseContainer.AddComponent <T> ();

                    heroController.horse = _horse.GetComponentInChildren <Renderer>().gameObject;

                    _horse.transform.localScale = new Vector3(_horseScale, _horseScale, _horseScale);

                    if (isDownHouse)
                    {
                        _hero.transform.localPosition = Vector3.zero;

                        _hero.transform.SetParent(horseContainer.transform, false);
                    }
                    else
                    {
                        GameObject bone = PublicTools.FindChild(_horse, HORSE_CHAIN_BONE_NAME);

                        bone.transform.localScale = new Vector3(1 / _horseScale, 1 / _horseScale, 1 / _horseScale);

                        _hero.transform.SetParent(bone.transform, true);

                        _hero.transform.localPosition = Vector3.zero;
                    }
                }
                else
                {
                    heroController = _hero.AddComponent <T> ();
                }

                heroController.body = body;

                if (_particles != null)
                {
                    for (int i = 0; i < _particles.Length; i++)
                    {
                        PublicTools.AddChild(_hero, _particles[i], _particleJoints[i]);
                    }

                    heroController.particles = _particles;
                }

                if (_mainHandWeapon != null)
                {
                    GameObject mainWeaponContainer = new GameObject();                    //为了让武器上的粒子配合武器进行缩放  所以添加了这个容器

                    mainWeaponContainer.name = "mainHandWeapon";

                    heroController.mainHandWeaponContainer = mainWeaponContainer;

                    mainWeaponContainer.transform.localScale = new Vector3(_weaponScale, _weaponScale, _weaponScale);

                    PublicTools.AddChild(_hero, mainWeaponContainer, _mainHandWeaponJoint);

                    heroController.mainHandWeapon = _mainHandWeapon;

                    _mainHandWeapon.transform.SetParent(mainWeaponContainer.transform, false);

                    if (_mainHandWeaponParticles != null)
                    {
                        heroController.mainHandWeaponParticles = _mainHandWeaponParticles;

                        for (int i = 0; i < _mainHandWeaponParticles.Length; i++)
                        {
                            _mainHandWeaponParticles[i].transform.SetParent(mainWeaponContainer.transform, false);
                        }
                    }
                }

                if (_offHandWeapon != null)
                {
                    GameObject offWeaponContainer = new GameObject();                    //为了让武器上的粒子配合武器进行缩放  所以添加了这个容器

                    offWeaponContainer.name = "offHandWeapon";

                    heroController.offHandWeaponContainer = offWeaponContainer;

                    offWeaponContainer.transform.localScale = new Vector3(_weaponScale, _weaponScale, _weaponScale);

                    PublicTools.AddChild(_hero, offWeaponContainer, _offHandWeaponJoint);

                    heroController.offHandWeapon = _offHandWeapon;

                    _offHandWeapon.transform.SetParent(offWeaponContainer.transform, false);

                    if (_offHandWeaponParticles != null)
                    {
                        heroController.offHandWeaponParticles = _offHandWeaponParticles;

                        for (int i = 0; i < _offHandWeaponParticles.Length; i++)
                        {
                            _offHandWeaponParticles[i].transform.SetParent(offWeaponContainer.transform, false);
                        }
                    }
                }

                if (_wing != null)
                {
                    GameObject heroDummy = PublicTools.FindChild(_hero, WING_DUMMY_NAME);
                    GameObject wingDummy = PublicTools.FindChild(_wing, WING_DUMMY_NAME);

                    _wing.transform.localPosition = (wingDummy.transform.worldToLocalMatrix * wingDummy.transform.parent.localToWorldMatrix).MultiplyPoint(_wing.transform.localPosition);

                    _wing.transform.SetParent(heroDummy.transform, false);

                    heroController.wing = _wing.GetComponentInChildren <Renderer>().gameObject;
                }

                heroController.Init();

                if (_horse != null)
                {
                    PublicTools.SetGameObjectVisible(horseContainer, true);

                    _callBack(horseContainer);
                }
                else
                {
                    PublicTools.SetGameObjectVisible(_hero, true);

                    _callBack(_hero);
                }
            }
            else
            {
                _callBack(_hero);
            }
        }