// todo: move methods below to separate class private ChildScript CreateChildObject(Child child, GameObject parent) { Shape shape = PartLoader.GetShape(child); GameObject GameObject = shape.Instantiate(parent.transform); ChildScript childScript = GameObject.AddComponent <ChildScript>(); childScript.shape = shape; childScript.Controller = child.Controller; childScript.SetColor(child.Color); if (!GameController.Instance.potatoMode) { shape.ApplyTextures(GameObject); } if (shape is Block && child.Bounds != null) { childScript.SetBlueprintBounds(child.Bounds); } childScript.SetBlueprintPosition(child.Pos); childScript.SetBlueprintRotation(child.Xaxis, child.Zaxis); return(childScript); }
public new void Awake() { SceneRequiresPlayer = false; Avatar = GetComponentInChildren <AvatarScript>(); Trump = GetComponentInChildren <TrumpScript>(); Child = GetComponentInChildren <ChildScript>(); cam = GetComponentInChildren <Camera>(); }
protected override void Start() { base.Start(); childListGORt = childListGO.GetComponent <RectTransform> (); if (Application.isPlaying) { widthCS = MakeChild("Width"); heightCS = MakeChild("Height"); xCS = MakeChild("X"); yCS = MakeChild("Y"); downCS = MakeChild("Down"); timeCSList = new ChildScript[4]; for (int i = 0; i < 4; ++i) { timeCSList[i] = MakeChild(""); } childBase.SetActive(false); EventTrigger trigger = GetComponent <EventTrigger>(); EventTrigger.Entry entry; entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.PointerDown; entry.callback.AddListener((data) => { OnDown((PointerEventData)data); }); trigger.triggers.Add(entry); entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.BeginDrag; entry.callback.AddListener((data) => { OnDown((PointerEventData)data); }); trigger.triggers.Add(entry); entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.Drag; entry.callback.AddListener((data) => { OnDown((PointerEventData)data); }); trigger.triggers.Add(entry); entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.EndDrag; entry.callback.AddListener((data) => { OnUp((PointerEventData)data); }); trigger.triggers.Add(entry); entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.PointerUp; entry.callback.AddListener((data) => { OnUp((PointerEventData)data); }); trigger.triggers.Add(entry); } }
private ChildScript MakeChild(string title) { GameObject go = Instantiate(childBase); go.SetActive(true); RectTransform goRt = go.GetComponent <RectTransform> (); goRt.SetParent(childListGORt); childRtList.Add(goRt); ChildScript cs = go.GetComponent <ChildScript> (); cs.title = title; return(cs); }
protected override void Awake() { base.Awake(); Name = "actionCheck"; preconditions.Set("checkChild", false); preconditions.Set("nearChild", true); effects.Set("checkChild", true); effects.Set("nearChild", false); //find child and its details child = GameObject.FindWithTag("child"); childDets = child.GetComponent <ChildScript>(); //find goals hungry = GetComponent <HungryGoal>(); happy = GetComponent <HappyGoal>(); check = GetComponent <CheckGoal>(); }
protected override void Awake() { base.Awake(); Name = "actionFindFood"; preconditions.Set("childHungry", true); preconditions.Set("foundFood", false); preconditions.Set("hasFood", false); effects.Set("foundFood", true); effects.Set("move", true); //find needed components rb = GetComponentInParent <Rigidbody>(); child = GameObject.FindWithTag("child").GetComponent <ChildScript>(); //set up lists foodAbove = new List <DetsFood>(); foodBelow = new List <DetsFood>(); foodWanted = new List <DetsFood>(); }
// Use this for initialization void Start() { playerRefer = GameObject.Find("Mario").GetComponent <Player_controller> (); testItem = GameObject.FindGameObjectWithTag("block").GetComponentInChildren <ChildScript>(); stop = GameObject.FindGameObjectWithTag("block").GetComponentInChildren <contactCheck> (); }
// Use this for initialization void Start () { playerRefer = GameObject.Find ("Mario").GetComponent<Player_controller> (); testItem = GameObject.FindGameObjectWithTag("block").GetComponentInChildren<ChildScript>(); stop = GameObject.FindGameObjectWithTag ("block").GetComponentInChildren<contactCheck> (); }
public void CollisionDetected(ChildScript childScript) { road = childScript.ground; Debug.Log("child collided"); //AddReward (0.001f); }
public void CollisionDetected(ChildScript childScript) { //Debug.Log("child collided"); // AddReward (0.001f); }
// Use this for initialization void Start () { testing = gameObject.GetComponentInChildren<ChildScript> (); }
// Use this for initialization void Start() { testing = gameObject.GetComponentInChildren <ChildScript> (); }
/// <summary> /// create child - joint references so both know what they are connected to /// </summary> /// <param name="blueprintScript"></param> /// <param name="blueprintData"></param> private void ArrangeJointReferencesUsingData(BlueprintScript blueprintScript, BlueprintData blueprintData) { // child -> joint is a bit of a pain because scriptchild knows nothing of joints[] int childIndex = 0; IEnumerable <Child> flatDataChildList = blueprintData.Bodies.SelectMany(body => body.Childs).Select(child => child); List <ChildScript> flatLiveChildList = blueprintScript.Bodies.SelectMany(body => body.Childs).Select(child => child).ToList(); IEnumerable <Joint> flatDataJointList = blueprintData.Joints; List <JointScript> flatLiveJointsList = blueprintScript.Joints; if (blueprintData.Joints == null || blueprintData.Joints.Count == 0) { Debug.Log($"no joints found, skipping reference step"); return; } foreach (Child childData in flatDataChildList) { if (childData.Joints?.Count > 0) { ChildScript childScript = flatLiveChildList[childIndex]; childScript.connectedJoints = new List <JointScript>(); foreach (JointReference jointRef in childData.Joints) { JointScript jointScript = flatLiveJointsList.FirstOrDefault(joint => joint.Id == jointRef.Id); if (jointScript == default) { Debug.LogWarning($"child.joints: reference to missing joint!"); continue; } childScript.connectedJoints.Add(jointScript); // connect that joint to this child if it has the data to connect to this child: Joint jointData = flatDataJointList.FirstOrDefault(joint => joint.Id == jointRef.Id); if (jointData.ChildA == childScript.shapeIdx) { jointScript.childA = childScript; } if (jointData.ChildB == childScript.shapeIdx) { jointScript.childB = childScript; } } } childIndex++; } //Debug.Log($"Verifying joint-child connection references"); // verify connections, perspective: joint int jointIndex = 0; foreach (Joint jointData in flatDataJointList) { JointScript jointScript = flatLiveJointsList[jointIndex]; if (jointData.ChildA == -1 || jointData.ChildA >= flatLiveChildList.Count) { if (jointScript.childA == null) { Debug.LogError($"Invalid Joints! no joint.childA information. Attempting fix"); // todo: attempt fix: find child(s) that is connected to this jointscript, 1 child: childA, 2 childs: check childB || error } else { Debug.LogWarning($"joint.childA had invalid information! resolved via child.joints!"); } } else { ChildScript childScriptA = flatLiveChildList[jointData.ChildA]; if (childScriptA.connectedJoints == null) { childScriptA.connectedJoints = new List <JointScript>(); } if (!childScriptA.connectedJoints.Contains(jointScript)) { Debug.LogWarning($"child.joints had missing information. resolving with joint.childA info!"); childScriptA.connectedJoints.Add(jointScript); } } if (jointData.ChildB == -1 || jointData.ChildB >= flatLiveChildList.Count) { if (jointScript.childB == null) { // this is allowed. a joint doesn't have to have a childB // todo: attempt fix: find child(s) that is connected to this jointscript, 1 child: childA, 2 childs: check childB || ok } else { Debug.LogWarning($"joint.childB had invalid information! resolved via child.joints!"); // 'recovered' in prev step } } else { ChildScript childScriptB = flatLiveChildList[jointData.ChildB]; if (childScriptB.connectedJoints == null) { childScriptB.connectedJoints = new List <JointScript>(); } if (!childScriptB.connectedJoints.Contains(jointScript)) { Debug.LogWarning($"child.joints had missing information. resolving with joint.childA info!"); childScriptB.connectedJoints.Add(jointScript); } } jointIndex++; } // todo: to be complete there should be another verify run on all childs to check if connected joints actually reference them back. }
/// <summary> /// click event that should trigger when clicking the 'load' button /// </summary> public void LoadSelectedBlueprint() { GameObject rootGameObject = null; try { if (BlueprintMenu.blueprintObject != null) { //clean up existing blueprintobject Destroy(BlueprintMenu.blueprintObject.gameObject); } Debug.Log("trying to load bp"); BlueprintData blueprintData = SelectedBlueprintButton.BlueprintContextReference.LoadBlueprint(); rootGameObject = Instantiate(GameController.Instance.Blueprint); BlueprintScript blueprintScript = rootGameObject.GetComponent <BlueprintScript>(); int shapeIdx = 0; foreach (var body in blueprintData.Bodies) { GameObject bodyGameObject = Instantiate(GameController.Instance.Body, rootGameObject.transform); BodyScript bodyScript = bodyGameObject.GetComponent <BodyScript>(); blueprintScript.Bodies.Add(bodyScript); foreach (var child in body.Childs) { ChildScript childScript = CreateChildObject(child, bodyGameObject); childScript.shapeIdx = shapeIdx; childScript.Body = bodyScript; bodyScript.Childs.Add(childScript); shapeIdx++; } } if (blueprintData.Joints != null) { foreach (var joint in blueprintData.Joints) { blueprintScript.Joints.Add(CreateJointObject(joint, rootGameObject)); } } ArrangeJointReferencesUsingData(blueprintScript, blueprintData); #region handle camera position PlayerController playerController = GameController.Instance.playerController; if (playerController.snapToCreation) { Camera camera = playerController.gameObject.GetComponent <Camera>(); var center = blueprintScript.CalculateCenter(); var destination = center - camera.transform.forward * playerController.distanceToSnap; var cameraState = playerController.m_TargetCameraState; cameraState.x = destination.x; cameraState.y = destination.y; cameraState.z = destination.z; //GameObject.Find("Sphere").transform.position = center; } #endregion BlueprintMenu.blueprintObject = blueprintScript; Debug.Log("successfully loaded bp"); } catch (Exception e) { Debug.LogException(new Exception($"\nan error occurred while loading this blueprint.", e)); if (rootGameObject != null) { Debug.Log("failed loading blueprint"); Destroy(rootGameObject); } } }
public void CollisionDetected(ChildScript childScript) { Debug.Log("child collided"); Instantiate(prefab, new Vector3(-46.565f, 2, -23.32f), Quaternion.identity); }
public void CollisionDetected(ChildScript childScript) { Debug.Log("child collided"); }