コード例 #1
0
ファイル: GetFiles.cs プロジェクト: stark355/NeolantTest
    /// <summary>
    /// сгенерировать массив объектов
    /// </summary>
    public void Generate()
    {
        int size = -1;

        try
        {
            size = GetPrefabArraySize();
        }
        catch (System.Exception)
        {
            errEngine.SetError("Wrong value");
        }

        if (size < 1 || size > 15)
        {
            errEngine.SetError("Set value between 1 and 15");
        }
        else
        {
            if (pathToPrefab == "")
            {
                errEngine.SetError("Prefab have not chosen");
            }
            //если все в порядке
            else
            {
                SetNullPrefabArray();
                GameObject gmobj = Resources.Load(pathToPrefab) as GameObject;
                GameObject realObject;
                //realObject = Instantiate(gmobj);
                //Collider realObjCollider = realObject.GetComponent<Collider>();
                //Vector3 boundsSize = new Vector3(realObjCollider.bounds.size.x, realObjCollider.bounds.size.y, realObjCollider.bounds.size.z);
                //Destroy(realObject);
                Vector3 boundsSize = new Vector3(0, 0, 0);
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        for (int k = 0; k < size; k++)
                        {
                            realObject = Instantiate(gmobj);
                            if (i == 0 && j == 0 && k == 0)
                            {
                                Collider realObjCollider = realObject.GetComponent <Collider>();
                                boundsSize = new Vector3(realObjCollider.bounds.size.x, realObjCollider.bounds.size.y, realObjCollider.bounds.size.z);
                            }
                            realObject.transform.Translate(new Vector3(boundsSize.x * 2 * i, boundsSize.y * 2 * j, boundsSize.z * 2 * k));
                            //realObject.transform.Translate(new Vector3((2 * i), (2 * j), (2 * k)));
                            prefabList.Add(realObject);
                        }
                    }
                }
            }
        }
    }
コード例 #2
0
ファイル: RedactorExt.cs プロジェクト: stark355/NeolantTest
    public void Generate()
    {
        int size = -1;

        try
        {
            size = GetPrefabArraySize();
        }
        catch (System.Exception)
        {
            errEngine.SetError("Wrong value");
        }

        if (size < 1 || size > 15)
        {
        }
        else
        {
            try
            {
                pathToPrefab = "Prefabs\\" + prefabNameArr[index];
                SetNullPrefabArray();
                if (itemsContainer == null)
                {
                    CreateItemsContainer();
                }
                GameObject gmobj = Resources.Load(pathToPrefab) as GameObject;
                GameObject realObject;
                Vector3    boundsSize = new Vector3(0, 0, 0);
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        for (int k = 0; k < size; k++)
                        {
                            realObject = Instantiate(gmobj);
                            if (i == 0 && j == 0 && k == 0)
                            {
                                Collider realObjCollider = realObject.GetComponent <Collider>();
                                boundsSize = new Vector3(realObjCollider.bounds.size.x, realObjCollider.bounds.size.y, realObjCollider.bounds.size.z);
                            }
                            realObject.transform.Translate(new Vector3(boundsSize.x * 2 * i, boundsSize.y * 2 * j, boundsSize.z * 2 * k));
                            prefabList.Add(realObject);
                            realObject.gameObject.transform.SetParent(itemsContainer.transform);
                        }
                    }
                }
            }
            catch (System.Exception)
            {
                Debug.Log("Error");
            }
        }
    }
コード例 #3
0
ファイル: ObjectChanger.cs プロジェクト: stark355/NeolantTest
    Vector3 rotateVector;                       //вектор, на который необходимо повернуть объект, которому прикреплены направляющие

    void OnMouseDown()
    {
        //если зажат "пробел", то объект будет масштабироваться
        if (Input.GetKey(KeyCode.Space))
        {
            currentMode = CurrentMode.scale;
        }
        //если зажать "левый Ctrl", то объект будет вращаться
        else if (Input.GetKey(KeyCode.LeftControl))
        {
            currentMode = CurrentMode.rotate;
        }
        //если не зажато ничего, то объект будет перемещаться
        else
        {
            currentMode = CurrentMode.move;
        }
        try
        {
            attachedInstance = axisController.GetAttachedInstance();
            objLogic         = attachedInstance.GetComponent <ObjectLogic>();
        }
        catch (System.Exception e)
        {
            //errEngine.SetError(e.Message);
            errEngine.SetError("Error. There is no attached object");
        }

        Debug.Log(gameObject.name);
        //для каждой оси смещение относительно центра родительского элемента рассчитывается отдельно
        if (currentAxis == CurrentAxis.xAxis)
        {
            centerShift = new Vector3(thisCollider.bounds.size.x / 2, 0, 0);
        }
        else if (currentAxis == CurrentAxis.yAxis)
        {
            centerShift = new Vector3(0, thisCollider.bounds.size.y / 2, 0);
        }
        else if (currentAxis == CurrentAxis.zAxis)
        {
            centerShift = new Vector3(0, 0, thisCollider.bounds.size.z / 2);
        }

        savedPosition = gameObject.transform.position;
        screenPoint   = Camera.main.WorldToScreenPoint(transform.position);

        offset           = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
        curScreenPoint.x = Input.mousePosition.x;
        curScreenPoint.y = Input.mousePosition.y;
        curScreenPoint.z = screenPoint.z;
        prevPosition     = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
        rotateVector     = attachedInstance.transform.eulerAngles;
    }
コード例 #4
0
 public void Add()
 {
     if (childList.Count == 10)
     {
         errEngine.SetError("Error.Max limit.");
     }
     else
     {
         parentItem.SetActive(true);
         childList.Add(Instantiate(parentItem, parentItem.transform.position + new Vector3(3 * (childList.Count + 1), 0, 0), parentItem.transform.rotation));
         parentItem.SetActive(false);
     }
 }
コード例 #5
0
    public void ScaleObject(Vector3 v3)
    {
        //абсолютные значения
        //transform.localScale += v3;

        //классический Scaling, отсносительно текущего размера
        if ((v3.x > 0.1f || v3.x < -0.1f) && (v3.y > 0.1f || v3.y < -0.1f) && (v3.z > 0.1f || v3.z < -0.1f))
        {
            transform.localScale = Vector3.Scale(transform.localScale, v3);
            axisController.Redraw();
        }
        else
        {
            errEngine.SetError("Please do not scale object less than Abs(0.1)");
        }
    }
コード例 #6
0
    public void AddObject()
    {
        if (childList.Count == 10)
        {
            errEngine.SetError("Error.Max limit.");
        }
        else
        {
            //создание нового объекта префаба
            parentItem.SetActive(true);
            //сдвиг с учетом размера префаба
            //GameObject currentChild = Instantiate(parentItem, parentItem.transform.position + new Vector3(2 * parentItemCollider.bounds.size.x * objectId, 0, 0), parentItem.transform.rotation);
            GameObject currentChild;
            if (objectId == 0)
            {
                currentChild = Instantiate(parentItem);
                Collider tempCollider = currentChild.GetComponent <Collider>();
                colliderValues.x = tempCollider.bounds.size.x;
                colliderValues.y = tempCollider.bounds.size.y;
                colliderValues.z = tempCollider.bounds.size.z;
            }
            else
            {
                currentChild = Instantiate(parentItem, parentItem.transform.position + new Vector3(2 * colliderValues.x * objectId, 0, 0), parentItem.transform.rotation);
            }

            //сдвиг без учета размера префаба - если размер префаба больше задаваемого смещения - объекты "слипнутся"
            //GameObject currentChild = Instantiate(parentItem, parentItem.transform.position + new Vector3(3 * (objectId), 0, 0), parentItem.transform.rotation);
            childList.Add(currentChild);
            objLogic = currentChild.GetComponent <ObjectLogic>();
            objLogic.SetID(objectId);
            Debug.Log("Created " + objectId);

            objectId++;
            parentItem.SetActive(false);
        }
    }