// CheckEquipmentResource() will return FCEquipmentBase for resource loading. public FCEquipmentsBase CheckEquipmentResource(FCEquipmentsBase eeb) { bool checkFailed = false; foreach (FCEquipmentsBase.EquipmentSlot slot in eeb._equipmentSlots) { if (!string.IsNullOrEmpty(slot._modelPath)) //equipment does not have a mesh { GameObject prefab = InJoy.AssetBundles.AssetBundles.Load(slot._modelPath, typeof(GameObject)) as GameObject; if (prefab == null) { checkFailed = true; break; } } } if (eeb._texturePath != "") { Texture2D baseTex = InJoy.AssetBundles.AssetBundles.Load(eeb._texturePath, typeof(Texture2D)) as Texture2D; if (baseTex == null) { checkFailed = true; } } // check failed, look for default equipment. if (checkFailed) { return(GetDefaultEquipment(eeb)); } // check passed, use origin configuration for resource loading. return(eeb); }
//Refresh avatar with the equipments listed in the equipmentsRoot object public void RefreshEquipments(Transform equipmentRoot) { RemoveCurrentEquipments(); // FCEquipmentsBase[] equipments = equipmentRoot.GetComponentsInChildren<FCEquipmentsBase>(); List <FCEquipmentsBase> equipments = new List <FCEquipmentsBase>(); foreach (Transform child in equipmentRoot) { FCEquipmentsBase childEquip = child.GetComponent <FCEquipmentsBase>(); if (childEquip != null) { equipments.Add(childEquip); } } foreach (FCEquipmentsBase equipment in equipments) { equipment.SetOwner(_actionCtrl); EquipmentAssembler.Singleton.Assemble(equipment, this); } InitRenderers(); if (_actionCtrl != null && _actionCtrl.AIUse != null && _actionCtrl.AIUse._isInTown && _actionCtrl.ThisObject.name.Contains("warrior")) { Debug.Log("----------Equipment from the backpack-----------"); _actionCtrl.SwitchWeaponTo(EnumEquipSlot.weapon_hang, _actionCtrl.AIUse._defaultWeaponType); } }
//refresh all ports public void RefreshPorts(GameObject root) { for (int i = 0; i < (int)_nodesMapping.Length; ++i) { _nodesMapping[i] = Utils.FindTransformByNodeName(root.transform, FCEquipmentsBase.GetNodeByEquipSlot((EnumEquipSlot)i)); } }
public static void GetOtherEquipmentInstanceWithIds(List <GameObject> equipmentInstances, List <EquipmentIdx> ids) { equipmentInstances.Clear(); for (int i = 0; i < ids.Count; i++) { ItemData itemData = DataManager.Instance.GetItemData(ids[i]._id); if (itemData.type == ItemType.ornament) { continue; } if (ItemInventory.IsEquipment(itemData) || itemData.type == ItemType.vanity) { string path = itemData.instance; if (path != null && path.Length > 1) { GameObject prefab = InJoy.AssetBundles.AssetBundles.Load(path) as GameObject; GameObject instance = GameObject.Instantiate(prefab) as GameObject; FCEquipmentsBase equipBase = instance.GetComponent <FCEquipmentsBase>(); equipBase._evolutionLevel = ids[i]._evolutionLevel; equipmentInstances.Add(instance); } else { Debug.LogError(string.Format("Wrong equipment path. ID = {0}", itemData.id)); } } } }
public void GetSelfEquipmentInstance(List <GameObject> equipmentInstances) { equipmentInstances.Clear(); foreach (ItemInventory item in _equippedInventory.itemList) { ItemData itemData = DataManager.Instance.GetItemData(item.ItemID); if (itemData.type == ItemType.ornament) { continue; } if (ItemInventory.IsEquipment(itemData) || itemData.type == ItemType.vanity) { string path = itemData.instance; if (path != null && path.Length > 1) { GameObject prefab = InJoy.AssetBundles.AssetBundles.Load(path) as GameObject; GameObject instance = GameObject.Instantiate(prefab) as GameObject; FCEquipmentsBase equipBase = instance.GetComponent <FCEquipmentsBase>(); equipBase._evolutionLevel = 0; equipmentInstances.Add(instance); } else { Debug.LogError("GetSelfEquipmentInstance:[" + itemData.id + "] path:[" + path + "]"); } } } }
//refresh only damage ports, which is on weapon //this should be executed after RefreshPorts() public void RefreshDemagePorts(GameObject root) { _nodesMapping[(int)EnumEquipSlot.damage_main_A] = Utils.FindTransformByNodeName(root.transform, FCEquipmentsBase.GetNodeByEquipSlot(EnumEquipSlot.damage_main_A)); _nodesMapping[(int)EnumEquipSlot.damage_main_B] = Utils.FindTransformByNodeName(root.transform, FCEquipmentsBase.GetNodeByEquipSlot(EnumEquipSlot.damage_main_B)); }
FCEquipmentsBase GetDefaultEquipment(FCEquipmentsBase eeb) { string equipName = eeb.gameObject.name; // looking for character's class... string [] defaultEquipment = null; if (equipName.Contains("mage_")) { defaultEquipment = _mageDefaultEquipments; } else if (equipName.Contains("monk_")) { defaultEquipment = _monkDefaultEquipments; } else if (equipName.Contains("warrior_")) { defaultEquipment = _warriorDefaultEquipments; } if (defaultEquipment == null) { Debug.LogError("Can not find default equipment for " + equipName); return(eeb); } // looking for type of equipment... string equipmentEntity = null; for (int i = 0; i < _equipmentMap.Length; ++i) { if (equipName.Contains(_equipmentMap[i])) { equipmentEntity = defaultEquipment[i]; break; } } if (equipmentEntity == null) { Debug.LogError("Can not get type of equipment " + equipName); return(eeb); } // try to load default prefab... FCEquipmentsBase res = null; GameObject go = InJoy.AssetBundles.AssetBundles.Load(equipmentEntity, typeof(GameObject)) as GameObject; if (go != null) { res = go.GetComponent <FCEquipmentsBase>(); } if (res == null) { Debug.LogError("Fail to load default equipment " + equipmentEntity + " for " + equipName); return(eeb); } // succeeded to load default equipment. Debug.LogWarning("Can not load equipment " + equipName + ", load default equipment " + equipmentEntity + " instead."); return(res); }
void Awake() { _animator = GetComponent <Animator>(); if (GameManager.Instance.GameState == EnumGameState.InBattle) { if (GameManager.Instance.IsPVPMode) { _animator.runtimeAnimatorController = animatorCtl_PVP; } } _thisTransform = transform; _thisObject = gameObject; _characterController = GetComponent <CharacterController>(); for (int i = 0; i < (int)_nodesMapping.Length; ++i) { _nodesMapping[i] = Utils.FindTransformByNodeName(gameObject.transform, FCEquipmentsBase.GetNodeByEquipSlot((EnumEquipSlot)i)); } }
/// <summary> /// Add the game object to equipment node list /// </summary> public void AddEquipmentNode(EnumEquipSlot slot, GameObject node, bool replaceOther) { if (replaceOther) { _nonReplacedEquipments.Add(node); return; } if (_equipmentMapping[(int)slot] != null) { Destroy(_equipmentMapping[(int)slot]); _equipmentMapping[(int)slot] = null; } _equipmentMapping[(int)slot] = node; // for slot on weapons, find child node. if (slot == EnumEquipSlot.damage_main_A) { Transform transSlot = Utils.FindTransformByNodeName(node.transform, FCEquipmentsBase.GetNodeByEquipSlot(slot)); if (transSlot != null) { _equipmentMapping[(int)slot] = transSlot.gameObject; } } }
//play effect //lifetime: character effect may have a lift time from outside, > 0 will take effect. // < 0 means use effect's built-in life time. public EffectInstance PlayEffect(FC_CHARACTER_EFFECT effId, AvatarController avatar, float liftTime) { if (effId == FC_CHARACTER_EFFECT.INVALID) { return(null); } //get empty gameobject? List <EffectInstance> effList = _allEffectArray[effId]; EffectInstance effResult = null; if (effList.Count > 0) { foreach (EffectInstance effInst in effList) { if (effInst == null || effInst.myObject == null) { int zz = 0; zz++; } if (!effInst.myObject.activeSelf) { effResult = effInst; break; } } } //no empty? create one if (effResult == null) { GameObject ego = AddEffectToPool(effId); effResult = ego.GetComponent <EffectInstance>(); Assertion.Check(effResult != null); effResult.character_effect_id = effId; effResult.myTransform = ego.transform; effResult.myObject = ego; effList.Add(effResult); } //set enable and parent and pos Assertion.Check(effResult != null); effResult.myObject.SetActive(true); //find parent node CharacterEffectConfig effConfig = _characterEffectTable[effId] as CharacterEffectConfig; Assertion.Check(effConfig != null); Transform parent = Utils.FindTransformByNodeName(avatar.myTransform, FCEquipmentsBase.GetNodeByEquipSlot(effConfig._parentSlot) ); if (parent == null) { parent = avatar.myTransform; } Assertion.Check(parent != null); effResult.myTransform.parent = parent; effResult.myTransform.localPosition = Vector3.zero; effResult.myTransform.localRotation = Quaternion.identity; //add to living list LivingEffect liveEff = new LivingEffect(); liveEff._effect = effResult; liveEff._avatar = avatar; liveEff._effID = (int)effId; _livingEffects.Add(liveEff); //get effect instance and start effect EffectInstance eff = effResult; Assertion.Check(eff != null); if (liftTime > 0) { eff.LifeTick = liftTime; } else { eff.LifeTick = eff._lifeTime; } eff.DeadTick = eff._deadTime; eff.BeginEffect(); return(effResult); }
public void Assemble(FCEquipmentsBase equipment, AvatarController avatar) { // check if the equipment is resource-meet, if not, load default resource. FCEquipmentsBase equipmentRes = CheckEquipmentResource(equipment); if (equipmentRes == null) { return; } System.Collections.Generic.List <Renderer> renderers = new System.Collections.Generic.List <Renderer>(); //mount the equipment models foreach (FCEquipmentsBase.EquipmentSlot slot in equipmentRes._equipmentSlots) { if (!string.IsNullOrEmpty(slot._modelPath)) //equipment does not have a mesh { GameObject prefab = InJoy.AssetBundles.AssetBundles.Load(GetModelPathOnQuality(slot._modelPath, avatar._quality)) as GameObject; GameObject equipmentInstance = null; if (prefab != null) { Transform transSlot = avatar.GetSlotNode(slot._equipSlot); if (equipment._specNode != "" && equipment._isLogicEquipment) { transSlot = Utils.GetNode(equipment._specNode, avatar.gameObject).transform; } equipmentInstance = Utils.InstantiateGameObjectWithParent(prefab, transSlot).gameObject; equipmentInstance.name = prefab.name; // create connection. MessageReciever[] receivers = equipmentInstance.GetComponentsInChildren <MessageReciever>(); foreach (MessageReciever mr in receivers) { mr._parent = equipment; } equipment.OnAssembled(slot._equipSlot, equipmentInstance, slot._equipmentType); Renderer [] equipmentRenderers = equipmentInstance.GetComponentsInChildren <Renderer>(); foreach (Renderer r in equipmentRenderers) { if (r.gameObject.tag != "weaponEffect") { renderers.Add(r); } } if (!equipment._isLogicEquipment) { avatar.AddEquipmentNode(slot._equipSlot, equipmentInstance, false); } UpgradeEffect [] effects = equipmentInstance.GetComponentsInChildren <UpgradeEffect>(); foreach (UpgradeEffect e in effects) { e.SetGrade(equipment._evolutionLevel); } } } } if (equipmentRes is FCArmor) { string[] avatarAreas = new string[equipmentRes._avatarAreas.Length]; for (int i = 0; i < avatarAreas.Length; ++i) { avatarAreas[i] = FCEquipmentsBase.GetAvatarAreaNameByArea(equipmentRes._avatarAreas[i]); } string baseTexPath = GetTexturePathOnQuailty(equipmentRes._texturePath, avatar._quality); Texture2D baseTex = InJoy.AssetBundles.AssetBundles.Load(baseTexPath, typeof(Texture2D)) as Texture2D; Assertion.Check(baseTex != null); Texture2D normalTex = null; Texture2D speTex = null; FCArmor armor = equipmentRes as FCArmor; string normTexPath = armor._normalTexturePath; if (normTexPath != "" && avatar._quality == CharacterGraphicsQuality.CharacterGraphicsQuality_Preview) { normalTex = InJoy.AssetBundles.AssetBundles.Load(normTexPath, typeof(Texture2D)) as Texture2D; Assertion.Check(normalTex != null); } avatar._materialBuilder.UpdateMaterialOfEquipment(avatar.materialInst, renderers.ToArray(), avatarAreas, baseTex, normalTex, armor._customColor, avatar._quality); // clean up. Resources.UnloadAsset(baseTex); Resources.UnloadAsset(normalTex); Resources.UnloadAsset(speTex); } // for weapon, only collect materials, do not take part in atlas. if (equipment is FCWeapon) { if (!equipment._isLogicEquipment) { avatar.materialInst.GetWeaponMaterial(renderers.ToArray()); } } // perhaps there are extra game objects to display upgrade effect. foreach (FCEquipmentsBase.EquipmentSlot es in equipmentRes._upgradeSlots) { // create a game object for display upgrade effect only. GameObject prefab = InJoy.AssetBundles.AssetBundles.Load(es._modelPath) as GameObject; Transform transSlot = avatar.GetSlotNode(es._equipSlot); GameObject effectInst = Utils.InstantiateGameObjectWithParent(prefab, transSlot).gameObject; // active level effect on this instance. UpgradeEffect [] effects = effectInst.GetComponentsInChildren <UpgradeEffect>(); foreach (UpgradeEffect e in effects) { e.SetGrade(equipment._evolutionLevel); } avatar.AddEquipmentGradeEffect(es._equipSlot, effectInst); } }
//WARNING!!!!!!!!!!! only use for cheat drop!!! public void LootOneForCheatDrop(LootObjData lootObjData, Vector3 pos, Vector3 offset) { GameObject moveObj = new GameObject("Loot[" + lootObjData._lootId + "]"); LootMove move = moveObj.AddComponent <LootMove>(); move.transform.parent = _lootRoot; move.transform.localPosition = pos; GameObject lootMovePrefab = null; GameObject lootObjPrefab = null; GameObject lootParticlePrefab = null; int particleIndex = 0; if (lootObjData._lootId == "money") { lootMovePrefab = _lootMoveParticlePrefab; if (lootObjData._lootCount <= _smallScMax) { lootObjPrefab = _lootSmallScPrefab; particleIndex = 0; } else if (lootObjData._lootCount <= _middleScMax) { lootObjPrefab = _lootMiddleScPrefab; particleIndex = 1; } else { lootObjPrefab = _lootLargeScPrefab; particleIndex = 2; } } else { lootMovePrefab = _lootMoveMathfPrefab; ItemData itemData = getItemData(lootObjData._lootId); if (itemData.subType == ItemSubType.weapon) { // get entity. int role = (int)PlayerInfo.Instance.Role; string entityPath = itemData.instance; GameObject entity = InJoy.AssetBundles.AssetBundles.Load(entityPath) as GameObject; FCEquipmentsBase eb = entity.GetComponent <FCEquipmentsBase>(); Assertion.Check(eb != null); // get model. Assertion.Check(eb._equipmentSlots.Length > 0); GameObject model = InJoy.AssetBundles.AssetBundles.Load(eb._equipmentSlots[0]._modelPath) as GameObject; if (model == null) { Debug.LogError("[Loot Manager] Can not find asset " + eb._equipmentSlots[0]._modelPath); } lootObjPrefab = model; } else { string path = _lootArmors[(int)itemData.subType]; int level = itemData.rareLevel; string [] levelsuffix = new string[] { "0", "0", "1", "2", "2", "2", "2", "2" }; path = path.Replace(".prefab", levelsuffix[level] + ".prefab"); GameObject model = InJoy.AssetBundles.AssetBundles.Load(path) as GameObject; if (model == null) { Debug.LogError("[Loot Manager] Can not find asset " + path); } lootObjPrefab = model; } particleIndex = itemData.rareLevel; } if (particleIndex > _lootParticlePath.Count - 1) { particleIndex = _lootParticlePath.Count - 1; } lootParticlePrefab = _lootParticlePrefab[particleIndex]; move.SetData(lootMovePrefab, lootObjPrefab, lootParticlePrefab, lootObjData._lootId, lootObjData._lootCount, _liftTime); move.StartMoveForCheatDrop(offset, _time); }
public void PrepareOneLootPrefab(LootObjData lootObjData) { GameObject lootMovePrefab = null; //move trace GameObject lootObjPrefab = null; //loot obj GameObject lootParticlePrefab = null; //particle //creata move object GameObject moveObj = new GameObject("Loot[" + lootObjData._lootId + "]"); lootObjData._lootObject = moveObj; LootMove move = moveObj.AddComponent <LootMove>(); //add move obj to root move.transform.parent = _lootRoot; Debug.Log("prepare loot object " + lootObjData._lootId + ":" + lootObjData._lootObject.name); //determine the 3 prefabs int particleIndex = 0; if (lootObjData._lootId == "money") { lootMovePrefab = _lootMoveParticlePrefab; if (lootObjData._lootCount <= _smallScMax) { lootObjPrefab = _lootSmallScPrefab; particleIndex = 0; } else if (lootObjData._lootCount <= _middleScMax) { lootObjPrefab = _lootMiddleScPrefab; particleIndex = 1; } else { lootObjPrefab = _lootLargeScPrefab; particleIndex = 2; } } else { ItemData itemData = getItemData(lootObjData._lootId); if (itemData == null) { Destroy(moveObj); Debug.LogError("Loot id (" + lootObjData._lootId + ") not found."); return; } lootMovePrefab = _lootMoveMathfPrefab; if (itemData.subType == ItemSubType.weapon) { // get entity. int role = (int)PlayerInfo.Instance.Role; string entityPath = itemData.instance; GameObject entity = InJoy.AssetBundles.AssetBundles.Load(entityPath) as GameObject; FCEquipmentsBase eb = entity.GetComponent <FCEquipmentsBase>(); Assertion.Check(eb != null); eb = EquipmentAssembler.Singleton.CheckEquipmentResource(eb); // get model. Assertion.Check(eb._equipmentSlots.Length > 0); GameObject model = InJoy.AssetBundles.AssetBundles.Load(eb._equipmentSlots[0]._modelPath) as GameObject; if (model == null) { Debug.LogError("[Loot Manager] Can not find asset " + eb._equipmentSlots[0]._modelPath); } lootObjPrefab = model; } else { string path; if (itemData.subType == ItemSubType.none) { path = _lootArmors[(int)ItemSubType.weapon]; } else { path = _lootArmors[(int)itemData.subType]; } int level = itemData.rareLevel; string [] levelsuffix = new string[] { "0", "0", "1", "2", "2", "2", "2", "2" }; path = path.Replace(".prefab", levelsuffix[level] + ".prefab"); GameObject model = InJoy.AssetBundles.AssetBundles.Load(path) as GameObject; if (model == null) { Debug.LogError("[Loot Manager] Can not find asset " + path); } lootObjPrefab = model; } particleIndex = itemData.rareLevel; } if (particleIndex > _lootParticlePath.Count - 1) { particleIndex = _lootParticlePath.Count - 1; } lootParticlePrefab = _lootParticlePrefab[particleIndex]; move.SetData(lootMovePrefab, lootObjPrefab, lootParticlePrefab, lootObjData._lootId, lootObjData._lootCount, _liftTime); move.PrepareMovePrefabs(); moveObj.SetActive(false); }