//********************************************************// // // // Copyright © All rights reserved. MyNameIsVoo. 2020. // // // // REPRODUCTION FORBIDEN // // // //********************************************************// using System.Collections; using UnityEngine; using UnityEngine.UI; using ItemsClassList; using ICWM.IconSystem; using ICWM.MenuSystem; using ICWM.RenderSystem; namespace ICWM { namespace HelperSystem { public class ModdingSystem : MonoBehaviour { #region Attributes [Header("ATTRIBUTES")] [ToolTipAttribute.Tooltip("The mode of displaying icons in the modding window. Ellipse mode - icons will move along an ellipse in a certain plane (screen place). Space mode - the icons will move in space with the weapon.")] public IconRender.ModeRotate modeModdingRotate = IconRender.ModeRotate.SPACE; [ToolTipAttribute.Tooltip("Reference to the button in the modding window. The button responds to the hide/unhide of icons.")] public GameObject ToggleVisibleIcons; // For the modding button [ToolTipAttribute.Tooltip("Reference to the button in the modding window. The button is responsible for the Tooltip mode in the modding window.")] public GameObject ToggleRaycast; // For the modding button //public GameObject ToggleVisibleCriticalIcons; // For the modding button [Header("DEBUG")] public bool isActiveModding = false; public bool isActiveCarModding = false; public bool isHideIcons = false; public static ModdingSystem instance; #endregion private void Start() { instance = this; IconRender.instance.modeRotate = modeModdingRotate; if (!InventoryBase.instance.toolTip.IsModdingToolTip) ToggleRaycast.SetActive(false); } #region PUBLIC #region Button Event public void HideIcons(int mode) { if (WeaponRender.instance.vspModel) { if (mode == 0) { Component[] p = WeaponRender.instance.vspModel.GetComponentsInChildren(typeof(LineRenderer), true); if (ToggleVisibleIcons.GetComponentInChildren().text == "Hide all") // Скрываем все { if (p != null) { foreach (LineRenderer g in p) g.enabled = false; } isHideIcons = true; ToggleVisibleIcons.GetComponentInChildren().text = "Unhide all"; IconRender.instance.RootSpawnImage.SetActive(false); } else // Делаем видимыми { if (p != null) { foreach (LineRenderer g in p) g.enabled = true; } isHideIcons = false; ToggleVisibleIcons.GetComponentInChildren().text = "Hide all"; IconRender.instance.RootSpawnImage.SetActive(true); } } else if (mode == 1) { if (ToggleRaycast.GetComponentInChildren().text == "Activate Rays") // Скрываем все { ToggleRaycast.GetComponentInChildren().text = "Deactivate Rays"; InventoryBase.instance.toolTip.isActiveRaycastHit = true; if (ToggleVisibleIcons.GetComponentInChildren().text == "Hide all") HideIcons(0); else { ToggleVisibleIcons.GetComponent().isOn = false; ToggleVisibleIcons.GetComponentInChildren().text = "Unhide all"; isHideIcons = true; } ToggleVisibleIcons.GetComponent().enabled = false; InventoryBase.instance.toolTip.SeachMeshRenderer(0); } else // Делаем видимыми { ToggleRaycast.GetComponentInChildren().text = "Activate Rays"; InventoryBase.instance.toolTip.isActiveRaycastHit = false; HideIcons(0); ToggleVisibleIcons.GetComponent().enabled = true; InventoryBase.instance.toolTip.SeachMeshRenderer(1); } } //else if (mode == 1) // Critical //{ // Component[] p = WeaponRender.instance.vspItem.GetComponentsInChildren(typeof(LineRenderer), true); // if (ToggleVisibleCriticalIcons.GetComponentInChildren().text == "Hide critical") // { // if (p != null) // { // foreach (LineRenderer g in p) // { // if(g.GetComponent().IsCritical) // g.enabled = false; // } // } // IsHideIcons = true; // ToggleVisibleCriticalIcons.GetComponentInChildren().text = "Unhide critical"; // // ToggleVisibleIcons.GetComponent().isOn = true; // ToggleVisibleIcons.GetComponentInChildren().text = "Unhide all"; // // IconRender.instance.RootSpawnImage.SetActive(false); // } // else // { // if (p != null) // { // foreach (LineRenderer g in p) // { // if (g.GetComponent().IsCritical) // g.enabled = true; // } // } // IsHideIcons = false; // ToggleVisibleCriticalIcons.GetComponentInChildren().text = "Hide critical"; // // ToggleVisibleIcons.GetComponent().isOn = false; // ToggleVisibleIcons.GetComponentInChildren().text = "Hide all"; // // IconRender.instance.RootSpawnImage.SetActive(true); // } //} } } #endregion #region Weapon Modding public void Modding() { if (InventoryBase.instance.miniMenu && InventoryBase.instance.miniMenu.GetMiniMenu()) InventoryBase.instance.miniMenu.CloseMiniMenu(); // Reset icon state if (ToggleVisibleIcons.GetComponent().isOn == true) ToggleVisibleIcons.GetComponent().isOn = false; if (ToggleRaycast.GetComponent().isOn == true) ToggleRaycast.GetComponent().isOn = false; if (IconRender.instance.RootSpawnImage) IconRender.instance.RootSpawnImage.SetActive(true); // // Search for the desired button (small button on the upper right of the icon) // bool isFindClickButton = false; // Indicates that we found the button Component[] h = GetComponentsInChildren(typeof(ButtonOptions), true); if (h != null) { foreach (ButtonOptions n in h) { if ((n.isActive == true || n.isActiveMiniMenu) && n.CL.isActiveMiniMenu == true) // To which we clicked (which is active) { WeaponRender.instance.SetWeaponParameters(n.CL.itemModding, n.CL); isFindClickButton = true; break; } } } // // If we did not find it, we will search among the open mini-menus // if (!isFindClickButton) { h = null; h = GetComponentsInChildren(typeof(MenuRightClickButtonState), true); // Looking for all the menu buttons if (h != null) { foreach (MenuRightClickButtonState n in h) { if (n.isActive == true) { WeaponRender.instance.SetWeaponParameters(n.CL.itemModding, n.CL); n.isActive = false; break; } } } } // // We need to enable the modding mode // h = null; h = WeaponRender.instance.vspModel.GetComponentsInChildren(typeof(Helpers), true); if (h != null) { foreach (Helpers g in h) g.IsNotModdingMode = false; } else Debug.Log("h = WeaponRender.instance.vspWeapon.GetComponentsInChildren(typeof(Helpers), true) = null"); ToggleVisibleIcons.GetComponentInChildren().text = "Hide all"; ToggleRaycast.GetComponentInChildren().text = "Activate Rays"; //ToggleVisibleCriticalIcons.GetComponentInChildren().text = "Hide critical"; InventoryBase.instance.scavenger.FreeObjects(); InventoryBase.instance.textSaveBack.text = "SAVE"; StartCoroutine(ActivateModdingScene()); } #endregion #region Car Modding // Car modding etc... public void CarModding(bool state, ItemList cl) { isActiveCarModding = true; if (InventoryBase.instance.miniMenu && InventoryBase.instance.miniMenu.GetMiniMenu()) InventoryBase.instance.miniMenu.CloseMiniMenu(); // Reset icon state if (ToggleVisibleIcons.GetComponent().isOn == true) ToggleVisibleIcons.GetComponent().isOn = false; ToggleVisibleIcons.GetComponentInChildren().text = "Hide all"; if (ToggleRaycast.GetComponent().isOn == true) ToggleRaycast.GetComponent().isOn = false; ToggleRaycast.GetComponentInChildren().text = "Activate Rays"; //if (ToggleVisibleCriticalIcons.GetComponent().isOn == true) // ToggleVisibleCriticalIcons.GetComponent().isOn = false; //ToggleVisibleCriticalIcons.GetComponentInChildren().text = "Hide critical"; if (IconRender.instance.RootSpawnImage) IconRender.instance.RootSpawnImage.SetActive(true); // // Prepare the model for modding // if (cl.tagItem == ItemList.TagItems.MODDING) { cl.supportPlaneReserve = Instantiate(cl.supportPlane); cl.supportPlaneReserve.transform.SetParent(cl.supportPlaneRoot, false); cl.item.SetActive(false); } if (cl.itemModding) { Component[] p = cl.itemModding.GetComponentsInChildren(typeof(Helpers), true); if (p != null) { foreach (Helpers g in p) g.IsNotModdingMode = false; } else Debug.Log("p = WeaponRender.instance.vspWeapon.GetComponentsInChildren(typeof(Helpers), true) = null"); //if (m_ToolTip.IsModdingToolTip) // Если включен этот режим //{ // p = null; // p = cl.itemModding.GetComponentsInChildren(typeof(Transform), true); // // if (p != null) // { // foreach (Transform n in p) // { // if (n.GetComponent() || n.GetComponent()) // { // if (n.GetComponent() == null) // n.gameObject.AddComponent(); // } // } // } //} WeaponRender.instance.SetWeaponParameters(cl.itemModding, cl); } else { Debug.Log("WeaponRender.instance.itemModding = false"); } InventoryBase.instance.scavenger.FreeObjects(); InventoryManager.instance.isPauseInventory = state; InventoryBase.instance.textSaveBack.text = "SAVE"; isActiveModding = true; } public void CloseCarModdingScene() { if (isActiveCarModding) { Destroy(WeaponRender.instance.CL.supportPlaneReserve); //WeaponRender.instance.CL.Item.GetComponentInChildren().enabled = true; //WeaponRender.instance.CL.Item.GetComponentInChildren().enabled = true; WeaponRender.instance.CL.item.SetActive(true); isActiveCarModding = false; } } #endregion #region Set, Get, ... public void SetActiveToggleButtons(bool isActive) { ToggleVisibleIcons.SetActive(isActive); if (InventoryBase.instance.toolTip.IsModdingToolTip) ToggleRaycast.SetActive(isActive); //ToggleVisibleCriticalIcons.SetActive(isActive); } #endregion #region Reset, Close, ... public void ResetModdingParameters() { isActiveModding = false; isHideIcons = false; } #endregion #endregion #region PRIVATE #region Weapon Modding private IEnumerator ActivateModdingScene() { yield return new WaitForSeconds(0.25f); InventoryManager.instance.isPauseInventory = true; isActiveModding = true; } #endregion #endregion } } }