void Start() { mDistance = CurrentCameraProfile.Distance; mDownViewAngle = CurrentCameraProfile.ViewAngle; mPlayer = GetComponentInParent <Entity_Player>(); }
public override void Equip(Entity_Player targetPlayer) { base.Equip(targetPlayer); //Call base equip function if (armSide == Direction.Left) //Equip as LEFT ARM... { if (player.leftArm != null) //If this arm is REPLACING another... { } player.leftArm = this; //Establish connecction on playercontroller side if (player.rightArm != null) //If player has another arm... { otherArm = player.rightArm; //Get controller from other arm otherArm.otherArm = this; //Establish connection on other arm side } } else if (armSide == Direction.Right) //Equip as RIGHT ARM... { if (player.rightArm != null) //If this arm is REPLACING another... { } player.rightArm = this; //Establish connection on playercontroller side if (player.leftArm != null) //If player has another arm... { otherArm = player.leftArm; //Get controller from other arm otherArm.otherArm = this; //Establish connection on other arm side } } }
public void OnPlayerInteract(Entity_Player Player) { if (mPickupCooldown == 0 && Player.mInventory.TryGive(ref mItem)) { Destroy(gameObject); } }
void OnTriggerExit(Collider collider) { Entity_Player player = collider.GetComponent <Entity_Player>(); if (player != null) { ExitEvent.Invoke(player); } }
/// <summary> /// World update tick called from world update thread /// </summary> /// <param name="Tick">The current tick number for this update</param> public void WorldUpdate(uint Tick) { // Attempt to load chunks around player HashSet <ChunkID> loadArea = new HashSet <ChunkID>(); // Populate load are near player Entity_Player player = Entity_Player.Main; if (player == null) { return; } const int radius = 3; ChunkID c = player.mChunkID; for (int x = -radius; x <= radius; ++x) { for (int z = -radius; z <= radius; ++z) { loadArea.Add(new ChunkID(c.X + x, c.Z + z)); } } // Update or unload chunks near player VoxelChunk[] activeChunks = mCurrentTerrain.GetActiveChunks(); foreach (VoxelChunk chunk in activeChunks) { // In view, so update and remove from load area check if (loadArea.Contains(chunk.mChunkID)) { chunk.UpdateChunk(Tick); loadArea.Remove(chunk.mChunkID); } // Request that this chunk is unload else { mCurrentTerrain.RequestChunkUnload(chunk.mChunkID.X, chunk.mChunkID.Z); } } // Load all remaining areas in load area foreach (ChunkID id in loadArea) { mCurrentTerrain.RequestChunkLoad(id.X, id.Z); } }
public override void CreateMenu(RectTransform Parent) { Entity_Player player = Entity_Player.Main; Vector2 startPoint = new Vector2(0, -Parent.rect.height * 0.5f); // Add callback mInventory = player.mInventory; mInventory.mChangeEvent += OnInventoryChange; // Create player hotbar uint width = Entity_Player.InventoryWidth; uint height = Entity_Player.InventoryHeight; float halfWidth = width * 0.5f; mInventorySlots = new InventorySlotUI[width, height]; for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { // Inventory slot InventorySlotUI slot = Instantiate(InventorySlotUI.DefaultSlot, Parent); slot.name = "Slot " + x + "," + y; slot.Construct(mInventory, x, y); // Make sure inventory is in order from top-left to bottom-right int displayY = y; if (y != 0) { displayY = (int)height - y; } RectTransform slotRect = slot.GetComponent <RectTransform>(); slotRect.localPosition = startPoint + new Vector2(slotRect.rect.width * (x - halfWidth + 0.5f), slotRect.rect.height * (displayY + 0.5f)); // Set hotbar different colour if (y != 0) { slot.SetColour(Color.grey); } // Set contents slot.SetItem(player.mInventory.Get(x, y)); mInventorySlots[x, y] = slot; } } }
public virtual void Equip(Entity_Player targetPlayer) { //EQUIP: Attaches this piece of equipment to player and fulfills all necessary contingencies //Initialization & Validation: if (targetPlayer == null) //If given playerController is not valid or present... { Debug.LogError(name + " failed Equip, no player given."); //Log error return; //End equip function } //Establish Initial Connections: player = targetPlayer; //Record given player script //Additional Cleanup: equipped = true; //Indicate that this arm is now equipped }
//==|CORE EQUIPMENT FUNCTIONS|==----------------------------------------------------------------------------------- public virtual void Initialize() { //INITIALIZE: Fully Initializes this equipment in scene based on current parent //Find Equipment Parent: player = gameObject.GetComponentInParent <Entity_Player>(); //Try to find player script in parent //Initialization Variants: if (player != null) //PLAYER INIT: If equipment is attached to player... { Equip(player); //Equip this arm to player } else //UNSUCCESSFUL INIT: If equipment init state has not been accounted for... { Debug.LogError(name + " could not be initialized. Is parent missing?"); //Log error } }
//==|CORE FUNCTIONS|==--------------------------------------------------------------------------------------------- public override void Initialize() { //Description: Validates all objects specific to this controller (in addition to initial validation phase) base.Initialize(); //Call base initialization method //Attempt to Get Components: player = GameObject.FindGameObjectWithTag("Player").GetComponent <Entity_Player>(); //Attempt to locate player object and script in scene //Contingencies: if (player == null) //If player could not be found... { Debug.LogError(name + " could not identify player."); //Log error } if (interceptField == null) //If enemy does not have an intercept field... { Debug.LogError(name + " does not have an intercept field assigned."); //Log error } }
/// <summary> /// Called when this item attempts to be used by some entity /// </summary> public override bool Use(Entity User, ref ItemStack Source) { Entity_Player player = Entity_Player.Main; // Ignore if not used by player if (User != player) { return(false); } VoxelHitInfo hit; // Ignore liquids int mask = ~(1 << (int)VoxelType.Liquid); if (player.mTerrain.PerformRayCast(player.InteractionRay, out hit, 100, false, mask)) { return(player.mTerrain.DestroyVoxel(hit.X, hit.Y, hit.Z)); } return(false); }
/// <summary> /// Called when this item attempts to be used by some entity /// </summary> public override bool Use(Entity User, ref ItemStack Source) { Entity_Player player = Entity_Player.Main; // Ignore if not used by player if (User != player) { return(false); } VoxelHitInfo hit; // Ignore liquids int mask = ~(1 << (int)VoxelType.Liquid); if (player.mTerrain.PerformRayCast(player.InteractionRay, out hit, 100, false, mask)) { Point p = new Point( Mathf.RoundToInt(hit.X + hit.Normal.x), Mathf.RoundToInt(hit.Y + hit.Normal.y), Mathf.RoundToInt(hit.Z + hit.Normal.z) ); bool placed = player.mTerrain.PlaceVoxel(p.x, p.y, p.z, mVoxelMaterial, ushort.MaxValue, ~mask); if (placed) { Source.mItemCount--; if (Source.mItemCount == 0) { Source = new ItemStack(0); } return(true); } } return(false); }
void Start() { if (Main == null) { Main = this; Debug.Log("World Manager created."); // Make sure library is initialized ResourceLoader.AttemptImport(); mWorker = GetComponent <WorldWorker>(); mCurrentTerrain = VoxelTerrain.New(-1); Entity_Player player = Resources.Load <Entity_Player>("Entities/Human/Player/Player Prefab"); Instantiate(player.gameObject); } else { Debug.LogError("Cannot have multiple world managers active at once."); Destroy(gameObject); } }
void Start() { mMovement = GetComponent <HumanMovement>(); mPlayer = GetComponent <Entity_Player>(); mPlayerCamera = GetComponentInChildren <PlayerCamera>(); }
void Update() { if (mPickupCooldown > 0) { mPickupCooldown -= Time.deltaTime; if (mPickupCooldown < 0) { mPickupCooldown = 0; } } bool invOpen = MenuController.Main.bIsInventoryOpen; // If different state, update visibility if (invOpen != bIsInventoryOpen) { bIsInventoryOpen = invOpen; mItemDisplay.bIsVisible = bIsInventoryOpen; } // Move cursor to mouse position if (bIsInventoryOpen) { transform.position = Input.mousePosition; Entity_Player player = Entity_Player.Main; if (Input.GetKeyDown(KeyCode.Mouse0)) { if (CurrentSlot != null) { CurrentSlot.OnPrimaryClick(this); } // Drop whole stack else { if (mCurrentItem.mType != ItemType.None) { // Throw item Entity_DroppedItem.NewObj( mCurrentItem, player.transform.position, new Vector3(200 * (player.mMovement.bIsFacingRight ? 1 : -1), 100, Random.Range(-50, 50)) ); mCurrentItem = new ItemStack(0); } } } if (Input.GetKey(KeyCode.Mouse1)) { if (mPickupCooldown == 0) { // Increase the pickup speed steadily mPickupCooldown = mPickupCooldownAmount; mPickupCooldownAmount -= 0.7f * Time.deltaTime; if (mPickupCooldownAmount < 0.005f) { mPickupCooldownAmount = 0.005f; } if (CurrentSlot != null) { CurrentSlot.OnSecondaryClick(this); } // Drop 1 item else { ItemStack item = mCurrentItem; if (item.mType != ItemType.None) { // Throw item Entity_DroppedItem.NewObj( new ItemStack(item.mItemID, 1), player.transform.position, new Vector3(200 * (player.mMovement.bIsFacingRight ? 1 : -1), 100, Random.Range(-50, 50)) ); // If empty, replace hand with nothing if (--item.mItemCount == 0) { item = new ItemStack(0); } mCurrentItem = item; } } } } else { mPickupCooldownAmount = 0.15f; } } }