예제 #1
0
 public void CorrectSelectedPrefabIndex(bool p_force = false, bool p_canRefillFolders = true)
 {
     if (Application.isEditor || p_force)
     {
         if (CachedPrefab != null)
         {
             for (int i = 0; i < Folders.Count; i++)
             {
                 FolderPrefabs v_foldPrefab = Folders[i];
                 if (v_foldPrefab != null)
                 {
                     for (int j = 0; j < v_foldPrefab.PrefabsInFolder.Count; j++)
                     {
                         GameObject v_prefab = v_foldPrefab.PrefabsInFolder[j];
                         if (v_prefab == CachedPrefab)
                         {
                             if (m_selectedFolderIndex != i)
                             {
                                 m_selectedFolderIndex = i;
                             }
                             if (m_selectedPrefabInFolderIndex != j)
                             {
                                 m_selectedPrefabInFolderIndex = j;
                             }
                             if (p_canRefillFolders)
                             {
                                 string v_cachedPrefabPath = KiltUtils.PathCorrection(GetPrefabResourcesFilePath(CachedPrefab));
                                 string v_pathByIndex      = KiltUtils.PathCorrection("Resources/" + MainFolderPath + "/" + SelectedFolderName + "/" + SelectedPrefabName + ".prefab");
                                 if (!v_pathByIndex.Equals(v_cachedPrefabPath))
                                 {
                                     FillObjectsInFolderList(true);
                                     CorrectSelectedPrefabIndex(true, false);                                         //After refill, call it again forcing find corret index but preventing to fill again
                                 }
                             }
                             return;
                         }
                     }
                 }
             }
         }
         else
         {
             if (m_selectedFolderIndex != -1)
             {
                 m_selectedFolderIndex = -1;
             }
             if (m_selectedPrefabInFolderIndex != -1)
             {
                 m_selectedPrefabInFolderIndex = -1;
             }
         }
     }
 }
예제 #2
0
    public int FindFolderIndexByNameInList(string p_name, List <FolderPrefabs> p_list)
    {
        int v_index = -1;

        if (p_list != null)
        {
            for (int i = 0; i < p_list.Count; i++)
            {
                FolderPrefabs v_folder = p_list[i];
                if (v_folder != null && v_folder.Folder.Equals(p_name))
                {
                    v_index = i;
                    break;
                }
            }
        }
        return(v_index);
    }
예제 #3
0
    public void FillObjectsInFolderList(bool p_forceRefreshFolderList = false, bool p_onlyExecuteInEditMode = true)
    {
        if (Application.isEditor || !p_onlyExecuteInEditMode)
        {
            if (Folders == null || Folders.Count <= 0 || p_forceRefreshFolderList)
            {
                Folders.Clear();
                foreach (string v_folderPath in FoldersPath)
                {
                    string        v_finalFolder        = MainFolderPath + "/" + v_folderPath;
                    FolderPrefabs v_folderPrefabStruct = new FolderPrefabs(v_folderPath);
                    v_folderPrefabStruct.PrefabsInFolder = new List <GameObject>(KiltUtils.FindAllPrefabsAtFolder(v_finalFolder));
                    Folders.Add(v_folderPrefabStruct);
                }

                //Re-check Index Dont Calling Changes
                m_selectedFolderIndex         = FindFolderIndexByNameInList(SelectedFolderName, Folders);
                m_selectedPrefabInFolderIndex = FindPrefabIndexByNameInList(SelectedPrefabName, SelectedFolderPrefab != null? SelectedFolderPrefab.PrefabsInFolder : null);
            }
        }
    }
예제 #4
0
    public override void OnInspectorGUI()
    {
        m_component = target as BlockSelector;
        if (m_component != null)
        {
            m_component.ApplyShowHideComponent();
            m_component.FillObjectsInFolderList();
            if (!m_firstCorrection)
            {
                m_firstCorrection = true;
                m_component.CorrectSelectedPrefabIndex();
            }
            bool v_needRecreate = false;
            int  v_folderIndex  = -1;

            EditorGUILayout.BeginHorizontal();

            bool v_buttonRefreshClicked = GUILayout.Button("Refresh");
            if (v_buttonRefreshClicked)
            {
                m_component.FillObjectsInFolderList(true);
            }
            bool v_buttonRecreateClicked = GUILayout.Button("Force Recreate");
            bool v_buttonResetLife       = GUILayout.Button("Reset Block Life");
            if (v_buttonResetLife || v_buttonRecreateClicked)
            {
                v_needRecreate = true;
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();

            EditorGUILayout.BeginHorizontal();

            bool v_buttonFlipXClicked = GUILayout.Button("Flip X");
            bool v_buttonFlipYClicked = GUILayout.Button("Flip Y");

            if (v_buttonFlipXClicked || v_buttonFlipYClicked)
            {
                m_component.PerformFlip(v_buttonFlipXClicked, v_buttonFlipYClicked);
            }

            EditorGUILayout.EndHorizontal();

            string [] v_stringFolderPath = m_component.FoldersPath.GetStringList().ToArray();
            v_folderIndex = EditorGUILayout.Popup("Folder", m_component.SelectedFolderIndex, v_stringFolderPath);
            if (v_folderIndex != m_component.SelectedFolderIndex)
            {
                v_needRecreate = true;
                m_component.SelectedFolderIndex = v_folderIndex;
            }

            FolderPrefabs v_selectedFolder = m_component.SelectedFolderPrefab;
            if (v_selectedFolder != null)
            {
                string [] v_stringPrefabsInFolder = GetListOfNames(v_selectedFolder.PrefabsInFolder).ToArray();
                int       v_prefabIndex           = EditorGUILayout.Popup("Prefab", m_component.SelectedPrefabInFolderIndex, v_stringPrefabsInFolder);
                if (v_prefabIndex != m_component.SelectedPrefabInFolderIndex)
                {
                    v_needRecreate = true;
                    m_component.SelectedPrefabInFolderIndex = v_prefabIndex;
                }
            }

            EditorGUILayout.Separator();

            bool v_hideOtherComponents = EditorGUILayout.Toggle("Hide Other Components", m_component.HideComponentsInInspector);
            if (m_component.HideComponentsInInspector != v_hideOtherComponents)
            {
                m_component.HideComponentsInInspector = v_hideOtherComponents;
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(m_component);
            }
            if (v_needRecreate && m_component.SelectedObject != null)
            {
                GameObject v_newObject = m_component.InstantiateObjectByPrefab(m_component.SelectedObject, !v_buttonResetLife, true, true);
                Selection.activeObject = v_newObject;
            }
        }
    }
예제 #5
0
	public void FillObjectsInFolderList(bool p_forceRefreshFolderList = false, bool p_onlyExecuteInEditMode = true)
	{
		if(Application.isEditor || !p_onlyExecuteInEditMode)
		{
			if(Folders == null || Folders.Count <= 0 || p_forceRefreshFolderList)
			{
				Folders.Clear();
				foreach(string v_folderPath in FoldersPath)
				{
					string v_finalFolder = MainFolderPath + "/" + v_folderPath;
					FolderPrefabs v_folderPrefabStruct = new FolderPrefabs(v_folderPath);
					v_folderPrefabStruct.PrefabsInFolder = new List<GameObject>(KiltUtils.FindAllPrefabsAtFolder(v_finalFolder));
					Folders.Add(v_folderPrefabStruct);
				}

				//Re-check Index Dont Calling Changes
				m_selectedFolderIndex = FindFolderIndexByNameInList(SelectedFolderName, Folders);
				m_selectedPrefabInFolderIndex = FindPrefabIndexByNameInList(SelectedPrefabName, SelectedFolderPrefab != null? SelectedFolderPrefab.PrefabsInFolder : null);
			}
		}
	}