public DS_HazeContextItem GetRenderContextAtPosition(Vector3 position) { List <DS_HazeZone> dsHazeZoneList = new List <DS_HazeZone>(); for (int index = 0; index < this.m_Zones.Count; ++index) { if (this.m_Zones[index].Contains(position) && ((Behaviour)this.m_Zones[index]).get_enabled()) { dsHazeZoneList.Add(this.m_Zones[index]); } } if (dsHazeZoneList.Count == 0) { return((DS_HazeContextItem)null); } if (dsHazeZoneList.Count == 1) { return(dsHazeZoneList[0].Context.GetContextItemBlended(this.m_Time)); } dsHazeZoneList.Sort((Comparison <DS_HazeZone>)((z1, z2) => z1 < z2 ? -1 : 1)); DS_HazeContextItem contextItemBlended = dsHazeZoneList[0].Context.GetContextItemBlended(this.m_Time); for (int index = 1; index < dsHazeZoneList.Count; ++index) { float blendWeight = dsHazeZoneList[index].GetBlendWeight(position); contextItemBlended.Lerp(dsHazeZoneList[index].Context.GetContextItemBlended(this.m_Time), blendWeight); } return(contextItemBlended); }
/// <summary> /// Return a DS_HazeContextVariant that has the linearly interpolated values, from top-to-bottom /// in the stack. If a variant is 'soloed', or there's only one, then that is returned as-is. /// </summary> public DS_HazeContextItem GetContextItemBlended(float time = -1) { DS_HazeContextItem blended = new DS_HazeContextItem(); blended.CopyFrom(m_ContextItems[0]); // If there's only the default variant, return it directly. if (m_ContextItems.Count == 1) { return(blended); } // Check for a 'soloed' variant (editor only). #if UNITY_EDITOR if (m_SoloItem > -1 && m_SoloItem < m_ContextItems.Count) { blended.CopyFrom(m_ContextItems[m_SoloItem]); return(blended); } #endif // Created a blended variant. time = Mathf.Clamp01(time); float weight = 0; for (int cv = 1; cv < m_ContextItems.Count; cv++) { weight = m_ContextItems[cv].m_Weight.Evaluate(time); blended.Lerp(m_ContextItems[cv], weight); } return(blended); }
public DS_HazeContextItem GetContextItemBlended(float time = -1f) { DS_HazeContextItem dsHazeContextItem = new DS_HazeContextItem(); dsHazeContextItem.CopyFrom(this.m_ContextItems[0]); if (this.m_ContextItems.Count == 1) { return(dsHazeContextItem); } time = Mathf.Clamp01(time); for (int index = 1; index < this.m_ContextItems.Count; ++index) { float dt = this.m_ContextItems[index].m_Weight.Evaluate(time); dsHazeContextItem.Lerp(this.m_ContextItems[index], dt); } return(dsHazeContextItem); }
/// <summary> /// Find the zones containing the given position and blend between them. /// The render context will be null if the position is not within any zones. /// If there is only one zone, that will provide the context as-is. /// </summary> public DS_HazeContextItem GetRenderContextAtPosition(Vector3 position) { List <DS_HazeZone> blendZones = new List <DS_HazeZone>(); for (int zi = 0; zi < m_Zones.Count; zi++) { if (m_Zones[zi].Contains(position) && m_Zones[zi].enabled) { blendZones.Add(m_Zones[zi]); } } if (blendZones.Count == 0) { return(null); } if (blendZones.Count == 1) { return(blendZones[0].Context.GetContextItemBlended(m_Time)); } blendZones.Sort(delegate(DS_HazeZone z1, DS_HazeZone z2) { if (z1 < z2) { return(-1); } else { return(1); } }); // With the list in priority order (lowest to highest), iterate through and blend from first to last. DS_HazeContextItem renderContext = blendZones[0].Context.GetContextItemBlended(m_Time); float weight = 0; for (int ci = 1; ci < blendZones.Count; ci++) { weight = blendZones[ci].GetBlendWeight(position); renderContext.Lerp(blendZones[ci].Context.GetContextItemBlended(m_Time), weight); } return(renderContext); }