private void AddObjectToScene(GameObject prefabToCreateInScene) { ObjectBuilderScript myScript = (ObjectBuilderScript)target; GameObject newGo = Instantiate(prefabToCreateInScene, myScript.gameObject.transform.position, Quaternion.identity); newGo.name = prefabToCreateInScene.name; }
private static void MegaRigidbodyOption(MenuCommand command) { Debug.Log(Selection.activeObject.name); // var go = Selection.activeObject as GameObject; // DestroyImmediate(go.GetComponent<ObjectBuilderScript>()); ObjectBuilderScript obs = command.context as ObjectBuilderScript; DestroyImmediate(obs); }
// Use this for initialization void Start() { att_fields = getFieldofType(1); follow_me = att_fields [0]; ObjectBuilderScript script = GameObject.FindObjectOfType <ObjectBuilderScript>(); script.BuildObject(); followArrow = GameObject.FindObjectOfType <ObjectFollow> ().gameObject; nodes = ObjectBuilderScript.nodes; Vector3 roboLoc = myLocation(); Vector3 goalLoc = GameObject.FindGameObjectWithTag("Goal").transform.position; float startDist = float.MaxValue; float goalDist = float.MaxValue; NodeSquare start = new NodeSquare(new Vector3(0, 0, 0), new Vector3(0, 0, 0)); NodeSquare goal = new NodeSquare(new Vector3(0, 0, 0), new Vector3(0, 0, 0)); foreach (NodeSquare node in nodes) { if (Vector3.Distance(node.getRenderLoc(), roboLoc) < startDist) { start = node; startDist = Vector3.Distance(node.getRenderLoc(), roboLoc); } if (Vector3.Distance(node.getRenderLoc(), goalLoc) < goalDist) { goal = node; goalDist = Vector3.Distance(node.getRenderLoc(), goalLoc); } } // find the nodes that are impassable List <Field> obstacles = getFieldofType(3); foreach (Field block in obstacles) { foreach (NodeSquare node in nodes) { if (PointInOABB(node.getRenderLoc(), block.gameObject.GetComponent <BoxCollider> ())) { node.makeImpassable(); } } } // calculate the path path = a_star(start, goal); foreach (NodeSquare node in path) { node.makePath(); } path.Reverse(); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); ObjectBuilderScript myScript = (ObjectBuilderScript)target; if (GUILayout.Button("Build Object")) { myScript.BuildObject(); } }
public override void OnInspectorGUI() { DrawDefaultInspector(); ObjectBuilderScript myScript = (ObjectBuilderScript)target; if (GUILayout.Button("Build Grid")) { myScript.BuildObject(); } }
public override void OnInspectorGUI() { DrawDefaultInspector(); ObjectBuilderScript myScript = (ObjectBuilderScript)target; if (GUILayout.Button("Delete All Player Prefs")) { myScript.DeleteAllPlayerPrefs(); } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); ObjectBuilderScript myScript = (ObjectBuilderScript)target; // 添加一个按钮,名叫Build Object if (GUILayout.Button("Build Object")) { // 当按钮被按下时执行 myScript.BuildObject(); } }
public override void OnInspectorGUI() { DrawDefaultInspector(); ObjectBuilderScript myScript = (ObjectBuilderScript)target; if (GUILayout.Button("Build Object")) { myScript.BuildObject(); } EditorGUILayout.TextArea("hahaha"); if (GUILayout.Toggle(myScript._bON, myScript._Tex)) { EditorGUILayout.TextArea(myScript._Text0); } EditorGUILayout.TextArea(myScript._Text1); }
/*-------------------------------------------------------- * each frame when object's properties to be displayed in the Inspector * * offer 3 buttons to the user * * when clicked, call method AddObjectToScene() with the prefab corresponding to the button * */ public override void OnInspectorGUI() { // 'myScript' is a reference to the object whose properties are being displayed // in the Inspector // (the one that shows the 'cross hairs' so we know where new pickup GameObject will be created) ObjectBuilderScript myScript = (ObjectBuilderScript)target; GUILayout.Label(""); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label("Click button to create instance of prefab"); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Label(""); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(iconStar)) { myScript.AddObjectToScene(prefabStar); } GUILayout.FlexibleSpace(); if (GUILayout.Button(iconHeart)) { myScript.AddObjectToScene(prefabHeart); } GUILayout.FlexibleSpace(); if (GUILayout.Button(iconKey)) { myScript.AddObjectToScene(prefabKey); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); }
// Use this for initialization void Start() { att_fields = getFieldofType(1); follow_me = att_fields [0]; ObjectBuilderScript script = GameObject.FindObjectOfType <ObjectBuilderScript>(); script.BuildObject(); //followArrow = GameObject.FindObjectOfType<ObjectFollow> ().gameObject; nodes = ObjectBuilderScript.nodes; Vector3 roboLoc = myLocation(); Vector3 goalLoc = GameObject.FindGameObjectWithTag("Goal").transform.position; float startDist = float.MaxValue; float goalDist = float.MaxValue; NodeSquare start = new NodeSquare(new Vector3(0, 0, 0), new Vector3(0, 0, 0)); NodeSquare goal = new NodeSquare(new Vector3(0, 0, 0), new Vector3(0, 0, 0)); Debug.Log("Begin Start/Goal Identification"); foreach (NodeSquare node in nodes) { if (Vector3.Distance(node.getRenderLoc(), roboLoc) < startDist) { start = node; startDist = Vector3.Distance(node.getRenderLoc(), roboLoc); } if (Vector3.Distance(node.getRenderLoc(), goalLoc) < goalDist) { goal = node; goalDist = Vector3.Distance(node.getRenderLoc(), goalLoc); } } Debug.Log("Completed Start/Goal Identification"); // find the nodes that are impassable Debug.Log("Begin Obstacle Identification"); List <Field> obstacles = getFieldofType(3); foreach (Field block in obstacles) { foreach (NodeSquare node in nodes) { if (PointInOABB(node.getRenderLoc(), block.gameObject.GetComponent <BoxCollider> ())) { node.makeImpassable(); } } } Debug.Log("Completed Obstacle Identification"); if (runtype.Equals(RunType.one)) { // calculate the path uisng A* Debug.Log("Begin A* Calculation"); path = a_star(start, goal); Debug.Log("Completed A* Calculation"); foreach (NodeSquare node in path) { node.makePath(); } path.Reverse(); } else if (runtype.Equals(RunType.two)) { // calculate the path using RRT Debug.Log("Begin RRT Calculation"); path = rrt(start, goal); Debug.Log("Completed RRT Calculation"); for (int i = 0; i < path.Count - 1; i++) { Debug.DrawLine(path [i].getRenderLoc(), path [i + 1].getRenderLoc(), Color.blue, float.PositiveInfinity, false); } foreach (NodeSquare node in path) { node.makePath(); } } }