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 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); } } }
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); }
/*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(); }
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(); }
// 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 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()*/); } } }
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; } }
// 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; } }