private void Awake()
        {
            m_editor = IOC.Resolve <IRTE>();

            m_layersInfo = (LayersInfo)m_editor.Selection.activeObject;

            foreach (LayersInfo.Layer layer in m_layersInfo.Layers)
            {
                GameObject editor = Instantiate(m_editorPrefab, m_editorsPanel, false);

                TextMeshProUGUI text = editor.GetComponentInChildren <TextMeshProUGUI>(true);
                if (text != null)
                {
                    text.text = layer.Index + ": ";
                }

                StringEditor stringEditor = editor.GetComponentInChildren <StringEditor>(true);
                if (stringEditor != null)
                {
                    if (layer.Index <= 5)
                    {
                        TMP_InputField inputField = stringEditor.GetComponentInChildren <TMP_InputField>(true);
                        inputField.selectionColor = new Color(0, 0, 0, 0);
                        inputField.readOnly       = true;
                    }

                    stringEditor.Init(layer, layer, Strong.MemberInfo((LayersInfo.Layer x) => x.Name), null, string.Empty, null, () => m_isDirty = true, null, false);
                }
            }
        }
Esempio n. 2
0
        public override PropertyDescriptor[] GetProperties(ComponentEditor editor, object converter)
        {
            object[] converters = (object[])converter;

            ILocalization lc = IOC.Resolve <ILocalization>();

            PropertyEditorCallback valueChanged     = () => editor.BuildEditor();
            MemberInfo             projection       = Strong.PropertyInfo((CameraPropertyConverter x) => x.Projection, "Projection");
            MemberInfo             orthographic     = Strong.PropertyInfo((Camera x) => x.orthographic, "orthographic");
            MemberInfo             fov              = Strong.PropertyInfo((Camera x) => x.fieldOfView, "fieldOfView");
            MemberInfo             orthographicSize = Strong.PropertyInfo((Camera x) => x.orthographicSize, "orthographicSize");
            MemberInfo             cullingMask      = Strong.PropertyInfo((Camera x) => x.cullingMask, "cullingMask");

            List <PropertyDescriptor> descriptors = new List <PropertyDescriptor>();

            descriptors.Add(new PropertyDescriptor(lc.GetString("ID_RTEditor_CD_Camera_Projection", "Projection"), converters, projection, orthographic, valueChanged));

            Camera[] cameras = editor.NotNullComponents.OfType <Camera>().ToArray();
            if (cameras.Length > 0)
            {
                bool isCameraOrthographic = cameras[0].orthographic;
                for (int i = 1; i < cameras.Length; ++i)
                {
                    if (cameras[i].orthographic != isCameraOrthographic)
                    {
                        return(descriptors.ToArray());
                    }
                }

                if (!isCameraOrthographic)
                {
                    descriptors.Add(new PropertyDescriptor(lc.GetString("ID_RTEditor_CD_Camera_Fov", "Field Of View"), editor.Components, fov, "field of view"));
                }
                else
                {
                    descriptors.Add(new PropertyDescriptor(lc.GetString("ID_RTEditor_CD_Camera_Size", "Size"), editor.Components, orthographicSize, "orthographic size"));
                }

                List <RangeOptions.Option> flags = new List <RangeOptions.Option>();
                LayersInfo layersInfo            = LayersEditor.LoadedLayers;
                foreach (LayersInfo.Layer layer in layersInfo.Layers)
                {
                    if (!string.IsNullOrEmpty(layer.Name))
                    {
                        flags.Add(new RangeOptions.Option(layer.Name, layer.Index));
                    }
                }


                descriptors.Add(new PropertyDescriptor(lc.GetString("ID_RTEditor_CD_Camera_CullingMask", "Culling Mask"), editor.Components, cullingMask)
                {
                    Range = new RangeFlags(flags.ToArray())
                });
            }

            return(descriptors.ToArray());
        }
        protected override void InitOverride(object[] target, object[] accessor, MemberInfo memberInfo, Action <object, object> eraseTargetCallback, string label = null)
        {
            List <RangeOptions.Option> options = new List <RangeOptions.Option>();
            LayersInfo layersInfo = LayersEditor.LoadedLayers;

            foreach (LayersInfo.Layer layer in layersInfo.Layers)
            {
                if (!string.IsNullOrEmpty(layer.Name))
                {
                    options.Add(new RangeOptions.Option(layer.Name, layer.Index));
                }
            }

            Options = options.ToArray();

            base.InitOverride(target, accessor, memberInfo, eraseTargetCallback, label);
        }
        private static IEnumerator CoLoadLayer(Action <LayersInfo> callback)
        {
            IProject project = IOC.Resolve <IProject>();

            if (m_loadedLayers == null || project.ProjectInfo.Name != m_currentProject)
            {
                m_currentProject = project.ProjectInfo.Name;

                ProjectAsyncOperation <RuntimeTextAsset> getLayersInfoAo = project.GetValue <RuntimeTextAsset>("Battlehub.RTEditor.LayersInfo");
                yield return(getLayersInfoAo);

                if (getLayersInfoAo.HasError)
                {
                    if (getLayersInfoAo.Error.ErrorCode != Error.E_NotFound)
                    {
                        Debug.LogErrorFormat("Unable to load LayersInfo {0}", getLayersInfoAo.Error);
                        yield break;
                    }

                    m_loadedLayers        = ScriptableObject.CreateInstance <LayersInfo>();
                    m_loadedLayers.Layers = new List <LayersInfo.Layer>
                    {
                        new LayersInfo.Layer("Default", 0),
                        new LayersInfo.Layer("Transparent FX", 1),
                        new LayersInfo.Layer("Ignore Raycast", 2),
                        new LayersInfo.Layer("Water", 4),
                        new LayersInfo.Layer("UI", 5)
                    };

                    for (int i = 10; i <= 15; ++i)
                    {
                        m_loadedLayers.Layers.Add(new LayersInfo.Layer(LayerMask.LayerToName(i), i));
                    }

                    for (int i = 25; i <= 30; ++i)
                    {
                        m_loadedLayers.Layers.Add(new LayersInfo.Layer(LayerMask.LayerToName(i), i));
                    }

                    RuntimeTextAsset layersTextAsset = ScriptableObject.CreateInstance <RuntimeTextAsset>();
                    layersTextAsset.Text = JsonUtility.ToJson(m_loadedLayers);

                    ProjectAsyncOperation setLayersInfoAo = project.SetValue("Battlehub.RTEditor.LayersInfo", layersTextAsset);
                    yield return(setLayersInfoAo);

                    if (setLayersInfoAo.HasError)
                    {
                        Debug.LogErrorFormat("Unable to set LayersInfo {0}", setLayersInfoAo.Error);
                        yield break;
                    }
                }
                else
                {
                    m_loadedLayers = ScriptableObject.CreateInstance <LayersInfo>();
                    JsonUtility.FromJsonOverwrite(getLayersInfoAo.Result.Text, m_loadedLayers);

                    foreach (LayersInfo.Layer layer in m_loadedLayers.Layers)
                    {
                        if (string.IsNullOrEmpty(layer.Name))
                        {
                            layer.Name = LayerMask.LayerToName(layer.Index);
                        }
                    }
                }
            }

            callback(m_loadedLayers);
        }