Exemple #1
0
        private void PutOn(AccessoryButton accessoryButton)
        {
            this.TakeOff(accessoryButton);

            Transform bodyPart = UnityHelper.FindDeepChild(this.petObject.transform, accessoryButton.Region.ToString("G"));

            if (bodyPart == null)
            {
                bodyPart = this.petObject.transform;
            }
            AssetBundle assetBundle = this.GetAssetBundle(accessoryButton.AB);

            UnityEngine.Object obj             = assetBundle.LoadAsset(accessoryButton.Prefab);
            GameObject         accessoryObject = GameObject.Instantiate(obj) as GameObject;

            accessoryObject.name = string.Format("{0}(Clone)", accessoryButton.name);
            accessoryObject.transform.SetParent(bodyPart);
            accessoryObject.transform.localPosition = Vector3.zero;
            accessoryObject.transform.localRotation = Quaternion.identity;
            accessoryObject.transform.localScale    = Vector3.one;
            accessoryObject.AddComponent <FixShader>();
            this.PlayAccessoryAnimation(accessoryObject.GetComponent <Animator>());
            this.accessories.Add(accessoryButton, accessoryObject);
            StatusBar.Instance.ShowMessage(accessoryButton.ImageBox.sprite);
            Debug.LogFormat("<><PetLoader.PutOn>{0}", accessoryButton.Prefab);
        }
Exemple #2
0
        public void SetupPetAccessory(Accessory accessory)
        {
            if (this.objModel == null)
            {
                Debug.LogError("<><PetPlayer.SetupPetAccessory>Parameter 'petRoot' is null");
                return;
            }

            if (accessory != null)
            {
                if (accessory.CanWear)
                {                                                                             //只有配饰和套装能穿在身上
                    UnityHelper.DeleteAllChildren(this.objModel.transform, accessory.Region); //删除此部位的配饰
                    Transform bodyPart = UnityHelper.FindDeepChild(this.objModel.transform, accessory.Region);
                    if (bodyPart == null)
                    {
                        bodyPart = this.objModel.transform;
                    }

                    this.AssetBundleUtils.LoadAssetAsync(accessory.AB, accessory.Prefab, (gameObject) =>
                    {
                        if (gameObject != null)
                        {
                            gameObject.transform.SetParent(bodyPart);
                            gameObject.transform.localPosition = Vector3.zero;
                            gameObject.transform.localRotation = Quaternion.identity;
                            gameObject.transform.localScale    = Vector3.one;
                            gameObject.AddComponent <FixShader>();
                            gameObject.SetActive(true);
                            this.PlayAccessoryAnimation(gameObject.GetComponent <Animator>());
                            Debug.LogFormat("<><PetPlayer.SetupPetAccessory>AB: {0}, Prefab: {1}, GameObject: {2}", accessory.AB, accessory.Prefab, gameObject.name);
                        }
                    },
                                                         (errorText) =>
                    {
                        Debug.LogErrorFormat("<><PetPlayer.SetupPetAccessory>Error: {0}", errorText);
                    });
                }
            }
            else
            {
                Debug.LogErrorFormat("<><PetPlayer.SetupPetAccessory>Can't find the accessory [{0}]", accessory);
            }
        }