コード例 #1
0
ファイル: PlacingManage.cs プロジェクト: GhoulFeast/testgame
 /// <summary>
 ///
 /// </summary>
 /// <param name="prefabOnButton"></param>
 public void OnPlaceable(BuildingSO prefabOnButton)
 {
     if (placeable == null)
     {
         SetPlaceable(prefabOnButton);
     }
 }
コード例 #2
0
    /// <summary>
    /// 在地图上设置建造完的建筑
    /// </summary>
    /// <param name="placeablePrefab"></param>
    public void SetPlaceable(Vector3 initPosition, BuildingSO placeablePrefab)
    {
        //place = placeablePrefab.GetComponent<PlaceControl>();
        GameObject place = Instantiate(placeablePrefab.buildingPrefab, initPosition, Quaternion.identity);

        placeable.AddComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Static;
        BoxCollider2D boxCollider2D = placeable.GetComponent <BoxCollider2D>();

        //  boxCollider2D.isTrigger = true;
        boxCollider2D.size = new Vector2(boxCollider2D.size.x - boxCollider2D.size.x / 20, boxCollider2D.size.y - boxCollider2D.size.y / 20);
        BuildControl build = placeable.GetComponent <BuildControl>();

        placeable.name          = placeablePrefab.objectName;
        build.name              = placeablePrefab.objectName;
        build.durable           = placeablePrefab.durable;
        build.buildProgress     = buildProgress;
        build.dismantleProgress = dismantleProgress;
        build.dTime             = placeablePrefab.dTime;
        build.buildTime         = 0;
        build.type              = placeablePrefab.type;
        build.cost              = new Dictionary <string, int>();
        build.capacity          = placeablePrefab.capacity;
        build.Build();
        placeable.layer = 11;
        // prefabToPlace = placeablePrefab;
    }
コード例 #3
0
    /// <summary>
    /// 在鼠标位置初始化未建造的建筑
    /// </summary>
    /// <param name="placeablePrefab"></param>
    public void SetPlaceable(BuildingSO placeablePrefab)
    {
        Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        mousePosition.z = 0;
        //place = placeablePrefab.GetComponent<PlaceControl>();
        placeable = Instantiate(placeablePrefab.buildingPrefab, mousePosition, Quaternion.identity);
        placeable.AddComponent <Rigidbody2D>();
        BoxCollider2D boxCollider2D = placeable.AddComponent <BoxCollider2D>();

        boxCollider2D.isTrigger = true;
        boxCollider2D.size      = new Vector2(boxCollider2D.size.x - boxCollider2D.size.x / 20, boxCollider2D.size.y - boxCollider2D.size.y / 20);

        place = placeable.AddComponent <PlaceControl>();
        BuildControl build = placeable.GetComponent <BuildControl>();

        placeable.name          = placeablePrefab.objectName;
        build.sprite            = placeablePrefab.lowSource;
        build.name              = placeablePrefab.objectName;
        build.durable           = placeablePrefab.durable;
        build.buildProgress     = buildProgress;
        build.dismantleProgress = dismantleProgress;
        build.dTime             = placeablePrefab.dTime;
        build.buildTime         = placeablePrefab.buildTime;
        build.type              = placeablePrefab.type;
        build.cost              = placeablePrefab.cost;
        build.colType           = placeablePrefab.res;
        build.colNum            = placeablePrefab.collectNum;
        build.capacity          = placeablePrefab.capacity;
        placeable.layer         = 11;
        // prefabToPlace = placeablePrefab;
    }
コード例 #4
0
 public void UnassignBuildMode()
 {
     GameManager.MyInstance.GameStateEnum = gameState.gameMode;
     UIBaseManager.MyInstance.TurnOnMainInterface();
     Destroy(instancedStructureOutline);
     //Destroy(activeStructureOuline);
     activeStructureOuline     = null;
     instancedStructureOutline = null;
 }
コード例 #5
0
    /// <summary>
    /// 准备建造
    /// </summary>
    /// <param name="prefabOnButton"></param>
    public void OnPlaceable(BuildingSO prefabOnButton)
    {
        if (placeable == null)
        {
            AppManage.Instance.CloseOpenUI();

            SetPlaceable(prefabOnButton);
        }
    }
コード例 #6
0
 /// <summary>
 /// 全局激活建筑
 /// </summary>
 public static void AvailableNode(BuildingSO build)
 {
     if (GameObject.FindObjectOfType <BuildMenu>() == null)
     {
         AppManage.Instance.saveData.buildNodes[build.hierarchy][build.objectName] = true;
     }
     else
     {
         GameObject.FindObjectOfType <BuildMenu>().SetAvailable(build.objectName);
     }
 }
コード例 #7
0
    public void Init(BuildingSO buildingSO) {
        this.buildingSO = buildingSO;
        workersMax = buildingSO._workersMax;
        customersMax = buildingSO._customersMax;
        buildingType = buildingSO._buildingType;
        materialToUse = buildingSO._materialToUse;


        GetComponent<MeshRenderer>().material = materialToUse;

        canStart = true;
    }
コード例 #8
0
    public void SetBuildModeActive()
    {
        GameManager.MyInstance.GameStateEnum = gameState.buildMode;
        GameManager.MyInstance.CancelModesButton.SetActive(true);
        UIController.MyInstance.TurnCursorOn();
        //close the playermaininterface
        UIBaseManager.MyInstance.TurnOffMainInterface();
        //set the selected object as the activestructureoutline
        activeStructureOuline = BuildingUIController.MyInstance.ActiveStructueOutline;
        //add the selected object to the crosshair
        instancedStructureOutline = Instantiate(activeStructureOuline.structurePrefab, liveMousePosition, Quaternion.identity, tempStructureParent);

        //disable the ability to harvest nodes
    }
コード例 #9
0
    /// <summary>
    /// 开始放置建筑
    /// </summary>
    /// <param name="building"></param>
    public void SpawnBuilding(BuildingSO building)
    {
        // 如果没有放置建筑,则返回
        if (currentSpawnedBuilding)
        {
            return;
        }

        currentSpawnedBuilding = Instantiate(building.buildingPrefab);
        buildingToPlace        = building;
        PlacementHelpers.ToggleRenderers(currentSpawnedBuilding, false);

        Collider2D cols = currentSpawnedBuilding.GetComponent <Collider2D>();

        if (cols != null)
        {
            FillRectWithTiles(cols);
        }
    }
コード例 #10
0
    public void SpawnBuilding(BuildingSO building)
    {
        // if haven't placed the spawned building, then return
        if (currentSpawnedBuilding)
        {
            return;
        }

        currentSpawnedBuilding          = Instantiate(building.buildingPrefab);
        buildingToPlace.currentBuilding = building;
        PlacementHelpers.ToggleRenderers(currentSpawnedBuilding, false);
        Collider[] cols = currentSpawnedBuilding.GetComponentsInChildren <Collider>();
        if (cols.Length > 0)
        {
            FillRectWithTiles(cols[0]);
        }
        else
        {
            Debug.LogError("Building has no colliders");
        }
    }
コード例 #11
0
ファイル: PlacingManage.cs プロジェクト: GhoulFeast/testgame
    public void SetPlaceable(BuildingSO placeablePrefab)
    {
        //place = placeablePrefab.GetComponent<PlaceControl>();
        Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        mousePosition.z = 0;
        placeable       = Instantiate(placeablePrefab.buildingPrefab, mousePosition, Quaternion.identity);
        placeable.GetComponent <CircleCollider2D>().isTrigger = true;
        placeable.GetComponent <CircleCollider2D>().radius   -= placeable.GetComponent <CircleCollider2D>().radius / 10;
        place = placeable.AddComponent <PlaceControl>();
        BuildControl build = placeable.GetComponent <BuildControl>();

        build.name              = placeablePrefab.objectName;
        build.durable           = placeablePrefab.durable;
        build.buildProgress     = buildProgress;
        build.dismantleProgress = dismantleProgress;
        build.dTime             = placeablePrefab.dTime;
        build.buildTime         = placeablePrefab.buildTime;
        build.type              = placeablePrefab.type;
        build.cost              = placeablePrefab.cost;

        // prefabToPlace = placeablePrefab;
    }
コード例 #12
0
ファイル: BuildOSEditor.cs プロジェクト: zuojiashun/testgame
    //重写OnInspectorGUI方法,当激活此面板区域时调用
    public override void OnInspectorGUI()
    {
        //加入此句,不影响原在Inspector绘制的元素
        // base.OnInspectorGUI();

        //获取指定脚本对象
        m_Target           = target as BuildingSO;
        m_Target.hierarchy = EditorGUILayout.IntField("菜单中层级", m_Target.hierarchy);

        m_Target.objectName     = EditorGUILayout.DelayedTextField("建筑名称", m_Target.objectName);
        m_Target.buildingPrefab = EditorGUILayout.ObjectField("建筑预制", m_Target.buildingPrefab, typeof(GameObject), true) as GameObject;
        m_Target.lowSource      = EditorGUILayout.ObjectField("预览图", m_Target.lowSource, typeof(Sprite), true) as Sprite;
        m_Target.buildTime      = EditorGUILayout.FloatField("建造时间", m_Target.buildTime);
        //EditorGUILayout.PropertyField(cost,true);
        m_Target.dTime   = EditorGUILayout.FloatField("拆除时间", m_Target.dTime);
        m_Target.durable = EditorGUILayout.FloatField("耐久", m_Target.durable);

        m_Target.type = (BuildingSO.BuildType)EditorGUILayout.EnumFlagsField("特殊类型", m_Target.type);
        if (m_Target.type == BuildingSO.BuildType.collect)
        {
            m_Target.res = (ResourceType.AttributionType)EditorGUILayout.EnumFlagsField("采集的资源", m_Target.res);
            //  m_Target.res = EditorGUILayout.ObjectField("采集的资源", m_Target.res, typeof(ResourceType), true) as ResourceType;
            m_Target.collectNum      = EditorGUILayout.IntField("每个循环采集数量", m_Target.collectNum);
            m_Target.collectInterval = EditorGUILayout.FloatField("采集间隔", m_Target.collectInterval);
        }

        m_Target.showPosition = EditorGUILayout.BeginFoldoutHeaderGroup(m_Target.showPosition, "建造费用");
        if (m_Target.showPosition)
        {
            m_Target.costLength = EditorGUILayout.IntField("需资源种类数量", m_Target.costLength);
            if (m_Target.costLength > 0)
            {
                if (m_Target.costc == null)
                {
                    m_Target.costc = new BuildingSO.ResourcePrefab[m_Target.costLength];
                }
                else
                {
                    BuildingSO.ResourcePrefab[] c = new BuildingSO.ResourcePrefab[m_Target.costLength];
                    m_Target.costc.CopyTo(c, 0);
                    m_Target.costc = c;
                }

                for (int i = 0; i < m_Target.costLength; i++)
                {
                    m_Target.costc[i].type = EditorGUILayout.ObjectField("资源种类", m_Target.costc[i].type, typeof(ResourceType), true) as ResourceType;
                    m_Target.costc[i].num  = EditorGUILayout.IntField("资源数量", m_Target.costc[i].num);
                }
                if (m_Target.cost == null)
                {
                    m_Target.cost = new Dictionary <string, int>();
                }
                else
                {
                    m_Target.cost.Clear();
                }
                foreach (var c in m_Target.costc)
                {
                    if (c.type != null)
                    {
                        m_Target.cost.Add(c.type.resName, c.num);
                    }
                }
            }
            // showPosition = !showPosition;
        }
        //  EditorGUILayout.EndFoldoutHeaderGroup();
    }
コード例 #13
0
 public void InitRecipe(BuildingSO initiatedRecipe)
 {
     recipe = initiatedRecipe;
 }