예제 #1
0
    ///<summary>
    /// Add selected object to currentItems if not in it, else remove it.
    ///</summary>
    public async Task UpdateCurrentItems(GameObject _obj)
    {
        previousItems = currentItems.GetRange(0, currentItems.Count);
        if (currentItems[0].GetComponent <OgreeObject>().category != _obj.GetComponent <OgreeObject>().category ||
            currentItems[0].transform.parent != _obj.transform.parent)
        {
            AppendLogLine("Multiple selection should be same type of objects and belong to the same parent.", true, eLogtype.warning);
            return;
        }
        if (currentItems.Contains(_obj))
        {
            AppendLogLine($"Remove {_obj.name} from selection.", true, eLogtype.success);
            currentItems.Remove(_obj);
            if (currentItems.Count == 0)
            {
                OObject oObject = _obj.GetComponent <OObject>();
                if (oObject != null)
                {
                    await oObject.LoadChildren("0");
                }
            }
            else
            {
                bool    unloadChildren    = true;
                OObject currentDeselected = _obj.GetComponent <OObject>();

                //Checking all of the previously selected objects
                foreach (GameObject previousObj in currentItems)
                {
                    OObject previousSelected = previousObj.GetComponent <OObject>();

                    //Are the previous and current selection both a rack or smaller and part of the same rack ?
                    if (previousSelected != null && currentDeselected != null && previousSelected.referent != null && previousSelected.referent == currentDeselected.referent)
                    {
                        unloadChildren = false;
                    }
                }
                //if no to the previous question and previousSelected is a rack or smaller, unload its children
                if (unloadChildren)
                {
                    await currentDeselected.LoadChildren("0");
                }
            }
        }
        else
        {
            await _obj.GetComponent <OgreeObject>().LoadChildren("1");

            AppendLogLine($"Select {_obj.name}.", true, eLogtype.success);
            currentItems.Add(_obj);
        }
        EventManager.Instance.Raise(new OnSelectItemEvent());
    }
예제 #2
0
    ///<summary>
    /// Save current object and change the CLI idle text.
    ///</summary>
    ///<param name="_obj">The object to save. If null, set default text</param>
    public async Task SetCurrentItem(GameObject _obj)
    {
        try
        {
            previousItems = currentItems.GetRange(0, currentItems.Count);

            //////////////////////////////////////////////////////////
            //Should the previous selection's children be unloaded ?//
            //////////////////////////////////////////////////////////

            //if we are selecting, we don't want to unload children in the same rack as the selected object
            if (_obj != null)
            {
                OObject currentSelected = _obj.GetComponent <OObject>();
                //Checking all of the previously selected objects
                foreach (GameObject previousObj in currentItems)
                {
                    bool    unloadChildren   = true;
                    OObject previousSelected = previousObj.GetComponent <OObject>();

                    //Are the previous and current selection both a rack or smaller and part of the same rack ?
                    if (previousSelected != null && currentSelected != null && previousSelected.referent != null && previousSelected.referent == currentSelected.referent)
                    {
                        unloadChildren = false;
                    }

                    //if no to the previous question and previousSelected is a rack or smaller, unload its children
                    if (unloadChildren && previousSelected != null)
                    {
                        if (previousSelected.referent)
                        {
                            await previousSelected.referent.LoadChildren("0");
                        }
                        if (previousSelected.category != "rack")
                        {
                            previousItems.Remove(previousObj);
                            if (previousSelected.referent && !previousItems.Contains(previousSelected.referent.gameObject))
                            {
                                previousItems.Add(previousSelected.referent.gameObject);
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (GameObject previousObj in currentItems)
                {
                    OObject oObject = previousObj.GetComponent <OObject>();
                    if (oObject != null)
                    {
                        await oObject.LoadChildren("0");
                    }
                }
            }
            //Clear current selection
            currentItems.Clear();

            if (_obj)
            {
                await _obj.GetComponent <OgreeObject>().LoadChildren("1");

                AppendLogLine($"Select {_obj.name}.", true, eLogtype.success);
                currentItems.Add(_obj);
            }
            else
            {
                AppendLogLine("Empty selection.", true, eLogtype.success);
            }
            EventManager.Instance.Raise(new OnSelectItemEvent());
        }
        catch (System.Exception _e)
        {
            Debug.LogError(_e);
        }
    }