public void VerifyAnimations(TouchGUIBase touchGUIBaseOld) { if (unlatchedAnimationTop == null) unlatchedAnimationTop = new TouchAnimationInformation(); unlatchedAnimationTop.Verify(touchGUIBaseOld); if (unlatchedAnimationBase == null) unlatchedAnimationBase = new TouchAnimationInformation(); unlatchedAnimationBase.Verify(touchGUIBaseOld); if (latchedAnimationTop == null) latchedAnimationTop = new TouchAnimationInformation(); latchedAnimationTop.Verify(touchGUIBaseOld); if (latchedAnimationBase == null) latchedAnimationBase = new TouchAnimationInformation(); latchedAnimationBase.Verify(touchGUIBaseOld); }
void Start() { _touchGUIBaseOld = GetComponent<TouchGUIBase>(); VerifyPresets(); if (allPresets.Count == 0) { Destroy(this); return; } if (string.IsNullOrEmpty(initialPreset)) { initialPreset = allPresets[0].presetID; } SwapToPreset(initialPreset); _activePreset.SnapToAnimation(_touchGUIBaseOld); }
private TouchAnimationPreset Aimation_GenerateDefaultAnimPreset(string presetName, TouchGUIBase t) { TouchAnimationPreset newAnimPreset = new TouchAnimationPreset{ presetID = presetName }; newAnimPreset.latchedAnimationTop = new TouchAnimationInformation(t.topPart); newAnimPreset.unlatchedAnimationTop = new TouchAnimationInformation(t.topPart); newAnimPreset.latchedAnimationBase = new TouchAnimationInformation(t.basePart); newAnimPreset.unlatchedAnimationBase = new TouchAnimationInformation(t.basePart); return newAnimPreset; }
protected void GUI_EditPanel_GUIBase(TouchGUIBase t) { if(t == null) return; bool hasAnimation = t.GetComponent<TouchAnimation>() != null; if (!hasAnimation) { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); { GUILayout.Label("Base ", EditorStyles.boldLabel); _selectedTouchBase.baseImg = EditorGUILayout.ObjectField(_selectedTouchBase.baseImg, typeof (Texture), false, GUILayout.Height(currentSelectedTouchBaseSettings._width/2)) as Texture; if (_selectedTouchBase.baseImg != t.basePart.texture) { t.basePart.texture = _selectedTouchBase.baseImg; /*t.basePart.pixelInset = new Rect(t.basePart.texture.width/-2, t.basePart.texture.height/-2, t.basePart.texture.width, t.basePart.texture.height);*/ EditorUtility.SetDirty(t.basePart); } GUILayout.Label("Layer", EditorStyles.miniLabel); int newLayer = EditorGUILayout.IntField(t.basePartLayer); if (newLayer != t.basePartLayer) { t.basePartLayer = newLayer; EditorUtility.SetDirty(t); } GUILayout.Label("Color", EditorStyles.miniLabel); Color newColor = EditorGUILayout.ColorField(t.basePart.color); if (newColor != t.basePart.color) { t.basePart.color = newColor; EditorUtility.SetDirty(t.basePart.gameObject); } } GUILayout.EndVertical(); GUILayout.BeginVertical(); { GUILayout.Label("Top ", EditorStyles.boldLabel); _selectedTouchBase.topImg = EditorGUILayout.ObjectField(_selectedTouchBase.topImg, typeof (Texture), false, GUILayout.Height(currentSelectedTouchBaseSettings._width/2)) as Texture; if (_selectedTouchBase.topImg != t.topPart.texture) { t.topPart.texture = _selectedTouchBase.topImg; /*t.topPart.pixelInset = new Rect(t.topPart.texture.width/-2, t.topPart.texture.height/-2, t.topPart.texture.width, t.topPart.texture.height);*/ EditorUtility.SetDirty(t.topPart); } GUILayout.Label("Layer", EditorStyles.miniLabel); int newLayer = EditorGUILayout.IntField(t.topPartLayer); if (newLayer != t.topPartLayer) { t.topPartLayer = newLayer; EditorUtility.SetDirty(t); } GUILayout.Label("Color", EditorStyles.miniLabel); Color newColor = EditorGUILayout.ColorField(t.topPart.color); if (newColor != t.topPart.color) { t.topPart.color = newColor; EditorUtility.SetDirty(t.topPart.gameObject); } } GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Label("Size on screen: ", EditorStyles.boldLabel); float newScale = EditorGUILayout.Slider(t.scale, 0f, 1f); if (newScale != t.scale) { t.scale = newScale; EditorUtility.SetDirty(t); } } GUILayout.Label("Recenter on Release: ", EditorStyles.boldLabel); TouchGUIBase.RecenterMethod newR = (TouchGUIBase.RecenterMethod)EditorGUILayout.EnumPopup(t.recenterBaseOnRelease); if (newR != t.recenterBaseOnRelease) { t.recenterBaseOnRelease = newR; if (t.recenterBaseOnRelease != TouchGUIBase.RecenterMethod.Smooth) t.recenterBaseMethodValue = 0; EditorUtility.SetDirty(t); } if (t.recenterBaseOnRelease == TouchGUIBase.RecenterMethod.Smooth) { GUILayout.BeginHorizontal(); GUILayout.Label("Speed: ", EditorStyles.miniLabel); float oldSpeed = EditorGUILayout.Slider(t.recenterBaseMethodValue, 0f, 1f); GUILayout.EndHorizontal(); if (oldSpeed != t.recenterBaseMethodValue) { t.recenterBaseMethodValue = oldSpeed; EditorUtility.SetDirty(t); } } GUILayout.Label("Animation: ",EditorStyles.boldLabel); if(!hasAnimation) { GUILayout.Label("No Animation component.",EditorStyles.miniLabel); if(GUILayout.Button("Add Animation component",EditorStyles.miniButton)) { TouchAnimation ta = t.gameObject.AddComponent<TouchAnimation>(); ta.initialPreset = "Default"; ta.allPresets.Add(Aimation_GenerateDefaultAnimPreset("Default",t)); _gamePreview.SetPreset(ta.allPresets.First(a => a.presetID == ta.initialPreset)); EditorUtility.SetDirty(t.gameObject); } } else { TouchAnimation ta = t.gameObject.GetComponent<TouchAnimation>(); if(ta.allPresets.GroupBy(a => a.presetID).Any( a => a.Count() > 1)) { GUILayout.Space(5); EditorGUILayout.HelpBox("Presets must have unique names.", MessageType.Error); GUILayout.Space(5); } /*else EditorGUILayout.HelpBox("Animations will ignore size and texture settings above.",MessageType.Info);*/ GUILayout.BeginHorizontal(); GUILayout.Label("Initial Preset: ",EditorStyles.miniLabel); int currentIndex = ta.allPresets.IndexOf (ta.allPresets.First(a => a.presetID == ta.initialPreset)); string[] popUpVals = new string[ta.allPresets.Count]; int ii = 0; ta.allPresets.ForEach(a => { popUpVals[ii] = a.presetID; ii++; }); int newIndex = EditorGUILayout.Popup(currentIndex,popUpVals); if(newIndex != currentIndex) { ta.initialPreset = popUpVals[newIndex]; EditorUtility.SetDirty(ta); } GUILayout.EndHorizontal(); for (int i = 0; i < ta.allPresets.Count; i++) { GUILayout.Space(5); GUILayout.BeginHorizontal(); GUILayout.Label(new GUIContent( (ta.allPresets[i].presetID), _animationIcon), EditorStyles.label); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Animate", EditorStyles.miniButtonLeft)) { _selectedTouchBase._touchAnimationActivePreset = ta.allPresets[i]; if(_selectedTouchBase.selectedMiscPanel == null) { _selectedTouchBase.selectedMiscPanel = new TouchInputManagerEditor_GUISidebar(340,500,_styleDarkWithBorderBG,GUI_EditPanel_Animation,null,Repaint); _selectedTouchBase.selectedMiscPanel.Expand(); } else { float w = _selectedTouchBase.selectedMiscPanel._width; _selectedTouchBase.selectedMiscPanel = new TouchInputManagerEditor_GUISidebar(340,500,_styleDarkWithBorderBG,GUI_EditPanel_Animation,null,Repaint); _selectedTouchBase.selectedMiscPanel._width = w; } _gamePreview.SetPreset(ta.allPresets[i]); } if (GUILayout.Button("Delete", EditorStyles.miniButtonRight)) { if(ta.allPresets.Count == 1) { EditorUtility.DisplayDialog("Last Preset","You must have atleast one preset.","Ok"); } else { if(EditorUtility.DisplayDialog("Are you sure?","You are about to delete preset '"+ta.allPresets[i].presetID +"'.","Ok","Cancel")) { if(_selectedTouchBase._touchAnimationActivePreset != null && _selectedTouchBase._touchAnimationActivePreset.presetID == ta.allPresets[i].presetID) { _selectedTouchBase._touchAnimationActivePreset = null; } if(ta.allPresets[i].presetID == ta.initialPreset) { ta.initialPreset = (i == 0) ? ta.allPresets[1].presetID : ta.allPresets[0].presetID; } if(ta.allPresets[i].presetID == _gamePreview.ActivePreset()) _gamePreview.SetPreset(ta.allPresets.First(a => a.presetID == ta.initialPreset)); LooseFocus(); ta.allPresets.RemoveAt(i); i--; EditorUtility.SetDirty(ta); } } } GUILayout.EndHorizontal(); } GUILayout.Space(5); GUILayout.BeginHorizontal(); if (GUILayout.Button("Add Preset", EditorStyles.miniButton)) { string toAdd = "NewAnim_1"; int counter = 1; while(ta.allPresets.Any(a => a.presetID == toAdd)) { counter++; toAdd = "NewAnim_"+counter; } ta.allPresets.Add(Aimation_GenerateDefaultAnimPreset(toAdd,t)); EditorUtility.SetDirty(t); LooseFocus(); } GUILayout.EndHorizontal(); GUILayout.Space(15); if(GUILayout.Button("Remove animation component",EditorStyles.miniButton)) { if(EditorUtility.DisplayDialog("Are you sure?","This will destroy all the animations.","Ok","Cancel")) { _selectedTouchBase._touchAnimationActivePreset = null; _gamePreview.ClearPreset(); Component.DestroyImmediate(t.gameObject.GetComponent<TouchAnimation>(),true); EditorUtility.SetDirty(t.gameObject); } } } }
public void Verify(TouchGUIBase touchGUIBaseOld) { ///we now allow no textures.. guess there is nothing else left to verify.. xD /*if (changeToTexture == null) changeToTexture = touchGUIBaseOld.topPart.texture;*/ }
public void UpdateAnimations(TouchGUIBase touchGUIBaseOld) { if (touchGUIBaseOld.tracker.AnyLatchedFingers) { switch (latchedAnimationBase.transitionMethod) { case TouchAnimationInformation.TransitionMethod.Snap: LerpAnimationInformation(touchGUIBaseOld.basePart, unlatchedAnimationBase, latchedAnimationBase, 1); break; case TouchAnimationInformation.TransitionMethod.Smooth: LerpAnimationInformation(touchGUIBaseOld.basePart, new TouchAnimationInformation(touchGUIBaseOld.basePart), latchedAnimationBase, latchedAnimationBase.transitionMethodValue); break; } switch (latchedAnimationTop.transitionMethod) { case TouchAnimationInformation.TransitionMethod.Snap: LerpAnimationInformation(touchGUIBaseOld.topPart, unlatchedAnimationTop, latchedAnimationTop, 1); break; case TouchAnimationInformation.TransitionMethod.Smooth: LerpAnimationInformation(touchGUIBaseOld.topPart, new TouchAnimationInformation(touchGUIBaseOld.topPart), latchedAnimationTop, latchedAnimationTop.transitionMethodValue); break; } } else { switch (unlatchedAnimationBase.transitionMethod) { case TouchAnimationInformation.TransitionMethod.Snap: LerpAnimationInformation(touchGUIBaseOld.basePart, latchedAnimationBase, unlatchedAnimationBase, 1); break; case TouchAnimationInformation.TransitionMethod.Smooth: LerpAnimationInformation(touchGUIBaseOld.basePart, new TouchAnimationInformation(touchGUIBaseOld.basePart), unlatchedAnimationBase, unlatchedAnimationBase.transitionMethodValue); break; } switch (unlatchedAnimationTop.transitionMethod) { case TouchAnimationInformation.TransitionMethod.Snap: LerpAnimationInformation(touchGUIBaseOld.topPart, latchedAnimationTop, unlatchedAnimationTop, 1); break; case TouchAnimationInformation.TransitionMethod.Smooth: LerpAnimationInformation(touchGUIBaseOld.topPart, new TouchAnimationInformation(touchGUIBaseOld.topPart), unlatchedAnimationTop, unlatchedAnimationTop.transitionMethodValue); break; } } }
public void SnapToAnimation(TouchGUIBase touchGUIBaseOld) { LerpAnimationInformation(touchGUIBaseOld.basePart, latchedAnimationBase, unlatchedAnimationBase, 1); LerpAnimationInformation(touchGUIBaseOld.topPart, latchedAnimationTop, unlatchedAnimationTop, 1); }