public void OnEnable()
    {
        targetScript = target as TrajectoryPreview;

        from = serializedObject.FindProperty("from");
        to   = serializedObject.FindProperty("to");
        go   = serializedObject.FindProperty("go");

        data        = serializedObject.FindProperty("data");
        config      = new TrajectoryCfg();
        config.Data = data.stringValue;
        TrajectoryCfgLoader.InitRuntimeData(config);
    }
예제 #2
0
    public bool SetTempConfig(int id, TrajectoryCfg config)
    {
        if (m_data.ContainsKey(id))
        {
            Debug.LogErrorFormat("Can not add trajectory config because of duplicated key {0}", id);
            return(false);
        }

        InitRuntimeData(config);
        m_tempData[id] = config;

        return(true);
    }
예제 #3
0
    private static TrajectoryObject FetchTrajectoryObject(int id)
    {
        TrajectoryCfg config = trajectoryConfigLoader.GetConfig(id);

        if (config == null)
        {
            Debug.LogErrorFormat("Failed to find config of trajectory {0}", id);
            return(null);
        }

        TrajectoryObject trajectoryObj = FetchFromPool();

        if (trajectoryObj == null)
        {
            trajectoryObj = CreateTrajectoryObject();
        }

        trajectoryObj.SetConfig(config);

        return(trajectoryObj);
    }
예제 #4
0
    public static void InitRuntimeData(TrajectoryCfg row)
    {
        row.trajectoryType       = TrajectoryTypes.Invalid;
        row.trajectoryParameters = null;

        if (!string.IsNullOrEmpty(row.Data))
        {
            int i = row.Data.IndexOf("=");
            if (i == -1)
            {
                return;
            }

            string typeStr  = row.Data.Substring(0, i);
            string paramStr = row.Data.Substring(i + 1);

            int typeInt;
            if (!int.TryParse(typeStr, out typeInt))
            {
                return;
            }

            row.trajectoryType = (TrajectoryTypes)typeInt;
            switch (row.trajectoryType)
            {
            case TrajectoryTypes.Line:
                var lineParams = JsonUtility.FromJson <TrajectoryLineParams>(paramStr);
                row.trajectoryParameters = lineParams;
                if (lineParams.Speed <= 0)
                {
                    lineParams.Speed = 1;
                    Debug.LogErrorFormat("Invalid trajectory speed {0} of {1}", lineParams.Speed, row.ID);
                }
                break;

            case TrajectoryTypes.Parabola:
                var parabolaParams = JsonUtility.FromJson <TrajectoryParabolaParams>(paramStr);
                row.trajectoryParameters = parabolaParams;
                if (parabolaParams.Speed <= 0)
                {
                    parabolaParams.Speed = 1;
                    Debug.LogErrorFormat("Invalid trajectory speed {0} of {1}", parabolaParams.Speed, row.ID);
                }
                if (parabolaParams.VAcceleration >= 0)
                {
                    parabolaParams.VAcceleration = -9.8f;
                    Debug.LogErrorFormat("Invalid trajectory acceleration {0} of {1}", parabolaParams.VAcceleration, row.ID);
                }
                break;

            case TrajectoryTypes.Bezier:
                var bezierParams = JsonUtility.FromJson <TrajectoryBezierParams>(paramStr);
                row.trajectoryParameters = bezierParams;
                if (bezierParams.Speed <= 0)
                {
                    bezierParams.Speed = 1;
                    Debug.LogErrorFormat("Invalid trajectory speed {0} of {1}", bezierParams.Speed, row.ID);
                }
                break;

            //case TrajectoryTypes.CatmullRom:
            //    var catmullRomParams = JsonUtility.FromJson<TrajectoryCatmullRomParams>(paramStr);
            //    row.trajectoryParameters = catmullRomParams;
            //    if (catmullRomParams.Speed <= 0)
            //    {
            //        catmullRomParams.Speed = 1;
            //        Debug.LogErrorFormat("Invalid trajectory speed {0} of {1}", catmullRomParams.Speed, row.ID);
            //    }
            //    break;
            default:
                row.trajectoryType       = TrajectoryTypes.Invalid;
                row.trajectoryParameters = null;
                break;
            }
        }
    }
예제 #5
0
 private void OnReadRow(TrajectoryCfg row)
 {
     InitRuntimeData(row);
     m_data[row.ID] = row;
 }
예제 #6
0
 public void SetConfig(TrajectoryCfg config)
 {
     this.config = config;
 }