public void SelectionChange(int index) { childCreator.SetParentSceneNode(mSelectedTransform[index].gameObject.GetComponent <SceneNode>()); NodePrimitive nodePrimEq = FindEquivalentNodePrim(mSelectedTransform[index].name, RootNodePrim.transform); smallViewCamera.selectedNode = mSelectedTransform[index]; //childCreator.SetParentNode(nodePrimEq.transform); }
/// <summary> /// Add a new node primitive to the current snowman scene node /// </summary> /// <param name="newPrimitive"></param> public void AddPrimitive(NodePrimitive newPrimitive) { if (newPrimitive != null) { Vector3 currentSceneNodePosition = combinedParentTransform.GetColumn(3); Vector3 updatedLocalPosition = newPrimitive.transform.position - currentSceneNodePosition; newPrimitive.transform.localPosition = updatedLocalPosition; PrimitiveList.Add(newPrimitive); newPrimitive.TryEnableSmallCam(); } }
public void CreateChild(int val) { if (val == 0) { return; } string food = foodNames[val - 1]; GameObject newFood = Instantiate <GameObject>(foods[food]); if (newFood == null) { return; } string foodId = RandomID(4); newFood.name = food + foodId; // create a newSceneNode GameObject GameObject newSceneNodeGO = new GameObject(food); newSceneNodeGO.name = food + foodId; SceneNode newSceneNode = newSceneNodeGO.AddComponent <SceneNode>(); newSceneNode.gameObject.tag = "SceneNode"; // Create a new nodePrimitive NodePrimitive newFoodNP = newFood.AddComponent <NodePrimitive>(); newFoodNP.GetComponent <Renderer>().material = NPMaterial; newFoodNP.GetComponent <Renderer>().material.mainTexture = foodTextures[val - 1]; // sets as child of parent node primitive not scene node. //newFood.transform.SetParent(parentNode); newFood.transform.localScale = new Vector3(10, 10, 10); // set new scene node to child of old scene node newSceneNodeGO.transform.SetParent(sceneNodeParent.transform); newSceneNodeGO.transform.localPosition = new Vector3(0, 0.5f, 0); SetAllSceneNodes(newSceneNode, newFoodNP); childMenu.value = 0; // update scene node hierarchy sceneNodeControl.UpdateSceneNodeMenu(); // set pet and human location newSceneNode.PetLocation = PetLocation; newSceneNode.HumanLocation = HumanLocation; newSceneNode.sceneNodeControl = sceneNodeControl; newSceneNode.rootNP = rootNP; // attach scene node to collider newSceneNode.SceneCollider = Instantiate <GameObject>(sceneColliderPrefab).transform; newSceneNode.SceneCollider.gameObject.AddComponent <KindGetter>(); newSceneNode.SceneCollider.gameObject.GetComponent <KindGetter>().nodeType = newSceneNode; }
private void SetAllSceneNodes(SceneNode newSceneNode, NodePrimitive newNodePrim) { NodePrimitive curr = newNodePrim; while (curr != null) { newSceneNode.PrimitiveList.Add(curr); if (curr.transform.parent != null) { curr = curr.transform.parent.GetComponent <NodePrimitive>(); } else { curr = null; } } }
private void CutSegment(GrowingSceneNode targetNode) { // Create a new TheWorld so that the cut segment can remain visible GameObject tempParent = new GameObject("tempParent"); tempParent.AddComponent <TheWorld>(); tempParent.GetComponent <TheWorld>().RootNode = targetNode.GetComponent <SceneNode>(); Debug.Log("Cut"); NodePrimitive primitive = targetNode.transform.GetChild(0).GetChild(0).GetComponent <NodePrimitive>(); Vector3 lastAttachedPosition; lastAttachedPosition = primitive.currentLoc; targetNode.NodeOrigin = lastAttachedPosition; targetNode.transform.parent = tempParent.transform; plantParts.Remove(targetNode); targetNode.gameObject.AddComponent <FallingBranch>(); }
public NodePrimitive FindEquivalentNodePrim(string name, Transform rootNP) { if (rootNP.transform.name.Equals(name)) { return(rootNP.GetComponent <NodePrimitive>()); } for (int i = 0; i < rootNP.childCount; i++) { Transform child = rootNP.GetChild(i); NodePrimitive cn = child.GetComponent <NodePrimitive>(); if (cn == null) { continue; } NodePrimitive foundNode = FindEquivalentNodePrim(name, child); if (foundNode != null) { return(foundNode); } } return(null); }
/// <summary> /// If no objects are currently being held and we're currently lookin at objects, attempt to grab hold /// of the closet object. /// </summary> /// <returns></returns> public bool TryHoldObject() { if (!objectHeld && lookedAtPrimitives != null && lookedAtPrimitives.Count > 0) { NodePrimitive closestPrimitive = lookedAtPrimitives[0]; foreach (NodePrimitive primitive in lookedAtPrimitives) { Vector3 closestPos = closestPrimitive.currentTransform.GetColumn(2); Vector3 primPos = primitive.currentTransform.GetColumn(2); Vector3 camToClosest = closestPos - Camera.main.transform.position; Vector3 camToPrim = primPos - Camera.main.transform.position; if (camToPrim.magnitude < camToClosest.magnitude) { closestPrimitive = primitive; } } closestPrimitive.PerformHoldActions(Camera.main.transform); objectHeld = true; } return(objectHeld); }
/// <summary> /// Adds a game object as a node primitive to the world /// </summary> /// <param name="snowmanObject"></param> public void AddPrimitiveToCurrentNode(GameObject snowmanObject) { if (snowmanObject != null) { SnowmanAccessory accessory = snowmanObject.GetComponent <SnowmanAccessory>(); if (accessory != null) { snowmanObject.layer = 0; //Change the layer since we no longer want to treat this object as an free object snowmanObject.GetComponent <Renderer>().material = stardardObjectMat; accessory.UpdateMaterial(stardardObjectMat); NodePrimitive primitive = snowmanObject.AddComponent <NodePrimitive>(); primitive.PrimitiveColor = accessory.PrimaryColor; primitive.detectionType = accessory.DetectionType; accessory.SetColor(accessory.PrimaryColor); SceneNode node = GetSnowmanSceneNode(); node.AddPrimitive(primitive); } else { Debug.LogError("The object grab is not a valid snowman accessory object"); } } }
private void Start() { bladePrimitive = GameObject.Find("BladePrimitive").GetComponent <NodePrimitive>(); }
void Awake() { Myself = GetComponent <NodePrimitive>(); }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftAlt)) { Debug.Log("Mouse clicked"); prevX = Input.mousePosition.x; prevY = Input.mousePosition.y; // Ensure not clicking GUI if (!EventSystem.current.IsPointerOverGameObject()) { Debug.Log("Raycasting..."); RaycastHit hitInfo = new RaycastHit(); bool hit = Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out hitInfo, Mathf.Infinity, 1); if (hit) { Debug.Log("Hit " + hitInfo.transform.gameObject.name); if (hitInfo.transform.name.Contains("Ref")) { Debug.Log("Selected " + hitInfo.transform.name); mSelectedObject = hitInfo.transform.gameObject; dragging = true; } } } else { Debug.Log("Did not raycast: over GUI"); } } //user is dragging as long as getMouseButton else if (dragging && (Input.GetMouseButton(0))) { float dx = prevX - Input.mousePosition.x; float dy = prevY - Input.mousePosition.y; prevX = Input.mousePosition.x; prevY = Input.mousePosition.y; Debug.Log("Dragged by {" + dx + ", " + dy + "}"); if (mSelectedObject != null) { NodePrimitive np = mSelectedObject.GetComponent <ReferenceToPrimitive>().np; Vector3 q = np.manipulateIfHit.transform.localRotation.eulerAngles; if (np.name == "BasePrimitive") { q.y += dx; } else { q.z += dx; } mSelectedObject.GetComponent <ReferenceToPrimitive>().np.manipulateIfHit.transform.localRotation = Quaternion.Euler(q.x, q.y, q.z); } } else { if (dragging) { Debug.Log("Stopped dragging"); } dragging = false; } }
void SetSpeed(NodePrimitive node, float v) { node.SetCurrentSpeed(node.AngularSpeed * v); }