private void OnDragStart(GameObject obj) { CritterController critter = obj.GetComponent <CritterController>(); ItemDescriptor itemDescriptor = obj.GetComponent <ItemDescriptor>(); if (critter != null) { CreatureDescriptor dna = critter.GetDNA(); StringBuilder descStringBuilder = new StringBuilder(); descStringBuilder.AppendLine(string.Format("Shape: {0}", CritterConstants.GetCreatureShapeDisplayString(dna.Shape))); descStringBuilder.AppendLine(string.Format("Color: {0}", CritterConstants.GetCreatureColorDisplayString(dna.Color))); descStringBuilder.AppendLine(string.Format("Size: {0}", CritterConstants.GetCreatureSizeDisplayString(dna.Size))); var attachmentCountMap = dna.GetAttachmentTypeCounts(); foreach (var countPair in attachmentCountMap) { if (countPair.Value > 0) { descStringBuilder.AppendLine(string.Format("{0}: {1}", countPair.Key.AttachmentType, countPair.Value)); } } _itemDescText.SetText(descStringBuilder); } else if (itemDescriptor != null) { _itemDescText.SetText(itemDescriptor.Description); } }
public static CreatureDescriptor CreateCreatureDescriptorFromParents(CritterController parent0, CritterController parent1) { CreatureDescriptor parentDNA0 = parent0.GetDNA(); CreatureDescriptor parentDNA1 = parent1.GetDNA(); CreatureDescriptor childDNA = new CreatureDescriptor(); // Randomly pick a color from one of the parents childDNA.Color = Random.Range(0, 1) == 0 ? parentDNA0.Color : parentDNA1.Color; // Randomly pick a shape from one of the parents childDNA.Shape = Random.Range(0, 1) == 0 ? parentDNA0.Shape : parentDNA1.Shape; // Always start small childDNA.Size = CritterConstants.CreatureSize.Small; // Combine the attachment from both parents into one big list List <GameObject> combinedParentAttachments = new List <GameObject>(); combinedParentAttachments.AddRange(parentDNA0.Attachments); combinedParentAttachments.AddRange(parentDNA1.Attachments); List <CreatureAttachmentDescriptor> combinedParentAttachmentTypes = new List <CreatureAttachmentDescriptor>(); combinedParentAttachmentTypes.AddRange(parentDNA0.AttachmentTypes); combinedParentAttachmentTypes.AddRange(parentDNA1.AttachmentTypes); // Create a shuffled index into the combined attachent list int[] shuffledParentAttachmentIndices = ArrayUtilities.MakeShuffledIntSequence(0, combinedParentAttachments.Count - 1); // Decide how many attachments the child will have // 1 -> SpawnAttachmentCount // but no more than parents had available to draw from int childAttachmentCount = System.Math.Min(System.Math.Max(CritterSpawner.Instance.SpawnAttachmentCount.RandomValue, 1), combinedParentAttachments.Count); // Fill in the child attachment list using the shuffled indices childDNA.Attachments = new GameObject[childAttachmentCount]; childDNA.AttachmentTypes = new CreatureAttachmentDescriptor[childAttachmentCount]; for (int childAttachmentIndex = 0; childAttachmentIndex < childAttachmentCount; ++childAttachmentIndex) { int randomAttachmentIndex = shuffledParentAttachmentIndices[childAttachmentIndex]; childDNA.Attachments[childAttachmentIndex] = combinedParentAttachments[randomAttachmentIndex]; childDNA.AttachmentTypes[childAttachmentIndex] = combinedParentAttachmentTypes[randomAttachmentIndex]; } //childDNA.SortAttachments(); return(childDNA); }
public GameObject CreateDuplicate() { CritterController critter = GetComponent <CritterController>(); GameObject dupe; if (critter != null) { dupe = CritterSpawner.Instance.SpawnCritter(critter.GetDNA(), null); } else { dupe = Instantiate(_duplicatePrefab.Prefab); dupe.transform.SetParent(transform.parent); } Duplicated?.Invoke(dupe); return(dupe); }
public void OnCreatureDeposited(CritterController critter) { bool bOrderSatisfied = false; if (_selectedOrderPanel != null) { // Get the order we are supposed to be fulfilling CustomerOrder order = _selectedOrderPanel.GetCustomerOrder(); // Get the game object that owns the panel GameObject panelGameObject = _selectedOrderPanel.gameObject; // Remove the panel's GameObject from panel list _customerOrderPanelList.Remove(panelGameObject); // Deselect this panel // - closes the out hatch // - invalidates _selectedOrderPanel SetSelectedPanel(null); // Apply the creature too the order bOrderSatisfied = order.TrySatisfyDesireWithCreatureDescriptor(critter.GetDNA()); // Add the order to the completed order list _completedOrdersList.Add(order); // Destroy the panel StartCoroutine(DehydrateOrderPanelAsync(panelGameObject)); } // Play the appropriate effect if (_outHatchController != null) { _outHatchController.OnCrittedScored(bOrderSatisfied); } // Destroy the creature deposited in the hatch Destroy(critter.gameObject); }