public override void Write(Data data) { if (!(data is DataCreature)) { return; } DataCreature dataCreature = data as DataCreature; bool exist = false; int index = 0; foreach (DataCreature d in creatures) { if (d.creature == dataCreature.creature) { exist = true; break; } ++index; } if (exist) { if (dataCreature.RegistrationDate >= creatures[index].RegistrationDate) { Replace(new DataCreature(dataCreature), index); } } else { creatures.Add(new DataCreature(dataCreature)); } }
public void RemoveByKey(Creature key) { DataCreature element = creatures.Find(data => data.creature == key); if (element != null) { creatures.Remove(element); } }
public static void HandleAppear(DataCreature data) { data.sr_creature.color = data.sr_creature.color.SetColorAlpha(0); data.sr_back.color = data.sr_back.color.SetColorAlpha(0); data.sr_shadow.color = data.sr_shadow.color.SetColorAlpha(0); var color = data.sr_creature.color; data.tw1 = DOTween.To(getter: () => color.a, setter: x => color.a = x, endValue: 1.0f, duration: 0.6f) .OnUpdate(() => data.sr_creature.color = color); color = data.sr_back.color; data.tw2 = DOTween.To(getter: () => color.a, setter: x => color.a = x, endValue: 1.0f, duration: 0.6f) .OnUpdate(() => data.sr_back.color = color); color = data.sr_shadow.color; data.tw3 = DOTween.To(getter: () => color.a, setter: x => color.a = x, endValue: 0.5f, duration: 0.6f) .OnUpdate(() => data.sr_shadow.color = color); }
public override void Process() { if (!target || !target.gameObject.activeSelf) { status = GoalStatus.Failed; return; } /*float oldDistance = Mathf.Abs(Vector3.Distance(owner.transform.position, target.transform.position)); * if(oldDistance > distance){ * deltaDistance = 0; * }else{ * deltaDistance += distance - oldDistance; * } * distance = oldDistance; * * if(deltaDistance > 0.1f){ * status = GoalStatus.Failed; * return; * }*/ IReadOnlyCollection <DataCreature> creatures = owner.Memory.Creatures.Read(); DataCreature targetData = null; foreach (DataCreature data in creatures) { if (!data.creature || !data.creature.gameObject.activeSelf) { continue; } if (data.creature.agentCreature == target) { targetData = data; break; } } if (targetData == null) { status = GoalStatus.Failed; return; } if (targetData.RegistrationDate > Time.time - 1f) { if (!chase) { chase = true; owner.Steering.Target = target; owner.Steering.Behavior = eSteeringBehavior.Pursuit; } if (owner.Steering.Behavior != eSteeringBehavior.Pursuit) { status = GoalStatus.Failed; return; } float distance = Vector3.Distance(owner.transform.position, target.transform.position); if (distance < 2) { status = GoalStatus.Completed; } else if (distance > owner.PerceptionConfig.viewRadius) { status = GoalStatus.Failed; } } else { if (chase) { chase = false; owner.Steering.SetDestination(targetData.lastPos); owner.Steering.Behavior = eSteeringBehavior.Seek; } if (owner.Steering.IsArrivedToDestination) { status = GoalStatus.Failed; return; } } }
public DataCreature(DataCreature dataCreature) : base(expirationTime - (Time.time - dataCreature.RegistrationDate)) { this.creature = dataCreature.creature; this.lastPos = dataCreature.lastPos; }
public override void Process() { IReadOnlyCollection <DataCreature> creatures = owner.Memory.Creatures.Read(); DataCreature agentData = null; float distanceToAgent = Mathf.Infinity; foreach (DataCreature data in creatures) { if (!data.creature) { continue; } Creature creature = data.creature; Agent agent = creature.agentCreature; Vector3 lastPos = data.lastPos; if (Time.time - data.RegistrationDate > 5f) { seen.RemoveAll(c => c == creature); } if (agent == owner || !agent.gameObject.activeSelf) { continue; } if (seen.Contains(creature) || !filter(creature)) { continue; } float distanceToPos = Vector3.Distance(owner.transform.position, lastPos); if (agent != owner && distanceToPos < distanceToAgent) { agentData = data; distanceToAgent = distanceToPos; } } if (agentData != null) { if (Time.time - agentData.RegistrationDate < 0.5f) { seen.Add(agentData.creature); } else if (!owner.Steering.IsArrivedToDestination) { owner.Steering.SetDestination(agentData.lastPos); owner.Steering.Behavior = eSteeringBehavior.Seek; } else { if (owner.Steering.Behavior == eSteeringBehavior.Wander) { return; } owner.Memory.Creatures.RemoveByKey(agentData.creature); owner.Steering.Behavior = eSteeringBehavior.Wander; } } else { /*if(owner.Steering.Behavior == eSteeringBehavior.Wander) return; * * owner.Steering.Behavior = eSteeringBehavior.Wander;*/ status = GoalStatus.Failed; } }