Ejemplo n.º 1
0
    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);
        }
    }
Ejemplo n.º 2
0
    public void SetDNA(CreatureDescriptor DNA)
    {
        _critterDNA = DNA;

        // Spawn attachments on the critter
        CritterAttachmentManager AttachmentManager = GetComponentInChildren <CritterAttachmentManager>();

        if (AttachmentManager != null)
        {
            AttachmentManager.SpawnAttachments(_critterDNA);
        }

        // Apply color settings
        HasCritterColor[] childColors = _visualRoot.GetComponentsInChildren <HasCritterColor>();
        foreach (var childColor in childColors)
        {
            var r = childColor.GetComponent <Renderer>();
            if (r != null)
            {
                if (_critterMaterialInstance == null)
                {
                    _critterMaterialInstance = Instantiate(r.sharedMaterial);
                }

                _critterMaterialInstance.color = CritterConstants.GetCreatureColorValue(_critterDNA.Color);
                r.sharedMaterial = _critterMaterialInstance;
            }
        }

        SetAge(CritterConstants.GetCreatureAgeAtSize(_critterDNA.Size), animate: false);
    }
Ejemplo n.º 3
0
    public void SetDNA(CreatureDescriptor DNA)
    {
        _critterDNA = DNA;

        Renderer r = GetComponentInChildren <Renderer>();

        _materialInstance       = r.material;
        _materialInstance.color = CritterConstants.GetCreatureColorValue(_critterDNA.Color);
    }
Ejemplo n.º 4
0
    private IEnumerator UpdateSizeAsync()
    {
        AudioManager.Instance.PlaySound(_growSound);

        Vector3 startScale = _visualRoot.localScale;
        Vector3 endScale   = Vector3.one * CritterConstants.GetCreatureSizeScale(_size);

        for (float time = 0; time < kGrowAnimationDuration; time += Time.deltaTime)
        {
            float t      = time / kGrowAnimationDuration;
            float tCurve = _growUpCurve.Evaluate(t);
            _visualRoot.localScale = Vector3.LerpUnclamped(startScale, endScale, tCurve);
            yield return(null);
        }
    }
Ejemplo n.º 5
0
    private void SetSize(CritterConstants.CreatureSize newSize, bool animate)
    {
        _size            = newSize;
        _critterDNA.Size = newSize;
        _vigorUI.gameObject.SetActive(((int)_size >= (int)kMinVigorSize));

        if (animate)
        {
            StartCoroutine(UpdateSizeAsync());
        }
        else
        {
            _visualRoot.localScale = Vector3.one * CritterConstants.GetCreatureSizeScale(_size);
        }
    }
Ejemplo n.º 6
0
    public static CreatureDescriptor CreateRandomCreatureDescriptor()
    {
        CreatureDescriptor randomDNA = new CreatureDescriptor();

        randomDNA.Color = CritterConstants.PickRandomCreatureColor();
        randomDNA.Shape = CritterConstants.PickRandomCreatureShape();
        randomDNA.Size  = CritterConstants.PickRandomCreatureSize();

        if (CritterSpawner.Instance != null)
        {
            CritterSpawner.Instance.PickNRandomAttachmentPrefabs(randomDNA);
            //randomDNA.SortAttachments();
        }

        return(randomDNA);
    }
Ejemplo n.º 7
0
 public override string ToUIString()
 {
     return(string.Format("Size: {0}", CritterConstants.GetCreatureSizeDisplayString(DesiredSize)));
 }
Ejemplo n.º 8
0
 public override string ToUIString()
 {
     return(string.Format("Color: {0}", CritterConstants.GetCreatureColorDisplayString(DesiredColor)));
 }
Ejemplo n.º 9
0
    private void Update()
    {
        // Age over time
        _age = Mathf.Clamp01(_age + Time.deltaTime * kAgeRate);
        CritterConstants.CreatureSize ageNewSize = CritterConstants.GetCreatureSizeAtAge(_age);
        if (ageNewSize != _size)
        {
            SetSize(ageNewSize, animate: true);
        }

        // Gain vigor, if we're old enough
        if ((int)_size >= (int)kMinVigorSize)
        {
            _vigorLevel          = Mathf.Clamp01(_vigorLevel + Time.deltaTime * kVigorGainRate);
            _vigorUI.FillPercent = _vigorLevel;
        }

        // Change direction sometimes
        _changeDirectionTimer -= Time.deltaTime;
        if (_changeDirectionTimer < 0)
        {
            _changeDirectionTimer = _changeDirTimeRange.RandomValue;
            _desiredDirection     = Random.onUnitSphere.WithY(0).normalized;
            _isMoving             = Random.value > _moveChance;

            if (_animator != null)
            {
                _animator.SetBool(kAnimParamIsWalking, _isMoving);
            }
        }

        // Slowly change move direction towards current desired direction / rotate to face move direction
        _moveDirection = Mathfx.Damp(_moveDirection, _desiredDirection, 0.5f, Time.deltaTime * _turnSpeed).WithY(0);

        if (_moveDirection.magnitude > 0.1f)
        {
            Quaternion desiredRot = Quaternion.LookRotation(_moveDirection, Vector3.up);
            _rigidBody.rotation = Mathfx.Damp(_rigidBody.rotation, desiredRot, 0.5f, Time.deltaTime * _turnSpeed);
        }

        // Occaisonally raycast for obstacles
        _obstacleRaycastTimer -= Time.deltaTime;
        if (_obstacleRaycastTimer < 0)
        {
            _obstacleRaycastTimer = 2;

            RaycastHit hitInfo;
            if (Physics.Raycast(transform.position, _desiredDirection, out hitInfo, _obstacleAvoidDistance, _obstacleMask))
            {
                _desiredDirection     = Quaternion.Euler(0, 90, 0) * _desiredDirection;
                _changeDirectionTimer = _changeDirTimeRange.MaxValue;
                Debug.DrawLine(transform.position, hitInfo.point, Color.red, 1.0f);
            }
            else
            {
                Debug.DrawRay(transform.position, _desiredDirection * _obstacleAvoidDistance, Color.white, 0.5f);
            }
        }

        // If we have full vigor, look for the closest mate and go get em
        if (IsReadyForLove)
        {
            if (_mateSearchIndex >= _instances.Count)
            {
                _mateSearchIndex = 0;
            }

            // Find nearest available mate lazily over time
            if (_mateSearchIndex < _instances.Count)
            {
                CritterController potentialMate = _instances[_mateSearchIndex];
                if (potentialMate != this && potentialMate.IsReadyForLove)
                {
                    float distToMate        = Vector3.Distance(transform.position, potentialMate.transform.position);
                    float distToNearestMate = _nearestMate != null?Vector3.Distance(transform.position, _nearestMate.transform.position) : Mathf.Infinity;

                    if (distToMate < distToNearestMate)
                    {
                        _nearestMate = potentialMate;
                    }
                }

                ++_mateSearchIndex;
            }

            // Move towards current desired mate
            if (_nearestMate != null)
            {
                Vector3 toMateVec = _nearestMate.transform.position - transform.position;
                _changeDirectionTimer = 1;
                _isMoving             = true;
                _desiredDirection     = toMateVec.normalized;

                // If someone gets to our potential mate first we have to try for someone else
                if (!_nearestMate.IsReadyForLove)
                {
                    _nearestMate = null;
                    return;
                }

                // If we get close enough, begin the process
                float distToMate = toMateVec.magnitude;
                if (distToMate < kMinMateDistance)
                {
                    MateWith(_nearestMate, isLeader: true);
                }
            }
        }

        Debug.DrawRay(transform.position, _desiredDirection, Color.blue);
    }
Ejemplo n.º 10
0
 public void SetAge(float newAge, bool animate)
 {
     _age = newAge;
     SetSize(CritterConstants.GetCreatureSizeAtAge(_age), animate);
 }
Ejemplo n.º 11
0
    CustomerOrder CreateRandomOrder()
    {
        CustomerOrder newOrder = new CustomerOrder();

        newOrder.OrderNumber     = _ordersIssued + 1;
        newOrder.SpawnDescriptor = CreatureDescriptor.CreateRandomCreatureDescriptor();

        int numDesiredChanges = OrderDesiredChanges.RandomValue;

        CustomerDesire.DesireType[] desiredChangeSequence = new CustomerDesire.DesireType[4] {
            CustomerDesire.DesireType.ChangeColor,
            CustomerDesire.DesireType.ChangeShape,
            CustomerDesire.DesireType.ChangeSize,
            CustomerDesire.DesireType.ChangeAttachments
        };
        ArrayUtilities.KnuthShuffle <CustomerDesire.DesireType>(desiredChangeSequence);

        newOrder.CustomerDesires = new CustomerDesire[numDesiredChanges];
        for (int desireIndex = 0; desireIndex < numDesiredChanges; ++desireIndex)
        {
            CustomerDesire.DesireType desiredChangeType = desiredChangeSequence[desireIndex];
            switch (desiredChangeType)
            {
            case CustomerDesire.DesireType.ChangeAttachments:
            {
                CreatureAttachmentDesire newDesire = new CreatureAttachmentDesire();
                newDesire.AttachmentDescriptor = CritterSpawner.Instance.PickRandomAttachmentDescriptor();
                newDesire.Count = DesiredAttachmentCount.RandomValue;

                newOrder.CustomerDesires[desireIndex] = newDesire;
            }
            break;

            case CustomerDesire.DesireType.ChangeColor:
            {
                CustomerColorDesire newDesire = new CustomerColorDesire();
                newDesire.DesiredColor = CritterConstants.PickRandomCreatureColor();

                newOrder.CustomerDesires[desireIndex] = newDesire;
            }
            break;

            case CustomerDesire.DesireType.ChangeShape:
            {
                CustomerShapeDesire newDesire = new CustomerShapeDesire();
                newDesire.DesiredShape = CritterConstants.PickRandomCreatureShape();

                newOrder.CustomerDesires[desireIndex] = newDesire;
            }
            break;

            case CustomerDesire.DesireType.ChangeSize:
            {
                CustomerSizeDesire newDesire = new CustomerSizeDesire();
                newDesire.DesiredSize = CritterConstants.PickRandomCreatureSize();

                newOrder.CustomerDesires[desireIndex] = newDesire;
            }
            break;
            }
        }

        return(newOrder);
    }