//called whenever this inspector window is loaded public void OnEnable() { //we create a reference to our script object by passing in the target script = (BezierPathManager)target; //initialize path position oldGizmoPos = script.transform.position; }
void Start() { Debug.Log("Here is your button"); playButton = GameObject.FindGameObjectWithTag("PlayButton").GetComponent <Button>(); pathManager = FindObjectOfType <BezierPathManager>(); // Debug.Log(playButton); // Debug.Log(playButton.text); // Button btn = playButton; // playButton.clicked += TaskOnClick; // playButton.onClicked += TaskOnClick; }
public void CreatePathBySpriteShape() { // 根据配置 动态加载map if (mapShape != null) { Destroy(mapShape.gameObject); } var obj = Resources.Load <GameObject>(CurrLevelData.Map); mapShape = Instantiate(obj, Vector3.zero, Quaternion.identity).GetComponent <SpriteShapeController>(); mapCurve = mapShape.GetComponentInChildren <BezierPathManager>(); mapCurve.name = "WayPath" + CurrLevel; mapShape.gameObject.SetActive(true); //List<Vector3> pointList = new List<Vector3>(); //List<Vector3> leftList = new List<Vector3>(); //List<Vector3> rightList = new List<Vector3>(); //for (int i = 0; i < mapShape.spline.GetPointCount() - 1; i++) //{ //pointList.Add(mapShape.spline.GetPosition(i)); //leftList.Add(mapShape.spline.GetLeftTangent(i)); //rightList.Add(mapShape.spline.GetLeftTangent(i)); //} //BezierPoint[] beziers = new BezierPoint[pointList.Count]; //Transform[] wayPoints = new Transform[pointList.Count]; //for (int i = 0; i < wayPoints.Length; i++) //{ //GameObject obj = new GameObject("WayPoint" + i); //GameObject left = new GameObject("left" + i); //GameObject right = new GameObject("right" + i); //left.transform.SetParent(obj.transform); //right.transform.SetParent(obj.transform); //wayPoints[i] = obj.transform; //wayPoints[i].position = pointList[i]; //wayPoints[i] = obj.transform; //wayPoints[i].position = pointList[i]; //var l = wayPoints[i].GetChild(0); //l = left.transform; //wayPoints[i].GetChild(0).transform.position = leftList[i]; //var r =wayPoints[i].GetChild(1); //r = right.transform; //wayPoints[i].GetChild(1).transform.position = rightList[i]; //} //mapCurve.Create(wayPoints, true); //mapCurve.gameObject.AddComponent<PathRenderer>(); //mapCurve.GetComponent<LineRenderer>().material = new Material(Shader.Find("Sprites/Default")); //Debug.Log($"生成结束"); }
private List<GameObject> wpList = new List<GameObject>(); //temporary list for editor created waypoints in a path #endregion Fields #region Methods //inspector input public override void OnInspectorGUI() { //show default variables of script "WaypointManager" DrawDefaultInspector(); //get WaypointManager.cs reference script = (WaypointManager)target; //make the default styles used by EditorGUI look like controls EditorGUIUtility.LookLikeControls(); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); //draw path text label GUILayout.Label("Enter Path Name: ", EditorStyles.boldLabel, GUILayout.Height(15)); //display text field for creating a path with that name pathName = EditorGUILayout.TextField(pathName, GUILayout.Height(15)); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); //create new waypoint path button if (!placing && GUILayout.Button("Start Waypoint Path", GUILayout.Height(40))) { //no path name defined, abort with short editor warning if (pathName == "") { Debug.LogWarning("no path name defined"); return; } //path name already given, abort with short editor warning if (script.transform.FindChild(pathName) != null) { Debug.LogWarning("path name already given"); return; } //create a new container transform which will hold all new waypoints path = new GameObject(pathName); //attach PathManager component to this new waypoint container pathMan = path.AddComponent<PathManager>(); //create waypoint array instance of PathManager pathMan.waypoints = new Transform[0]; //reset position and parent container gameobject to this manager gameobject path.transform.position = script.gameObject.transform.position; path.transform.parent = script.gameObject.transform; //we passed all prior checks, toggle waypoint placing on placing = true; //fokus sceneview for placing new waypoints SceneView sceneView = (SceneView)SceneView.sceneViews[0]; sceneView.Focus(); } //finish path button //create new bezier path button if (!placing && GUILayout.Button("Start Bezier Path", GUILayout.Height(40))) { //same as above if (pathName == "") { Debug.LogWarning("no path name defined"); return; } if (script.transform.FindChild(pathName) != null) { Debug.LogWarning("path name already given"); return; } path = new GameObject(pathName); //attach BezierPathManager component to this new waypoint container bezierPathMan = path.AddComponent<BezierPathManager>(); bezierPathMan.showGizmos = true; //create waypoint list instance of BezierPathManager bezierPathMan.points = new List<BezierPoint>(); //reset position and parent container gameobject to this manager gameobject path.transform.position = script.gameObject.transform.position; path.transform.parent = script.gameObject.transform; //we passed all prior checks, toggle waypoint placing on placing = true; //fokus sceneview for placing new waypoints SceneView sceneView = (SceneView)SceneView.sceneViews[0]; sceneView.Focus(); } //finish path button if (placing && GUILayout.Button("Finish Editing", GUILayout.Height(40))) { //return if no path was started or not enough waypoints, so wpList/bwpList is empty if (pathMan && wpList.Count < 2 || bezierPathMan && bwpList.Count < 2) { Debug.LogWarning("not enough waypoints placed"); //if we have created a path already, destroy it again if (path) DestroyImmediate(path); } else if (pathMan) { //switch name of last created waypoint to waypointEnd, //so we will recognize this path ended (this gets an other editor gizmo) wpList[wpList.Count - 1].name = "WaypointEnd"; //do the same with first waypoint wpList[0].name = "WaypointStart"; } else if (bezierPathMan) { //do the same with the bezier path points in case they were used bwpList[bwpList.Count - 1].wp.name = "WaypointEnd"; bwpList[0].wp.name = "WaypointStart"; } //toggle placing off placing = false; //clear list with temporary waypoint references, //we only needed this list for getting first and last waypoint easily wpList.Clear(); bwpList.Clear(); //reset path name input field pathName = ""; //make the new path the active selection Selection.activeGameObject = path; } EditorGUILayout.Space(); GUILayout.Label("Hint:\nPress 'Start Path' to begin a new path," + "\npress 'p' on your keyboard to place\nwaypoints onto objects with colliders." + "\nPress 'Finish Editing' to end your path."); }
//method to change the current path of this walker object public void SetPath(BezierPathManager newPath) { //disable any running movement methods Stop(); //set new path container pathContainer = newPath; //restart/continue movement on new path StartMove(); }