public static void Hide() { OpLock.Undo(); currentEdit?.Destroy(); currentEdit = null; }
public static void Show() { OpLock.Apply(); try { Item item = ItemManager.Instance.currentSelect.GetComponent <CustomDecoration>().item; if (!cache_prop.ContainsKey(item.GetType())) { _reflectProps(item.GetType()); } if (cache_prop.TryGetValue(item.GetType(), out var itemProps)) { var insp = new InspectPanel(); currentEdit = insp; int idx = 0; foreach (var kv in itemProps) { string name = kv.Key; Type propType = kv.Value.PropertyType; object value = kv.Value.GetValue(item, null); value = Convert.ToSingle(value); ConstraintAttribute con = kv.Value.GetCustomAttributes(typeof(ConstraintAttribute), true).OfType <ConstraintAttribute>().FirstOrDefault(); LogProp(propType, name, value); if (idx == 0) { insp.UpdateName(idx, name); if (con is IntConstraint) { //Logger.LogDebug($"Check1 {con.Min}-{con.Max}"); insp.UpdateSliderConstrain(name, idx, (float)Convert.ChangeType(con.Min, typeof(float)), Convert.ToInt32(con.Max), true); } else if (con is FloatConstraint) { //Logger.LogDebug($"Check2 {con.Min}-{con.Max}"); insp.UpdateSliderConstrain(name, idx, (float)(con.Min), (float)(con.Max), false); } else { throw new ArgumentException(); } //Logger.LogDebug($"Check3 {value}-{value.GetType()}"); insp.UpdateValue(idx, (float)value); } else { insp.AppendPropPanel(name); if (con is IntConstraint) { insp.UpdateSliderConstrain(name, idx, (int)con.Min, (int)con.Max, true); } else if (con is FloatConstraint) { insp.UpdateSliderConstrain(name, idx, (float)con.Min, (float)con.Max, false); } else { throw new ArgumentException(); } insp.UpdateValue(idx, (float)value); insp.UpdateTextDelegate(idx);//insp.AddListener(idx, insp.UpdateTextDelegate(idx)); } //insp.AddListener(idx, (v) => { kv.Value.SetValue(item, Convert.ChangeType(v, kv.Value.PropertyType), null); }); insp.AddListener(idx, (v) => { if (ItemManager.Instance.currentSelect == null) { return; } object val; try { if (kv.Value.PropertyType.IsSubclassOf(typeof(Enum))) { val = Enum.Parse(kv.Value.PropertyType, v.ToString("0")); } else { val = Convert.ChangeType(v, kv.Value.PropertyType); } ItemManager.Instance.currentSelect.GetComponent <CustomDecoration>().Setup(handler[kv.Value], val); } catch { Logger.LogError("Error occour at Inspect OnValue Chnaged"); Hide(); } }); idx++; } } else { Logger.LogError($"KeyNotFount at cache_prop,{item.GetType()}"); } } catch (NullReferenceException e) { Logger.LogError($"NulRef Error at Inspector.Show:{e}"); OpLock.Undo(); } }