示例#1
0
    public WE_BuildConfigData Clone()
    {
        WE_BuildConfigData item = new WE_BuildConfigData();

        item.hp = hp;
        item.settledPriority = settledPriority;
        item.buildConfig     = buildConfig;

        return(item);
    }
        void GUI_Build(GameObject go)
        {
            UnitCtl unitCtl = go.GetComponent <UnitCtl>();

            if (unitCtl == null || unitCtl.unitData == null || unitCtl.unitData.we_BuildConfigData == null)
            {
                return;
            }

            WE_BuildConfigData buildConfigData = unitCtl.unitData.we_BuildConfigData;

            string name = unitCtl.unitData == null ? unitCtl.gameObject.name : unitCtl.unitData.GetName();

            GUILayout.Box(name, style_select_name, GUILayout.ExpandWidth(true), GUILayout.Height(30));

            unitCtl.unitData.level = EditorGUILayout.IntField("等级", unitCtl.unitData.level);

            buildConfigData.hp = EditorGUILayout.IntField("初始兵力", buildConfigData.hp);
            EditorGUILayout.HelpBox("初始兵力为‘-1’时,通过计算公式计算", MessageType.None);

            buildConfigData.settledPriority = EditorGUILayout.IntField("上阵优先级", buildConfigData.settledPriority);
        }
示例#3
0
        static void DrawUnit(UnitCtl unitCtl)
        {
            if (unitCtl.gameObject.activeSelf == false)
            {
                return;
            }

            string     text      = unitCtl.unitData == null ? unitCtl.gameObject.name : unitCtl.unitData.GetName() + "Lv" + unitCtl.unitData.level;
            Transform  transform = unitCtl.transform;
            RaycastHit hit;
            Ray        r = new Ray(transform.position + Camera.current.transform.up * 8f, -Camera.current.transform.up);

            Collider collider = transform.GetComponent <Collider>();

            if (collider == null)
            {
                collider = transform.GetComponentInChildren <Collider>();
            }

            if (collider != null && collider.Raycast(r, out hit, Mathf.Infinity))
            {
                float dist = (Camera.current.transform.position - hit.point).magnitude;

                float fontSize = Mathf.Lerp(64, 12, dist / 10f);

                Style.fontSize = (int)fontSize;

                Vector3 wPos = hit.point;
                if (Camera.current.orthographic == false)
                {
                    wPos += Camera.current.transform.up * dist * 0.07f;
                }
                else
                {
                    wPos += Camera.current.transform.up * dist * 0.01f;
                }

                Vector3 scPos = Camera.current.WorldToScreenPoint(wPos);
                if (scPos.z <= 0)
                {
                    return;
                }

                float alpha = Mathf.Clamp(-Camera.current.transform.forward.y, 0f, 1f);
                alpha = 1f - ((1f - alpha) * (1f - alpha));

                alpha = Mathf.Lerp(-0.2f, 1f, alpha);

                Handles.BeginGUI();

                scPos.y = Screen.height - scPos.y;                 // Flip Y

                Vector2 strSize = Style.CalcSize(new GUIContent(text));

                Rect rect = new Rect(0f, 0f, strSize.x + 6, strSize.y + 4);
                rect.center = scPos - Vector3.up * rect.height * 0.5f;
                GUI.color   = new Color(0f, 0f, 0f, 0.8f * alpha);
                GUI.DrawTexture(rect, EditorGUIUtility.whiteTexture);
                GUI.color = Color.white;
                GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, alpha);
                //			GUI.Label(rect, text, Style);

                if (option == WarEditorSceneOption.Select && GUI.Button(rect, text, Style))
                {
                    Selection.activeGameObject = unitCtl.gameObject;
                }

                if (option == WarEditorSceneOption.Delete && GUI.Button(rect, "删除", Style))
                {
                    GameObject.Destroy(unitCtl.gameObject);
                }


                if (option == WarEditorSceneOption.Replace && GUI.Button(rect, "替换", Style))
                {
                    Selection.activeGameObject = unitCtl.gameObject;
                    WarEditor_LibraryWindow.Replace(unitCtl);
                }

                if (option == WarEditorSceneOption.HP)
                {
                    WE_BuildConfigData buildConfigData = null;
                    if (unitCtl.unitData != null)
                    {
                        buildConfigData = unitCtl.unitData.we_BuildConfigData;
                    }

                    if (buildConfigData != null && unitCtl.unitData.unitType == UnitType.Build)
                    {
                        buildConfigData.hp = EditorGUI.IntField(rect, buildConfigData.hp);
                    }
                }



                if (option == WarEditorSceneOption.SettledPriority)
                {
                    WE_BuildConfigData buildConfigData = null;
                    if (unitCtl.unitData != null)
                    {
                        buildConfigData = unitCtl.unitData.we_BuildConfigData;
                    }

                    if (buildConfigData != null && unitCtl.unitData.unitType == UnitType.Build)
                    {
                        buildConfigData.settledPriority = EditorGUI.IntField(rect, buildConfigData.settledPriority);
                    }
                }



                if (option == WarEditorSceneOption.Level)
                {
                    if (unitCtl.unitData.unitType == UnitType.Build)
                    {
                        int level = EditorGUI.IntField(rect, unitCtl.unitData.level);
                        if (level != unitCtl.unitData.level)
                        {
                            unitCtl.unitData.Uplevel(level);
                        }
                    }
                }


                if (option == WarEditorSceneOption.Legion)
                {
                    if (unitCtl.unitData.unitType == UnitType.Build)
                    {
                        int legionId = EditorGUI.IntField(rect, unitCtl.unitData.legionId);
                        if (legionId != unitCtl.unitData.legionId)
                        {
                            if (War.sceneData.legionDict.ContainsKey(legionId))
                            {
                                unitCtl.unitData.ChangeLegion(legionId);
                            }
                            else
                            {
                                if (SceneView.lastActiveSceneView != null)
                                {
                                    SceneView.lastActiveSceneView.ShowNotification(new GUIContent("关卡没有配置'" + WarColor.Names[legionId] + "'势力,请先到(关卡/关卡配置)里添加势力"));
                                }
                            }
                        }
                    }
                }

                GUI.color = Color.white;

                Handles.EndGUI();
            }
        }
示例#4
0
        public bool Create_Build(int colorId, int level, AbstractBuildConfig buildConfig, Vector3 position, WE_BuildConfigData weBuildConfig = null)
        {
            if (War.sceneData == null)
            {
                this.ShowNotification(new GUIContent("请先‘选择关卡’或者去‘新建关卡’"));
                return(false);
            }

            if (!War.sceneData.legionDict.ContainsKey(colorId))
            {
                this.ShowNotification(new GUIContent("关卡没有配置'" + WarColor.Names[colorId] + "'势力,请先到(关卡/关卡配置)里添加势力"));
                return(false);
            }

            int initHP = weBuildConfig == null ? 0 : weBuildConfig.hp;

            int index = GetMaxIndex() + 1;

            BuildType buildType = buildConfig.buildType;

            // 初始兵力--计算
            float[] firstProp = new float[PropId.MAX];
            firstProp[PropId.HpAdd] = initHP;


            // 兵营初始属性[Hp]
            float[] initProp = new float[PropId.MAX];
            initProp[PropId.InitHp] = initHP;


            War.sceneData.buildFirstProp.Add(index, firstProp);
            War.sceneData.buildInitProp.Add(index, initProp);

            // 生成兵营UnitData
            UnitData unitData = new UnitData();

            unitData.id                             = index;
            unitData.legionId                       = colorId;
            unitData.unitType                       = UnitType.Build;
            unitData.buildType                      = buildType;
            unitData.level                          = level;
            unitData.position                       = position;
            unitData.buildConfig                    = (BuildConfig)buildConfig;
            unitData.we_BuildConfigData             = new WE_BuildConfigData();
            unitData.we_BuildConfigData.buildConfig = buildConfig;
            if (weBuildConfig != null)
            {
                unitData.we_BuildConfigData.hp = weBuildConfig.hp;
                unitData.we_BuildConfigData.settledPriority = weBuildConfig.settledPriority;
            }
            unitData.hp       = 0;
            unitData.avatarId = buildConfig.avatarId;



            War.sceneData.InitAttachPropData(index);
            War.sceneData.buildDict.Add(index, unitData);

            Selection.activeGameObject = War.sceneCreate.GenerationBuild(unitData);

            return(true);
        }
示例#5
0
        public static bool SaveStagePosition(StageConfig stageConfig)
        {
            bool result = true;
            List <StagePositionConfig> list = new List <StagePositionConfig>();

            GameObject root = GameObject.Find("Scene/Caserns");

            if (root != null)
            {
                int count = root.transform.childCount;
                for (int i = 0; i < count; i++)
                {
                    Transform itemTransform = root.transform.GetChild(i);
                    if (itemTransform.gameObject.activeSelf)
                    {
                        UnitCtl unitCtl = itemTransform.GetComponent <UnitCtl>();
                        if (unitCtl != null && unitCtl.unitData != null && unitCtl.unitData.we_BuildConfigData != null)
                        {
                            UnitData            unitData        = unitCtl.unitData;
                            WE_BuildConfigData  buildConfigData = unitCtl.unitData.we_BuildConfigData;
                            StagePositionConfig positionConfig  = new StagePositionConfig();
                            positionConfig.stageId         = stageConfig.id;
                            positionConfig.index           = list.Count + 1;
                            positionConfig.position        = itemTransform.position;
                            positionConfig.hp              = buildConfigData.hp;
                            positionConfig.legionId        = unitData.legionId;
                            positionConfig.unitType        = unitData.unitType;
                            positionConfig.buildType       = unitData.buildType;
                            positionConfig.buildUid        = buildConfigData.buildConfig.id;
                            positionConfig.level           = unitData.level;
                            positionConfig.settledPriority = buildConfigData.settledPriority;
                            positionConfig.name            = buildConfigData.buildConfig.name;
                            positionConfig.stageName       = stageConfig.name;

                            list.Add(positionConfig);
                        }
                    }
                }
            }

            root = GameObject.Find("Scene/Walls");
            if (root != null)
            {
                int count = root.transform.childCount;
                for (int i = 0; i < count; i++)
                {
                    Transform itemTransform = root.transform.GetChild(i);
                    if (itemTransform.gameObject.activeSelf)
                    {
                        UnitCtl unitCtl = itemTransform.GetComponent <UnitCtl>();
                        if (unitCtl != null && unitCtl.unitData != null && unitCtl.unitData.we_BuildConfigData != null)
                        {
                            UnitData            unitData        = unitCtl.unitData;
                            WE_BuildConfigData  buildConfigData = unitCtl.unitData.we_BuildConfigData;
                            StagePositionConfig positionConfig  = new StagePositionConfig();
                            positionConfig.stageId   = stageConfig.id;
                            positionConfig.index     = list.Count + 1;
                            positionConfig.position  = itemTransform.position;
                            positionConfig.hp        = buildConfigData.hp;
                            positionConfig.legionId  = unitData.legionId;
                            positionConfig.unitType  = unitData.unitType;
                            positionConfig.buildType = unitData.buildType;
                            positionConfig.buildUid  = buildConfigData.buildConfig.id;
                            positionConfig.level     = 0;
                            positionConfig.name      = buildConfigData.buildConfig.name;
                            positionConfig.stageName = stageConfig.name;

                            list.Add(positionConfig);
                        }
                    }
                }
            }


            if (War.model.stagePositionConfigs.ContainsKey(stageConfig.id))
            {
                War.model.stagePositionConfigs.Remove(stageConfig.id);
            }

            War.model.stagePositionConfigs.Add(stageConfig.id, list);

            stageConfig.GenerationPositionData();

            Save_stage_position_csv();
            return(result);
        }