protected override bool ValidateObject(UTinyObject tiny, UTinyType type) { if (type.TypeCode == UTinyTypeCode.Component) { return(Targets.Cast <UTinyEntity>().All(e => e.Components.Any(c => c.Type.Id == tiny.Type.Id))); } return(base.ValidateObject(tiny, type)); }
override protected void OnBeginCapture(Ray3f worldRay, Standard3DWidget w) { foreach (var v in Widgets) { if (v.Value is SnapDragSourceWidget) { (v.Value as SnapDragSourceWidget).TargetObjects = new List <SceneObject>(Targets.Cast <SceneObject>()); } } }
protected override void OnPrepare() { base.OnPrepare(); var viewers = Targets.Cast <UTinyConfigurationViewer>(); // ReSharper disable once PossibleMultipleEnumeration foreach (var viewer in viewers) { viewer.Entity?.Refresh(); } }
public override void OnAlloySceneGUI(SceneView sceneView) { Material[] allMaterials = Targets.Cast <Material>().ToArray(); foreach (var drawer in m_fieldDrawers) { if (drawer != null) { drawer.OnSceneGUI(this, allMaterials); } } }
public override void OnAlloySceneGUI(SceneView sceneView) { foreach (var drawer in m_propInfo) { if (drawer.Value == null) { continue; } drawer.Value.Serialized = GetProperty(drawer.Key.type, drawer.Key.name); drawer.Value.OnSceneGUI(Targets.Cast <Material>().ToArray()); } }
public override void Visit() { var entity = Targets.Cast <UTinyConfigurationViewer>().FirstOrDefault()?.Entity; if (null == entity) { return; } IPropertyContainer c = entity; c.Visit(this); }
protected override void OnPrepare() { base.OnPrepare(); var registry = Registry; Targets = Targets .Cast <UTinyEntity>() .Select(t => registry.FindById <UTinyEntity>(t.Id)) .Where(t => null != t) .Cast <IPropertyContainer>().ToList(); foreach (var component in Targets.Cast <UTinyEntity>().SelectMany(e => e.Components)) { component.Refresh(); } }
protected override void OnPrepare() { base.OnPrepare(); var viewers = Targets.Cast <UTinyTypeViewer>(); // ReSharper disable once PossibleMultipleEnumeration foreach (var viewer in viewers) { viewer.Type?.Refresh(); } var type = viewers.First().TypeRef; var project = UTinyEditorApplication.Project; var module = project.Module.Dereference(Registry); if (!module.Types.Contains(type)) { GUI.enabled = false; } }
public override void Visit() { base.Visit(); GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); var content = new GUIContent("Add Tiny Component"); Rect rect = GUILayoutUtility.GetRect(content, UTinyStyles.AddComponentStyle); if (EditorGUI.DropdownButton(rect, content, FocusType.Passive, UTinyStyles.AddComponentStyle)) { var targets = Targets.Cast <UTinyEntity>(); AddComponentWindow.Show(rect, targets.First().Registry, Targets.Cast <UTinyEntity>().ToArray()); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); }
protected override void OnComplete() { base.OnComplete(); if (Changes.Count == 0) { return; } var type = Targets.Cast <UTinyTypeViewer>().First().Type; var binding = type.GetAttribute <BindingsAttribute>()?.Binding; if (null == binding) { return; } var typeRef = (UTinyType.Reference)type; foreach (var entityGroupRef in UTinyEditorApplication.EntityGroupManager.LoadedEntityGroups) { var entityGroup = entityGroupRef.Dereference(Registry); if (null == entityGroup) { continue; } foreach (var entityRef in entityGroup.Entities) { var entity = entityRef.Dereference(Registry); var component = entity?.GetComponent(typeRef); if (component == null) { continue; } component.Refresh(null, true); binding.Run(BindingTiming.OnUpdateBindings, entity, component); } } GUI.enabled = true; }
private void AddMissingComponent(ComponentInfo info) { var enabled = GUI.enabled; GUI.enabled &= info.Enabled; if (null == Target.GetComponent(info.GetTypeRef(Registry))) { EditorGUILayout.BeginHorizontal(); GUILayout.Space(15.0f); if (GUILayout.Button("+", GUILayout.Width(20))) { foreach (var entity in Targets.Cast <UTinyEntity>()) { entity.GetOrAddComponent(info.GetTypeRef(Registry)); } } EditorGUILayout.LabelField(info.ButtonName); EditorGUILayout.EndHorizontal(); } GUI.enabled = enabled; }
protected override void OnAlloyShaderGUI() { var args = new AlloyFieldDrawerArgs() { Editor = this, Materials = Targets.Cast <Material>().ToArray(), PropertiesSkip = new List <string>(), MatInst = MatInst, TabGroup = TabGroup, AllTabNames = m_allTabs, OpenCloseAnim = m_openCloseAnim }; foreach (var animBool in m_openCloseAnim) { if (animBool.Value.isAnimating) { MatEditor.Repaint(); } } foreach (var kv in m_propInfo) { var drawer = kv.Value; if (drawer != null && drawer.ShouldDraw(args)) { drawer.Draw(args); } } if (!string.IsNullOrEmpty(args.CurrentTab)) { EditorGUILayout.EndFadeGroup(); } GUILayout.Space(10.0f); AlloyEditor.DrawAddTabGUI(args.TabsToAdd); }
private void ShowRemoveComponent(UTinyType.Reference typeRef) { var type = typeRef.Dereference(Registry); if ((null == type || type.TypeCode == UTinyTypeCode.Component) && TargetType == typeof(UTinyEntity)) { var rect = EditorGUILayout.GetControlRect(false, GUILayout.Width(16.0f)); if (GUI.Button(rect, UTinyIcons.X_Icon_8, UTinyStyles.MiddleCenteredLabel)) { var targets = Targets.Cast <UTinyEntity>().ToList(); EditorApplication.delayCall += () => { foreach (var entity in targets.Cast <UTinyEntity>()) { entity.RemoveComponent(typeRef); } // This is called manually because we want the scene graphs to be recreated. UTinyEventDispatcher <ChangeSource> .Dispatch(ChangeSource.DataModel); }; } GUILayout.Space(5.0f); } }
private void ShowRemoveComponent(UTinyType.Reference typeRef) { var type = typeRef.Dereference(Registry); if ((null == type || type.TypeCode == UTinyTypeCode.Component) && TargetType == typeof(UTinyEntity)) { var rect = EditorGUILayout.GetControlRect(false, GUILayout.Width(16.0f)); if (GUI.Button(rect, UTinyIcons.X_Icon_8, UTinyStyles.MiddleCenteredLabel)) { var targets = Targets.Cast <UTinyEntity>().ToList(); EditorApplication.delayCall += () => { foreach (var entity in targets.Cast <UTinyEntity>()) { entity.RemoveComponent(typeRef); } UTinyHierarchyWindow.InvalidateDataModel(); UTinyInspector.RepaintAll(); }; } GUILayout.Space(5.0f); } }
protected override void OnAlloyShaderGUI(MaterialProperty[] properties) { //Refresh drawer structure if needed bool structuralChange = false; if (m_fieldDrawers == null || m_fieldDrawers.Length != properties.Length) { m_fieldDrawers = new AlloyFieldDrawer[properties.Length]; structuralChange = true; } //Rebuild name -> prop cache m_stringToProperty.Clear(); for (int i = 0; i < properties.Length; ++i) { string propName = properties[i].name; m_stringToProperty.Add(propName, properties[i]); } for (int i = 0; i < properties.Length; ++i) { string propName = properties[i].name; if (m_fieldDrawers[i] == null && !s_knownNulls.Contains(propName) || m_fieldDrawers[i] != null && m_fieldDrawers[i].Property.name != propName) { m_fieldDrawers[i] = AlloyFieldDrawerFactory.GetFieldDrawer(this, properties[i]); if (m_fieldDrawers[i] == null) { s_knownNulls.Add(propName); } else { structuralChange = true; } } } //If changed, update the animation stuff if (structuralChange) { m_openCloseAnim.Clear(); var allTabs = new List <string>(); for (var i = 0; i < m_fieldDrawers.Length; i++) { var drawer = m_fieldDrawers[i]; if (!(drawer is AlloyTabDrawer)) { continue; } bool isOpenCur = TabGroup.IsOpen(drawer.DisplayName + MatInst); var anim = new AnimBool(isOpenCur) { speed = 6.0f, value = isOpenCur }; m_openCloseAnim.Add(properties[i].name, anim); allTabs.Add(drawer.DisplayName); } m_allTabs = allTabs.ToArray(); } //Formulate arguments to pass to drawing var args = new AlloyFieldDrawerArgs { Editor = this, Materials = Targets.Cast <Material>().ToArray(), PropertiesSkip = new List <string>(), MatInst = MatInst, TabGroup = TabGroup, AllTabNames = m_allTabs, OpenCloseAnim = m_openCloseAnim }; for (var i = 0; i < m_fieldDrawers.Length; i++) { var drawer = m_fieldDrawers[i]; if (drawer == null) { continue; } drawer.Index = i; drawer.Property = properties[i]; if (drawer.ShouldDraw(args)) { drawer.Draw(args); } } if (!string.IsNullOrEmpty(args.CurrentTab)) { EditorGUILayout.EndFadeGroup(); } GUILayout.Space(10.0f); AlloyEditor.DrawAddTabGUI(args.TabsToAdd); //If animating -> Repaint foreach (var animBool in m_openCloseAnim) { if (animBool.Value.isAnimating) { MatEditor.Repaint(); break; } } }
public override void Header() { var entities = Targets.Cast <UTinyEntity>(); var firstEntity = entities.FirstOrDefault(); if (null == firstEntity) { return; } UTinyGUI.BackgroundColor(new Rect(0, 0, Screen.width, 15 + 2 * UTinyGUIUtility.SingleLineAndSpaceHeight), UTinyColors.Inspector.HeaderBackground); GUILayout.Space(10); var name = firstEntity.Name; name = entities.All(entity => entity.Name == name) ? name : "-"; var enabled = firstEntity.Enabled; var sameEnabled = entities.All(tiny => tiny.Enabled == enabled); using (new EditorGUILayout.HorizontalScope()) { EditorGUI.BeginChangeCheck(); var mixed = EditorGUI.showMixedValue; EditorGUI.showMixedValue = !sameEnabled; enabled = EditorGUILayout.ToggleLeft(GUIContent.none, enabled, GUILayout.Width(EditorGUIUtility.singleLineHeight)); EditorGUI.showMixedValue = mixed; if (EditorGUI.EndChangeCheck()) { foreach (var entity in entities) { entity.Enabled = enabled; entity.View.gameObject.SetActive(enabled); } UTinyHierarchyWindow.InvalidateDataModel(); UTinyEditorUtility.RepaintAllWindows(); } EditorGUI.BeginChangeCheck(); name = EditorGUILayout.DelayedTextField(name, UTinyStyles.ComponentHeaderStyle); if (EditorGUI.EndChangeCheck()) { foreach (var entity in entities) { entity.Name = name; } UTinyHierarchyWindow.InvalidateDataModel(); UTinyEditorUtility.RepaintAllWindows(); } GUILayout.Space(EditorGUIUtility.singleLineHeight); } var layer = firstEntity.Layer; var sameLayer = entities.All(tiny => tiny.Layer == layer); using (new EditorGUILayout.HorizontalScope()) { GUILayout.Space(50); EditorGUILayout.LabelField("Layer", GUILayout.Width(50)); EditorGUI.BeginChangeCheck(); var mixed = EditorGUI.showMixedValue; EditorGUI.showMixedValue = !sameLayer; layer = EditorGUILayout.LayerField(layer); if (EditorGUI.EndChangeCheck()) { foreach (var entity in entities) { entity.Layer = layer; entity.View.gameObject.layer = layer; } UTinyHierarchyWindow.InvalidateDataModel(); UTinyEditorUtility.RepaintAllWindows(); } GUILayout.Space(EditorGUIUtility.singleLineHeight); EditorGUI.showMixedValue = mixed; } GUILayout.Space(5); UTinyGUILayout.Separator(UTinyColors.Inspector.Separator, UTinyGUIUtility.ComponentHeaderSeperatorHeight); }