public virtual void OnNodeConnect(ViewSystemNode node) { // CurrentConnectLine.Add(line); if (this is ViewPageNode) { ((ViewPageNode)this).viewPage.viewState = ((ViewStateNode)node).viewState.name; } if (this is ViewStateNode) { ((ViewPageNode)node).viewPage.viewState = ((ViewStateNode)this).viewState.name; } }
public ViewStateNode AddViewStateNode(Vector2 position, ViewState viewState = null) { var node = new ViewStateNode(position, CheckCanMakeConnect, viewState); node.OnNodeSelect += (m) => { lastSelectNode = m; inspector.SetCurrentSelectItem(m); }; node.OnNodeDelete += () => { dataReader.OnViewStateDelete(node); viewStateList.Remove(node); }; if (viewState == null) { dataReader.OnViewStateAdd(node); } viewStateList.Add(node); return(node); }
public bool SetData(Transform root, Transform root_prefab, System.Action <IEnumerable <ViewElementPropertyOverrideData> > OnImport, ViewSystemNode node) { this.root = root; this.root_prefab = root_prefab; this.node = node; this.OnImport = OnImport; titleContent = new GUIContent("ViewElement Overrides Importer"); propertyModification = PrefabUtility.GetPropertyModifications(root.gameObject) .ToArray(); var group = propertyModification.GroupBy(x => x.target); var groupedByTarget = group.Where(m => m.Key != null).ToDictionary(o => o.Key, o => o.ToList()); foreach (var target in groupedByTarget.Keys) { var groupedByProperty = groupedByTarget[target].GroupBy(x => x.propertyPath.Split('.')[0]).ToDictionary(o => o.Key, o => o.ToList()); foreach (var property in groupedByProperty.Keys) { // This find the orignal SerializedObject var so = new SerializedObject(target); // This find the orignal SerializedProperty var sp = so.FindProperty(property); if (VS_EditorUtility.IsPropertyNeedIgnore(sp)) { continue; } var temp = new OverridesPropertiesCheckerData(); temp.serializedPropertyType = sp.propertyType; temp.overrideData.targetPropertyName = property; //temp.overrideData.targetPropertyType = sp.propertyType.ToString(); //temp.overrideData.targetPropertyPath = VS_EditorUtility.ParseUnityEngineProperty(property); Transform t; if (sp.serializedObject.targetObject as Component == null) { t = ((GameObject)sp.serializedObject.targetObject).transform; } else { t = ((Component)sp.serializedObject.targetObject).transform; } var path = AnimationUtility.CalculateTransformPath(t, root); var selfName = root_prefab.name.Length + 1; if (path.Length > selfName - 1) { path = path.Substring(selfName, path.Length - selfName); } else if (path.Length == selfName - 1) { path = ""; } temp.overrideData.targetTransformPath = path; temp.overrideData.targetComponentType = target.GetType().ToString(); temp.displayName = $"{sp.displayName} ({property})"; //Find the prefab instance SerializedObject var overrideGameObject = root.Find(path); if (overrideGameObject == null) { ViewSystemLog.LogError("Target GameObject is not found, this feature only works on a root prefab instance, make sure which is not a child of other prefab instance."); return(false); } UnityEngine.Object obj; if (target is GameObject) { obj = overrideGameObject.gameObject; } else { obj = overrideGameObject.GetComponent(target.GetType()); } var so_instance = new SerializedObject(obj); //Find the prefab instance SerializedProperty var sp_instance = so_instance.FindProperty(property); // Add PropertyOverride to OverridesPropertiesCheckerData PropertyOverride overProperty = new PropertyOverride(); overProperty.SetValue(sp_instance); temp.overrideData.Value = overProperty; // Add OverridesPropertiesCheckerData to list wait for user check overridesPropertiesCheckerDatas.Add(temp); } } maxSize = new Vector2(800, 800); return(true); }
public ViewPageNode AddViewPageNode(Vector2 position, bool isOverlay, ViewPage viewPage = null) { var node = new ViewPageNode(position, isOverlay, CheckCanMakeConnect, (vsn, vpn) => { if (vsn != null) { vsn.currentLinkedViewPageNode.Remove(vpn); } }, viewPage ); node.OnPreviewBtnClick += (m) => { var bps = HasBreakPoint(m); if (bps.Length > 0) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent($"Preview with Default BreakPoint "), false, () => { dataReader.OnViewPagePreview(m, null); }); foreach (var item in bps) { menu.AddItem(new GUIContent($"Preview with {item} BreakPoint "), false, () => { dataReader.OnViewPagePreview(m, new Dictionary <string, bool> { { item, true } }); }); } menu.ShowAsContext(); } else { dataReader.OnViewPagePreview(m, null); } string[] HasBreakPoint(ViewPage _viewPage) { List <string> result = new List <string>(); foreach (var item in _viewPage.viewPageItems) { if (item.breakPointViewElementTransforms != null) { foreach (var bp in item.breakPointViewElementTransforms) { if (!result.Contains(bp.breakPointName)) { result.Add(bp.breakPointName); } } } } var viewState = viewStateList.SingleOrDefault(x => x.viewState.name == _viewPage.viewState); if (viewState != null) { foreach (var item in viewState.viewState.viewPageItems) { if (item.breakPointViewElementTransforms != null) { foreach (var bp in item.breakPointViewElementTransforms) { if (!result.Contains(bp.breakPointName)) { result.Add(bp.breakPointName); } } } } } return(result.ToArray()); } }; node.OnNodeSelect += (m) => { lastSelectNode = m; inspector.SetCurrentSelectItem(m); }; node.OnNodeDelete += () => { dataReader.OnViewPageDelete(node); viewPageList.Remove(node); }; node.OnDisConnect = OnDisconnect; if (viewPage == null) { dataReader.OnViewPageAdd(node); } viewPageList.Add(node); return(node); } void CheckCanMakeConnect(ViewSystemNode currentClickNode) { switch (currentClickNode.nodeType) { case ViewSystemNode.NodeType.ViewState: selectedViewStateNode = (ViewStateNode)currentClickNode; //如果當前的 ViewPagePoint 不是 null if (selectedViewPageNode != null) { if (selectedViewStateNode.currentLinkedViewPageNode.Count(m => m.nodeType != selectedViewPageNode.nodeType) > 0) { if (EditorUtility.DisplayDialog( "Warring", $"The target ViewState is already connect to one or more {selectedViewPageNode.nodeType} Page.\nSince ViewState can only connect to one type of ViewPage(FullPage or Overlay) you should remove all {selectedViewPageNode.nodeType} connection on ViewState to continue.\nOr press 'OK' the editor will help you do this stuff.", "Go Ahead", "I'll do it myself")) { //刪掉線 foreach (var pagenode in selectedViewStateNode.currentLinkedViewPageNode) { pagenode.viewPage.viewState = string.Empty; pagenode.currentLinkedViewStateNode = null; } selectedViewStateNode.currentLinkedViewPageNode.Clear(); CreateConnection(); ClearConnectionSelection(); } else { ClearConnectionSelection(); } return; } //檢查是不是已經有跟這個 ViewPageNode 節點連線過了 if (!selectedViewStateNode.currentLinkedViewPageNode.Contains(selectedViewPageNode) && selectedViewPageNode.currentLinkedViewStateNode == null ) { CreateConnection(); ClearConnectionSelection(); } // 如果連線的節點跟原本的不同 刪掉舊的連線 然後建立新了 else if (selectedViewPageNode.currentLinkedViewStateNode != null) { //刪掉 ViewStateNode 裡的 ViewPageNode selectedViewPageNode.currentLinkedViewStateNode.currentLinkedViewPageNode.Remove(selectedViewPageNode); //刪掉線 CreateConnection(); ClearConnectionSelection(); } else { ClearConnectionSelection(); } } break; //被聯線的是 FullPage case ViewSystemNode.NodeType.FullPage: selectedViewPageNode = (ViewPageNode)currentClickNode; if (selectedViewStateNode != null) { if (selectedViewStateNode.currentLinkedViewPageNode.Count(m => m.nodeType != selectedViewPageNode.nodeType) > 0) { if (EditorUtility.DisplayDialog( "Warring", $"The target ViewPage is already connect to one or more {selectedViewPageNode.nodeType} Page.\nSince ViewState can only connect to one type of ViewPage(FullPage or Overlay) you should remove all {selectedViewPageNode.nodeType} connection on ViewState to continue.\nOr press 'OK' the editor will help you do this stuff.", "Go Ahead", "I'll do it myself")) { //刪掉線 foreach (var pagenode in selectedViewStateNode.currentLinkedViewPageNode) { pagenode.viewPage.viewState = string.Empty; pagenode.currentLinkedViewStateNode = null; } selectedViewStateNode.currentLinkedViewPageNode.Clear(); CreateConnection(); ClearConnectionSelection(); } else { ClearConnectionSelection(); } return; } //檢查是不是已經有跟這個 ViewStateNode 節點連線過了 if (selectedViewPageNode.currentLinkedViewStateNode == null) { CreateConnection(); ClearConnectionSelection(); } // 如果連線的節點跟原本的不同 刪掉舊的連線 然後建立新了 else if (selectedViewPageNode.currentLinkedViewStateNode != selectedViewStateNode) { //刪掉 ViewStateNode 裡的 ViewPageNode selectedViewPageNode.currentLinkedViewStateNode.currentLinkedViewPageNode.Remove(selectedViewPageNode); CreateConnection(); ClearConnectionSelection(); } else { ClearConnectionSelection(); } } break; //Overlay case ViewSystemNode.NodeType.Overlay: selectedViewPageNode = (ViewPageNode)currentClickNode; if (selectedViewStateNode != null) { if (selectedViewStateNode.currentLinkedViewPageNode.Count(m => m.nodeType != selectedViewPageNode.nodeType) > 0) { if (EditorUtility.DisplayDialog( "Warring", $"The target ViewPage is already connect to one or more {selectedViewPageNode.nodeType} Page.\nSince ViewState can only connect to one type of ViewPage(FullPage or Overlay) you should remove all {selectedViewPageNode.nodeType} connection on ViewState to continue.\nOr press 'OK' the editor will help you do this stuff.", "Go Ahead", "I'll do it myself")) { //刪掉線 foreach (var pagenode in selectedViewStateNode.currentLinkedViewPageNode) { pagenode.viewPage.viewState = string.Empty; pagenode.currentLinkedViewStateNode = null; } selectedViewStateNode.currentLinkedViewPageNode.Clear(); CreateConnection(); ClearConnectionSelection(); } else { ClearConnectionSelection(); } return; } //檢查是不是已經有跟這個 ViewStateNode 節點連線過了 if (selectedViewPageNode.currentLinkedViewStateNode == null) { CreateConnection(); ClearConnectionSelection(); } // 如果連線的節點跟原本的不同 刪掉舊的連線 然後建立新了 else if (selectedViewPageNode.currentLinkedViewStateNode != selectedViewStateNode) { //刪掉 ViewStateNode 裡的 ViewPageNode selectedViewPageNode.currentLinkedViewStateNode.currentLinkedViewPageNode.Remove(selectedViewPageNode); //刪掉線 CreateConnection(); ClearConnectionSelection(); } else { ClearConnectionSelection(); } } break; } }