private CharacterSpawnRequest(MechSettings mechSettings, Vector3 position, Quaternion rotation, Entity playerEntity) { this.mechSettings = mechSettings; this.position = position; this.rotation = rotation; this.playerEntity = playerEntity; }
public Character SpawnCharacter(GameWorld world, PlayerState owner, Vector3 position, Quaternion rotation, MechSettings mechSettings, BundledResourceManager resourceSystem) { var mechTypeRegistry = resourceSystem.GetResourceRegistry <MechTypeRegistry>(); var mechIndex = Mathf.Min(mechSettings.MechType, mechTypeRegistry.entries.Count); var mechTypeAsset = mechTypeRegistry.entries[mechIndex]; var replicatedEntityRegistry = resourceSystem.GetResourceRegistry <ReplicatedEntityRegistry>(); var charEntity = replicatedEntityRegistry.Create(EntityManager, resourceSystem, m_world, m_settings.character); var character = EntityManager.GetComponentObject <Character>(charEntity); character.teamId = 0; character.TeleportTo(position, rotation); var charRepAll = EntityManager.GetComponentData <CharacterReplicatedData>(charEntity); charRepAll.MechSettings = mechSettings; charRepAll.abilityCollection = resourceSystem.CreateEntity(mechTypeAsset.abilities); EntityManager.SetComponentData(charEntity, charRepAll); // Set as predicted by owner var replicatedEntity = EntityManager.GetComponentData <ReplicatedEntityData>(charEntity); replicatedEntity.predictingPlayerId = owner.playerId; EntityManager.SetComponentData(charEntity, replicatedEntity); var behaviorCtrlRepEntity = EntityManager.GetComponentData <ReplicatedEntityData>(charRepAll.abilityCollection); behaviorCtrlRepEntity.predictingPlayerId = owner.playerId; EntityManager.SetComponentData(charRepAll.abilityCollection, behaviorCtrlRepEntity); return(character); }
public static void Create(EntityCommandBuffer commandBuffer, MechSettings mechSettings, Vector3 position, Quaternion rotation, Entity playerEntity) { var data = new CharacterSpawnRequest(mechSettings, position, rotation, playerEntity); commandBuffer.AddComponent(commandBuffer.CreateEntity(), data); }
public static void Build(BundledResourceManager resourceManager, MechPresentationSetup mechPresentationSetup, MechSkeleton mechSkeleton, MechSettings mechSettings, bool server) { var mechPartRegistry = resourceManager.GetResourceRegistry <MechPartRegistry>(); // Create new array to store skinned mesh renderers SkinnedMeshRenderer[] newSMR = new SkinnedMeshRenderer[4]; var partPrefabs = new Object[5]; HeadPartAsset head = mechPartRegistry.heads[mechSettings.Head]; partPrefabs[0] = resourceManager.GetSingleAssetResource(head.Prefab); CorePartAsset core = mechPartRegistry.cores[mechSettings.Core]; partPrefabs[1] = resourceManager.GetSingleAssetResource(core.Prefab); ArmsPartAsset arms = mechPartRegistry.arms[mechSettings.Arms]; partPrefabs[2] = resourceManager.GetSingleAssetResource(arms.Prefab); LegsPartAsset legs = mechPartRegistry.legs[mechSettings.Legs]; partPrefabs[3] = resourceManager.GetSingleAssetResource(legs.Prefab); BoosterPartAsset booster = mechPartRegistry.boosters[mechSettings.Booster]; partPrefabs[4] = resourceManager.GetSingleAssetResource(booster.Prefab); //Extract Skinned Mesh for (int i = 0; i < 4; i++) { newSMR[i] = ((GameObject)partPrefabs[i]).GetComponentInChildren <SkinnedMeshRenderer>(); } // Replace all SkinnedMeshRenderer[] curSMR = mechPresentationSetup.CurSMRs; for (int i = 0; i < 4; i++) //TODO : remake the order part //Note the order of parts in MechFrame.prefab matters { if (newSMR[i] == null) { Debug.LogError(i + " is null."); continue; } MapBones(mechSkeleton, newSMR[i], curSMR[i]); curSMR[i].sharedMesh = newSMR[i].sharedMesh; //Material[] mats = new Material[2]; //mats[0] = Resources.Load("MechPartMaterials/" + partPrefabs[i].name + "mat", typeof(Material)) as Material; //mats[1] = Resources.Load("MechPartMaterials/" + partPrefabs[i].name + "_2mat", typeof(Material)) as Material; //curSMR[i].materials = mats; curSMR[i].enabled = true; } //Load booster Transform boosterbone = mechSkeleton.BoosterBone; //Destroy previous booster GameObject preBooster = (boosterbone.childCount == 0) ? null : boosterbone.GetChild(0).gameObject; if (preBooster != null) { GameObject.DestroyImmediate(preBooster); } GameObject newBooster = GameObject.Instantiate((GameObject)partPrefabs[4], boosterbone); newBooster.transform.localPosition = Vector3.zero; newBooster.transform.localRotation = Quaternion.Euler(90, 0, 0); }