Example #1
0
        /// <summary>
        /// Retreives skill collections without any parents
        /// </summary>
        /// <returns>The root skill collections.</returns>
        public List <SkillCollectionBase> GetRootSkillCollections()
        {
            List <SkillCollectionBase> skills = new List <SkillCollectionBase>();

            // Loop through and find all collection that are a child of something
            Dictionary <Transform, bool> blacklist = new Dictionary <Transform, bool>();

            foreach (Transform child in transform)
            {
                foreach (SkillCollectionBase childNode in child.GetComponent <SkillCollectionBase>().childSkills)
                {
                    blacklist[childNode.transform] = true;
                }
            }

            // Anything not blacklisted as a child node is a root, return those
            foreach (Transform child in transform)
            {
                if (!blacklist.ContainsKey(child))
                {
                    SkillCollectionBase skill = child.GetComponent <SkillCollectionBase>();
                    skills.Add(skill);
                }
            }

            return(skills);
        }
        public void SnapNodeToGrid(SkillCollectionBase node)
        {
            Vector2 snapRatio = target.gridCellSize;

            node.windowRect.x = Mathf.Round(node.windowRect.x / snapRatio.x) * snapRatio.x;
            node.windowRect.y = Mathf.Round(node.windowRect.y / snapRatio.y) * snapRatio.y;
            // Get the currently active SkillTreeBase and
        }
        void AddSkill(SkillCollectionBase col)
        {
            GameObject go = new GameObject();

            go.name = "Skill";
            SkillBase s = go.AddComponent(target.Skill) as SkillBase;

            s.Uuid = Guid.NewGuid().ToString();
            go.transform.SetParent(col.transform);
        }
        void CreateSkillGroup()
        {
            GameObject go = new GameObject();

            go.name = "SkillCollection";
            SkillCollectionBase skill = go.AddComponent(target.SkillCollection) as SkillCollectionBase;

            skill.windowRect = new Rect(mousePosGlobal.x, mousePosGlobal.y, 220, 150);
            go.transform.SetParent(target.currentCategory.transform);

            AddSkill(skill);
        }
Example #5
0
        /// <summary>
        /// Visual print out of requirements
        /// </summary>
        /// <returns>The requirements.</returns>
        virtual public string GetRequirements()
        {
            string            requirements = "";
            SkillCategoryBase category     = transform.parent.parent.GetComponent <SkillCategoryBase>();

            if (requiredLevel > 0)
            {
                requirements += string.Format("* {0} Skill Lv {1} \n", category.displayName, requiredLevel);
            }

            foreach (SkillBase skill in extraRequirements)
            {
                SkillCollectionBase collection = skill.transform.parent.GetComponent <SkillCollectionBase>();
                requirements += string.Format("* {0} Lv {1} \n", collection.displayName, skill.transform.GetSiblingIndex() + 1);
            }

            return(requirements);
        }
        void DeleteSkillGroup()
        {
            if (EditorUtility.DisplayDialog("Delete Skill Collection?",
                                            "Are you sure you want to delete this skill collection? It will delete this collection plus all skills it contains.",
                                            "Delete Skill Collection",
                                            "Cancel"))
            {
                SkillCollectionBase[] collect = target.currentCategory.GetComponentsInChildren <SkillCollectionBase>();
                SkillCollectionBase   t       = collect[selectIndex];

                // Clean out all references to our skill collection
                foreach (SkillCollectionBase node in collect)
                {
                    node.childSkills.Remove(t);
                }

                DestroyImmediate(t.gameObject);
            }
        }
Example #7
0
        /// <summary>
        /// Determines if a parent collection is properly unlocked
        /// </summary>
        /// <returns><c>true</c> if this instance is parent unlocked the specified collection; otherwise, <c>false</c>.</returns>
        /// <param name="collection">Collection.</param>
        public virtual bool IsParentUnlocked(SkillCollectionBase collection)
        {
            // Check to see if it has no parent
            if (!childParents.ContainsKey(collection))
            {
                return(true);
            }

            // Check all parents to see if any are unlocked
            foreach (SkillCollectionBase parent in childParents[collection])
            {
                if (parent.GetSkill(0).unlocked)
                {
                    return(true);
                }
            }

            // No matches
            return(false);
        }
Example #8
0
        public SkillCollectionGrid GetGrid(SkillCategoryBase category)
        {
            SkillCollectionBase[] collect = category.GetComponentsInChildren <SkillCollectionBase>();
            Vector2 min = new Vector2(Mathf.Infinity, Mathf.Infinity);
            Vector2 max = new Vector2(Mathf.NegativeInfinity, Mathf.NegativeInfinity);

            // Find the min x, min y, max x, and max y
            foreach (SkillCollectionBase col in collect)
            {
                if (col.windowRect.x < min.x)
                {
                    min.x = col.windowRect.x;
                }
                if (col.windowRect.x > max.x)
                {
                    max.x = col.windowRect.x;
                }
                if (col.windowRect.y < min.y)
                {
                    min.y = col.windowRect.y;
                }
                if (col.windowRect.y > max.y)
                {
                    max.y = col.windowRect.y;
                }
            }

            int x, y;
            int width  = Mathf.CeilToInt(Mathf.Abs(min.x - max.x) / gridCellSize.x) + 1;
            int height = Mathf.CeilToInt(Mathf.Abs(min.y - max.y) / gridCellSize.y) + 1;

            SkillCollectionBase[,] grid = new SkillCollectionBase[width, height];
            foreach (SkillCollectionBase col in collect)
            {
                x          = Mathf.RoundToInt((col.windowRect.x - min.x) / gridCellSize.x);
                y          = Mathf.RoundToInt((col.windowRect.y - min.y) / gridCellSize.y);
                grid[x, y] = col;
            }

            return(new SkillCollectionGrid(grid));
        }
        void AddSkill(object obj)
        {
            SkillCollectionBase col = obj as SkillCollectionBase;

            AddSkill(col);
        }
		void BeginSkillGroupTransition () {
			isTransition = true;
			SkillCollectionBase[] collect = target.currentCategory.GetComponentsInChildren<SkillCollectionBase>();
			selectNode = collect[selectIndex];
		}
		/// <summary>
		/// Determines if a parent collection is properly unlocked
		/// </summary>
		/// <returns><c>true</c> if this instance is parent unlocked the specified collection; otherwise, <c>false</c>.</returns>
		/// <param name="collection">Collection.</param>
		public virtual bool IsParentUnlocked (SkillCollectionBase collection) {
			// Check to see if it has no parent
			if (!childParents.ContainsKey(collection)) {
				return true;
			}

			// Check all parents to see if any are unlocked
			foreach (SkillCollectionBase parent in childParents[collection]) {
				if (parent.GetSkill(0).unlocked) return true;
			}

			// No matches
			return false;
		}
 void BeginSkillGroupTransition()
 {
     isTransition = true;
     SkillCollectionBase[] collect = target.currentCategory.GetComponentsInChildren <SkillCollectionBase>();
     selectNode = collect[selectIndex];
 }
        void OnGUI()
        {
            if (target == null)
            {
                return;
            }

            DrawTitle();

            Event e = Event.current;

            mousePos       = e.mousePosition;                        // Mouse position local to the viewing window
            mousePosGlobal = camera.GetMouseGlobal(e.mousePosition); // Mouse position local to the scroll window
            bool clickedNode = false;

            // Poll the current skill collection
            if (target.currentCategory != null)
            {
                collect = target.currentCategory.GetComponentsInChildren <SkillCollectionBase>();
            }
            else
            {
                collect = new SkillCollectionBase[0];
            }

            // Main content area
            if (target.currentCategory != null)
            {
                // Clicked outside of sidebar and scrollbar GUI
                if (mousePos.x < position.width - sidebarWidth - GUI.skin.verticalScrollbar.fixedWidth &&
                    mousePos.y < position.height - GUI.skin.horizontalScrollbar.fixedHeight)
                {
                    // Context menu
                    if (e.button == 1 && !isTransition)
                    {
                        if (e.type == EventType.MouseDown)
                        {
                            for (int i = 0; i < collect.Length; i++)
                            {
                                if (collect[i].windowRect.Contains(mousePosGlobal))
                                {
                                    selectIndex = i;
                                    clickedNode = true;
                                    break;
                                }
                            }

                            if (clickedNode)
                            {
                                GenericMenu menu = new GenericMenu();
                                menu.AddItem(new GUIContent("Add Skill"), false, AddSkill, collect[selectIndex]);
                                menu.AddItem(new GUIContent("Add Child Transition"), false, BeginSkillGroupTransition);
                                menu.AddSeparator("");
                                menu.AddItem(new GUIContent("Delete Skill Group"), false, DeleteSkillGroup);
                                menu.AddSeparator("");

                                foreach (SkillCollectionBase child in collect[selectIndex].childSkills)
                                {
                                    menu.AddItem(new GUIContent("Delete Transition " + child.displayName), false, DeleteSkillGroupTransition, new TransitionParentChild {
                                        parent = collect[selectIndex],
                                        child  = child
                                    });
                                }

                                menu.ShowAsContext();
                                e.Use();
                            }
                            else
                            {
                                GenericMenu menu = new GenericMenu();
                                menu.AddItem(new GUIContent("Add Skill Group"), false, CreateSkillGroup);
                                menu.ShowAsContext();
                                e.Use();
                            }
                        }
                    }
                    else if (e.button == 0)
                    {
                        if (e.type == EventType.MouseDown)
                        {
                            for (int i = 0; i < collect.Length; i++)
                            {
                                if (collect[i].windowRect.Contains(mousePosGlobal))
                                {
                                    selectIndex = i;
                                    clickedNode = true;
                                    snapNode    = collect[i];
                                    break;
                                }
                            }

                            if (isTransition)
                            {
                                selectNode.childSkills.Remove(collect[selectIndex]);
                                selectNode.childSkills.Add(collect[selectIndex]);
                                EndSkillGroupTransition();
                            }
                            else
                            {
                                if (clickedNode)
                                {
                                    Selection.activeGameObject = target.currentCategory.transform.GetChild(selectIndex).gameObject;
                                }
                                else
                                {
                                    camera.BeginMove(mousePos);
                                }
                            }
                        }
                        else if (e.type == EventType.MouseUp && snapNode != null)
                        {
                            if (forceSnapping)
                            {
                                SnapNodeToGrid(snapNode);
                            }
                            snapNode = null;
                        }
                    }
                }

                camera.offset = GUI.BeginScrollView(new Rect(0f, 0f, position.width - sidebarWidth, position.height), camera.offset, new Rect(camera.viewportSize / -2f, camera.viewportSize / -2f, camera.viewportSize, camera.viewportSize));

                BeginWindows();
                for (int i = 0; i < collect.Length; i++)
                {
                    collect[i].windowRect = GUI.Window(i, collect[i].windowRect, DrawNodeWindow, collect[i].displayName);

                    foreach (SkillCollectionBase child in collect[i].childSkills)
                    {
                        DrawLineBottomToTop(collect[i].windowRect, child.windowRect);
                    }
                }
                EndWindows();

                GUI.EndScrollView();                 // Camera scroll for windows
            }

            // Draw a transistion if in transistion mode
            if (isTransition && selectNode != null)
            {
                Vector2 globalOffset = camera.GetOffsetGlobal();
                Rect    beginRect    = selectNode.windowRect;
                beginRect.x -= globalOffset.x;
                beginRect.y -= globalOffset.y;
                Rect mouseRect = new Rect(mousePos.x, mousePos.y, 10f, 10f);

                DrawNodeCurve(beginRect, mouseRect);

                Repaint();
            }

            sidebar.DrawSidebar(new Rect(position.width - sidebarWidth, 0, sidebarWidth, position.height), 10f, Color.gray);

            // Always stop the camera on mouse up (even if not in the window)
            if (Event.current.rawType == EventType.MouseUp)
            {
                camera.EndMove();
            }

            // Poll and update the viewport if the camera has moved
            if (camera.PollCamera(mousePos))
            {
                Repaint();
            }
        }
		void OnGUI () {
			if (target == null) return;

			DrawTitle();

			Event e = Event.current;
			mousePos = e.mousePosition; // Mouse position local to the viewing window
			mousePosGlobal = camera.GetMouseGlobal(e.mousePosition); // Mouse position local to the scroll window
			bool clickedNode = false;

			// Poll the current skill collection
			if (target.currentCategory != null) {
				collect = target.currentCategory.GetComponentsInChildren<SkillCollectionBase>();
			} else {
				collect = new SkillCollectionBase[0];
			}

			// Main content area
			if (target.currentCategory != null) {
				// Clicked outside of sidebar and scrollbar GUI
				if (mousePos.x < position.width - sidebarWidth - GUI.skin.verticalScrollbar.fixedWidth &&
				    mousePos.y < position.height - GUI.skin.horizontalScrollbar.fixedHeight) {

					// Context menu
					if (e.button == 1 && !isTransition) {
						if (e.type == EventType.MouseDown) {
							for (int i = 0; i < collect.Length; i++) {
								if (collect[i].windowRect.Contains(mousePosGlobal)) {
									selectIndex = i;
									clickedNode = true;
									break;
								}
							}

							if (clickedNode) {
								GenericMenu menu = new GenericMenu();
								menu.AddItem(new GUIContent("Add Skill"), false, AddSkill, collect[selectIndex]);
								menu.AddItem(new GUIContent("Add Child Transition"), false, BeginSkillGroupTransition);
								menu.AddSeparator("");
								menu.AddItem(new GUIContent("Delete Skill Group"), false, DeleteSkillGroup);
								menu.AddSeparator("");

								foreach (SkillCollectionBase child in collect[selectIndex].childSkills) {
									menu.AddItem(new GUIContent("Delete Transition " + child.displayName), false, DeleteSkillGroupTransition, new TransitionParentChild {
										parent = collect[selectIndex],
										child = child
									});
								}

								menu.ShowAsContext();
								e.Use();
							} else {
								GenericMenu menu = new GenericMenu();
								menu.AddItem(new GUIContent("Add Skill Group"), false, CreateSkillGroup);
								menu.ShowAsContext();
								e.Use();
							}
						}
					} else if (e.button == 0) {
						if (e.type == EventType.MouseDown) {
							for (int i = 0; i < collect.Length; i++) {
								if (collect[i].windowRect.Contains(mousePosGlobal)) {
									selectIndex = i;
									clickedNode = true;
									snapNode = collect[i];
									break;
								}
							}

							if (isTransition) {
								selectNode.childSkills.Remove(collect[selectIndex]);
								selectNode.childSkills.Add(collect[selectIndex]);
								EndSkillGroupTransition();
							} else {
								if (clickedNode) {
									Selection.activeGameObject = target.currentCategory.transform.GetChild(selectIndex).gameObject;
								} else {
									camera.BeginMove(mousePos);
								}
							}
						} else if (e.type == EventType.MouseUp && snapNode != null) {
							if (forceSnapping) SnapNodeToGrid(snapNode);
							snapNode = null;
						}
					}
				}

				camera.offset = GUI.BeginScrollView(new Rect(0f, 0f, position.width - sidebarWidth, position.height), camera.offset, new Rect(camera.viewportSize / -2f, camera.viewportSize / -2f, camera.viewportSize, camera.viewportSize));
				
				BeginWindows();
				for (int i = 0; i < collect.Length; i++) {
					collect[i].windowRect = GUI.Window(i, collect[i].windowRect, DrawNodeWindow, collect[i].displayName);
					
					foreach (SkillCollectionBase child in collect[i].childSkills) {
						DrawLineBottomToTop(collect[i].windowRect, child.windowRect);
					}
				}
				EndWindows();
				
				GUI.EndScrollView(); // Camera scroll for windows
			}

			// Draw a transistion if in transistion mode
			if (isTransition && selectNode != null) {
				Vector2 globalOffset = camera.GetOffsetGlobal();
				Rect beginRect = selectNode.windowRect;
				beginRect.x -= globalOffset.x;
				beginRect.y -= globalOffset.y;
				Rect mouseRect = new Rect(mousePos.x, mousePos.y, 10f, 10f);

				DrawNodeCurve(beginRect, mouseRect);

				Repaint();
			}

			sidebar.DrawSidebar(new Rect(position.width - sidebarWidth, 0, sidebarWidth, position.height), 10f, Color.gray);

			// Always stop the camera on mouse up (even if not in the window)
			if (Event.current.rawType == EventType.MouseUp) {
				camera.EndMove();
			}

			// Poll and update the viewport if the camera has moved
			if (camera.PollCamera(mousePos)) {
				Repaint();
			}
		}
		void AddSkill (SkillCollectionBase col) {
			GameObject go = new GameObject();
			go.name = "Skill";
			SkillBase s = go.AddComponent(target.Skill) as SkillBase;
			s.Uuid = Guid.NewGuid().ToString();
			go.transform.SetParent(col.transform);
		}
		void EndSkillGroupTransition () {
			isTransition = false;
			selectNode = null;
		}
		public SkillCollectionGrid GetGrid (SkillCategoryBase category) {
			SkillCollectionBase[] collect = category.GetComponentsInChildren<SkillCollectionBase>();
			Vector2 min = new Vector2(Mathf.Infinity, Mathf.Infinity);
			Vector2 max = new Vector2(Mathf.NegativeInfinity, Mathf.NegativeInfinity);

			// Find the min x, min y, max x, and max y
			foreach (SkillCollectionBase col in collect) {
				if (col.windowRect.x < min.x) min.x = col.windowRect.x;
				if (col.windowRect.x > max.x) max.x = col.windowRect.x;
				if (col.windowRect.y < min.y) min.y = col.windowRect.y;
				if (col.windowRect.y > max.y) max.y = col.windowRect.y;
			}

			int x, y;
			int width = Mathf.CeilToInt(Mathf.Abs(min.x - max.x) / gridCellSize.x) + 1;
			int height = Mathf.CeilToInt(Mathf.Abs(min.y - max.y) / gridCellSize.y) + 1;
			SkillCollectionBase[,] grid = new SkillCollectionBase[width, height];
			foreach (SkillCollectionBase col in collect) {
				x = Mathf.RoundToInt((col.windowRect.x - min.x) / gridCellSize.x);
				y = Mathf.RoundToInt((col.windowRect.y - min.y) / gridCellSize.y);
				grid[x, y] = col;
			}

			return new SkillCollectionGrid(grid);
		}
 void EndSkillGroupTransition()
 {
     isTransition = false;
     selectNode   = null;
 }
		public SkillCollectionGrid (SkillCollectionBase[,] grid) {
			_grid = grid;
		}
		public void SnapNodeToGrid (SkillCollectionBase node) {
			Vector2 snapRatio = target.gridCellSize;
			node.windowRect.x = Mathf.Round(node.windowRect.x / snapRatio.x) * snapRatio.x;
			node.windowRect.y = Mathf.Round(node.windowRect.y / snapRatio.y) * snapRatio.y;
			// Get the currently active SkillTreeBase and 
		}