public void Bind(ExposedField property, IExposedToLevelEditor exposed)
        {
            exposed.OnValueChanged += OnExposedValueChanged;

            boundProperty  = property;
            boundComponent = exposed;

#if ALE_LOCALIZATION
            if (!string.IsNullOrWhiteSpace(property.CustomName) && localStringComp != null)
            {
                Label = TextUtility.FormatVariableLabel(property.Name);
                LocalizedString result = UI.InspectorPanel.GetLocalizedInspectorField(property.CustomName);
                if (result != null)
                {
                    localStringComp.StringReference = result;
                }
            }
            else
#endif
            {
                Label = string.IsNullOrEmpty(property.CustomName) ? TextUtility.FormatVariableLabel(property.Name) : property.CustomName;
            }

            OnBound(property, exposed);
            SetFieldValue(exposed.GetValue(property.ID));
        }
Esempio n. 2
0
        private IEnumerator EventTest <T>(int id, Action <IExposedToLevelEditor, Action <int, object> > subscribeToEvent) where T : Component
        {
            cube.AddComponent <T>();
            ILevelEditorObject    newCube = objectManager.CreateObject("cube");
            IExposedToLevelEditor exposed = newCube.MyGameObject.GetComponent <T>() as IExposedToLevelEditor;

            sceneObjects.Add(newCube.MyGameObject);

            Assert.IsNotNull(exposed);

            int    changedId    = -1;
            object changedValue = null;
            bool   eventCalled  = false;

            subscribeToEvent.Invoke(exposed, (id, value) =>
            {
                eventCalled  = true;
                changedId    = id;
                changedValue = value;
            });

            exposed.SetValue(0, 10, true);

            Assert.AreEqual(true, eventCalled);
            Assert.AreEqual(0, changedId);
            Assert.AreEqual(10, changedValue);

            yield return(null);
        }
Esempio n. 3
0
        protected override void OnBound(ExposedField property, IExposedToLevelEditor exposed)
        {
            if (property.Type == typeof(Vector2))
            {
                type = VectorTypes.Vector2;
            }
            else if (property.Type == typeof(Vector2Int))
            {
                type = VectorTypes.Vector2Int;
            }
            else if (property.Type == typeof(Vector3))
            {
                type = VectorTypes.Vector3;
            }
            else if (property.Type == typeof(Vector3Int))
            {
                type = VectorTypes.Vector3Int;
            }
            else if (property.Type == typeof(Vector4))
            {
                type = VectorTypes.Vector4;
            }
            else
            {
                type = VectorTypes.Invalid;
            }

            xField.contentType = IsInt ? TMP_InputField.ContentType.IntegerNumber : TMP_InputField.ContentType.DecimalNumber;
            yField.contentType = IsInt ? TMP_InputField.ContentType.IntegerNumber : TMP_InputField.ContentType.DecimalNumber;
        }
Esempio n. 4
0
 public LevelEditorPropertyData(ExposedProperty property, IExposedToLevelEditor exposedComponent)
 {
     id    = property.ID;
     value = exposedComponent?.GetValue(property.ID);
     // Used for Unity references. They need to be converted to a simple component.
     type = property.Type;
     if (property is ExposedArray array)
     {
         if (array.ElementType.IsSubclassOf(typeof(Component)))
         {
             if (type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(List <>)))
             {
                 //type = typeof(List<>).MakeGenericType(typeof(Component));
                 throw new NotSupportedException($"List<{array.ElementType}> is not supported. For collection of Unity objects, use array instead.");
             }
             else
             {
                 type = typeof(Component).MakeArrayType();
             }
         }
     }
     else
     {
         // type = property.Type.IsSubclassOf(typeof(Component)) ? typeof(Component) : property.Type;
         type = ComponentDataWrapper.IsComponent(property.Type) ? typeof(ComponentDataWrapper) : property.Type;
     }
     typeName = type.FullName;
 }
Esempio n. 5
0
        public IEnumerator SetValueParentAndChild()
        {
            cube.AddComponent <InheritChild>();
            ILevelEditorObject    newCube = objectManager.CreateObject("cube");
            IExposedToLevelEditor exposed = newCube.MyGameObject.GetComponent <InheritChild>() as IExposedToLevelEditor;

            Assert.IsNotNull(exposed);

            var parentValue = (int)exposed.GetValue(0);
            var childValue  = (int)exposed.GetValue(1);

            Assert.AreEqual(0, parentValue);
            Assert.AreEqual(0, childValue);

            exposed.SetValue(0, 10, true);
            exposed.SetValue(1, 20, true);

            parentValue = (int)exposed.GetValue(0);
            childValue  = (int)exposed.GetValue(1);

            Assert.AreEqual(10, parentValue);
            Assert.AreEqual(20, childValue);

            yield break;
        }
 public SetValueUndoAction(IExposedToLevelEditor exposed, int propertyId, object previousValue, object newValue)
 {
     this.exposed       = exposed;
     this.propertyId    = propertyId;
     this.previousValue = previousValue;
     this.newValue      = newValue;
 }
Esempio n. 7
0
        public void Initialize(ILevelEditorInspector inspector, Component target, IExposedToLevelEditor exposed, RectTransform content)
        {
            Inspector       = inspector;
            TargetComponent = target;
            Exposed         = exposed;
            this.content    = content;

            exposedProperties = exposed.GetProperties();
        }
Esempio n. 8
0
        private IEnumerator SetValueTest <TValue, TScript1, TScript2>(TValue value1, TValue value2) where TScript1 : Component where TScript2 : Component
        {
            cube.AddComponent <TScript1>();
            if (typeof(TScript1) != typeof(TScript2))
            {
                cube.AddComponent <TScript2>();
            }

            ILevelEditorObject    newCube  = objectManager.CreateObject("cube");
            IExposedToLevelEditor exposed1 = newCube.MyGameObject.GetComponent <TScript1>() as IExposedToLevelEditor;
            IExposedToLevelEditor exposed2 = null;

            if (typeof(TScript1) != typeof(TScript2))
            {
                exposed2 = newCube.MyGameObject.GetComponent <TScript2>() as IExposedToLevelEditor;
            }

            Assert.IsNotNull(exposed1);
            if (exposed2 != null)
            {
                Assert.IsNotNull(exposed2);
            }

            exposed1.SetValue(0, value1, true);
            if (exposed2 != null)
            {
                exposed2.SetValue(512, value2, true);
            }
            else
            {
                exposed1.SetValue(512, value2, true);
            }

            yield return(null);

            TValue newValue1 = (TValue)exposed1.GetValue(0);
            TValue newValue2;

            if (exposed2 != null)
            {
                newValue2 = (TValue)exposed2.GetValue(512);
            }
            else
            {
                newValue2 = (TValue)exposed1.GetValue(512);
            }

            Assert.AreEqual(typeof(TValue), value1.GetType());
            Assert.AreEqual(typeof(TValue), value2.GetType());

            Assert.AreEqual(newValue1, value1);
            Assert.AreEqual(newValue2, value2);

            yield return(null);
        }
Esempio n. 9
0
        protected override void OnBound(ExposedField property, IExposedToLevelEditor exposed)
        {
            isChar = property.Type == typeof(char);

            textField.characterLimit = isChar ? 1 : 0;

            if (placeholderAsName && textField.placeholder is TextMeshProUGUI placeholder)
            {
                placeholder.text = property.Name;
            }
        }
        public static bool CollectionEquals <T>(this IExposedToLevelEditor exposed, object value, T existing, out T returnValue) where T : ICollection
        {
            if (value == null && existing != null)
            {
                returnValue = default;
                return(false);
            }

            if (value is T a && !a.IsSameAs(existing))
            {
                returnValue = a;
                return(false);
            }

            returnValue = default;
            return(true);
        }
Esempio n. 11
0
        public IEnumerator SetValueParentOnly()
        {
            cube.AddComponent <InheritParent>();
            ILevelEditorObject    newCube = objectManager.CreateObject("cube");
            IExposedToLevelEditor exposed = newCube.MyGameObject.GetComponent <InheritParent>() as IExposedToLevelEditor;

            Assert.IsNotNull(exposed);

            var value = (int)exposed.GetValue(0);

            Assert.AreEqual(0, value);

            exposed.SetValue(0, 10, true);

            value = (int)exposed.GetValue(0);

            Assert.AreEqual(10, value);

            yield break;
        }
        public static bool ClassEquals <T>(this IExposedToLevelEditor exposed, object value, T existing, out T returnValue) where T : class
        {
            if (value == null && existing != null)
            {
                returnValue = default;
                return(false);
            }

            if (value is UnityEngine.Object unityObj && existing is UnityEngine.Object eUnity && unityObj != eUnity)
            {
                returnValue = (T)value;
                return(false);
            }

            if (value is T val && !val.Equals(existing))
            {
                returnValue = (T)value;
                return(false);
            }

            returnValue = default;
            return(true);
        }
Esempio n. 13
0
        protected override void OnBound(ExposedField property, IExposedToLevelEditor exposed)
        {
            enumNames.Clear();
            enumValues.Clear();

            string[] names = Enum.GetNames(property.Type);
            enumNames.AddRange(names);

            Array values = Enum.GetValues(property.Type);

            for (int i = 0; i < values.Length; i++)
            {
                enumValues.Add(values.GetValue(i));
            }

            dropdown.ClearOptions();

            for (int i = 0; i < enumNames.Count; i++)
            {
                dropdown.options.Add(new TMP_Dropdown.OptionData(enumNames[i]));
            }

            dropdown.RefreshShownValue();
        }
 /// <summary>
 /// Sets a value WITHOUT registering undo.
 /// </summary>
 /// <param name="exposed"></param>
 /// <param name="id"></param>
 /// <param name="value"></param>
 /// <param name="notify"></param>
 public static void SetValue(this IExposedToLevelEditor exposed, int id, object value, bool notify)
 {
     exposed.SetValue(id, value, notify, null);
 }
 public static void SetValue(this IExposedToLevelEditor exposed, int id, object value, bool notify, ILevelEditorUndo undo)
 {
     exposed.BeginEdit(id);
     exposed.ModifyValue(value, notify);
     exposed.EndEdit(notify, undo);
 }
 protected virtual void OnBound(ExposedField property, IExposedToLevelEditor exposed)
 {
 }
Esempio n. 17
0
 public LevelEditorComponentData(IExposedToLevelEditor exposed)
 {
     type    = exposed.ComponentType;
     wrapper = exposed.GetWrapper();
 }
Esempio n. 18
0
        protected override void OnBound(ExposedField property, IExposedToLevelEditor exposed)
        {
            editing = false;

            if (property.Type == typeof(sbyte))
            {
                currentType = NumberType.Sbyte;
            }
            else if (property.Type == typeof(byte))
            {
                currentType = NumberType.Byte;
            }
            else if (property.Type == typeof(short))
            {
                currentType = NumberType.Short;
            }
            else if (property.Type == typeof(ushort))
            {
                currentType = NumberType.UShort;
            }
            else if (property.Type == typeof(int))
            {
                currentType = NumberType.Int;
            }
            else if (property.Type == typeof(uint))
            {
                currentType = NumberType.UInt;
            }
            else if (property.Type == typeof(long))
            {
                currentType = NumberType.Long;
            }
            else if (property.Type == typeof(ulong))
            {
                currentType = NumberType.ULong;
            }
            else if (property.Type == typeof(float))
            {
                currentType = NumberType.Float;
            }
            else if (property.Type == typeof(double))
            {
                currentType = NumberType.Double;
            }
            else
            {
                currentType = NumberType.Decimal;
            }

            switch (currentType)
            {
            case NumberType.Sbyte:
                textField.contentType = TMP_InputField.ContentType.IntegerNumber;
                break;

            case NumberType.Byte:
                textField.contentType = TMP_InputField.ContentType.IntegerNumber;
                break;

            case NumberType.Short:
                textField.contentType = TMP_InputField.ContentType.IntegerNumber;
                break;

            case NumberType.UShort:
                textField.contentType = TMP_InputField.ContentType.IntegerNumber;
                break;

            case NumberType.Int:
                textField.contentType = TMP_InputField.ContentType.IntegerNumber;
                break;

            case NumberType.UInt:
                textField.contentType = TMP_InputField.ContentType.IntegerNumber;
                break;

            case NumberType.Long:
            case NumberType.ULong:
                textField.contentType = TMP_InputField.ContentType.IntegerNumber;
                break;

            case NumberType.Float:
                textField.contentType = TMP_InputField.ContentType.DecimalNumber;
                break;

            case NumberType.Double:
                textField.contentType = TMP_InputField.ContentType.DecimalNumber;
                break;

            case NumberType.Decimal:
                textField.contentType = TMP_InputField.ContentType.DecimalNumber;
                break;
            }

            if (placeholderAsName && textField.placeholder is TextMeshProUGUI placeholder)
            {
                placeholder.text = property.Name;
            }
        }