public void load(string fname,GameObject[] modelList)
    {
        sensor = new MySensor[bName.Length];
        for (int i=0; i<bName.Length; i++) {
            sensor[i]=new MySensor(bName[i]);
        }

        FileStream f = new FileStream(fname, FileMode.Open, FileAccess.Read);
        StreamReader reader = new StreamReader(f);
        if (reader != null) {
            int lineNum=0;

            while (!reader.EndOfStream) {
                string str = reader.ReadLine();
                string[] line = str.Split();
                if(lineNum==0){
                    modelName=line[0];
                    for(int i=0;i<modelList.Length;i++){

                        if(modelList[i].name==modelName){
                            body = (GameObject)Instantiate(modelList[i]);
                            body.SetActive(true);

                            break;
                        }
                    }
                }
                else{
                    if(line.Length<7){
                        print (fname+" "+lineNum+"  "+str);
                    }
                    else{
                        float time = float.Parse(line[1]);
                        float tx =  float.Parse(line[2]);
                        float ty =  float.Parse(line[3]);
                        float tz =  float.Parse(line[4]);
                        Vector3 p = new Vector3(tx,ty,tz);

                        float rx =  float.Parse(line[5]);
                        float ry =  float.Parse(line[6]);
                        float rz =  float.Parse(line[7]);
                        Vector3 r = new Vector3(rx,ry,rz);

                        int id = getBodyPartID(line[0]);
                        sensor[id].addData(time,p,r);
                    }
                }
                lineNum++;

            }
            maxFrame = sensor[0].getMaxFrame();
            for(int i=1;i<sensor.Length;i++){
                if(maxFrame<sensor[i].getMaxFrame()){
                    maxFrame = sensor[i].getMaxFrame();
                }
            }

            reader.Close();
        }
    }
示例#2
0
 public void OnEnter(MySensor sensor, MyRigidBody rbo, MyRBElement rbElement)
 {
     if (m_isOn && rbo.m_UserData != null)
     {
         MyEntity entity = (rbo.m_UserData as MyPhysicsBody).Entity;
         if (entity != null && (Parent == null || Parent != entity))
         {
             int  meetCriterias      = 0;
             bool canRegisteForClose = false;
             if (IsEntityMeetCritarias(entity, ref meetCriterias))
             {
                 AddDetectedEntity(entity, meetCriterias);
                 canRegisteForClose = true;
             }
             else
             {
                 if (m_containsCriteriumToReCheck)
                 {
                     if (CanBeEntityObserved(entity))
                     {
                         m_observableEntities.Add(entity);
                         canRegisteForClose = true;
                     }
                 }
             }
             if (canRegisteForClose)
             {
                 RegisterOnCloseHandlers(entity);
             }
         }
     }
 }
示例#3
0
        public MyEntityDetector(bool isSlowDetector = false)
            : base()
        {
            m_detectedEntities   = new Dictionary <MyEntity, int>();
            m_observableEntities = new List <MyEntity>();
            m_sensor             = new MySensor();
            m_detectionCriterias = new List <IMyEntityDetectorCriterium>();

            m_onEntityMarkForClose   = new Action <MyEntity>(OnMarkForCloseHandler);
            m_onEntityClose          = new Action <MyEntity>(OnCloseHandler);
            m_onEntityPositionChange = new EventHandler(OnDetectedEntityPositionChange);
            m_isSlowDetector         = isSlowDetector;
            //InitCriterias(detectionCriterias);
        }
示例#4
0
        /// <summary>
        /// Called when rigid body enters sensor.
        /// </summary>
        /// <param name="rbo">Rigid body that entered.</param>
        public void OnEnter(MySensor sensor, MyRigidBody rbo, MyRBElement rbElement)
        {
            //smallship
            var userData    = rbo.m_UserData;
            var physicsBody = userData as MyPhysicsBody;

            if (physicsBody != null && physicsBody.Entity is MySmallShip)
            {
                m_counter++;
                if (m_counter > 0)
                {
                    m_owner.OrderToOpen();
                }
            }
        }
示例#5
0
        public void OnLeave(MySensor sensor, MyRigidBody rbo, MyRBElement rbElement)
        {
            if (rbo == null)
            {
                return;
            }

            if (m_isOn && rbo.m_UserData != null)
            {
                MyEntity entity = (rbo.m_UserData as MyPhysicsBody).Entity;
                if (entity != null && (Parent == null || Parent != entity))
                {
                    RemoveEntityFromDetectedAndObservable(entity);
                }
            }
        }
示例#6
0
 public override void Close()
 {
     Debug.Assert(!m_isClosed);
     m_sensor.MarkForClose();
     SetOff(false);
     //ClearDetectedEntities(false);
     //RemoveSensor();
     //m_isOn = false;
     m_detectionCriterias.Clear();
     m_sensor               = null;
     OnEntityEnter          = null;
     OnEntityLeave          = null;
     OnEntityPositionChange = null;
     base.Close();
     m_isClosed = true;
 }
示例#7
0
        /// <summary>
        /// Called when rigid body leaves sensor.
        /// </summary>
        /// <param name="rbo">Rigid body that left.</param>
        public void OnLeave(MySensor sensor, MyRigidBody rbo, MyRBElement rbElement)
        {
            ////TODO: Temporary solution - there must not be rbo==null, fix the error and change to assert
            //if (rbo == null)
            //    return;
            Debug.Assert(rbo != null);
            //smallship
            var userData    = rbo.m_UserData;
            var physicsBody = userData as MyPhysicsBody;

            if (physicsBody != null && physicsBody.Entity is MySmallShip)
            {
                m_counter--;
                if (m_counter <= 0)
                {
                    m_owner.OrderToClose();
                }
            }
        }
        public override void Close()
        {
            MyGuiScreenGamePlay.OnGameLoaded -= m_onGameLoaded;
            if (m_sensor != null)
            {
                //m_sensor.GetElement().ProxyData = MyElement.PROXY_UNASSIGNED;
                m_sensor.MarkForClose();
                MyPhysics.physicsSystem.GetSensorModule().RemoveSensor(m_sensor);
                m_sensor = null;
            }

            foreach (var part in Parts)
            {
                if (part != null && part.EntityId.HasValue)
                {
                    MyEntities.Remove(part);
                }
            }

            base.Close();
        }
        protected override void InitPrefab(string displayName, Vector3 relativePosition, Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig)
        {
            MyPrefabConfigurationKinematic     prefabKinematicConfig = (MyPrefabConfigurationKinematic)prefabConfig;
            MyMwcObjectBuilder_PrefabKinematic kinematicBuilder      = objectBuilder as MyMwcObjectBuilder_PrefabKinematic;

            MyModel model = MyModels.GetModelOnlyDummies(m_config.ModelLod0Enum);

            for (int i = 0; i < prefabKinematicConfig.KinematicParts.Count; i++)
            {
                MyPrefabConfigurationKinematicPart kinematicPart = prefabKinematicConfig.KinematicParts[i];
                MyModelDummy open, close;
                if (model.Dummies.TryGetValue(kinematicPart.m_open, out open) && model.Dummies.TryGetValue(kinematicPart.m_close, out close))
                {
                    float?kinematicPartHealth    = kinematicBuilder.KinematicPartsHealth[i];
                    float?kinematicPartMaxHealth = kinematicBuilder.KinematicPartsMaxHealth[i];
                    uint? kinematicPartEntityId  = kinematicBuilder.KinematicPartsEntityId[i];

                    // if health is not set or not destroyed, then create part
                    if (kinematicPartHealth == null || kinematicPartHealth != 0)
                    {
                        MyPrefabKinematicPart newPart = new MyPrefabKinematicPart(m_owner);
                        if (kinematicPartEntityId.HasValue)
                        {
                            newPart.EntityId = new MyEntityIdentifier(kinematicPartEntityId.Value);
                        }
                        Parts[i] = newPart;
                        newPart.Init(this, kinematicPart, prefabKinematicConfig.m_openTime, prefabKinematicConfig.m_closeTime, (MyModelsEnum)kinematicPart.m_modelMovingEnum, open.Matrix, close.Matrix, prefabKinematicConfig.MaterialType, prefabKinematicConfig.m_soundLooping, prefabKinematicConfig.m_soundOpening, prefabKinematicConfig.m_soundClosing /*, m_groupMask*/, kinematicPartHealth, kinematicPartMaxHealth, Activated);
                    }
                }
            }

            //make handler
            m_sensorHandler = new MyPrefabKinematicSensor(this);
            MySphereSensorElement sensorEl = new MySphereSensorElement();

            sensorEl.Radius                = DETECT_RADIUS;
            sensorEl.LocalPosition         = new Vector3(0, 0, 0);
            sensorEl.DetectRigidBodyTypes  = MyConstants.RIGIDBODY_TYPE_SHIP;
            sensorEl.SpecialDetectingAngle = DETECTION_ANGLE;
            MySensorDesc senDesc = new MySensorDesc();

            senDesc.m_Element            = sensorEl;
            senDesc.m_Matrix             = WorldMatrix;
            senDesc.m_SensorEventHandler = m_sensorHandler;
            m_sensor = new MySensor();
            m_sensor.LoadFromDesc(senDesc);
            MyPhysics.physicsSystem.GetSensorModule().AddSensor(m_sensor);

            GetOwner().UpdateAABB();

            UseProperties = new MyUseProperties(MyUseType.FromHUB | MyUseType.Solo, MyUseType.FromHUB);
            if (kinematicBuilder.UseProperties == null)
            {
                UseProperties.Init(MyUseType.FromHUB, MyUseType.FromHUB, 3, 4000, false);
            }
            else
            {
                UseProperties.Init(kinematicBuilder.UseProperties);
            }
            UpdateHudAndCloseStatus();
        }
示例#10
0
    public void load(string fname, GameObject[] modelList)
    {
        sensor = new MySensor[bName.Length];
        for (int i = 0; i < bName.Length; i++)
        {
            sensor[i] = new MySensor(bName[i]);
        }

        FileStream   f      = new FileStream(fname, FileMode.Open, FileAccess.Read);
        StreamReader reader = new StreamReader(f);

        if (reader != null)
        {
            int lineNum = 0;

            while (!reader.EndOfStream)
            {
                string   str  = reader.ReadLine();
                string[] line = str.Split();
                if (lineNum == 0)
                {
                    modelName = line[0];
                    for (int i = 0; i < modelList.Length; i++)
                    {
                        if (modelList[i].name == modelName)
                        {
                            body = (GameObject)Instantiate(modelList[i]);
                            body.SetActive(true);

                            break;
                        }
                    }
                }
                else
                {
                    if (line.Length < 7)
                    {
                        print(fname + " " + lineNum + "  " + str);
                    }
                    else
                    {
                        float   tx = float.Parse(line[1]);
                        float   ty = float.Parse(line[2]);
                        float   tz = float.Parse(line[3]);
                        Vector3 p  = new Vector3(tx, ty, tz);

                        float   rx = float.Parse(line[4]);
                        float   ry = float.Parse(line[5]);
                        float   rz = float.Parse(line[6]);
                        Vector3 r  = new Vector3(rx, ry, rz);

                        int id = getBodyPartID(line[0]);
                        sensor[id].addData(p, r);
                    }
                }
                lineNum++;
            }

            maxFrame = sensor[0].getMaxTime();
            for (int i = 1; i < sensor.Length; i++)
            {
                if (maxFrame < sensor[i].getMaxTime())
                {
                    maxFrame = sensor[i].getMaxTime();
                }
            }

            //datas.Add (sensor);
            reader.Close();
        }
    }