예제 #1
0
    //创建种植物
    public static GameObject CreatePlant(Object resource, Vector3 worldpos, Vector3 scale, SceneElementType type, bool BornAtMap = true, Vector3 worldrotation = default(Vector3))
    {
        GameObject createObj  = PrefabUtility.InstantiatePrefab(resource) as GameObject;
        UISceneMap uiSceneMap = SceneEditorSettings.currMap.GetComponent <UISceneMap>();
        int        TypeIndex  = (int)type;

        if (uiSceneMap != null)
        {
            createObj.transform.parent     = uiSceneMap.ElementParents[TypeIndex - 1];
            createObj.transform.localScale = scale;
            createObj.transform.rotation   = Quaternion.Euler(worldrotation);
            createObj.transform.position   = worldpos;
        }

        switch (type)
        {
        case SceneElementType.NPC:
        {
            UINPC npc = null;
            if (createObj != null)
            {
                npc = createObj.AddComponent <UINPC>();
            }
            if (npc != null)
            {
                //保存数据
                npc.npcSettingData.isAtMap    = BornAtMap;
                npc.npcSettingData.Type       = type;
                npc.npcSettingData.sourcePath = AssetDatabase.GetAssetPath(resource);

                CharacterController controller = npc.GetComponent <CharacterController>();
                if (controller != null)
                {
                    CapsuleCollider capsule = npc.gameObject.AddComponent <CapsuleCollider>();
                    if (capsule != null)
                    {
                        capsule.center    = controller.center;
                        capsule.radius    = controller.radius;
                        capsule.height    = controller.height;
                        capsule.direction = 1;
                    }
                }
            }
            break;
        }

        case SceneElementType.BUILDING:
        {
            break;
        }

        case SceneElementType.TREE:
        {
            break;
        }

        default:
        {
            UISpecialArea area = createObj.GetComponent <UISpecialArea>();
            if (area == null)
            {
                area = createObj.AddComponent <UISpecialArea>();
            }
            //保存数据
            area.areaSettingData.isAtMap    = BornAtMap;
            area.areaSettingData.Type       = type;
            area.areaSettingData.sourcePath = AssetDatabase.GetAssetPath(resource);
            break;
        }
        }
        Selection.activeObject = createObj;
        return(createObj);
    }
예제 #2
0
 //设置种植物文件夹Object
 public static void SetPlantFileObject(SceneElementType type, Object _object)
 {
     Set("SceneElementType_" + type.ToString(), _object);
 }
예제 #3
0
    //创建种植物
    public static GameObject CreatePlant(string sourcePath, Vector3 worldpos, Vector3 scale, SceneElementType type, bool BornAtMap = true, Vector3 worldrotation = default(Vector3))
    {
        Object plantSource = AssetDatabase.LoadMainAssetAtPath(sourcePath);

        if (plantSource != null)
        {
            return(CreatePlant(plantSource, worldpos, scale, type, BornAtMap, worldrotation));
        }
        EditorUtility.DisplayDialog(EditorStringConfig.getString(10042), "Not found: " + sourcePath, EditorStringConfig.getString(10025));
        return(null);
    }
예제 #4
0
 //获取种植物文件夹Object
 public static Object GetPlantFileObject(SceneElementType type)
 {
     return(Get <Object>("SceneElementType_" + type.ToString(), null));
 }