예제 #1
0
 void Refresh()
 {
     if (activationStrategy == ActivationStrategy.OnlyClosestZone)
     {
         var newClosest = InfZone.ClosestZone(transform.position, zones);
         if (newClosest != closest)
         {
             if (closest)
             {
                 closest.Freeze();
             }
             newClosest.Unfreeze();
             closest = newClosest;
         }
     }
     else if (activationStrategy == ActivationStrategy.AllZonesWithinDistance)
     {
         foreach (var zone in zones)
         {
             float distance = Vector3.Distance(transform.position, zone.transform.position);
             if (distance < distanceThreshold)
             {
                 zone.Unfreeze();
             }
             else
             {
                 zone.Freeze();
             }
         }
     }
 }
예제 #2
0
파일: InfActor.cs 프로젝트: eriksvedang/Inf
 /// <summary>
 /// Alters the activity status of the actor's GameObject.
 /// If the status is changed from it's previous value the approperiate callback is called (FixAfterFreeze / FixAfterUnfreeze).
 /// </summary>
 public void SetActive(bool newActiveStatus, InfZone zone)
 {
     if (!isActiveAndEnabled && newActiveStatus)
     {
         FixAfterUnfreeze(zone);
     }
     else if (isActiveAndEnabled && !newActiveStatus)
     {
         FixAfterFreeze(zone);
     }
     gameObject.SetActive(newActiveStatus);
 }
예제 #3
0
파일: InfActor.cs 프로젝트: eriksvedang/Inf
 /// <summary>
 /// The correct way to move an actor from its current Zone to another one.
 /// </summary>
 public void TransferToZone(InfZone newZone)
 {
     if (zone == newZone)
     {
         return;             // Already in that zone
     }
     if (zone != null)
     {
         zone.RemoveActor(this);
     }
     newZone.AddActor(this);
     zone = newZone;
     SetActive(!zone.frozen, zone);
 }
예제 #4
0
    public static InfZone ClosestZone(Vector3 position, InfZone[] zones)
    {
        if (zones.Length == 0)
        {
            throw new UnityException("No zones to choose from");
        }
        float   minimum = float.MaxValue;
        InfZone closest = null;

        foreach (var zone in zones)
        {
            float distance = Vector3.Distance(position, zone.transform.position);
            if (distance < minimum)
            {
                minimum = distance;
                closest = zone;
            }
        }
        return(closest);
    }
예제 #5
0
파일: InfActor.cs 프로젝트: eriksvedang/Inf
 public void TransferToClosestZone()
 {
     TransferToZone(InfZone.ClosestZone(transform.position, zones));
 }
예제 #6
0
파일: InfActor.cs 프로젝트: eriksvedang/Inf
 public void FixAfterFreeze(InfZone zone)
 {
     onFreeze(zone);
 }
예제 #7
0
파일: InfActor.cs 프로젝트: eriksvedang/Inf
 public void FixAfterUnfreeze(InfZone zone)
 {
     onUnfreeze(zone);
 }
예제 #8
0
    public void Unfreeze(InfZone zone)
    {
        float t = distanceTravelledWhileFrozen / Vector3.Distance(freezePosition, target);

        transform.position = Vector3.Lerp(freezePosition, target, t);
    }
예제 #9
0
 public void Freeze(InfZone zone)
 {
     distanceTravelledWhileFrozen = 0;
     freezePosition = transform.position;
 }
예제 #10
0
 public void UpdateWhileFrozen(InfZone zone)
 {
     distanceTravelledWhileFrozen += Time.deltaTime * 2f;
 }