コード例 #1
0
        protected LevelEditorInspectorField GetField <T>(ExposedProperty property, string label)
        {
            LevelEditorInspectorField field = GetField <T>(property);

            field.Label = label;

            return(field);
        }
コード例 #2
0
        public void PoolField(LevelEditorInspectorField field)
        {
            field.Unbind();

            pooledFields[field.Index].Push(field);
            activeFields.Remove(field);

            field.gameObject.SetActive(false);
        }
コード例 #3
0
 protected bool TryGetField <T>(ExposedProperty property, string label, out LevelEditorInspectorField field)
 {
     if (TryGetField <T>(property, out field))
     {
         field.Label = label;
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #4
0
 protected bool TryGetField <T>(ExposedField property, out LevelEditorInspectorField field)
 {
     if (Inspector.HasField(typeof(T)))
     {
         field = Inspector.GetField(typeof(T), content);
         field.Bind(property, Exposed);
         return(true);
     }
     else
     {
         field = null;
         return(false);
     }
 }
コード例 #5
0
        private void GenerateFields()
        {
            if (UI != null && UI.InspectorPanel is LevelEditorInspector inspector)
            {
                object[] valueArray = (object[])RawValue;
                float    height     = originalHeight + fieldsSpacing;
                for (int i = 0; i < valueArray.Length; i++)
                {
                    LevelEditorInspectorField field = inspector.GetField(BoundProperty.Type, contentHolder);
                    field.Depth = Depth + 1;
                    field.Label = $"Element {i}";
                    height     += ((RectTransform)field.transform).sizeDelta.y + fieldsSpacing;

                    fields.Add(field);
                }
                rect.sizeDelta = new Vector2(rect.sizeDelta.x, height);
            }
        }
コード例 #6
0
        public static void LogIfStripped(this LevelEditorInspectorField x)
        {
#if STRIP_UGUI
            UnityEngine.Debug.LogError($"{x.gameObject.name} is still using {x.GetType().Name}. It will be stripped on build. Make sure to remove it!", x.gameObject);
#endif
        }
コード例 #7
0
        public LevelEditorInspectorField GetField(Type fieldType, Transform parent)
        {
            LevelEditorInspectorField result = null;

            TypeAndArray type = new TypeAndArray(fieldType, fieldType.IsArray);

            if (fields.TryGetValue(type, out int fieldIndex))
            {
                if (pooledFields[fieldIndex].Count > 0)
                {
                    result = pooledFields[fieldIndex].Pop();
                    result.transform.SetParent(parent);
                }
                else
                {
                    result       = Instantiate(fieldPrefabs[fieldIndex], parent);
                    result.UI    = LevelEditor.UI;
                    result.Index = fieldIndex;
                }
            }
            else
            {
                int selectedIndex = -1;

                for (int i = 0; i < fieldPrefabs.Length; i++)
                {
                    if (fieldPrefabs[i].SupportsTypeDirect(fieldType))
                    {
                        selectedIndex = i;
                        break;
                    }

                    if (fieldPrefabs[i].SupportsType(fieldType, fieldType.IsArray))
                    {
                        selectedIndex = i;
                    }
                }

                if (selectedIndex >= 0)
                {
                    fields.Add(type, selectedIndex);
                    if (!pooledFields.ContainsKey(selectedIndex))
                    {
                        pooledFields.Add(selectedIndex, new Stack <LevelEditorInspectorField>());
                    }

                    result       = Instantiate(fieldPrefabs[selectedIndex], parent);
                    result.Index = selectedIndex;
                }
            }

            if (result == null)
            {
                Debug.LogWarning("No field that supports " + fieldType.FullName);
                return(null);
            }

            activeFields.Add(result);

            result.gameObject.SetActive(true);
            result.transform.SetAsLastSibling();
            return(result);
        }
コード例 #8
0
        public void BindObject(ILevelEditorObject target)
        {
            boundItem = target;

            for (int i = activeFields.Count - 1; i >= 0; i--)
            {
                PoolField(activeFields[i]);
            }

            for (int i = 0; i < activeComponents.Count; i++)
            {
                if (activeComponents[i].Editor != null)
                {
                    activeComponents[i].Editor.Deconstruct();
                }

                pooledComponents.Push(activeComponents[i]);
                activeComponents[i].gameObject.SetActive(false);
            }

            activeComponents.Clear();

            if (objectInfoHolder != null)
            {
                objectInfoHolder.SetActive(target != null);
            }

            if (target != null)
            {
                if (objectActiveToggle != null)
                {
                    objectActiveToggle.SetIsOnWithoutNotify(target.MyGameObject.activeSelf);
                }

                if (objectNameField != null)
                {
                    objectNameField.SetTextWithoutNotify(target.MyGameObject.name);
                }

                IExposedToLevelEditor[] components = target.GetExposedComponents();
                for (int i = 0; i < components.Length; i++)
                {
                    if (!components[i].HasVisibleFields)
                    {
                        continue;
                    }

                    if (!includeTransform && components[i].ComponentType == typeof(Transform))
                    {
                        continue;
                    }

                    LevelEditorComponentUI compUI = GetComponentUI();
                    compUI.Title = components[i].ComponentName;

                    if (LevelEditorComponentEditor.TryGetEditor(components[i].ComponentType, out LevelEditorComponentEditor editor))
                    {
                        editor.Initialize(this, (Component)components[i], components[i], compUI.FieldHolder);
                        editor.BuildUI();
                        compUI.Editor = editor;
                    }
                    else
                    {
                        IReadOnlyList <ExposedField> properties = components[i].GetProperties();
                        for (int j = 0; j < properties.Count; j++)
                        {
                            if (!properties[j].IsVisible)
                            {
                                continue;
                            }

                            if (!HasField(properties[j].Type))
                            {
                                continue;
                            }

                            LevelEditorInspectorField field = GetField(properties[j].Type, compUI.FieldHolder);
                            field.Depth = 0;
                            field.Bind(properties[j], components[i]);
                        }
                    }
                }
            }
        }