示例#1
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;
        }
示例#2
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);
        }
        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));
        }
示例#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;
 }
示例#5
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;
        }