protected bool CheckSelection(bool mustBeContainer, bool renderMessage = true) { if (null == Selection.activeTransform) { if (renderMessage) { GUILayout.Label(GuiContentCache.Instance.NoSelectionContent, StyleCache.Instance.CenteredLabel, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); } return(false); } Adapter = GuiLookup.GetAdapter(Selection.activeTransform); GroupAdapter = Adapter as GroupAdapter; if (null == Adapter) { if (renderMessage) { GUILayout.Label(GuiContentCache.Instance.NotEDrivenComponentContent, StyleCache.Instance.CenteredLabel, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); } return(false); } if (mustBeContainer && null == GroupAdapter) { if (renderMessage) { GUILayout.Label(GuiContentCache.Instance.NotAContainerContent, StyleCache.Instance.CenteredLabel, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); } return(false); } return(true); }
internal void Select(DisplayObject target) { var dlm = target as DisplayListMember; // do not analyze anything from this stage if (null != dlm && !DesignerOverlay.IsInspectable(dlm)) { return; } var go = GuiLookup.GetGameObject((Component)target); if (null != go) { _selectionOverlay.Visible = true; var bounds = target.Transform.GlobalBounds; /** * 1. Expand around component * */ bounds = bounds.Expand(PlayModeOverlaySelectionBorderStyle.BorderWidth); /** * 2. Constrain with stage bounds * */ bounds.ConstrainWithin(Rectangle.FromSize(SystemManager.Instance.ScreenSize)); _selectionOverlay.Redraw(bounds, Bounds, GuiLookup.PathToString(go.transform, " -> ")); _selectionOverlay.ValidateNow(); } }
public static void Process(List <Node> nodes) { if (nodes.Count == 0) { return; } //Debug.Log(string.Format("Processing {0} top level additions in edit mode.", nodes.Count)); foreach (Node node in nodes) { /** * 1. Process transforms * */ Transform transform = node.Transform; if (null == transform) { continue; // ROOT } ComponentAdapter adapter = GuiLookup.GetAdapter(transform); bool isStage = adapter is StageAdapter; Transform parentTransform = node.ParentTransform; /* This happens when a stage added to root */ if (null == parentTransform && !isStage) { continue; // not a stage, return (if stage, should process) } GroupAdapter parentAdapter = null; if (null != parentTransform) { parentAdapter = GuiLookup.GetAdapter(node.ParentTransform) as GroupAdapter; } /** * 2. Process adapters * */ if (null != adapter) { // this is eDriven.Gui component. process it properly if (null == parentAdapter) { if (!isStage) { const string txt = "eDriven.Gui components could be added to containers only"; throw new Exception(txt); } } else { parentAdapter.AddChild(adapter, true); //if (!PrefabUtil.IsCreatedFromPrefab(parentAdapter)) ParentChildLinker.Instance.Update(parentAdapter); } } } }
// ReSharper restore UnassignedField.Global #endif internal static void Process(List <Node> removals) { if (0 == removals.Count) { return; } #if DEBUG if (DebugMode) { Debug.Log(string.Format("Processing {0} removals.", removals.Count)); } #endif //Debug.Log(string.Format("Processing {0} removals.", removals.Count)); // TODO: do removals bottom up! nesting level should be used here foreach (Node node in removals) { //if (null == node.Transform) // continue; // ROOT node.RemoveFromHierarchy(); //Debug.Log("node.ParentTransform: " + node.ParentTransform); if (null == node.ParentTransform) //|| /*!*/(adapter is StageAdapter)) { continue; // not a stage, return (if stage, should process) } // consolidate parent transform ComponentAdapter adapter = node.Adapter; GroupAdapter parentGroupAdapter = GuiLookup.GetAdapter(node.ParentTransform) as GroupAdapter; if (null != parentGroupAdapter) { /** * Stop monitoring * */ PersistenceManager.Instance.Unwatch(node.AdapterId); //PersistenceManager.Instance.RemoveAdapter(node.AdapterId); /** * Note: if object removed from the hierarchy, the adapter is destroyed * In that case following command doesn nothing (doesn not remove the slot from the parent) * Thus we have the consolidation below (removing null) * */ parentGroupAdapter.RemoveChild(adapter); // TODO: consolidate only for top level removals (add parameter) /*parentContainerAdapter.RemoveChild(adapter);*/ //parentContainerAdapter.RemoveAllChildren(); ChildGroupPack pack = ChildGroupPack.Read(parentGroupAdapter); pack.Consolidate(); // there is a null slot here. We have to re-render children //Debug.Log("*pack: " + pack); parentGroupAdapter.InstantiateChildren(true); } } }
public Node(Transform transform) { _transform = transform; if (null != _transform) { _parentTransform = _transform.parent; } if (null == transform) { _name = "ROOT"; } else { _name = transform.name; _transformId = transform.GetInstanceID(); _adapter = transform.GetComponent <ComponentAdapter>(); if (null != _adapter) { _adapterId = _adapter.GetInstanceID(); } } _description = string.Format("[{0}]", GuiLookup.PathToString(transform, "->")); }
internal static void Process(List <Node> nodes) { if (nodes.Count == 0) { return; } //Debug.Log(string.Format("Processing {0} top level removals in edit mode.", nodes.Count)); foreach (Node node in nodes) { if (null == node.ParentTransform) { continue; } GroupAdapter parentGroupAdapter = GuiLookup.GetAdapter(node.ParentTransform) as GroupAdapter; if (null != parentGroupAdapter) { /** * Important: the removal could happen when we *move* components outside of the Stage hierarchy * From group's standpoint, these components have been *removed* * However, the adapters are not null, so the consolidation without a prior * removal would do nothing to the parent collection (e.g. the moved adapter * would still be on the list) * */ parentGroupAdapter.RemoveChild(node.Adapter); ChildGroupPack pack = ChildGroupPack.Read(parentGroupAdapter); pack.Consolidate(); // there is a null slot here. We have to re-render children } } }
public void RemoveDialog(Event e) { Button button = e.Target as Button; if (button != null) { Dialog dialog = GuiLookup.FindParent <Dialog>(button); PopupManager.Instance.RemovePopup(dialog); } }
public void RemoveButtonColor(Event e) { // GUI lookup example Button button = GuiLookup.GetComponent("button1") as Button; if (null != button) { button.Color = Color.white; } }
public void PaintButtonGreen(Event e) { // GUI lookup example Button button = GuiLookup.GetComponent("button1") as Button; if (null != button) { button.Color = Color.green; } }
public void ChangeButtonColor(Event e) { // GUI lookup example Button button = GuiLookup.FindComponent <Button>(gameObject, "button1"); if (null != button) { button.Color = Color.green; } }
public void OnClick(eDriven.Core.Events.Event e) { //eDriven.Core.Events.MouseEvent e2 = (eDriven.Core.Events.MouseEvent)e; Component component = GuiLookup.Produce("dialog"); //Debug.Log("Popping up " + component); if (null != component) { PopupManager.Instance.AddPopup(component, false); // modal = false } }
/*public static List<EventAttribute> GetEvents(Type componentType) * { * object[] list = componentType.GetCustomAttributes(typeof(EventAttribute), true); * var events = new List<EventAttribute>(); * foreach (var e in list) * { * events.Add((EventAttribute) e); * } * return events; * }*/ private static void GetEventsRecursive(ComponentAdapter clickedAdapter, ComponentAdapter currentAdapter, ref Dictionary <string, EventAttribute> dict, bool bubbling, ICollection <ComponentAdapter> adaptersToExclude) { Type componentType = currentAdapter.ComponentType; if (null == adaptersToExclude || !adaptersToExclude.Contains(currentAdapter)) { //object[] list = componentType.GetCustomAttributes(typeof (EventAttribute), true); var eventAttributes = CoreReflector.GetClassAttributes <EventAttribute>(componentType); foreach (EventAttribute attribute in eventAttributes) { if (clickedAdapter == currentAdapter) { /** * 1. If this is a clicked adapter, get all events * */ dict[attribute.Name] = attribute; } else if (bubbling && attribute.Bubbles) // if (bubbling) { /** * 2. Else get only events that may bubble from children * */ dict[attribute.Name] = attribute; } /*if (!bubbling || attribute.Bubbles) // if (bubbling) * { * // bubbling events only * if (attribute.Bubbles) * dict[attribute.Name] = attribute; * } * else * { * // target events only * dict[attribute.Name] = attribute; * }*/ //Debug.Log(" --> " + attribute.Name); } } if (bubbling) { Transform transform = currentAdapter.transform; var childCount = transform.childCount; for (int i = 0; i < childCount; i++) { var childTransform = transform.GetChild(i); ComponentAdapter childAdapter = GuiLookup.GetAdapter(childTransform); GetEventsRecursive(clickedAdapter, childAdapter, ref dict, true, adaptersToExclude); } } }
/// <summary> /// Removes all children /// </summary> public virtual void RemoveAllChildren() { for (int i = transform.childCount - 1; i >= 0; i--) { var childAdapter = GuiLookup.GetAdapter(transform.GetChild(i)); //Debug.Log("childAdapter: " + childAdapter); if (null != childAdapter) { RemoveChild(childAdapter); } } ContentChildren.Clear(); }
/// <summary> /// Monitors the object for property changes<br/> /// Monitoring an object means putting it on the list which will be checked for changes after the play mode is stopped<br/> /// When put on the list, all the original properties of the object are being saved (cloned)<br/> /// When play mode stopped, properties are being read from all the monitored objects<br/> /// For each property, the original and current value are being compared for change<br/> /// and the changed value list is being made<br/> /// Changed values are being applied to an object "resurrected" by Unity, after the play mode is stopped<br/> /// Here we are monitoring eDriven.Gui COMPONENTS, not transforms or game objects<br/> /// (however, they could also be monitored in some other scenario)<br/> /// </summary> /// <param name="target">Target (component) to monitor</param> public void Watch(Object target) { /** * 1. Get the instance ID because it is the key in the dictionary holding the monitored objects * */ int instanceId = target.GetInstanceID(); //Debug.Log("* Monitoring: " + instanceId); /** * 2. We need to check if the object is already being monitored * This is important because we must not overwrite the original values each time the component is being clicked * because this might lead to the loss of data (only changes from the last component click would be then be saved as the original values) * For instance, take a look at this scenario: * - this component click. Changing the text to "foo". * - other component click. * - this component click. Changing the color to green. * In play mode, all the changes would be accumulated, and there would seem to be no problems. * But after the play mode is stopped, and started again, we would discover that only the component color is being changed to green, * and no text has been changed - due to second component click rewriting the "original" values, thus deleting the change to "foo" * */ if (_monitoredObjects.ContainsKey(instanceId)) { return; } #if DEBUG if (DebugMode) { ComponentAdapter componentAdapter = target as ComponentAdapter; if (null != componentAdapter) { Debug.Log("Monitoring: " + GuiLookup.PathToString(componentAdapter.transform, " -> "), componentAdapter.transform); } } #endif /** * 3. This is the first time we are monitoring this object * Create a new PersistedComponent instance and add it to dictionary * */ _monitoredObjects[instanceId] = new PersistedComponent(target); //_currentInstanceId = target.GetInstanceID(); #if DEBUG if (DebugMode) { Debug.Log(string.Format(" Added [{0}] to monitored objects list. Total: {1}", target.name, _monitoredObjects.Count), target); } #endif //MonitoredObjectAddedSignal.Emit(target); }
public void ApplyChanges() { #if DEBUG if (DebugMode) { StringBuilder sb = new StringBuilder(); foreach (PersistedComponent persistedObject in MonitoredObjects.Values) { //Debug.Log("persistedObject.Target: " + persistedObject.Target); if (null == persistedObject.Target) { sb.AppendLine("Target is null"); } else { var target = persistedObject.Target; // as ComponentAdapterBase; // it doesn't have to be ComponentAdapterBase (if it is a stylesheet for instance) if (target is ComponentAdapterBase) { var transform = (target as ComponentAdapterBase).transform; sb.AppendLine(GuiLookup.PathToString(transform, " -> ")); } else if (target is eDrivenStyleSheet) { //var transform = (target as eDrivenStyleSheetBase).transform; sb.AppendLine("--- Stylesheet"); } } } // Debug.Log(string.Format(@"Applying changes to {0} components: //{1}", _monitoredObjects.Values.Count, sb)); } #endif /** * 3. Handle value changes * Each persistant object has the list of changes (delta between the original and final values) * This changes are being applied by calling the ApplyChanges on each persisted object * Internally, PersistedComponent handles the case of negative or positive instance IDs, * thus looking up for objects using the appropriate lookup * */ foreach (PersistedComponent persistedObject in _monitoredObjects.Values) { persistedObject.ApplyChanges(); } _monitoredObjects.Clear(); }
private static void ProcessMouseEvent(InputEvent e) { //Debug.Log(string.Format("e: {0}", e)); //Debug.Log(string.Format("e.CurrentEvent.button: {0}", e.CurrentEvent.button)); //switch (e.CurrentEvent.button) switch (e.Type) { //case 0: // left button case MouseEvent.RIGHT_CLICK: // left button MainTabBar.Instance.TabIndex = MainWindow.ORDER_DISPLAY; // order break; //case 0: // left button case MouseEvent.RIGHT_DOUBLE_CLICK: // left button MainTabBar.Instance.TabIndex = MainWindow.ORDER_DISPLAY; // order ToolboxDialog.Instance.ShowUtility(); break; case MouseEvent.MIDDLE_CLICK: // middle button MainTabBar.Instance.TabIndex = MainWindow.LAYOUT_DISPLAY; // layout break; case MouseEvent.DOUBLE_CLICK: // double click if (EditorSettings.MouseDoubleClickEnabled) { // show events dialog MainTabBar.Instance.TabIndex = MainWindow.EVENTS_DISPLAY; //Debug.Log("ProcessMouseEvent: " + @e.CurrentEvent.button); var adapter = GuiLookup.GetAdapter(Selection.activeTransform); if (null == adapter) { Debug.LogError("No adapter found"); return; } // bring up the Add Event Handler dialog var dialog = AddEventHandlerDialog.Instance; dialog.Reset(); dialog.Adapter = adapter; dialog.ShowUtility(); } break; } }
/// <summary> /// Removes all children /// </summary> override public void RemoveAllChildren() { if (!Instantiated || !DesignerState.IsPlaying) // not instantiated // 20130512 { return; } for (int i = transform.childCount - 1; i >= 0; i--) { var childAdapter = GuiLookup.GetAdapter(transform.GetChild(i)); if (null != childAdapter) { RemoveChild(childAdapter); } } ContentChildren.Clear(); }
/// <summary> /// Fires on mouse-overed component change<br/> /// Since in editor overlay we are dealing with adapters, we need to examine if the mouse-overed component is related to any adapter<br/> /// We do that by looking for the adapter via GuiLookup, which finds the adapter in component parent<br/> /// We then examine if the current selection changed. If it did, we are calling the Select method /// </summary> private void MouseOverSlot(params object[] parameters) { Component comp = (Component)parameters[0]; #if DEBUG if (DebugMode) { Debug.Log("DesignerOverlay->MouseOverSlot: " + comp); } #endif if (null == comp) { return; } GameObject go = GuiLookup.GetGameObject(comp); if (null == go) { return; } ComponentAdapter adapter = (ComponentAdapter)go.GetComponent(typeof(ComponentAdapter)); if (null == adapter) { return; } if (null == adapter.Component) { return; } _hoveredComponent = adapter.Component; #if DEBUG if (DebugMode) { Debug.Log("Hover: " + _hoveredComponent); } #endif Hover(_hoveredComponent); }
internal void SpecialClickHandler(Event e) { #if DEBUG if (DebugMode) { Debug.Log("DesignerOverlay->SpecialClickHandler: " + e.Target); } #endif MouseEvent me = (MouseEvent)e; if (me.CurrentEvent.control || me.CurrentEvent.shift) { e.CancelAndStopPropagation(); // disable the actual button click in the capture phase. Sweet ^_^ } GameObject go = GuiLookup.GetGameObject((Component)e.Target); if (null == go) { _hoveredComponent = null; ClickSignal.Emit(null, e); return; } ComponentAdapter adapter = (ComponentAdapter)go.GetComponent(typeof(ComponentAdapter)); if (null == adapter) { _hoveredComponent = null; ClickSignal.Emit(null, e); return; } if (null == adapter.Component) { _hoveredComponent = null; ClickSignal.Emit(null, e); return; } _hoveredComponent = adapter.Component; ClickSignal.Emit(_hoveredComponent, e); }
private static void ApplyMonitoredComponents(Dictionary <int, PersistedComponent> monitoredComponents, StringBuilder sb) { if (0 == monitoredComponents.Count) { return; } sb.AppendLine(string.Format("Monitored components ({0}):", monitoredComponents.Count)); sb.AppendLine( "------------------------------------------------------------------------------------------------------------------------"); foreach (KeyValuePair <int, PersistedComponent> pair in monitoredComponents) { var adapter = pair.Value.Target as ComponentAdapter; var value = pair.Value.ToString(); if (null != adapter) { value = string.Format("{0} [{1}][{2}]", adapter.GetType().Name, pair.Key, GuiLookup.PathToString(adapter.transform, "->")); } sb.AppendLine(value); } sb.AppendLine(); }
// ReSharper restore UnassignedField.Global #endif /// <summary> /// Is processing additions, as well as top level additions /// </summary> /// <param name="topLevelAdditions">Needed for adding into order</param> /// <param name="additions">Needed for child instantiation</param> internal static void Process(List <Node> topLevelAdditions, List <Node> additions) { if (0 == topLevelAdditions.Count && 0 == additions.Count) { return; } #if DEBUG if (DebugMode) { Debug.Log(string.Format("Processing {0} topLevelAdditions, {1} additions.", topLevelAdditions.Count, additions.Count)); } #endif foreach (Node node in additions) { bool isTopLevelAddition = topLevelAdditions.Contains(node); bool isPrefab = PrefabUtility.GetPrefabType(node.Adapter) == PrefabType.PrefabInstance; /** * 1. Process transforms * */ Transform transform = node.Transform; if (null == transform) { continue; // ROOT } ComponentAdapter adapter = GuiLookup.GetAdapter(transform); bool isStage = adapter is StageAdapter; Transform parentTransform = node.ParentTransform; if (null == parentTransform && !isStage) { continue; // not a stage, return (if stage, should process) } GroupAdapter parentAdapter = null; if (null != parentTransform) { parentAdapter = GuiLookup.GetAdapter(node.ParentTransform) as GroupAdapter; } /** * 2. Process adapters * */ if (null != adapter) { // this is eDriven.Gui component. process it properly if (null == parentAdapter) { if (!isStage) { const string txt = "eDriven.Gui components could be added to containers only"; throw new Exception(txt); } } else { /** * Update parent ordering for top level additions only! * */ if (isTopLevelAddition) { //node.Transform.parent = parentTransform; parentAdapter.AddChild(adapter, true); // instantiate and change the parent collection // ReSharper disable once RedundantCheckBeforeAssignment if (adapter.transform.parent != parentTransform) // avoid multiple OnHierarchyChange callbacks { adapter.transform.parent = parentTransform; } //adapter.transform.parent = parentTransform; ParentChildLinker.Instance.Update(parentAdapter); } else { //parentAdapter.DoInstantiate(adapter, true); // instantiate only ChildGroupPack pack = ChildGroupPack.Read(parentAdapter); pack.Consolidate(); // there is a null slot here. We have to re-render children parentAdapter.InstantiateChildren(true); } /** * Instantiate component * */ if (!adapter.Instantiated) { adapter.DoInstantiate(true); } /** * By now, the component should be instantiated * */ var cmp = adapter.Component; if (null == cmp) { throw new Exception("Component not found on ComponentAdapter: " + adapter); } } } /** * 3. If adapter stuff went without a problem... * */ // ReSharper disable once RedundantCheckBeforeAssignment if (node.Transform.parent != parentTransform) { node.Transform.parent = parentTransform; } } }
// ReSharper restore UnassignedField.Global #endif internal static void Process(List <Node> moves) { #if DEBUG if (DebugMode) { Debug.Log(string.Format("Processing {0} moves.", moves.Count)); } #endif foreach (Node node in moves) { /** * 1. Process transforms * */ Transform transform = node.Transform; Transform parentTransform = node.ParentTransform; if (null == transform) { continue; // ROOT } //Debug.Log("node.Transform: " + transform); ComponentAdapter adapter = GuiLookup.GetAdapter(transform); bool thisIsStage = adapter is StageAdapter; /** * The adapter has been moved * It is still placed on the same (moved) transform * We are accessing the old and the new parent adapter via transforms: * - the old parent transform could be referenced using the node.OldParentTransform * - the new parent transform could be referenced using the node.ParentTransform * */ if (null == node.Transform) { throw new Exception("Transform is null"); } GroupAdapter oldParentAdapter = GuiLookup.GetAdapter(node.OldParentTransform) as GroupAdapter; GroupAdapter newParentAdapter = GuiLookup.GetAdapter(node.ParentTransform) as GroupAdapter; //Debug.Log(string.Format(" -> moving from [{0}] to [{1}]", oldParentAdapter, newParentAdapter)); /** * 2. Process adapters * */ if (null != oldParentAdapter) { oldParentAdapter.RemoveChild(adapter); ParentChildLinker.Instance.Update(oldParentAdapter); } if (null == newParentAdapter) { if (!thisIsStage) { const string txt = "eDriven.Gui components could be added to containers only"; //Debug.LogWarning(txt); throw new Exception(txt); } } else { newParentAdapter.AddChild(adapter, true); ParentChildLinker.Instance.Update(newParentAdapter); } /** * 3. If adapter stuff went without a problem... * */ node.Transform.parent = parentTransform; //ComponentAdapter adapter = GuiLookup.GetAdapter(transform); //bool thisIsStage = adapter is StageAdapter; ////Debug.Log("done."); //Transform parentTransform = node.ParentTransform; //if (null == parentTransform && !thisIsStage) // continue; // not a stage, return (if stage, should process) - only stage could be added to root //ContainerAdapter newParentAdapter = null; //if (null != parentTransform) // newParentAdapter = GuiLookup.GetAdapter(parentTransform) as ContainerAdapter; // /** // * 2. Process adapters // * */ // if (null != adapter) // { // // this is eDriven.Gui component. process it properly // if (null == newParentAdapter) // { // if (!thisIsStage) { // const string txt = "eDriven.Gui components could be added to containers only"; // //Debug.LogWarning(txt); // throw new Exception(txt); // //return; // } // } // else // { // ContainerAdapter oldParentAdapter = node.OldParentTransform.GetComponent<ContainerAdapter>(); // //Debug.Log("oldParentAdapter: " + oldParentAdapter); // //Debug.Log("newParentAdapter: " + newParentAdapter); // oldParentAdapter.RemoveChild(adapter); // newParentAdapter.AddChild(adapter, true); // ////if (!PrefabUtil.IsCreatedFromPrefab(oldParentAdapter)) // TODO: Need this? // // ParentChildLinker.Instance.Update(oldParentAdapter); // ////if (!PrefabUtil.IsCreatedFromPrefab(newParentAdapter)) // TODO: Need this? // // ParentChildLinker.Instance.Update(newParentAdapter); // if (EditorApplication.isPlaying) // { // if (!adapter.Instantiated) // adapter.DoInstantiate(true); // //Debug.Log(string.Format("OnHierarchyChange: Component instantiated: {0} [{1}]", adapter.Component, adapter.transform.GetInstanceID())); // } // var cmp = adapter.Component; // if (null == cmp) // { // throw new Exception("Component not found on ComponentAdapter: " + adapter); // } // } // } // /** // * 3. If adapter stuff went without a problem... // * */ // node.Transform.parent = parentTransform; } }
// ReSharper disable MemberCanBeMadeStatic.Global public void Process(AddEventHandlerPersistedData persistedData) // ReSharper restore MemberCanBeMadeStatic.Global { //Debug.Log("Process"); int instanceId = persistedData.TransformInstanceId; Transform transform = EditorUtility.InstanceIDToObject(instanceId) as Transform; if (null == transform) { Debug.LogError("Cannot find object with InstanceID=" + instanceId); } else { ComponentAdapter adapter = GuiLookup.GetAdapter(transform); if (null == adapter) { Debug.LogError("Cannot find adapter on transform having InstanceID=" + instanceId); } else { //Debug.Log("Applying persistedData.Action: " + persistedData.Action); Component cmp; switch (persistedData.Action) // MapExistingHandler, AttachExistingScriptAndMapHandler, CreateNewScriptAndHandler { //case AddHandlerAction.MapExistingHandler: default: CreateMapping(persistedData, adapter); EventDisplay.Instance.Refresh(); cmp = adapter.gameObject.GetComponent(persistedData.ClassName); break; case AddHandlerAction.AttachExistingScriptAndMapHandler: /** * In the case of the new handler creation, we are allowing the already attached script to be "attached" again * It is not really attached if it already exists - we just don't throw an exception * So, if the ScriptAlreadyAttached flag is true, we are referencing the script using gameObject.GetComponent, * else we are using IO.Util * */ cmp = persistedData.ScriptAlreadyAttached ? adapter.gameObject.GetComponent(persistedData.ClassName) : IO.Util.AddHandlerScript(adapter, persistedData); if (null == cmp) { Debug.LogError("Couldn't add event handler script"); return; } CreateMapping(persistedData, adapter); //EventDisplay.Instance.Refresh(); break; case AddHandlerAction.CreateNewHandlerInExistingScript: /** * In the case of the new handler creation, we are allowing the already attached script to be "attached" again * It is not really attached if it already exists - we just don't throw an exception * So, if the ScriptAlreadyAttached flag is true, we are referencing the script using gameObject.GetComponent, * else we are using IO.Util * */ cmp = persistedData.ScriptAlreadyAttached ? adapter.gameObject.GetComponent(persistedData.ClassName) : IO.Util.AddHandlerScript(adapter, persistedData); if (null == cmp) { Debug.LogError("Couldn't add event handler script"); return; } CreateMapping(persistedData, adapter); //EventDisplay.Instance.Refresh(); break; case AddHandlerAction.CreateNewScriptAndHandler: cmp = IO.Util.AddHandlerScript(adapter, persistedData); if (null == cmp) { Debug.LogError("Couldn't add event handler script"); return; } CreateMapping(persistedData, adapter); break; } if (null == cmp) // MapExistingHandler { throw new Exception("Couldn't add event the script"); } MonoBehaviour mb = cmp as MonoBehaviour; if (null == mb) { throw new Exception("Component is not a MonoBehaviour"); } if (persistedData.OpenScript) { // open script var script = MonoScript.FromMonoBehaviour(mb); //Debug.Log("persistedData.SnippetLineNumber: " + persistedData.SnippetLineNumber); AssetDatabase.OpenAsset(script, persistedData.SnippetLineNumber); } /** * 3. Re-scan the hierarchy * */ HierarchyViewDecorator.Instance.ReScan(/*adapter.GetInstanceID()*/); } } }
private void SetLabelText(Point screenSize) { var label = GuiLookup.FindComponent <Label>(gameObject, "lblRuler"); label.Text = string.Format("{0} px", screenSize.X); }
/// <summary> /// Recursive! /// </summary> /// <param name="sb"></param> /// <param name="node"></param> private static void DoFix(ref StringBuilder sb, Node node) { bool isRoot = (null == node.Adapter); //if (!isRoot) // Debug.Log(StringUtil.Indent(node.Depth, "Fixing " + node.Adapter)); var childNodes = node.ChildNodes; var unprocessedNodes = ListUtil <Node> .Clone(node.ChildNodes); var adapter = node.Adapter; //Debug.Log(@"adapter: " + adapter); var containerAdapter = adapter as GroupAdapter; //Debug.Log(@"containerAdapter: " + containerAdapter); // Note: the ROOT node has no adapter no groups defined! if (null != containerAdapter) { ChildGroupPack pack = ChildGroupPack.Read(containerAdapter); // Debug.Log(@"pack: //" + pack); foreach (ChildGroup childGroup in pack.Groups) { //sb.AppendLine(StringUtil.Indent(node.Depth + 1, string.Format("== {0} ==", childGroup.GroupName))); //foreach (ComponentAdapter componentAdapter in childGroup.Adapters) for (int i = childGroup.Adapters.Count - 1; i >= 0; i--) { ComponentAdapter componentAdapter = childGroup.Adapters[i]; bool doRemove = false; /** * 1. Handle null * */ if (null == componentAdapter) { //sb.AppendLine(StringUtil.Indent(node.Depth + 1, "*** Not found ***")); // adapter is not child of this container, remove it from the list //toRemove.Add(componentAdapter); doRemove = true; } /** * 2. Not null. Handle the adapter * */ else { var childNode = GetNode(childNodes, componentAdapter); if (null == childNode) { //sb.AppendLine(StringUtil.Indent(node.Depth + 1, "*** Not found ***")); // adapter is not child of this container, remove it from the list //toRemove.Add(componentAdapter); doRemove = true; } else { unprocessedNodes.Remove(childNode); DoFix(ref sb, childNode); } } if (doRemove) { //Debug.Log("list 1: " + ComponentAdapterUtil.DescribeAdapterList(childGroup.Adapters)); childGroup.Adapters.RemoveAt(i); //childGroup.Adapters.Remove(adapterToRemove); if (null != componentAdapter) { sb.AppendLine(string.Format("{0}: {1} [A:{2}] removed", GuiLookup.PathToString(containerAdapter.transform, "->"), componentAdapter, componentAdapter.GetInstanceID())); } else { sb.AppendLine(string.Format("{0}: Adapter at position {1} removed", GuiLookup.PathToString(containerAdapter.transform, "->"), i)); } //Debug.Log("list 2: " + ComponentAdapterUtil.DescribeAdapterList(childGroup.Adapters)); } } } } // orphans foreach (Node childNode in unprocessedNodes) { if (!isRoot) { if (null != containerAdapter) { ChildGroupPack pack = ChildGroupPack.Read(containerAdapter); if (pack.Groups.Count > 0) { pack.Groups[0].Adapters.Add(childNode.Adapter); sb.AppendLine(string.Format("{0}: [{1}] added to the first group", GuiLookup.PathToString(containerAdapter.transform, "->"), childNode.Adapter)); } } } DoFix(ref sb, childNode); } }
internal static void Process(List <Node> nodes) { if (nodes.Count == 0) { return; } //Debug.Log(string.Format("Processing {0} moves in edit mode.", nodes.Count)); foreach (Node node in nodes) { /** * 1. Process transforms * */ Transform transform = node.Transform; if (null == node.Transform) { throw new Exception("Transform is null"); } /*if (null == transform) * continue; // ROOT*/ //Debug.Log("node.Transform: " + transform); ComponentAdapter adapter = GuiLookup.GetAdapter(transform); bool isStage = adapter is StageAdapter; Transform oldParentTransform = node.OldParentTransform; Transform newParentTransform = node.ParentTransform; /* This happens when a stage moved to root */ if (null == newParentTransform && !isStage) { continue; // not a stage, return (if stage, should process) - only stage could be added to root } /** * The adapter was moved * It is still placed on the same (moved) transform * We are accessing the old and the new parent adapter via transforms: * 1. old parent transform could be referenced using the node.OldParentTransform * 2. new parent transform could be referenced using the node.ParentTransform * */ GroupAdapter oldParentAdapter = null != oldParentTransform? GuiLookup.GetAdapter(oldParentTransform) as GroupAdapter: null; GroupAdapter newParentAdapter = null != newParentTransform? GuiLookup.GetAdapter(newParentTransform) as GroupAdapter: null; Debug.Log(string.Format("[{0}] -> moving from [{1}] to [{2}]", adapter, null == oldParentAdapter ? "-" : oldParentAdapter.ToString(), null == newParentAdapter ? "-" : newParentAdapter.ToString() )); /** * 2. Sanity check * */ if (null == newParentAdapter && !isStage) { throw new Exception("eDriven.Gui components could be added to containers only"); } /** * 3. Process adapters * */ if (null != oldParentAdapter) { oldParentAdapter.RemoveChild(adapter); ParentChildLinker.Instance.Update(oldParentAdapter); } if (null != newParentAdapter) { newParentAdapter.AddChild(adapter, true); ParentChildLinker.Instance.Update(newParentAdapter); } /** * 4. Set transform * */ node.Transform.parent = newParentTransform; } }
internal void RefreshPath() { _path = GuiLookup.GetPath(Selection.activeTransform); }
/// <summary> /// Fires when in-game GUI element clicked /// </summary> /// <param name="parameters"></param> internal static void ClickSlot(object[] parameters) { if (!EditorSettings.InspectorEnabled) { return; } /** * 1. No component with adapter selected -> remove the hierarchy selection * */ if (parameters.Length == 0) { // ReSharper disable ConditionIsAlwaysTrueOrFalse if (DipSwitches.DeselectHierarchyOnNonAdaptedComponentSelection) // ReSharper restore ConditionIsAlwaysTrueOrFalse #pragma warning disable 162 { Selection.activeTransform = null; } #pragma warning restore 162 return; } Component comp = parameters[0] as Component; #if DEBUG if (DebugMode) { Debug.Log(string.Format("Component clicked in the game view: {0}", comp)); } #endif DraggableList.StopDrag(); // solves the bug of still dragging when view changed /** * 2. The adapted component selected * */ if (null != comp) { /** * 2.a) Get game object having adapter for this component attached<br/> * If no adapter found, it means that this component is not bound to an adapter<br/> * For instance Alert (created from code), or component created by an adapter working in factory mode * */ GameObject gameObject = GuiLookup.GetGameObject(comp); /** * 2.b) Check if game object found * If not, nullify the selection and return * */ if (null == gameObject) { Selection.activeTransform = null; return; } /** * 2.c) If game object found, ping it (highlight it) and select it * Selecting it will in turn execute all the mechanisms for processing the selection change * */ //EditorGUIUtility.PingObject(gameObject); // ping Selection.activeTransform = gameObject.transform; // select if (parameters.Length > 1) { MouseEvent me = (MouseEvent)parameters[1]; ProcessMouseEvent(me); } } }