public IEnumerator addBillboard(string text, int color, int style) { GameObject billboard = Instantiate(GameObject.FindGameObjectWithTag("billboardObject")); TextMesh billboardText = billboard.GetComponentInChildren <TextMesh> (); setFontAndColor(billboardText, color, style); billboardText.text = text; //Place the billboard aligned to the map in front of the player Vector3 correctPos = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0)).GetPoint(10); Vector3 billboardRayOrigin = new Vector3(correctPos.x, rayCastObject.gameObject.transform.position.y, correctPos.z); float height = directionsHandler.castRaycastDownAtPosition(billboardRayOrigin); if (height != billboardRayOrigin.y) { directionsHandler.setTotalOffset(); height -= directionsHandler.totalOffset; } billboards.Add(billboard); Vector3 initPosition = new Vector3(correctPos.x, height + 20, correctPos.z); Vector3 droppedPosition = new Vector3(correctPos.x, height, correctPos.z); TransitionalObject billboardDrop = (TransitionalObject)billboard.GetComponent(typeof(TransitionalObject)); while (billboard.transform.localPosition != droppedPosition) { ratio += Time.deltaTime * multiplier; billboard.transform.localPosition = Vector3.Lerp(initPosition, droppedPosition, ratio); yield return(null); } Mapbox.Utils.Vector2d billboardVec2d = directionsHandler.Vec2dFromUnityVector(billboard.transform.position); sendAnnotation("billboard", text, billboardVec2d.x, billboardVec2d.y, height, color, style); }
public static void SetToEndDeviation() { for (int i = 0; i < Selection.gameObjects.Length; i++) { TransitionalObject temp = Selection.gameObjects[i].GetComponent <TransitionalObject>(); if (temp == null) { if (Selection.gameObjects.Length == 1) //if we have only selected one object { TransitionalObject[] children = Selection.gameObjects[0].GetComponentsInChildren <TransitionalObject>(); //find in children instead for (int j = 0; j < children.Length; j++) { children[j].ViewPosition(TransitionalObject.MovingDataType.MaxEnd); } return; } else { temp = Selection.gameObjects[i].GetComponentInChildren <TransitionalObject>(); } } temp.ViewPosition(TransitionalObject.MovingDataType.MaxEnd); } }
void Start() { base.Start(); if (beatingTransition == null) { beatingTransition = GetComponent <TransitionalObject>();//find the transition! //if(beatingTransition == null)//no transition, so make one //{ // beatingTransition = gameObject.AddComponent<TransitionalObject>(); // beatingTransition.transitions = new TransitionalObjects.BaseTransition[1]; // beatingTransition.transitions[0] = gameObject.AddComponent<TransitionalObjects.ScalingTransition>(); // beatingTransition.FirstTransition.EditorInitialise(beatingTransition); // beatingTransition.ScalingTransition.messagingEnabled = true; // beatingTransition.FirstTransition.whenToSends = new TransitionalObjects.BaseTransition.TransitionState[] { TransitionalObjects.BaseTransition.TransitionState.Waiting, TransitionalObjects.BaseTransition.TransitionState.LoopFinished }; // UnityEvent biggestEvent = new UnityEvent();//sadly this doesn't work and not sure why! // biggestEvent.AddListener(AtBiggestSize); // UnityEvent smallestEvent = new UnityEvent(); // smallestEvent.AddListener(AtSmallestSize); // beatingTransition.FirstTransition.events = new UnityEvent[] { biggestEvent, smallestEvent }; // beatingTransition.FirstTransition.stayForever = false; // beatingTransition.FirstTransition.triggerInstantly = true; // beatingTransition.FirstTransition.looping = true; //} } UpdateIndex(CheckIfIndexChanged()); }
/// <summary> /// Editor only! /// </summary> public void EditorInitialise(TransitionalObject parent) { this.parent = parent; hideFlags = HideFlags.HideInInspector;//don't show these components in the inspector mainDropDown = new AnimBool(); mainDropDown.target = true;//start by showing this frame can move events = new UnityEvent[0]; whenToSends = new TransitionState[0]; AnimationCurve defualtCurve = new AnimationCurve();//make a new defualt curve when there is no existing one Keyframe frame = new Keyframe(0, 0); defualtCurve.AddKey(frame); frame.time = 1; //this produces a linear diagonal line from 0 to 1 but... frame.value = 1; //unity will smooth these automatically to give a nice fade in and out defualtCurve.AddKey(frame); transitionInCurve = new AnimationCurve(defualtCurve.keys); fadeOutCurve = new AnimationCurve(defualtCurve.keys); previousTransitionInCurve = defualtCurve.keys; previousFadeOutCurve = defualtCurve.keys; }
public void Clone(TransitionalObject other) { for (int i = 0; i < transitions.Length; i++) { transitions[i].parent = other; transitions[i].Clone(other.transitions[i]); } }
protected override void Transition(float transitionPercentage) { #if (StoreVersion) SetColour(TransitionalObject.Lerp(startColour, endColour, transitionPercentage)); #else SetColour(K2Maths.Lerp(startColour, endColour, transitionPercentage)); #endif }
public static void UpdateEndDeviation() { for (int i = 0; i < Selection.gameObjects.Length; i++) { TransitionalObject temp = Selection.gameObjects[i].GetComponent <TransitionalObject>(); if (temp == null) { temp = Selection.gameObjects[i].GetComponentInChildren <TransitionalObject>(); } temp.UpdatePosition(TransitionalObject.MovingDataType.MaxEnd); } }
public void Clone(TransitionalObject other) { for (int i = 0; i < transitions.Length; i++) { DestroyImmediate(transitions[i]); } transitions = new BaseTransition[other.transitions.Length]; for (int i = 0; i < other.transitions.Length; i++) { CloneTransition(i, other.transitions[i]); transitions[i].parent = this; transitions[i].Clone(other.transitions[i]); } }
public virtual void Clone(BaseTransition other) { #if (UNITY_EDITOR) label = other.label; mainDropDown = new AnimBool(); transitionInDropDown = new AnimBool(); fadeOutDropDown = new AnimBool(); messagingDropDown = new AnimBool(); loopingDropDown = new AnimBool(); dataDropDown = new AnimBool();//these are for the editor. They are stored here to help act as saving your preferences whe viewing each object stayForever = other.stayForever; #endif parent = other.parent; state = other.state; currentTime = other.currentTime; delay = other.delay; transitionInTime = other.transitionInTime; fadeOutTime = other.fadeOutTime; displayTime = other.displayTime; fadeOutDelay = other.fadeOutDelay; transitionInCurve = new AnimationCurve(other.transitionInCurve.keys); fadeOutCurve = new AnimationCurve(other.fadeOutCurve.keys); looping = other.looping; triggerInstantly = other.triggerInstantly; #region Messaging messagingEnabled = other.messagingEnabled;//used to temporary enable and disable messages events = other.events; whenToSends = (TransitionState[])other.whenToSends.Clone(); #endregion }
const string menuName = "K2 Framework/"; //this simply moves the menu to a place we use. However Unity, wisely, recommend we don't do this for each published asset #endif #endregion void OnGUI() { this.position = new Rect(Screen.currentResolution.width / 2 - 125, Screen.currentResolution.height / 2 - 75, 250, 150); if (staggerType == StaggerType.Rename) { first = EditorGUILayout.ObjectField("First Object", first, typeof(GameObject), true) as GameObject; EditorGUILayout.LabelField(new GUIContent("Help (Hover)", "Assign your first object.\nThen select every object to rename and hit run.\nObjects are renamed according to their position in relation to the first object.")); } else { switch (staggerType) { case StaggerType.Delay: startDelay = EditorGUILayout.FloatField(new GUIContent("Start Delay", "What is the delay of the first selected object"), startDelay); break; case StaggerType.FadeOutDelay: startDelay = EditorGUILayout.FloatField(new GUIContent("Start Fade Out Delay", "What is the fade out delay of the first selected object"), startDelay); break; case StaggerType.DisplayTime: startDelay = EditorGUILayout.FloatField(new GUIContent("Start Display Time", "What is the display time of the first selected object"), startDelay); break; case StaggerType.TransitionTime: startDelay = EditorGUILayout.FloatField(new GUIContent("Start Transition Time", "What is the transition time of the first selected object"), startDelay); break; case StaggerType.FadeOutTime: startDelay = EditorGUILayout.FloatField(new GUIContent("Start Fade Out Time", "What is the fade out time of the first selected object"), startDelay); break; } increment = EditorGUILayout.FloatField(new GUIContent("Increment", "How much to add onto the delay for each object."), increment); reverse = EditorGUILayout.Toggle(new GUIContent("Reverse", "If the stagger should be applied in reverse order"), reverse); EditorGUILayout.LabelField(new GUIContent("Help (Hover)", "Selected objects will have the Start and Increment values added according to their position in the selection.\nTo ensure consistent results give each object a unqiue name and sort them alphabetically.")); } if (GUILayout.Button(new GUIContent("Run", "Staggers over all selected transitions"))) { if (staggerType == StaggerType.Rename) { char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray(); List <GameObject> objects = new List <GameObject>(); objects.Add(first);//add the first item float distance, lastDistance = 0; for (int i = 0; i < Selection.gameObjects.Length; i++) { if (Selection.gameObjects[i].Equals(first)) { continue;//ignore the first item when it appears } distance = Vector3.SqrMagnitude(objects[0].transform.position - Selection.gameObjects[i].transform.position); if (distance > lastDistance) //if we are further away than the last object { objects.Add(Selection.gameObjects[i]); //just add it onto the end lastDistance = distance; //and record the last distance } else { float newDistance; for (int j = 1; j < objects.Count; j++) //ignore the first { newDistance = Vector3.SqrMagnitude(objects[j].transform.position - objects[0].transform.position); //determine the distance to every object we have added already if (newDistance > distance) { objects.Insert(j, Selection.gameObjects[i]); lastDistance = Vector3.SqrMagnitude(objects[objects.Count - 1].transform.position - objects[0].transform.position); break; } } } } for (int i = 0; i < objects.Count; i++) { if (i < alphabet.Length) { objects[i].name += " " + alphabet[i]; } else { objects[i].name += " "; for (int j = 0; j < i / alphabet.Length; j++) { objects[i].name += alphabet[alphabet.Length - 1];//figure outhow many Z's to add on } objects[i].name += alphabet[i - alphabet.Length]; } } } else { GameObject[] selection = Selection.gameObjects; #if (StoreVersion) selection = SortAlphabetically(selection, !reverse); #else //selection = K2Maths.SortAlphabetically(selection, !reverse); #endif for (int i = 0; i < selection.Length; i++) { TransitionalObject temp = selection[i].GetComponent <TransitionalObject>(); if (temp == null) { temp = selection[i].GetComponentInChildren <TransitionalObject>(); } switch (staggerType) { case StaggerType.Delay: temp.Delay = startDelay + i * increment; break; case StaggerType.DisplayTime: temp.DisplayTime = startDelay + i * increment; break; case StaggerType.TransitionTime: temp.TransitionInTime = startDelay + i * increment; break; } } } this.Close(); } if (GUILayout.Button(new GUIContent("Close", "Closes this window"))) { this.Close(); } }