コード例 #1
0
    public void AddElementToCrowd(CrowdElement ce)
    {
        //ce.AssignNewTarget(followPoint);
        ce.currentlyInCrowd = true;
        if (!crowd.Contains(ce))
        {
            crowd.Add(ce);
            ce.onNewElementInCrowd?.Invoke();
        }
        if (!followingCrowd.Contains(ce))
        {
            followingCrowd.Add(ce);
        }

        bool inGroup = false;

        foreach (CinemachineTargetGroup.Target t in ctg.m_Targets)
        {
            if (t.target.transform == ce.transform)
            {
                inGroup = true;
                break;
            }
        }
        if (!inGroup)
        {
            ctg.AddMember(ce.transform, 1, 0);
        }
    }
コード例 #2
0
 public void RemoveElementFromCrowd(CrowdElement ce)
 {
     crowd.Remove(ce);
     followingCrowd.Remove(ce);
     ce.currentlyInCrowd = false;
     ctg.RemoveMember(ce.transform);
 }
コード例 #3
0
 // Start is called before the first frame update
 void Start()
 {
     element = GetComponent <CrowdElement>();
     if (element.price <= 0)
     {
         deactivateThis.SetActive(false);
     }
     else
     {
         text.text = element.price.ToString();
     }
 }
コード例 #4
0
    private void OnTriggerEnter(Collider other)
    {
        CrowdElement ce = other.GetComponentInParent <CrowdElement>();

        if (other.tag == allyTag && !ce.elementEnabled)
        {
            AddMoney(ce.Buy(money));
        }
        else if (other.tag == allyTag)
        {
            if (ce.sl.ded || !ce.elementEnabled)
            {
                ce.Buy(int.MaxValue);
            }
        }
    }
コード例 #5
0
ファイル: CrowdController.cs プロジェクト: OrangeeZ/Crandell
    private void ApplyPunishingForce( CrowdElement crowdElement, IList<SimpleSphereCollider> otherElements )
    {
        var buildingsPunishingForces = Building.instances
            .Select( _ => _.sphereCollider )
            .Select( _ => _.CalculatePunishingForce( crowdElement.sphereCollider ) );

        var force = otherElements
            //.Skip( elementIndex )
            //.Where( crowdElement.CanBeTested )
            //.Where( _ => 1f.Random() > 0.95f )
            //.Where( crowdElement.CompareHash )
            .Select( _ => _.CalculatePunishingForce( crowdElement.sphereCollider ) )
            .Concat( buildingsPunishingForces )
            .Aggregate( Vector3.zero, ( total, each ) => total + each );

        crowdElement.transform.position += force.Set( y: 0 );
    }
コード例 #6
0
 public void CheckCarryingItem(CrowdElement ce)
 {
     if (ce.carryingItem)
     {
         foreach (CrowdElement cee in followingCrowd)
         {
             if (cee.carryingItem)
             {
                 cee.carryingItem = false;
                 cee.AssignNewTarget(followPoint);
             }
         }
         if (currentItem)
         {
             currentItem.Drop();
         }
     }
 }
コード例 #7
0
    private void OnTriggerEnter(Collider other)
    {
        Transform raycastTrigger = null;

        for (int i = 0; i < transform.parent.childCount; i++)
        {
            if (transform.parent.GetChild(i).tag == "RaycastItem")
            {
                raycastTrigger = transform.parent.GetChild(i);
            }
        }
        if (other.tag == allyTag && !grabbed && other.GetComponentInParent <CrowdElement>().currentTarget == raycastTrigger)
        {
            interactingElements.Add(other.transform.parent);
        }

        if (other.transform == objective)
        {
            onUsed?.Invoke();
            //Debug.Log("ITEM USED");
            CrowdObjective co;
            if (!other.transform.parent.GetComponentInChildren <CrowdObjective>())
            {
                co = other.GetComponentInParent <CrowdObjective>();
            }
            else
            {
                co = other.transform.parent.GetComponentInChildren <CrowdObjective>();
            }

            co.Completed();

            foreach (Transform t in interactingElements)
            {
                CrowdElement ce = t.GetComponent <CrowdElement>();
                ce.AssignNewTarget(ce.player.followPoint);
            }
            Destroy(parent.gameObject);
        }
    }
コード例 #8
0
    public void Die()
    {
        if (!ded)
        {
            ded = true;
            onDie?.Invoke();
            if (transform.tag == "Player")
            {
                //Debug.Log("GAMEOVER");
            }
            else
            {
                CrowdElement ce = GetComponentInParent <CrowdElement>();
                if (ce)
                {
                    ce.player.CheckCarryingItem(ce);
                    ce.RemoveThisFromCrowd();
                }
            }
        }

        //Debug.Log("ded");
    }
コード例 #9
0
ファイル: CrowdController.cs プロジェクト: OrangeeZ/Crandell
 public void AddElement( CrowdElement element )
 {
     _crowdElements.Add( element );
 }
コード例 #10
0
ファイル: CrowdElement.cs プロジェクト: OrangeeZ/Crandell
 public bool CompareHash( CrowdElement otherElement )
 {
     var result = otherElement.spatialHash - spatialHash;
     return result.x.Abs() < 2 && result.y.Abs() < 2 && result.z.Abs() < 2;
 }
コード例 #11
0
ファイル: CrowdElement.cs プロジェクト: OrangeeZ/Crandell
 public bool CanBeTested( CrowdElement other )
 {
     return !_testedElements.Contains( other );
 }
コード例 #12
0
ファイル: CrowdElement.cs プロジェクト: OrangeeZ/Crandell
    public Vector3 CalculatePunishingForce( CrowdElement other )
    {
        //other._testedElements.Add( this );

        return sphereCollider.CalculatePunishingForce( other.sphereCollider );
    }
コード例 #13
0
    public void AssignTargetToRandomElement(Transform target)
    {
        CrowdElement ce = target.GetComponentInParent <CrowdElement>();

        if (ce)
        {
            if (!ce.sl.ded && ce.elementEnabled)
            {
                ce.AssignNewTarget(followPoint);
                if (!followingCrowd.Contains(ce))
                {
                    followingCrowd.Add(ce);
                }
            }
        }
        else
        {
            CrowdObjective co = target.parent.GetComponentInChildren <CrowdObjective>();
            if (co)
            {
                if (currentItem && (currentItem.objective.parent == target.parent))
                {
                    List <CrowdElement> ceToRemove = new List <CrowdElement>();
                    for (int i = 0; i < followingCrowd.Count; i++)
                    {
                        if (followingCrowd[i].carryingItem)
                        {
                            followingCrowd[i].AssignNewTarget(target);
                            ceToRemove.Add(followingCrowd[i]);
                            //followingCrowd.RemoveAt(i);
                        }
                    }
                    foreach (CrowdElement ceInList in ceToRemove)
                    {
                        followingCrowd.Remove(ceInList);
                    }
                }
            }
            else
            {
                if (crowd.Count > 0 && crowd.Count > CountCarryingElements())//Pablo: Ponía followingCrowd antes ambas veces en vez de crowd
                {
                    // Pablo ha tocao esto
                    bool noFollowerAvailable = true;
                    //
                    foreach (CrowdElement cee in followingCrowd)
                    {
                        if (!cee.carryingItem)
                        {
                            cee.AssignNewTarget(target);
                            followingCrowd.Remove(cee);
                            //
                            noFollowerAvailable = false;
                            //
                            break;
                        }
                    }
                    //
                    if (noFollowerAvailable)
                    {
                        foreach (CrowdElement cee in crowd)
                        {
                            if (!cee.carryingItem)
                            {
                                cee.AssignNewTarget(target);
                                break;
                            }
                        }
                    }
                    //
                }
            }
        }
    }