/// <summary> /// Starting new game /// </summary> public void StartGame() { m_isItInitialized = false; GameInitialization(); Loading(); PlaceOpenedItems(AbstractObject.GetOpennedItems()); m_isItInitialized = true; LearningTip.CreateTip("tip1"); }
static bool SetTargetObject(LearningTip obj, string targetObjectName, Transform parent) { var path = targetObjectName.Split('\\'); Transform nextObj = parent.Find(path[0]); if (path.Length > 1) { string newPath = targetObjectName.Split(new[] { '\\' }, 2)[1]; SetTargetObject(obj, newPath, nextObj ?? parent); } else { obj._targetObject = nextObj.gameObject; } return(path[0].Contains("Canvas")); }
/// <summary> /// loading data from xml files /// </summary> public void Loading() { //order is important! from parents to children, science the last one EffectTypeHolder.Load("effect_map"); MineralResource.Load("mineralResource_Map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); Resource.Load("resource_Map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); GameMaterial.Load("materials_Map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); Items.Load("items_Map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); Buildings.Load("buildings_Map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); Army.Load("army_map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); Process.Load("process_map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); Science.Load("science_map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); DomesticAnimal.Load("domesticAnimal_map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); WildAnimal.Load("wildAnimal_map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); LearningTip.Load("AllTips_Map"); GameAbstractItem.ParseDependency(); Population ppl = new Population { m_people = GetComponent <People>(), m_isItOpen = 1 }; AbstractObject.m_sEverything.Add(ppl); Localization.GetLocalization().FirstLoad(); Localization.GetLocalization().ChangeLanguage(Localization.GetLocalization().m_currentLanguage); AbstractObject.ClearUnparsed(); Debug.Log("loading finished"); }
/// <summary> /// Create a tip in the game /// </summary> /// <param name="name">tip uniquie name</param> /// <param name="forseShow">is it should be shown without the "can show" param?</param> public static void CreateTip(string name, bool forseShow = false) { if (m_sCanShow == false && forseShow == false) { return; } LearningTipData data; MainScript ms = Camera.main.GetComponent <MainScript>(); try { data = _sAllTips[name]; } catch (KeyNotFoundException) { Debug.LogError("Tip " + name + " set as the next, but was not found"); return; } AbstractObject depend = null; GameObject dependency = null; if (data.m_dependency != null && data.m_dependency.Length > 0) { depend = AbstractObject.GetByName(data.m_dependency); if (depend == null) { dependency = GameObject.Find(data.m_dependency); } } Vector3 coord = data.m_position; if (depend != null) { coord += depend.m_thisObject.transform.position; depend.m_thisObject.IconClick(); } coord.z = -3; //learning tips should be higher then icons; var LearningTipObj = Instantiate(Camera.main.GetComponent <MainScript>().m_LearingTipPrefab); LearningTipObj.name = "Learning Tip: " + data.m_name; LearningTipObj.transform.position = coord; coord.z = Camera.main.transform.position.z; Camera.main.transform.position = coord; LearningTip thisObj = LearningTipObj.GetComponent <LearningTip>(); thisObj._data = data; var Canvas = LearningTipObj.transform.Find("Canvas tips"); var txtObj = Canvas.Find("TipText").gameObject; var txt = txtObj.GetComponent <TextMeshProUGUI>(); txt.text = data.m_text; SetButton(Canvas, "PrevButton", thisObj.OnPrevious, data.m_previous != null); SetButton(Canvas, "NextButton", thisObj.OnNext, data.m_next != null && data.m_next.Length > 0); SetButton(Canvas, "OkButton", thisObj.OnClose, !(data.m_next != null && data.m_next.Length > 0)); var toggle = thisObj.m_showTips.GetComponent <Toggle>(); toggle.isOn = m_sCanShow; toggle.onValueChanged.AddListener(delegate { thisObj.OnShowTip(); }); if (depend != null || dependency != null) { bool hasCanvas = false; //TODO:yellow outline if (depend != null) { hasCanvas = SetTargetObject(thisObj, data.m_targetObject, depend.m_thisObject.transform); } else { thisObj._targetObject = dependency; } Rect rectB = new Rect(); if (data.m_yellowBox != null && data.m_yellowBox.width > 0) { rectB = data.m_yellowBox; rectB.center += (Vector2)thisObj._targetObject.transform.position; } else { if (data.m_isItUI || hasCanvas) { var rect = thisObj._targetObject.transform as RectTransform; rectB = rect.rect; rectB.center = thisObj._targetObject.transform.position; } else { var render = thisObj._targetObject.GetComponent <Renderer>(); rectB.size = render.bounds.size; rectB.center = render.bounds.center; } } data.m_outline = Instantiate(ms.m_OutlinePrefab).GetComponent <Outline>(); data.m_outline.transform.position = new Vector3(); data.m_outline.m_OutlineRect = rectB; data.m_outline.mb_IsItCanvas = thisObj._data.m_isItUI; } //var outline = thisObj.m_targetObject.AddComponent<Outline>(); //outline.OutlineMode = Outline.Mode.OutlineAll; //outline.OutlineColor = Color.yellow; //outline.OutlineWidth = 5f; }