示例#1
0
    static void ConvertToFish(FishGenerateWhenEnterWorld fishPot)
    {
        if (AssetDatabase.Contains(fishPot))
        {
            return;
        }

        if (fishPot.Prefab_Fish == null)
        {
            Debug.LogWarning("[警告]不存在Prefab_Fish,转化失败.", fishPot.gameObject);
            return;
        }
        //删除子对象
        foreach (Transform child in fishPot.transform)
        {
            DestroyImmediate(child.gameObject);
        }

        //创建鱼对象
        Fish f = Instantiate(fishPot.Prefab_Fish) as Fish;

        f.gameObject.name         = fishPot.gameObject.name;
        f.transform.parent        = fishPot.transform.parent;
        f.transform.localPosition = fishPot.transform.localPosition;
        f.transform.localRotation = fishPot.transform.localRotation;
        f.transform.localScale    = fishPot.transform.localScale;

        Selection.activeGameObject = f.gameObject;
        //删除Fishpot对象
        DestroyImmediate(fishPot.gameObject);
    }
    static void ConvertToFish(FishGenerateWhenEnterWorld fishPot)
    {
        if (AssetDatabase.Contains(fishPot))
            return;

        if (fishPot.Prefab_Fish == null)
        {
            Debug.LogWarning("[����]������Prefab_Fish,ת��ʧ��.", fishPot.gameObject);
            return;
        }
        //ɾ���Ӷ���
        foreach (Transform child in fishPot.transform)
        {
            DestroyImmediate(child.gameObject);
        }

        //���������
        Fish f = Instantiate(fishPot.Prefab_Fish) as Fish;

        f.gameObject.name = fishPot.gameObject.name;
        f.transform.parent = fishPot.transform.parent;
        f.transform.localPosition = fishPot.transform.localPosition;
        f.transform.localRotation = fishPot.transform.localRotation;
        f.transform.localScale = fishPot.transform.localScale;

        Selection.activeGameObject = f.gameObject;
        //ɾ��Fishpot����
        DestroyImmediate(fishPot.gameObject);
    }
示例#3
0
 static void Menu_ConvertToFish()
 {
     foreach (GameObject go in Selection.gameObjects)
     {
         FishGenerateWhenEnterWorld fp = go.GetComponent <FishGenerateWhenEnterWorld>();
         if (fp != null)
         {
             ConvertToFish(fp);
         }
     }
 }
示例#4
0
    static void ConvertToFishGenerateWhenEnterWorld(Fish fishInScene)
    {
        if (AssetDatabase.Contains(fishInScene))
        {
            return;
        }
        //ɾ���Ӷ���
        //int a = fishInScene.transform.childCount;
        int fishChildCount = fishInScene.transform.childCount;

        for (int i = 0; i != fishChildCount; ++i)
        {
            DestroyImmediate(fishInScene.transform.GetChild(0).gameObject);
        }

        //����gameobject���ֲ�����prefab
        Fish f = (Fish)AssetDatabase.LoadAssetAtPath("assets/prefab/fish/" + fishInScene.gameObject.name + ".prefab", typeof(Fish));

        if (f == null)
        {
            f = (Fish)AssetDatabase.LoadAssetAtPath("assets/prefab/FishQueue/" + fishInScene.gameObject.name + ".prefab", typeof(Fish));
        }

        //����FishGenerateWhenEnterWorld
        FishGenerateWhenEnterWorld fishGenerate = fishInScene.gameObject.AddComponent <FishGenerateWhenEnterWorld>();

        if (f != null)
        {
            fishGenerate.Prefab_Fish = f;
        }
        else
        {
            Debug.LogWarning("[����]����ԴĿ¼���Ҳ�������prefab,���ֶ������ϷŽ�prefab_Fish������.", fishInScene.gameObject);
        }

        //���������
        Component[] cmps = fishInScene.GetComponents <Component>();

        foreach (Component c in cmps)
        {
            if (c.GetType() != typeof(Transform) && c.GetType() != typeof(FishGenerateWhenEnterWorld))
            {
                DestroyImmediate(c);
            }
        }
    }