コード例 #1
0
ファイル: GameToolsMenu.cs プロジェクト: foxgame/Sword
    static void GameToolsAnimationCreatePrefab()
    {
//         if ( GameObject.Find( "testAnimations" ) != null )
//             GameObject.DestroyImmediate( GameObject.Find( "testAnimations" ) );
//
//         GameObject objTest = new GameObject( "testAnimations" );
//         RectTransform trans = objTest.AddComponent<RectTransform>();
//         trans.parent = GameObject.Find( "Canvas" ).transform;
//         trans.localPosition = new Vector3( 0.0f , 0.0f , 0.0f );
//         trans.localScale = new Vector3( 1.0f , 1.0f , 1.0f );


//        List<string> objTest2 = new List<string>();

        UnityEngine.Object[] arr = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.TopLevel);

        if (arr.Length == 0)
        {
            return;
        }

        GameObject[] objs = new GameObject[arr.Length];

        for (int i = 0; i < arr.Length; i++)
        {
            string pathDir = Path.GetDirectoryName(AssetDatabase.GetAssetPath(arr[i]));
            pathDir = pathDir.Replace('\\', '/');

            int n1 = pathDir.IndexOf("Objects/");

//             string pathDir2 = pathDir.Substring( n1 + 8 , pathDir.Length - n1 - 8 );
//
//             if ( objTest2.Find( o => o == pathDir2 ) == null )
//             {
//                 GameObject obj2 = new GameObject( pathDir2 );
//                 trans = obj2.AddComponent<RectTransform>();
//                 trans.parent = objTest.transform;
//                 trans.localPosition = new Vector3( 0.0f , 400 + objTest2.Count * 15 , 0.0f );
//                 trans.localScale = new Vector3( 1.0f , 1.0f , 1.0f );
//
//                 objTest2.Add( pathDir2 );
//            }

            string path = Path.ChangeExtension(AssetDatabase.GetAssetPath(arr[i]), ".prefab");
            path = path.Replace('\\', '/');
            path = path.Replace("Objects/SAF", "Resources/Prefab");
            //             if ( File.Exists( path ) )
            //             {
            //                 continue;
            //             }

            if (!Directory.Exists(Path.GetDirectoryName(path)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(path));
            }

            GameObject obj1 = new GameObject();

//             SpriteRenderer sprite = obj1.AddComponent<SpriteRenderer>();
//             sprite.spriteSortPoint = SpriteSortPoint.Pivot;

            GameAnimation ani = obj1.AddComponent <GameAnimation>();
            ani.load(AssetDatabase.GetAssetPath(arr[i]));

            PrefabUtility.SaveAsPrefabAsset(obj1, path);

            GameObject.DestroyImmediate(obj1);

            AssetDatabase.SaveAssets();
        }

        AssetDatabase.Refresh();

//         for ( int i = 0 ; i < objs.Length ; i++ )
//         {
//             for ( int j = 0 ; j < objTest2.Count ; j++ )
//             {
//                 if ( AssetDatabase.GetAssetPath( arr[ i ] ).Contains( objTest2[ j ] ) )
//                 {
//                     trans = objs[ i ].GetComponent<RectTransform>();
//                     trans.parent = GameObject.Find( objTest2[ j ] ).GetComponent< RectTransform >();
//                     trans.localPosition = new Vector3( GameObject.Find( objTest2[ j ] ).transform.childCount * 300.0f , 0 , 0 );
//                     break;
//                 }
//             }
//         }
    }