private void DisplayAllPropertiesAsContext(string group) { GenericMenu menu = new GenericMenu(); List <JAnimatedProperty> props = AllProperties.FindAll(p => p.DisplayName.StartsWith(group)); if (props.Count == 0) { menu.AddDisabledItem(new GUIContent("No item found")); menu.ShowAsContext(); return; } for (int i = 0; i < props.Count; ++i) { JAnimatedProperty p = props[i]; string itemLabel = p.DisplayName.Substring(p.DisplayName.IndexOf("/") + 1); bool added = profile.AnimatedProperties.FindIndex(p0 => p0.Name.Equals(p.Name)) >= 0; if (added) { menu.AddDisabledItem(new GUIContent(itemLabel)); } else { menu.AddItem( new GUIContent(itemLabel), false, () => { profile.AddProperty(p); }); } } menu.ShowAsContext(); }
public void Animate(JSky sky, float t) { CheckDefaultProfileAndThrow(sky.Profile); for (int i = 0; i < AnimatedProperties.Count; ++i) { JAnimatedProperty aProp = AnimatedProperties[i]; for (int p = 0; p < PropertiesInfo.Count; ++p) { if (aProp.Name.Equals(PropertiesInfo[p].Name)) { if (aProp.CurveOrGradient == JCurveOrGradient.Curve) { PropertiesInfo[p].SetValue(sky.Profile, aProp.EvaluateFloat(t)); } else { PropertiesInfo[p].SetValue(sky.Profile, aProp.EvaluateColor(t)); } break; } } } sky.Profile.UpdateMaterialProperties(); }
public static JAnimatedProperty Create(string name, string displayName, JCurveOrGradient curveOrGradient) { JAnimatedProperty props = new JAnimatedProperty(); props.name = name; props.displayName = displayName; props.curveOrGradient = curveOrGradient; return(props); }
private static void InitAllAnimatableProperties() { AllProperties.Clear(); Type type = typeof(JSkyProfile); PropertyInfo[] props = type.GetProperties(); for (int i = 0; i < props.Length; ++i) { Attribute att = props[i].GetCustomAttribute(typeof(JAnimatableAttribute)); if (att != null) { JAnimatableAttribute animAtt = att as JAnimatableAttribute; AllProperties.Add(JAnimatedProperty.Create(props[i].Name, animAtt.DisplayName, animAtt.CurveOrGradient)); } } }
public void AddProperty(JAnimatedProperty p, bool setDefaultValue = true) { if (setDefaultValue) { JDayNightCycleProfile defaultProfile = JJupiterSettings.Instance.DefaultDayNightCycleProfile; if (defaultProfile != null) { JAnimatedProperty defaultProp = defaultProfile.AnimatedProperties.Find(p0 => p0.Name != null && p0.Name.Equals(p.Name)); if (defaultProp != null) { p.Curve = defaultProp.Curve; p.Gradient = defaultProp.Gradient; } } } AnimatedProperties.Add(p); }
private void DisplayAddedProperties(string group) { EditorGUI.indentLevel -= 1; JAnimatedProperty toRemoveProp = null; List <JAnimatedProperty> props = profile.AnimatedProperties.FindAll(p => p.DisplayName.StartsWith(group)); for (int i = 0; i < props.Count; ++i) { EditorGUILayout.BeginHorizontal(); JAnimatedProperty p = props[i]; if (GUILayout.Button("▬", EditorStyles.miniLabel, GUILayout.Width(12))) { toRemoveProp = p; } string itemLabel = p.DisplayName.Substring(p.DisplayName.IndexOf("/") + 1); itemLabel = ObjectNames.NicifyVariableName(itemLabel); if (p.CurveOrGradient == JCurveOrGradient.Curve) { p.Curve = EditorGUILayout.CurveField(itemLabel, p.Curve); } else { p.Gradient = EditorGUILayout.GradientField(itemLabel, p.Gradient); } EditorGUILayout.EndHorizontal(); } if (props.Count > 0) { JEditorCommon.Separator(); } if (toRemoveProp != null) { profile.AnimatedProperties.Remove(toRemoveProp); } EditorGUI.indentLevel += 1; }
public void Animate(JSky sky, float t) { CheckDefaultProfileAndThrow(sky.Profile); for (int i = 0; i < AnimatedProperties.Count; ++i) { JAnimatedProperty aProp = AnimatedProperties[i]; int id = 0; if (!PropertyRemap.TryGetValue(aProp.Name, out id)) { continue; } if (aProp.CurveOrGradient == JCurveOrGradient.Curve) { sky.Profile.Material.SetFloat(id, aProp.EvaluateFloat(t)); } else { sky.Profile.Material.SetColor(id, aProp.EvaluateColor(t)); } } }