/*public Dictionary<GameObject, worldProp> worldProps {
         *      get { return _worldProps; }
         * }*/

        #endregion

        #region PublicMethods

        public void init()
        {
            _levelPropDefs = new List <propDef> ();

            PropsList propList = Resources.Load <PropsList> ("Data/" + Globals.propListName);
            int       i, len = propList.props.Count;

            for (i = 0; i < len; ++i)
            {
                PropDefinition propDef = propList.props [i];
                if (propDef.prefab != null)
                {
                    propDef p = new propDef();
                    p.id          = propDef.id;
                    p.name        = propDef.propName;
                    p.prefab      = propDef.prefab;
                    p.useCollider = propDef.isUsingCollider;
                    p.useGravity  = propDef.isUsingGravity;

                    _levelPropDefs.Add(p);
                }
            }

            _iSelectedItem = 0;

            //_worldProps = new Dictionary<GameObject, worldProp> ();
        }
示例#2
0
        public propDef getPropDefForGameObject(GameObject go)
        {
            propDef p = new propDef();

            p.id = -1;

            if (_worldProps.ContainsKey(go))
            {
                p = PropsManager.Instance.getPropDefForId(_worldProps [go].id);
            }

            return(p);
        }
        public void placeIt(Vector3 v3Pos)
        {
            string sName = _goCurProp.name + "_" + _levelEditor.curVoxelsLevelChunk.trfmProps.childCount;

            propDef prop = PropsManager.Instance.getSelectedPropDef();

            GameObject goNew = PropsManager.Instance.createProp(prop, v3Pos, sName, _levelEditor.curVoxelsLevelChunk.trfmProps, prop.useCollider, prop.useGravity);

            goNew.transform.forward = _goCurProp.transform.forward;

            _levelEditor.curVoxelsLevelChunk.addWorldProp(prop.id, goNew);

            _levelEditor.resetUndoActions();
            _levelEditor.addUndoAction(AppState.Props, goNew);
        }
        //
        public propDef getPropDefForId(int id)
        {
            propDef p = new propDef();

            p.id = -1;

            int i, len = _levelPropDefs.Count;

            for (i = 0; i < len; ++i)
            {
                if (_levelPropDefs [i].id == id)
                {
                    p = _levelPropDefs [i];
                    break;
                }
            }

            return(p);
        }
        //

        /*public propDef getPropDefForGameObject(GameObject go)
         * {
         *      propDef p = new propDef();
         *      p.id = -1;
         *
         *      if (_worldProps.ContainsKey (go)) {
         *              p = getPropDefForId(_worldProps [go].id);
         *      }
         *
         *      return p;
         * }*/

        //
        public GameObject createProp(propDef prop, Vector3 v3Pos, string name, Transform parent, bool useCollider = true, bool useGravity = true)
        {
            GameObject goNew = GameObject.Instantiate(prop.prefab);

            goNew.transform.SetParent(parent);
            goNew.transform.localPosition = v3Pos;
            goNew.name = name;

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

            if (collider != null)
            {
                collider.enabled = useCollider;
            }

            Rigidbody rigidBody = goNew.GetComponent <Rigidbody> ();

            if (rigidBody != null)
            {
                rigidBody.useGravity = useGravity;
            }

            return(goNew);
        }
        //
        public void newPropSelected()
        {
            if (AppController.Instance.appState == AppState.Null)
            {
                return;
            }

            if (propAim != null)
            {
                if (_goCurProp != null)
                {
                    Destroy(_goCurProp);
                    _goCurProp = null;
                }
                propDef prop = PropsManager.Instance.getSelectedPropDef();
                _goCurProp = PropsManager.Instance.createProp(prop, Vector3.zero, prop.name, propAim.transform, false, false);
                _goCurProp.transform.localPosition = Vector3.zero;
            }

            if (_curEditorTool != null)
            {
                _curEditorTool.resetProp();
            }
        }