void SetupDependencies(GameObject go)
    {
        PlaceObjectInWorld p = go.GetComponent <PlaceObjectInWorld>();
        //Box Collider
        BoxCollider bc = go.GetComponent <BoxCollider>();

        p.ObjectBoxCollider = bc;
        Transform    tChild = go.transform.GetChild(0).GetComponent <Transform>();
        MeshRenderer mr     = tChild.GetComponent <MeshRenderer>();

        go.layer = 8;
        tChild.gameObject.layer = 8;

        bc.isTrigger = true;
        bc.center    = mr.bounds.center;
        bc.size      = mr.bounds.size - new Vector3(0.1f, 0.1f, 0.1f);

        //Child's Transform
        p.ObjectTransform = tChild;
        //Child's MeshRenderer
        p.ObjectMeshRenderer = tChild.gameObject.GetComponent <MeshRenderer>();
        //Setting the collision flags
        p.LayerMask = flags;
        //Reference the material manager
        p.MaterialManager = MaterialManager.MyInstance;
        success[4]        = true;

        SetupScriptableObject(go);
    }
    void SetupScriptableObject(GameObject go)
    {
        PlaceObjectInWorld p  = go.GetComponent <PlaceObjectInWorld>();
        SO_Object          so = Resources.Load <SO_Object>("Prefabs/" + objectName + "/" + objectName) as SO_Object;

        p.PlaceableObject = so;

        p.PlaceableObject.multiPlace = multiPlace;

        if ((int)objectType == 2)
        {
            p.PlaceableObject.placeUnderground = true;
        }
        else
        {
            p.PlaceableObject.placeUnderground = false;
        }

        p.PlaceableObject.cost = buildCost;
        //p.PlaceableObject.thumbnail = image;
        p.PlaceableObject.unlockName   = objectName;
        p.PlaceableObject.description  = description;
        p.PlaceableObject.researchTime = researchTime;
        p.PlaceableObject.researchCost = researchCost;
        p.PlaceableObject.unlockObject = newUnlocks;
        p.PlaceableObject.prerequisits = prerequisits;
        p.PlaceableObject.baseObject   = baseObject;
        success[5] = true;

        CreatePrefab(go);
    }
Beispiel #3
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        //Find objects in the world
        if (Input.GetMouseButtonUp(0))
        {
            if (!EventSystem.current.IsPointerOverGameObject())
            {
                if (Physics.Raycast(ray, out hit))
                {
                    var heading   = hit.point - ray.origin;
                    var distance  = heading.magnitude;
                    var direction = heading / distance;

                    //Debug.DrawRay(ray.origin, direction * distance, Color.green);

                    editModel   = hit.transform.GetComponent <EditModel>();
                    placeObject = hit.transform.GetComponent <PlaceObjectInWorld>();

                    //if (editModel && !placeObject.enabled &&
                    //    !GameManager.MyInstance.ActiveModel)
                    //{
                    //    GameManager.MyInstance.ActiveModel = hit.transform.gameObject;
                    //    Debug.Log("Enabling Transform");
                    //    editModel.EnableTransformTools();
                    //}
                    if (editModel && !placeObject.enabled && GameManager.ActiveModels.Count == 0)
                    {
                        GameManager.ActiveModels.Add(hit.transform.gameObject);
                        Debug.Log("Enabling Transform");
                        editModel.EnableTransformTools();
                    }
                    if (editModel && !placeObject.enabled && Input.GetKey(KeyCode.LeftShift))
                    {
                        GameManager.ActiveModels.Add(hit.transform.gameObject);
                        Debug.Log("Enabling Transform");
                        editModel.EnableTransformTools();
                    }

                    if (hit.transform.CompareTag("SnapPoint"))
                    {
                        hit.transform.gameObject.GetComponent <MeshRenderer>().material = MaterialManager.MyInstance.GreenMat;
                    }
                }
            }
        }
        //Replace materials on the floor tiles
        if (Input.GetMouseButton(0))
        {
            if (!EventSystem.current.IsPointerOverGameObject())
            {
                if (Physics.Raycast(ray, out hit))
                {
                    var heading   = hit.point - ray.origin;
                    var distance  = heading.magnitude;
                    var direction = heading / distance;

                    Debug.DrawRay(ray.origin, direction * distance, Color.red);

                    MeshRenderer mr = hit.transform.GetComponent <MeshRenderer>();
                    FloorData    fd = hit.transform.GetComponent <FloorData>();

                    if (hit.transform.gameObject.layer == 9 && GameManager.ActiveModels.Count == 0)
                    {
                        if (MaterialManager.MyInstance.ActiveMaterial)
                        {
                            mr.materials[0] = MaterialManager.MyInstance.ActiveMaterial;
                        }
                        if (ZoningController.MyInstance.ActiveZone)
                        {
                            fd.Zone = ZoningController.MyInstance.ActiveZone;
                        }
                    }
                }
            }
        }
    }
Beispiel #4
0
 public void OnEnable()
 {
     placeObjectinWorld = transform.GetComponent <PlaceObjectInWorld>();
 }