public static bool IsInChildObject(this FieldView self)
 {
     return(self.fieldName != self.fullPath);
 }
 public static void LinkToModel(this FieldView self, string text)
 {
     self.mainLink.Get <Text>().text = text;
 }
예제 #3
0
 public static bool LinkToJsonModel(this FieldView self, JObject root, JToken value)
 {
     if (self is EnumFieldView enumFieldView && value?.Type == JTokenType.Integer)
     {
         int posInEnum  = int.Parse("" + value);
         var enumValues = self.field.contentEnum;
         enumFieldView.LinkToModel(enumValues[posInEnum], newVal => {
             var newPosInEnum = Array.FindIndex(enumValues, x => x == newVal);
             var jValueParent = self.CreateJValueParentsIfNeeded(root);
             if (value is JValue v)
             {
                 v.Value = newPosInEnum;
             }
             else
             {
                 value = new JValue(newPosInEnum);
                 jValueParent[self.fieldName] = value;
             }
         });
         return(true);
     }
     if (self is InputFieldView inputFieldView)
     {
         inputFieldView.LinkToModel("" + value, newVal => {
             try {
                 var newJVal      = self.field.ParseToJValue(newVal);
                 var jValueParent = self.CreateJValueParentsIfNeeded(root);
                 if (value is JValue v)
                 {
                     v.Value = newJVal.Value;
                 }
                 else
                 {
                     value = newJVal;
                     jValueParent[self.fieldName] = value;
                 }
             } // Ignore errors like e.g. FormatException when "" is parsed to int:
             catch (FormatException e) { Log.w("" + e, self.gameObject); }
         });
         return(true);
     }
     if (self is BoolFieldView boolFieldView)
     {
         bool val = (value as JValue)?.Value <bool>() == true;
         boolFieldView.LinkToModel(val, newVal => {
             var jValueParent = self.CreateJValueParentsIfNeeded(root);
             if (value is JValue v)
             {
                 v.Value = newVal;
             }
             else
             {
                 value = new JValue(newVal);
                 jValueParent[self.fieldName] = value;
             }
         });
         return(true);
     }
     if (self is SliderFieldView sliderFieldView)
     {
         bool  isInt = sliderFieldView.field.GetJTokenType() == JTokenType.Integer;
         float val   = float.Parse("" + value);
         sliderFieldView.LinkToModel(val, newVal => {
             var jValueParent = self.CreateJValueParentsIfNeeded(root);
             if (value is JValue v)
             {
                 if (isInt)
                 {
                     v.Value = (long)newVal;
                 }
                 else
                 {
                     v.Value = newVal;
                 }
             }
             else
             {
                 value = isInt ? new JValue((int)newVal) : new JValue(newVal);
                 jValueParent[self.fieldName] = value;
             }
         });
         return(true);
     }
     if (self.field.readOnly == true)
     {
         self.LinkToModel("" + value);
         return(true);
     }
     return(false);
 }