示例#1
0
	public override void OnInspectorGUI ()
	{
		DrawDefaultInspector ();

		EditorStyles.textField.wordWrap = true;

		GUI.color = Color.yellow;
		foreach (KeyValuePair <string,int> branch in pathEditor.AttachedTo) {
			if (branch.Key != pathEditor.Name) {
				GUILayout.Label (branch.Value.ToString () + ": " + branch.Key);
			}
		}

		GUI.color = Color.cyan;
		if (GUILayout.Button ("\nSave Path\n", EditorStyles.miniButton)) {
			pathEditor.EditorSave ();
		}
		if (GUILayout.Button ("\nLoad Path\n", EditorStyles.miniButton)) {
			pathEditor.EditorLoad ();
		}
		if (GUILayout.Button ("\nRefresh Path\n", EditorStyles.miniButton)) {
			pathEditor.EditorRefresh ();
		}
		GUI.color = Color.yellow;
		if (GUILayout.Button ("\nRebuild Path Spacing\n", EditorStyles.miniButton)) {
			pathEditor.RebuildPathSpacing ();
		}
		if (GUILayout.Button ("\nReverse Spline Node Order\n", EditorStyles.miniButton)) {
			pathEditor.ReverseSplineNodeOrder ();
		}
		if (GUILayout.Button ("\nFind Ground\n", EditorStyles.miniButton)) {
			pathEditor.EditorFindGround ();
		}
	}
示例#2
0
        public void DrawEditor()
        {
            UnityEngine.GUI.color = Color.cyan;
            if (GUILayout.Button("\nLoad Paths\n"))
            {
                foreach (PathEditor pathEditor in PathEditors)
                {
                    GameObject.DestroyImmediate(pathEditor.gameObject);
                }
                PathEditors.Clear();
                LoadedPaths.Clear();
                ChunkTransforms.Clear();

                if (!Manager.IsAwake <Mods> ())
                {
                    Manager.WakeUp <Mods> ("__MODS");
                }
                Mods.Get.Editor.InitializeEditor(true);

                ChunkParentTransform = gameObject.FindOrCreateChild("Chunks");
                PathParentTransform  = gameObject.FindOrCreateChild("Paths");

                List <string> chunkNames = Mods.Get.ModDataNames("Chunk");
                foreach (string chunkName in chunkNames)
                {
                    ChunkState chunkState = null;
                    if (Mods.Get.Runtime.LoadMod <ChunkState> (ref chunkState, "Chunk", chunkName))
                    {
                        GameObject newChunkGameObject = ChunkParentTransform.gameObject.FindOrCreateChild(chunkState.ID.ToString()).gameObject;
                        //look up the chunk terrain data and apply the offset
                        Vector3 chunkPosition = chunkState.TileOffset;
                        //chunkPosition.y = chunkState.YOffset;
                        newChunkGameObject.transform.position = chunkPosition;
                        //we'll use the ID for looking up path chunks later
                        ChunkTransforms.Add(newChunkGameObject.transform);
                        //now look for any terrain
                        GameObject terrainObject = GameObject.Find(chunkState.XTilePosition.ToString() + " " + chunkState.ZTilePosition.ToString());
                        if (terrainObject != null)
                        {
                            terrainObject.transform.parent = newChunkGameObject.transform;
                            terrainObject.transform.ResetLocal();
                            Terrain terrain = terrainObject.GetComponent <Terrain> ();
                            terrain.heightmapPixelError = 50;
                        }
                    }
                }
                Mods.Get.Editor.LoadAvailableMods <Path> (LoadedPaths, "Path");
                foreach (Path path in LoadedPaths)
                {
                    GameObject pathEditorGameObject = PathParentTransform.gameObject.FindOrCreateChild(path.Name).gameObject;
                    PathEditor pathEditor           = pathEditorGameObject.GetOrAdd <PathEditor> ();
                    pathEditor.DoNotRefreshOrSave = false;
                    pathEditor.Name  = path.Name;
                    pathEditor.State = path;
                    pathEditor.EditorRefresh();
                    pathEditor.BuildSpline();
                }

                MergeOverlappingTemplates();
            }

            if (GUILayout.Button("\nSnap Nearby Templates\n"))
            {
                SnapNearbyTemplates();
                MergeOverlappingTemplates();
            }

            if (GUILayout.Button("\nMinimum Height\n"))
            {
                AdjustMinimumHeight();
            }

            if (GUILayout.Button("\nRefreshAll\n"))
            {
                foreach (PathEditor pe in PathEditors)
                {
                    Debug.Log(pe.Name);
                    pe.EditorRefresh();
                }
            }

            if (GUILayout.Button("\nSave Paths\n"))
            {
                PathEditors.Clear();
                PathEditors.AddRange(PathParentTransform.GetComponentsInChildren <PathEditor> ());
                foreach (PathEditor editor in PathEditors)
                {
                    editor.EditorSave();
                }
            }
        }