Ejemplo n.º 1
0
    public void OnSceneGUI()
    {
        if (npc == null)
        {
            npc = (UINPC)target;
        }

        base.OnSceneGUI();

        //开始绘制GUI
        Handles.BeginGUI();

        GUILayout.BeginArea(new Rect(SceneView.currentDrawingSceneView.position.width - 200, 100, 200, 200));

        /*true显示资源细节   false显示合并资源*/
        string SelectedName = !npc.npcSettingData.isMergeResource ? EditorStringConfig.getString(10043):EditorStringConfig.getString(10044);

        if (GUILayout.Button(SelectedName, GUILayout.Width(100), GUILayout.Height(20)))
        {
            npc.npcSettingData.isMergeResource = !npc.npcSettingData.isMergeResource;
            HideFlags flags = npc.npcSettingData.isMergeResource ? HideFlags.HideInHierarchy | HideFlags.HideInInspector : HideFlags.None;
            npc.SetChildrenGameObjectHideFlags(flags);
        }

        GUILayout.EndArea();


        Handles.EndGUI();
    }
Ejemplo n.º 2
0
    //克隆代码
    public override void CloneScript(GameObject cloneSource, GameObject cloneObject)
    {
        UINPC oldareaScript = cloneSource.GetComponent <UINPC>();
        UINPC newareaScript = cloneObject.GetComponent <UINPC>();

        newareaScript.npcData        = oldareaScript.npcData;
        newareaScript.npcSettingData = oldareaScript.npcSettingData;
        newareaScript.InitData();
    }
Ejemplo n.º 3
0
 static void Update()
 {
     if (Selection.activeObject != null && Selection.activeObject is GameObject)
     {
         GameObject temp = Selection.activeObject as GameObject;
         UINPC      npc  = null;
         while ((npc = temp.GetComponent <UINPC>()) == null && temp.transform.parent != null)
         {
             temp = temp.transform.parent.gameObject;
         }
         if (temp.transform.parent != null && npc != null && npc.npcSettingData.isMergeResource)
         {
             Selection.activeObject = temp;
         }
     }
 }
Ejemplo n.º 4
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);
    }
Ejemplo n.º 5
0
    //自动导入配置文件
    public static void AutoImportSettingFile()
    {
        string path = EditorUtility.OpenFilePanel("导入场景配置文件", Application.dataPath + "/Editor/SceneEditor/JC", "bytes");

        if (string.IsNullOrEmpty(path))
        {
            return;
        }

        List <SceneEditorSettingBaseData> settingDataList = new List <SceneEditorSettingBaseData>();
        string strLine = null;

        try
        {
            FileStream   aFile = new FileStream(path, FileMode.Open);
            StreamReader sr    = new StreamReader(aFile);
            strLine = sr.ReadLine();
            while (strLine != null)
            {
                if (strLine.Length > 0)
                {
                    SceneEditorSettingBaseData settingData = null;
                    string content = strLine.Substring(1);
                    switch (strLine[0])
                    {
                    case 'M':
                    {
                        MapSettingData mapData = fastJSON.JSON.Instance.ToObject <MapSettingData>(content);
                        settingData = (SceneEditorSettingBaseData)mapData;
                        break;
                    }

                    case 'N':
                    {
                        NPCSettingData npcData = fastJSON.JSON.Instance.ToObject <NPCSettingData>(content);
                        settingData = (SceneEditorSettingBaseData)npcData;
                        break;
                    }

                    case 'C':
                    {
                        SpecialAreaSettingData areaData = fastJSON.JSON.Instance.ToObject <SpecialAreaSettingData>(content);
                        settingData = (SceneEditorSettingBaseData)areaData;
                        break;
                    }
                    }
                    if (settingData != null)
                    {
                        settingDataList.Add(settingData);
                    }
                }
                strLine = sr.ReadLine();
            }
            sr.Close();
        }
        catch (IOException ex)
        {
            EditorUtility.DisplayDialog("错误", ex.ToString(), "确定");
            return;
        }

        //Debug.LogError("settingDataList.count="+settingDataList.Count.ToString() );

        //生成场景
        foreach (SceneEditorSettingBaseData baseData in settingDataList)
        {
            GameObject create = null;
            if (baseData.Type == SceneElementType.MAP)
            {
                MapSettingData data = (MapSettingData)baseData;
                create = CreateMap(data.sourcePath, new Vector3(data.Attribute.pos[0], data.Attribute.pos[1], data.Attribute.pos[2]),
                                   new Vector2(data.GridSize[0], data.GridSize[1]), new Color(data.GridColor[0], data.GridColor[1], data.GridColor[2], data.GridColor[3]));
                if (create != null)
                {
                    UISceneMap uimap = create.GetComponent <UISceneMap>();
                    if (uimap != null)
                    {
                        uimap.settingData = data;
                        uimap.mapData     = data.Attribute;
                        uimap.InitData();
                    }
                }
                else
                {
                    break;
                }
            }
            else if (baseData.Type == SceneElementType.NPC)
            {
                NPCSettingData data = (NPCSettingData)baseData;
                create = CreatePlant(data.sourcePath, new Vector3(data.Attribute.pos[0], data.Attribute.pos[1], data.Attribute.pos[2]), new Vector3(data.Attribute.scale[0], data.Attribute.scale[1], data.Attribute.scale[2]),
                                     data.Type, data.isAtMap, new Vector3(data.Attribute.rotation[0], data.Attribute.rotation[1], data.Attribute.rotation[2]));
                if (create != null)
                {
                    //Debug.LogError(data.Attribute.startIntervalTime.ToString());
                    UINPC uinpc = create.GetComponent <UINPC>();
                    if (uinpc != null)
                    {
                        uinpc.settingData = data;
                        uinpc.npcData     = data.Attribute;
                        uinpc.InitData();
                    }
                }
            }
            else
            {
                SpecialAreaSettingData data = (SpecialAreaSettingData)baseData;
                create = CreatePlant(data.sourcePath, new Vector3(data.Attribute.pos[0], data.Attribute.pos[1], data.Attribute.pos[2]), new Vector3(data.Attribute.scale[0], data.Attribute.scale[1], data.Attribute.scale[2]),
                                     data.Type, data.isAtMap, new Vector3(data.Attribute.rotation[0], data.Attribute.rotation[1], data.Attribute.rotation[2]));
                UISpecialArea uiarea = create.GetComponent <UISpecialArea>();
                if (uiarea != null)
                {
                    uiarea.settingData = data;
                    uiarea.areaData    = data.Attribute;
                    uiarea.InitData();
                }
            }
        }
    }
Ejemplo n.º 6
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        UINPC npc = (UINPC)target;

        //npcID;
        if (npc.npcData.npcID == 0)
        {
            int.TryParse(npc.name, out npc.npcData.npcID);
        }
        npc.npcData.npcID = EditorGUILayout.IntField("npcID", npc.npcData.npcID);

        npc.npcData.CanThrough = EditorGUILayout.Toggle("CanThrough", npc.npcData.CanThrough);

        //CAMP
        //npc.npcData.camp = EditorGUILayout.Popup("Camp",npc.npcData.camp, System.Enum.GetNames( typeof(CAMP)  ));
        GUILayout.BeginHorizontal();
        GUILayout.Label("CAMP");
        string[] EnumNames = System.Enum.GetNames(typeof(CAMP));
        if (EnumNames.Length > 0)
        {
            string campStr   = ((CAMP)npc.npcData.camp).ToString();
            int    strIndex  = GetArrayIndex <string>(ref EnumNames, ref campStr);
            int    EnumIndex = GUILayout.Toolbar(strIndex, EnumNames);
            CAMP   camp      = (CAMP)System.Enum.Parse(typeof(CAMP), EnumNames[EnumIndex]);
            npc.npcData.camp = camp;
        }
        GUILayout.EndHorizontal();
        //isBoss
        npc.npcData.isBoss = System.Convert.ToInt32(EditorGUILayout.Toggle("isBoss", System.Convert.ToBoolean(npc.npcData.isBoss)));
        //group;
        npc.npcData.group = EditorGUILayout.IntField("group", npc.npcData.group);

        //freshParam1
        //npc.npcData.freshType = EditorGUILayout.IntField("freshType",npc.npcData.freshType);
        //freshParam1
        npc.npcData.freshParam1 = EditorGUILayout.IntField("freshParam1", npc.npcData.freshParam1);
        //freshParam2
        npc.npcData.freshParam2 = EditorGUILayout.IntField("freshParam2", npc.npcData.freshParam2);
        //lifeTime
        npc.npcData.lifeTime = EditorGUILayout.IntField("lifeTime", npc.npcData.lifeTime);
        //AIType
        npc.npcData.AIType = EditorGUILayout.Popup("AIType", npc.npcData.AIType, System.Enum.GetNames(typeof(NPCAIType)));
        //buffs
        EditorGUILayout.PropertyField(serializedObject.FindProperty("buffs"), true);

        /*
         * public BATTLE_WAY way;
         * //建筑的索引
         * public int index;
         * //是否需要营救
         * public bool bSaved;
         */

        //isNPCRefreshPoint
        npc.npcData.isBuliding = EditorGUILayout.Foldout(npc.npcData.isBuliding, "Buliding_Setting");
        if (npc.npcData.isBuliding)
        {
            ++EditorGUI.indentLevel;
            npc.npcData.way    = (BATTLE_WAY)EditorGUILayout.EnumPopup("BATTLE_WAY", npc.npcData.way);
            npc.npcData.index  = EditorGUILayout.IntField("BulidingIndex", npc.npcData.index);
            npc.npcData.bSaved = EditorGUILayout.Toggle("bSaved", npc.npcData.bSaved);
            --EditorGUI.indentLevel;
        }



        //isNPCRefreshPoint
        npc.npcData.isNPCRefreshPoint = EditorGUILayout.Foldout(npc.npcData.isNPCRefreshPoint, "NPCRefreshPoint_Setting");
        if (npc.npcData.isNPCRefreshPoint)
        {
            ++EditorGUI.indentLevel;
            npc.npcData.refreshRules = (NPCRefreshRules)EditorGUILayout.EnumPopup("refreshRules", npc.npcData.refreshRules);

            if (npc.npcData.freshParam == null)
            {
                npc.npcData.freshParam = new NPCRefreshParam();
            }

            /*
             *      public float starDelayTime;				//多久以后开始刷新
             *      public float timePerCount;				//没波怪之间的时间间隔
             *      public float timePerNPC;				//同一波怪,每个npc之间的刷新间隔
             *      public int freshCount;					//刷怪次数( -1 认为是无限刷怪)
             *      public int freshPoolID;					//刷新池的ID
             */
            EditorGUILayout.LabelField("freshParam {");
            ++EditorGUI.indentLevel;
            npc.npcData.freshParam.starDelayTime = EditorGUILayout.FloatField("starDelayTime", npc.npcData.freshParam.starDelayTime);
            npc.npcData.freshParam.timePerCount  = EditorGUILayout.FloatField("timePerCount", npc.npcData.freshParam.timePerCount);
            npc.npcData.freshParam.timePerNPC    = EditorGUILayout.FloatField("timePerNPC", npc.npcData.freshParam.timePerNPC);
            npc.npcData.freshParam.freshCount    = EditorGUILayout.IntField("freshCount", npc.npcData.freshParam.freshCount);
            npc.npcData.freshParam.freshPoolID   = EditorGUILayout.IntField("freshPoolID", npc.npcData.freshParam.freshPoolID);
            --EditorGUI.indentLevel;
            EditorGUILayout.LabelField("}");

            --EditorGUI.indentLevel;
        }
        else
        {
            if (npc.npcData.freshParam != null)
            {
                npc.npcData.freshParam = null;
            }
        }


        serializedObject.ApplyModifiedProperties();

        if (GUI.changed)
        {
            SceneView.RepaintAll();
        }
    }